From 3352727aa638fcfcc6461d2aaded8ef9603acc0d Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Tue, 4 Oct 2022 00:04:19 +0800 Subject: feat: Initial setup facilitating testing --- apps/kit/playwright.config.ts | 4 ++-- apps/kit/src/actions/pwKey.ts | 10 ++++++++++ apps/kit/src/lib/components/alert.svelte | 7 +++++-- apps/kit/src/lib/components/button.svelte | 10 ++++++++-- apps/kit/src/lib/components/checkbox.svelte | 3 +++ apps/kit/src/lib/components/input.svelte | 3 +++ apps/kit/src/lib/components/locale-switcher.svelte | 4 ++++ apps/kit/src/lib/components/switch.svelte | 8 ++++++++ apps/kit/src/lib/configuration.ts | 21 ++++++++++++++++++++- apps/kit/src/lib/helpers.ts | 4 ++++ apps/kit/svelte.config.js | 3 +++ apps/kit/tsconfig.json | 12 +++++++++++- 12 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 apps/kit/src/actions/pwKey.ts diff --git a/apps/kit/playwright.config.ts b/apps/kit/playwright.config.ts index 6ad3a7f..5926752 100644 --- a/apps/kit/playwright.config.ts +++ b/apps/kit/playwright.config.ts @@ -2,8 +2,8 @@ import type { PlaywrightTestConfig } from '@playwright/test'; const config: PlaywrightTestConfig = { webServer: { - command: 'npm run build && npm run preview', - port: 4173 + command: 'pnpm run dev', + port: 5173 } }; diff --git a/apps/kit/src/actions/pwKey.ts b/apps/kit/src/actions/pwKey.ts new file mode 100644 index 0000000..a2f22e7 --- /dev/null +++ b/apps/kit/src/actions/pwKey.ts @@ -0,0 +1,10 @@ +import { is_development, is_testing } from "$lib/configuration"; + +export default function pwKey(node: HTMLElement, value: string | undefined) { + if (!value) return; + if (!is_testing()) { + if (is_development()) console.warn("VITE_TESTING is false, so not setting pw-key attributes"); + return; + } + node.setAttribute("pw-key", value); +} \ No newline at end of file diff --git a/apps/kit/src/lib/components/alert.svelte b/apps/kit/src/lib/components/alert.svelte index 31e7357..fd57105 100644 --- a/apps/kit/src/lib/components/alert.svelte +++ b/apps/kit/src/lib/components/alert.svelte @@ -2,6 +2,7 @@ import { random_string } from "$lib/helpers"; import { createEventDispatcher } from "svelte"; import { onMount } from "svelte"; + import pwKey from "$actions/pwKey"; import { Temporal } from "temporal-polyfill"; import { ExclamationTriangleIcon, CheckCircleIcon, InformationCircleIcon, XCircleIcon, XMarkIcon } from "./icons"; @@ -61,10 +62,12 @@ $: cooldownEnabled = id.indexOf(noCooldownSetting) === -1 && closeable && (closeableCooldown === "~" || parseInt(closeableCooldown) > 0); /** - * Sets this alerts visibility state, when this is false it is removed from the dom using svelte a {#if} block. + * Sets this alerts visibility state, when this is false it is removed from the dom using an {#if} block. */ export let visible = closeableCooldown === "~" || parseInt(closeableCooldown) > 0 ? false : true; + export let _pwKey: string | undefined = undefined; + const cooldownStorageKey = "lastseen--" + id; $: switch (type) { @@ -160,7 +163,7 @@ {#if visible} -
+
diff --git a/apps/kit/src/lib/components/button.svelte b/apps/kit/src/lib/components/button.svelte index d345b37..cbc09e2 100644 --- a/apps/kit/src/lib/components/button.svelte +++ b/apps/kit/src/lib/components/button.svelte @@ -4,6 +4,8 @@
+ import pwKey from "$actions/pwKey"; import { random_string } from "$lib/helpers"; import { ExclamationCircleIcon } from "./icons"; @@ -18,6 +19,7 @@ export let addon: string | undefined = undefined; export let value: string | undefined; export let wrapperClass: string | undefined = undefined; + export let _pwKey: string | undefined = undefined; $: ariaErrorDescribedBy = id + "__" + "error"; $: attributes = { @@ -70,6 +72,7 @@ {/if} + import pwKey from "$actions/pwKey"; import { browser } from "$app/environment"; import { page } from "$app/stores"; import { CookieNames } from "$lib/configuration"; @@ -8,6 +9,8 @@ import { loadLocaleAsync } from "$lib/i18n/i18n-util.async"; import Cookies from "js-cookie"; + export let _pwKey: string | undefined = undefined; + async function switch_locale(newLocale: Locales) { if (!newLocale || $locale === newLocale) return; await loadLocaleAsync(newLocale); @@ -42,6 +45,7 @@