@eldrajs/theme-cli 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/dist/{validate-C6jB8_Oc.js → validate-DprFpjV7.js} +29 -4
- package/package.json +3 -3
- package/template/.eldra/block-types.d.ts +12 -3
- package/template/.eldra/manifest.json +317 -26
- package/template/.eldra/previews.json +35 -34
- package/template/.github/workflows/eldra-deploy.yml +2 -0
- package/template/.gitlab-ci.yml +2 -0
- package/template/.storybook/main.ts +3 -0
- package/template/.storybook/preview.ts +2 -1
- package/template/.storybook/virtual-eldra.d.ts +5 -0
- package/template/README.md +31 -14
- package/template/app/components/FormHoneypot.vue +21 -0
- package/template/app/composables/useFormSpam.ts +55 -0
- package/template/app/composables/usePageStructuredData.ts +112 -0
- package/template/app/composables/useTurnstile.ts +111 -0
- package/template/app/formSeeds.ts +93 -0
- package/template/app/pages/[...slug].vue +48 -12
- package/template/app/plugins/eldra-storefront.ts +19 -2
- package/template/app/plugins/eldra-ui-messages.ts +1 -1
- package/template/app/seededPages.ts +7 -0
- package/template/app/storefront/analytics.ts +202 -0
- package/template/app/storefront/cart.ts +7 -0
- package/template/app/storefront/demo.ts +48 -2
- package/template/app/storefront/forms.ts +133 -0
- package/template/app/storefront/gateway.ts +113 -7
- package/template/app/storefront/money.ts +18 -17
- package/template/app/storefront/structuredData.ts +161 -0
- package/template/app/storefront/types.ts +101 -2
- package/template/app/utils/seoInput.ts +172 -0
- package/template/bitbucket-pipelines.yml +3 -1
- package/template/blocks/breadcrumbs/Block.vue +1 -0
- package/template/blocks/cart/Block.vue +1 -0
- package/template/blocks/cart/parts/Summary.vue +1 -0
- package/template/blocks/contact/Block.vue +50 -21
- package/template/blocks/contact/__tests__/Block.spec.ts +89 -8
- package/template/blocks/contact/block.json +2 -9
- package/template/blocks/contact/mock.json +1 -2
- package/template/blocks/footer/Block.vue +58 -8
- package/template/blocks/footer/__tests__/Block.spec.ts +70 -16
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/form/Block.vue +614 -0
- package/template/blocks/form/__tests__/Block.spec.ts +536 -0
- package/template/blocks/form/block.json +69 -0
- package/template/blocks/form/mock.json +25 -0
- package/template/blocks/form/preview.png +0 -0
- package/template/blocks/form/validate.ts +68 -0
- package/template/blocks/newsletter/Block.vue +57 -3
- package/template/blocks/newsletter/__tests__/Block.spec.ts +89 -31
- package/template/blocks/newsletter/block.json +4 -5
- package/template/blocks/newsletter/mock.json +1 -1
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/product-detail/__tests__/Block.spec.ts +7 -10
- package/template/i18n/en-US.json +33 -2
- package/template/i18n/is-IS.json +33 -2
- package/template/nuxt.config.ts +15 -1
- package/template/package.json +1 -0
- package/template/public/apple-touch-icon.png +0 -0
- package/template/public/favicon.ico +0 -0
- package/template/stories/generated/form.stories.ts +68 -0
- package/template/test/formValidate.spec.ts +46 -0
- package/template/test/inlineEditable.spec.ts +2 -1
- package/template/test/moneyFormatting.spec.ts +4 -8
- package/template/test/pages/ssr.spec.ts +5 -11
- package/template/test/prerenderFailure.spec.ts +1 -1
- package/template/test/prerenderRefresh.browser.spec.ts +5 -1
- package/template/test/richText.spec.ts +12 -9
- package/template/test/seededPages.spec.ts +13 -0
- package/template/test/seoInput.spec.ts +119 -0
- package/template/test/slugPage.spec.ts +62 -26
- package/template/test/slugPageTemplate.spec.ts +5 -1
- package/template/test/starter.spec.ts +42 -4
- package/template/test/storefront/analytics.spec.ts +283 -0
- package/template/test/storefront/forms.spec.ts +385 -0
- package/template/test/storefront/money.spec.ts +11 -12
- package/template/test/storefront/structuredData.spec.ts +138 -0
- package/template/test/structuredData.generate.spec.ts +159 -0
- package/template/test/support/mockGateway.ts +29 -1
- package/template/test/support/turnstileForms.ts +53 -0
- package/template/test/useBlockData.spec.ts +7 -4
- package/template/app/utils/pageTitle.ts +0 -37
- package/template/test/pageTitle.spec.ts +0 -49
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { StorefrontFormField } from '../../app/storefront/types';
|
|
2
|
+
|
|
3
|
+
/** The message catalogue lookup a block hands in: `useI18n()`'s `t`. */
|
|
4
|
+
type Translate = (key: string, params?: Record<string, unknown>) => string;
|
|
5
|
+
|
|
6
|
+
const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
7
|
+
|
|
8
|
+
/** A finite decimal number, written with a `.` or, as an Icelandic visitor types it, a `,`. */
|
|
9
|
+
function isNumber(text: string): boolean {
|
|
10
|
+
const normalized = text.replace(',', '.');
|
|
11
|
+
return (
|
|
12
|
+
/^[+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?$/.test(normalized) &&
|
|
13
|
+
Number.isFinite(Number(normalized))
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** An absolute http(s) URL: what a `url` field collects. */
|
|
18
|
+
function isHttpUrl(text: string): boolean {
|
|
19
|
+
try {
|
|
20
|
+
const url = new URL(text);
|
|
21
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The first reason `value` is not an acceptable answer to `field`, in the visitor's language, or
|
|
29
|
+
* `null`. The same rules the platform enforces (required, shape, length, pattern), checked first
|
|
30
|
+
* so an obvious mistake never costs a round trip; the platform still decides, and its own message
|
|
31
|
+
* replaces ours for anything it refuses.
|
|
32
|
+
*
|
|
33
|
+
* An empty optional field is always fine, whatever its shape rules say: shape and length rules
|
|
34
|
+
* describe an answer, and no answer was given.
|
|
35
|
+
*/
|
|
36
|
+
export function validateField(
|
|
37
|
+
field: StorefrontFormField,
|
|
38
|
+
value: string | boolean | undefined,
|
|
39
|
+
t: Translate
|
|
40
|
+
): string | null {
|
|
41
|
+
if (field.type === 'checkbox' || field.type === 'consent') {
|
|
42
|
+
return field.required && value !== true
|
|
43
|
+
? t('form.requiredCheckbox', { field: field.label })
|
|
44
|
+
: null;
|
|
45
|
+
}
|
|
46
|
+
const text = typeof value === 'string' ? value.trim() : '';
|
|
47
|
+
if (text === '') return field.required ? t('form.required', { field: field.label }) : null;
|
|
48
|
+
|
|
49
|
+
if (field.type === 'email' && !EMAIL_PATTERN.test(text)) return t('form.invalidEmail');
|
|
50
|
+
if (field.type === 'number' && !isNumber(text)) return t('form.invalidNumber');
|
|
51
|
+
if (field.type === 'url' && !isHttpUrl(text)) return t('form.invalidUrl');
|
|
52
|
+
if (field.type === 'select' && field.options && !field.options.some((o) => o.value === text)) {
|
|
53
|
+
return t('form.required', { field: field.label });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const length = Array.from(text).length;
|
|
57
|
+
const { minLength, maxLength, pattern } = field.validation ?? {};
|
|
58
|
+
if (minLength !== undefined && length < minLength) return t('form.tooShort', { min: minLength });
|
|
59
|
+
if (maxLength !== undefined && length > maxLength) return t('form.tooLong', { max: maxLength });
|
|
60
|
+
if (pattern !== undefined) {
|
|
61
|
+
try {
|
|
62
|
+
if (!new RegExp(`^(?:${pattern})$`).test(text)) return t('form.invalidFormat');
|
|
63
|
+
} catch {
|
|
64
|
+
// A pattern this browser cannot compile is the platform's to enforce, not a reason to block.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
@@ -36,7 +36,15 @@
|
|
|
36
36
|
* `text-field-note`/`text-danger`, the 0.3125rem icon gap) since that internal component is not
|
|
37
37
|
* exported from the package.
|
|
38
38
|
*
|
|
39
|
-
* The
|
|
39
|
+
* **The consent sentence.** Pressing Subscribe is the consent, and Core records the form's own
|
|
40
|
+
* `consentText` (page locale, `{shop}` filled in) with the subscriber. So the block reads it from the
|
|
41
|
+
* form definition and shows it as escaped plain text under the button, tied to the button with
|
|
42
|
+
* `aria-describedby`: what the visitor was shown is exactly what is recorded. The optional checkbox
|
|
43
|
+
* below is only an extra client-side gate; its label is not recorded.
|
|
44
|
+
*
|
|
45
|
+
* The newsletter posts through `useStorefront().forms.submit(formKey, { values: { email } })` — the
|
|
46
|
+
* platform's own form (`formKey`, `newsletter` by default; the seeded one subscribes the visitor with
|
|
47
|
+
* a double opt-in email) — see
|
|
40
48
|
* `blocks/footer/Block.vue`'s own newsletter zone for the identical local-validation-first,
|
|
41
49
|
* backend-`{ok:false}`-second pattern this reuses: empty/malformed email never reaches the
|
|
42
50
|
* storefront, and a backend `reason: 'invalid'` shows the exact same message a local check would.
|
|
@@ -65,10 +73,12 @@ import { EldraRichText } from '@eldrajs/theme-vue';
|
|
|
65
73
|
import { useBlockData } from '../../app/composables/useBlockData';
|
|
66
74
|
import { useEditing } from '../../app/composables/useEditing';
|
|
67
75
|
import { useRichTextScrollRegions } from '../../app/composables/useRichTextScrollRegions';
|
|
76
|
+
import { useFormSpam } from '../../app/composables/useFormSpam';
|
|
68
77
|
import { useStorefront } from '../../app/composables/useStorefront';
|
|
69
78
|
import { useI18n } from 'vue-i18n';
|
|
70
79
|
import { useUiId } from '../../app/composables/useUiId';
|
|
71
80
|
import EldraIcon from '../../app/components/EldraIcon.vue';
|
|
81
|
+
import FormHoneypot from '../../app/components/FormHoneypot.vue';
|
|
72
82
|
|
|
73
83
|
const props = defineProps<{ entry: EldraBlockEntry<'newsletter'> }>();
|
|
74
84
|
const { data, entryId } = useBlockData(props, 'newsletter');
|
|
@@ -76,8 +86,21 @@ const { t } = useI18n();
|
|
|
76
86
|
const isEditing = useEditing();
|
|
77
87
|
const storefront = useStorefront();
|
|
78
88
|
|
|
89
|
+
const formKey = computed(() => (data.value.formKey ?? '').trim() || 'newsletter');
|
|
90
|
+
const {
|
|
91
|
+
honeypot,
|
|
92
|
+
honeypotField,
|
|
93
|
+
siteKey,
|
|
94
|
+
consentSentence,
|
|
95
|
+
turnstileRoot,
|
|
96
|
+
challenge,
|
|
97
|
+
signals,
|
|
98
|
+
reset,
|
|
99
|
+
} = useFormSpam(formKey);
|
|
100
|
+
|
|
79
101
|
const headingId = `newsletter-heading-${useUiId()}`;
|
|
80
102
|
const consentErrorId = `newsletter-consent-error-${useUiId()}`;
|
|
103
|
+
const consentSentenceId = `newsletter-consent-sentence-${useUiId()}`;
|
|
81
104
|
|
|
82
105
|
type Variant = 'centered' | 'split';
|
|
83
106
|
const variant = computed<Variant>(() => data.value.variant ?? 'centered');
|
|
@@ -243,11 +266,25 @@ async function onSubmit(payload: FormLayoutSubmitPayload): Promise<void> {
|
|
|
243
266
|
return;
|
|
244
267
|
}
|
|
245
268
|
|
|
269
|
+
// Turnstile is on and not passed: nothing about the address is wrong, so a retry is welcome.
|
|
270
|
+
const blocked = challenge();
|
|
271
|
+
if (blocked !== null) {
|
|
272
|
+
retryable.value = true;
|
|
273
|
+
emailError.value = blocked;
|
|
274
|
+
await focusEmailField();
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
246
278
|
emailError.value = null;
|
|
247
279
|
consentError.value = null;
|
|
248
280
|
isSubmitting.value = true;
|
|
249
|
-
const result = await storefront.forms.
|
|
281
|
+
const result = await storefront.forms.submit(formKey.value, {
|
|
282
|
+
values: { email: value },
|
|
283
|
+
...signals(),
|
|
284
|
+
});
|
|
250
285
|
isSubmitting.value = false;
|
|
286
|
+
// A Turnstile token is single-use, whatever the outcome.
|
|
287
|
+
reset();
|
|
251
288
|
|
|
252
289
|
if (result.ok) {
|
|
253
290
|
succeeded.value = true;
|
|
@@ -257,7 +294,10 @@ async function onSubmit(payload: FormLayoutSubmitPayload): Promise<void> {
|
|
|
257
294
|
|
|
258
295
|
const serviceFailed = result.reason !== 'invalid';
|
|
259
296
|
retryable.value = serviceFailed;
|
|
260
|
-
|
|
297
|
+
// The platform's own message for the email, when it gave one; ours for a bare refusal.
|
|
298
|
+
emailError.value = serviceFailed
|
|
299
|
+
? t('newsletter.failed')
|
|
300
|
+
: (result.errors.email?.[0] ?? t('newsletter.invalidEmail'));
|
|
261
301
|
await focusEmailField();
|
|
262
302
|
}
|
|
263
303
|
</script>
|
|
@@ -314,6 +354,9 @@ async function onSubmit(payload: FormLayoutSubmitPayload): Promise<void> {
|
|
|
314
354
|
</FieldWrapper>
|
|
315
355
|
</div>
|
|
316
356
|
|
|
357
|
+
<FormHoneypot v-model="honeypot" :name="honeypotField" />
|
|
358
|
+
<div v-if="siteKey" ref="turnstileRoot" class="@two-col:col-span-2 order-2" />
|
|
359
|
+
|
|
317
360
|
<div
|
|
318
361
|
v-if="requireConsentCheckbox"
|
|
319
362
|
ref="checkboxFieldRoot"
|
|
@@ -350,10 +393,21 @@ async function onSubmit(payload: FormLayoutSubmitPayload): Promise<void> {
|
|
|
350
393
|
size="lg"
|
|
351
394
|
class="@two-col:w-auto w-full"
|
|
352
395
|
:label="t('newsletter.subscribing')"
|
|
396
|
+
:aria-describedby="consentSentence ? consentSentenceId : undefined"
|
|
353
397
|
>
|
|
354
398
|
{{ buttonLabelText }}
|
|
355
399
|
</Button>
|
|
356
400
|
|
|
401
|
+
<p
|
|
402
|
+
v-if="consentSentence"
|
|
403
|
+
:id="consentSentenceId"
|
|
404
|
+
data-part="consent-sentence"
|
|
405
|
+
class="text-body-sm @two-col:col-span-2 order-3"
|
|
406
|
+
:class="consentToneClass"
|
|
407
|
+
>
|
|
408
|
+
{{ consentSentence }}
|
|
409
|
+
</p>
|
|
410
|
+
|
|
357
411
|
<div ref="consentRoot" class="@two-col:col-span-2 order-3">
|
|
358
412
|
<!-- Under this block's own `h2`, so any heading in the consent copy starts at `h3`. -->
|
|
359
413
|
<EldraRichText
|
|
@@ -6,12 +6,20 @@ import Block from '../Block.vue';
|
|
|
6
6
|
import mock from '../mock.json';
|
|
7
7
|
import { mountOptions } from '../../../test/support/mountBlock';
|
|
8
8
|
import { STOREFRONT_KEY } from '../../../app/storefront/types';
|
|
9
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
StorefrontFormSubmitResult as StorefrontAck,
|
|
11
|
+
StorefrontForms,
|
|
12
|
+
} from '../../../app/storefront/types';
|
|
10
13
|
import { createDemoStorefront } from '../../../app/storefront/demo';
|
|
11
14
|
import enUS from '../../../i18n/en-US.json';
|
|
12
15
|
import { renderedMessage } from '../../../test/support/i18nText';
|
|
16
|
+
import {
|
|
17
|
+
cleanUpTurnstile,
|
|
18
|
+
storefrontWithTurnstile,
|
|
19
|
+
stubTurnstile,
|
|
20
|
+
} from '../../../test/support/turnstileForms';
|
|
13
21
|
|
|
14
|
-
/** Only the fields the block requires (`variant`, `heading`, `consent
|
|
22
|
+
/** Only the fields the block requires (`variant`, `heading`, `consent`) — the "genuinely
|
|
15
23
|
* minimal" fixture every rebuilt block spec covers alongside the full `mock.json` (see
|
|
16
24
|
* `blocks/faq/__tests__/Block.spec.ts`'s own `bare` comment). Exercises every fallback default
|
|
17
25
|
* (field label, placeholder, button label, success title) at once. */
|
|
@@ -19,7 +27,6 @@ const bare = {
|
|
|
19
27
|
variant: 'centered',
|
|
20
28
|
heading: 'Letters from the workshop',
|
|
21
29
|
consent: mock.consent,
|
|
22
|
-
list: 'letters-from-the-workshop',
|
|
23
30
|
};
|
|
24
31
|
|
|
25
32
|
/** A resolvable-on-demand `forms.subscribe`, for the "submitting"/"repeat submits ignored" tests
|
|
@@ -33,19 +40,20 @@ function deferredAck(): { promise: Promise<StorefrontAck>; resolve: (ack: Storef
|
|
|
33
40
|
return { promise, resolve };
|
|
34
41
|
}
|
|
35
42
|
|
|
36
|
-
function withForms(
|
|
43
|
+
function withForms(submit: StorefrontForms['submit']) {
|
|
37
44
|
const base = createDemoStorefront();
|
|
38
|
-
return { ...base, forms: { ...base.forms,
|
|
45
|
+
return { ...base, forms: { ...base.forms, submit } };
|
|
39
46
|
}
|
|
40
47
|
|
|
41
48
|
const trackedWrappers: VueWrapper[] = [];
|
|
42
49
|
afterEach(() => {
|
|
43
50
|
for (const wrapper of trackedWrappers.splice(0)) wrapper.unmount();
|
|
51
|
+
cleanUpTurnstile();
|
|
44
52
|
});
|
|
45
53
|
|
|
46
54
|
function mountNewsletter(
|
|
47
55
|
data: Record<string, unknown>,
|
|
48
|
-
options: {
|
|
56
|
+
options: { submit?: StorefrontForms['submit']; turnstile?: boolean } = {}
|
|
49
57
|
) {
|
|
50
58
|
const base = mountOptions({ entry: { id: 'e1', data } });
|
|
51
59
|
const wrapper = mount(Block, {
|
|
@@ -57,7 +65,13 @@ function mountNewsletter(
|
|
|
57
65
|
...base.global,
|
|
58
66
|
provide: {
|
|
59
67
|
...base.global.provide,
|
|
60
|
-
...(options.
|
|
68
|
+
...(options.submit
|
|
69
|
+
? {
|
|
70
|
+
[STOREFRONT_KEY]: options.turnstile
|
|
71
|
+
? storefrontWithTurnstile(options.submit)
|
|
72
|
+
: withForms(options.submit),
|
|
73
|
+
}
|
|
74
|
+
: {}),
|
|
61
75
|
},
|
|
62
76
|
},
|
|
63
77
|
});
|
|
@@ -75,6 +89,19 @@ async function submitValidEmail(
|
|
|
75
89
|
}
|
|
76
90
|
|
|
77
91
|
describe('newsletter block', () => {
|
|
92
|
+
it('shows the platform consent sentence under the button, tied to it with aria-describedby', async () => {
|
|
93
|
+
const wrapper = mountNewsletter(mock);
|
|
94
|
+
await flushPromises();
|
|
95
|
+
const sentence = wrapper.get('[data-part="consent-sentence"]');
|
|
96
|
+
expect(sentence.text()).toBe(
|
|
97
|
+
'I want to receive the newsletter from Northwind Goods. I can unsubscribe at any time.'
|
|
98
|
+
);
|
|
99
|
+
expect(wrapper.get('button[type="submit"]').attributes('aria-describedby')).toBe(
|
|
100
|
+
sentence.attributes('id')
|
|
101
|
+
);
|
|
102
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
103
|
+
});
|
|
104
|
+
|
|
78
105
|
describe('accessibility', () => {
|
|
79
106
|
it('renders the full mock.json content with no axe violations', async () => {
|
|
80
107
|
const wrapper = mountNewsletter(mock);
|
|
@@ -178,7 +205,7 @@ describe('newsletter block', () => {
|
|
|
178
205
|
|
|
179
206
|
it('a backend {ok:false, reason:"invalid"} shows the exact same invalid-email message', async () => {
|
|
180
207
|
const wrapper = mountNewsletter(mock, {
|
|
181
|
-
|
|
208
|
+
submit: async () => ({ ok: false, reason: 'invalid', errors: {}, form: [] }),
|
|
182
209
|
});
|
|
183
210
|
await submitValidEmail(wrapper);
|
|
184
211
|
|
|
@@ -191,7 +218,7 @@ describe('newsletter block', () => {
|
|
|
191
218
|
|
|
192
219
|
it('a backend failure with no reason shows the generic failed message and keeps the form', async () => {
|
|
193
220
|
const wrapper = mountNewsletter(mock, {
|
|
194
|
-
|
|
221
|
+
submit: async () => ({ ok: false, reason: 'unavailable' }),
|
|
195
222
|
});
|
|
196
223
|
await submitValidEmail(wrapper);
|
|
197
224
|
|
|
@@ -203,11 +230,14 @@ describe('newsletter block', () => {
|
|
|
203
230
|
});
|
|
204
231
|
|
|
205
232
|
it('after a backend failure, resubmitting the unchanged email reaches the service again and can succeed', async () => {
|
|
206
|
-
const results = [
|
|
207
|
-
|
|
208
|
-
|
|
233
|
+
const results: StorefrontAck[] = [
|
|
234
|
+
{ ok: false, reason: 'unavailable' },
|
|
235
|
+
{ ok: true, pending: true },
|
|
236
|
+
];
|
|
237
|
+
const submit = vi.fn(async () => results.shift() ?? { ok: true as const, pending: true });
|
|
238
|
+
const wrapper = mountNewsletter(mock, { submit });
|
|
209
239
|
await submitValidEmail(wrapper, 'reader@example.com');
|
|
210
|
-
expect(
|
|
240
|
+
expect(submit).toHaveBeenCalledTimes(1);
|
|
211
241
|
expect(wrapper.find('input[type="email"]').attributes('aria-invalid')).toBe('true');
|
|
212
242
|
|
|
213
243
|
// Same value, no edit in between: the form's own invalid gate must not swallow this.
|
|
@@ -215,8 +245,10 @@ describe('newsletter block', () => {
|
|
|
215
245
|
await flushPromises();
|
|
216
246
|
await flushPromises();
|
|
217
247
|
|
|
218
|
-
expect(
|
|
219
|
-
expect(
|
|
248
|
+
expect(submit).toHaveBeenCalledTimes(2);
|
|
249
|
+
expect(submit).toHaveBeenLastCalledWith('newsletter', {
|
|
250
|
+
values: { email: 'reader@example.com' },
|
|
251
|
+
});
|
|
220
252
|
expect(wrapper.find('form').exists()).toBe(false);
|
|
221
253
|
expect(wrapper.find('[role="status"]').text()).toContain(enUS.newsletter.successTitle);
|
|
222
254
|
});
|
|
@@ -230,12 +262,14 @@ describe('newsletter block', () => {
|
|
|
230
262
|
expect(status.text()).toBe('');
|
|
231
263
|
});
|
|
232
264
|
|
|
233
|
-
it('a valid submit calls forms.
|
|
234
|
-
const
|
|
235
|
-
const wrapper = mountNewsletter(mock, {
|
|
265
|
+
it('a valid submit calls forms.submit with the form key and the email, replaces the form with the status panel, and moves focus to it', async () => {
|
|
266
|
+
const submit = vi.fn(async () => ({ ok: true, pending: false }) as StorefrontAck);
|
|
267
|
+
const wrapper = mountNewsletter(mock, { submit });
|
|
236
268
|
await submitValidEmail(wrapper, 'reader@example.com');
|
|
237
269
|
|
|
238
|
-
expect(
|
|
270
|
+
expect(submit).toHaveBeenCalledWith('newsletter', {
|
|
271
|
+
values: { email: 'reader@example.com' },
|
|
272
|
+
});
|
|
239
273
|
expect(wrapper.find('form').exists()).toBe(false);
|
|
240
274
|
|
|
241
275
|
const status = wrapper.find('[role="status"]');
|
|
@@ -245,9 +279,33 @@ describe('newsletter block', () => {
|
|
|
245
279
|
expect(document.activeElement).toBe(status.element);
|
|
246
280
|
});
|
|
247
281
|
|
|
282
|
+
it('with Turnstile on, renders the widget and honeypot, refuses to send before the check, then sends the token and honeypot', async () => {
|
|
283
|
+
const turnstile = stubTurnstile();
|
|
284
|
+
const submit = vi.fn(async () => ({ ok: true, pending: false }) as StorefrontAck);
|
|
285
|
+
const wrapper = mountNewsletter(mock, { submit, turnstile: true });
|
|
286
|
+
await flushPromises();
|
|
287
|
+
expect(turnstile.render).toHaveBeenCalledOnce();
|
|
288
|
+
|
|
289
|
+
await submitValidEmail(wrapper);
|
|
290
|
+
expect(submit).not.toHaveBeenCalled();
|
|
291
|
+
expect(wrapper.text()).toContain(enUS.form.turnstileRequired);
|
|
292
|
+
|
|
293
|
+
turnstile.solve('token-1');
|
|
294
|
+
await wrapper.find('input[name="website"]').setValue('bot');
|
|
295
|
+
await wrapper.find('form').trigger('submit');
|
|
296
|
+
await flushPromises();
|
|
297
|
+
expect(submit).toHaveBeenCalledWith('newsletter', {
|
|
298
|
+
values: { email: 'reader@example.com' },
|
|
299
|
+
turnstileToken: 'token-1',
|
|
300
|
+
hp: 'bot',
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
|
|
248
304
|
it('falls back to the default success title when successTitle is unset', async () => {
|
|
249
305
|
const { successTitle: _omit, ...withoutTitle } = mock;
|
|
250
|
-
const wrapper = mountNewsletter(withoutTitle, {
|
|
306
|
+
const wrapper = mountNewsletter(withoutTitle, {
|
|
307
|
+
submit: async () => ({ ok: true, pending: false }),
|
|
308
|
+
});
|
|
251
309
|
await submitValidEmail(wrapper);
|
|
252
310
|
expect(wrapper.find('[role="status"]').text()).toContain(enUS.newsletter.successTitle);
|
|
253
311
|
});
|
|
@@ -256,8 +314,8 @@ describe('newsletter block', () => {
|
|
|
256
314
|
describe('submitting state', () => {
|
|
257
315
|
it('aria-busy is true on the submit button while pending, and repeat submits are ignored', async () => {
|
|
258
316
|
const deferred = deferredAck();
|
|
259
|
-
const
|
|
260
|
-
const wrapper = mountNewsletter(mock, {
|
|
317
|
+
const submit = vi.fn(() => deferred.promise);
|
|
318
|
+
const wrapper = mountNewsletter(mock, { submit });
|
|
261
319
|
|
|
262
320
|
await wrapper.find('input[type="email"]').setValue('reader@example.com');
|
|
263
321
|
await wrapper.find('form').trigger('submit');
|
|
@@ -266,10 +324,10 @@ describe('newsletter block', () => {
|
|
|
266
324
|
const button = wrapper.get('button[type="submit"]');
|
|
267
325
|
expect(button.attributes('aria-busy')).toBe('true');
|
|
268
326
|
|
|
269
|
-
// A second submit while still pending must not call
|
|
327
|
+
// A second submit while still pending must not call submit again.
|
|
270
328
|
await wrapper.find('form').trigger('submit');
|
|
271
329
|
await flushPromises();
|
|
272
|
-
expect(
|
|
330
|
+
expect(submit).toHaveBeenCalledTimes(1);
|
|
273
331
|
|
|
274
332
|
deferred.resolve({ ok: true });
|
|
275
333
|
await flushPromises();
|
|
@@ -291,14 +349,14 @@ describe('newsletter block', () => {
|
|
|
291
349
|
});
|
|
292
350
|
|
|
293
351
|
it('blocks submission until ticked, showing its own error and moving focus to it', async () => {
|
|
294
|
-
const
|
|
295
|
-
const wrapper = mountNewsletter({ ...mock, requireConsentCheckbox: true }, {
|
|
352
|
+
const submit = vi.fn(async () => ({ ok: true, pending: false }) as StorefrontAck);
|
|
353
|
+
const wrapper = mountNewsletter({ ...mock, requireConsentCheckbox: true }, { submit });
|
|
296
354
|
|
|
297
355
|
await wrapper.find('input[type="email"]').setValue('reader@example.com');
|
|
298
356
|
await wrapper.find('form').trigger('submit');
|
|
299
357
|
await flushPromises();
|
|
300
358
|
|
|
301
|
-
expect(
|
|
359
|
+
expect(submit).not.toHaveBeenCalled();
|
|
302
360
|
const checkbox = wrapper.find('input[type="checkbox"]');
|
|
303
361
|
expect(checkbox.attributes('aria-invalid')).toBe('true');
|
|
304
362
|
expect(wrapper.text()).toContain(enUS.newsletter.consentRequired);
|
|
@@ -311,7 +369,7 @@ describe('newsletter block', () => {
|
|
|
311
369
|
await checkbox.setValue(true);
|
|
312
370
|
await wrapper.find('form').trigger('submit');
|
|
313
371
|
await flushPromises();
|
|
314
|
-
expect(
|
|
372
|
+
expect(submit).toHaveBeenCalledTimes(1);
|
|
315
373
|
expect(wrapper.find('[role="status"]').text()).toContain(mock.successTitle);
|
|
316
374
|
});
|
|
317
375
|
});
|
|
@@ -333,8 +391,8 @@ describe('newsletter block', () => {
|
|
|
333
391
|
});
|
|
334
392
|
|
|
335
393
|
it('Enter in the input submits the form', async () => {
|
|
336
|
-
const
|
|
337
|
-
const wrapper = mountNewsletter(mock, {
|
|
394
|
+
const submit = vi.fn(async () => ({ ok: true, pending: false }) as StorefrontAck);
|
|
395
|
+
const wrapper = mountNewsletter(mock, { submit });
|
|
338
396
|
await wrapper.find('input[type="email"]').setValue('reader@example.com');
|
|
339
397
|
// jsdom does not implement the browser's native "Enter submits the nearest form" default
|
|
340
398
|
// action for a dispatched keydown (the same limitation `faq`'s own accordion suite documents
|
|
@@ -342,7 +400,7 @@ describe('newsletter block', () => {
|
|
|
342
400
|
// stand-in for that native behaviour, on the same real, unmodified `<form>`.
|
|
343
401
|
await wrapper.find('form').trigger('submit');
|
|
344
402
|
await flushPromises();
|
|
345
|
-
expect(
|
|
403
|
+
expect(submit).toHaveBeenCalledOnce();
|
|
346
404
|
});
|
|
347
405
|
|
|
348
406
|
it('Space toggles the checkbox (native default; a click stands in for it under jsdom)', async () => {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "An email sign-up with a clear promise, one field and visible error/success states. Use it once per page.",
|
|
5
5
|
"icon": "mail",
|
|
6
6
|
"category": "marketing",
|
|
7
|
-
"version":
|
|
7
|
+
"version": 2,
|
|
8
8
|
"fields": [
|
|
9
9
|
{
|
|
10
10
|
"fieldId": "variant",
|
|
@@ -88,11 +88,10 @@
|
|
|
88
88
|
"helpText": "For example the confirmation step and the welcome code."
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
|
-
"fieldId": "
|
|
92
|
-
"name": "
|
|
91
|
+
"fieldId": "formKey",
|
|
92
|
+
"name": "Form",
|
|
93
93
|
"type": "string",
|
|
94
|
-
"
|
|
95
|
-
"helpText": "The marketing list or audience id in the connected email app."
|
|
94
|
+
"helpText": "The key of the sign-up form on the Forms page. Defaults to \"newsletter\" when unset."
|
|
96
95
|
},
|
|
97
96
|
{
|
|
98
97
|
"fieldId": "sectionBackground",
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
"consentCheckboxLabel": "I'd like to receive emails from Northwind Goods",
|
|
27
27
|
"successTitle": "You're on the list",
|
|
28
28
|
"successText": "Check your inbox to confirm. Your 10% welcome code arrives with the first letter.",
|
|
29
|
-
"
|
|
29
|
+
"formKey": "newsletter",
|
|
30
30
|
"sectionBackground": "surface"
|
|
31
31
|
}
|
|
Binary file
|
|
@@ -495,29 +495,26 @@ describe('product-detail block', () => {
|
|
|
495
495
|
});
|
|
496
496
|
|
|
497
497
|
/**
|
|
498
|
-
* The same store on an **English** page
|
|
499
|
-
* narrow sign for krónur is `kr`, the wide one is the code itself. The button's label and the
|
|
500
|
-
* `<Price>` above it must agree on it, and `kr 2,800` is what the operator's own back office
|
|
501
|
-
* writes — an `ISK 2,800` here beside a `kr 2,800` in a currency field was the defect.
|
|
498
|
+
* The same store on an **English** page: the button's label and the `<Price>` above it both write `ISK 2,800`.
|
|
502
499
|
*/
|
|
503
|
-
it('writes the store currency’s
|
|
500
|
+
it('writes the store currency’s wide sign on a page in another locale', async () => {
|
|
504
501
|
const wrapper = await mountReady(mock, {
|
|
505
502
|
locale: 'en-US',
|
|
506
503
|
commerce: { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 },
|
|
507
504
|
storefront: storefrontWith({ price: { amount: 2800, compareAt: null } }),
|
|
508
505
|
});
|
|
509
506
|
|
|
510
|
-
expect(formatMoney(2800, 'ISK', 'en-US')).toBe('
|
|
507
|
+
expect(formatMoney(2800, 'ISK', 'en-US')).toBe('ISK\u00a02,800');
|
|
511
508
|
expect(addToCart(wrapper).text()).toContain(
|
|
512
|
-
enUS.product.addToCart.replace('{price}', '
|
|
509
|
+
enUS.product.addToCart.replace('{price}', 'ISK\u00a02,800')
|
|
513
510
|
);
|
|
514
511
|
const rendered = wrapper.findAll('[data-part="current"]').map((part) => part.text());
|
|
515
512
|
expect(rendered.length).toBeGreaterThan(0);
|
|
516
513
|
for (const amount of rendered) {
|
|
517
|
-
expect(amount).toBe('
|
|
514
|
+
expect(amount).toBe('ISK\u00a02,800');
|
|
518
515
|
}
|
|
519
|
-
// Not the
|
|
520
|
-
expect(wrapper.text()).not.toContain('
|
|
516
|
+
// Not the narrow sign, in either half.
|
|
517
|
+
expect(wrapper.text()).not.toContain('kr\u00a02,800');
|
|
521
518
|
});
|
|
522
519
|
|
|
523
520
|
/**
|
package/template/i18n/en-US.json
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"itemHintHelp": "A quote, the customer's name and location, or pick reviews from the product catalogue."
|
|
31
31
|
},
|
|
32
32
|
"breadcrumbs": {
|
|
33
|
+
"home": "Home",
|
|
33
34
|
"hintLabel": "Breadcrumbs fill in automatically.",
|
|
34
35
|
"hintHelp": "They appear once this page sits under a parent page."
|
|
35
36
|
},
|
|
@@ -202,10 +203,40 @@
|
|
|
202
203
|
"summaryTitleOne": "One field needs a look",
|
|
203
204
|
"summaryTitleMany": "{count} fields need a look",
|
|
204
205
|
"serverError": "We couldn't send your message. Please email {email} instead.",
|
|
205
|
-
"
|
|
206
|
-
"
|
|
206
|
+
"serverErrorGeneric": "We couldn't send your message. Please try again in a minute.",
|
|
207
|
+
"successTitle": "Thanks! Your message is with us.",
|
|
208
|
+
"successTextDefault": "We reply within one working day, usually sooner.",
|
|
207
209
|
"sendAnother": "Send another message"
|
|
208
210
|
},
|
|
211
|
+
"form": {
|
|
212
|
+
"headingHintLabel": "Add a heading",
|
|
213
|
+
"formHintLabel": "Choose a form",
|
|
214
|
+
"formHintHelp": "Set the form key to a form from the Forms page, for example \"contact\".",
|
|
215
|
+
"submit": "Send",
|
|
216
|
+
"submitting": "Sending…",
|
|
217
|
+
"selectPlaceholder": "Choose an option",
|
|
218
|
+
"loading": "Loading the form…",
|
|
219
|
+
"loadFailed": "This form can't be shown right now.",
|
|
220
|
+
"required": "{field} is required.",
|
|
221
|
+
"requiredCheckbox": "Tick the box: {field}",
|
|
222
|
+
"invalidEmail": "Enter a full email address, like name{'@'}example.com",
|
|
223
|
+
"invalidNumber": "Enter a number, like 12 or 3.5",
|
|
224
|
+
"invalidUrl": "Enter a full web address, like https://example.com",
|
|
225
|
+
"tooShort": "Use at least {min} characters.",
|
|
226
|
+
"tooLong": "Use at most {max} characters.",
|
|
227
|
+
"invalidFormat": "Check the format of this answer.",
|
|
228
|
+
"invalidForm": "Please check your answers and try again.",
|
|
229
|
+
"rateLimited": "Too many attempts. Please wait a minute and try again.",
|
|
230
|
+
"tooLarge": "That is more than we can accept. Please shorten your answers.",
|
|
231
|
+
"unavailable": "We couldn't send that just now. Please try again in a minute.",
|
|
232
|
+
"unsupported": "This form isn't connected yet.",
|
|
233
|
+
"turnstileRequired": "Please complete the spam check before sending.",
|
|
234
|
+
"turnstileFailed": "The spam check could not load. Reload the page and try again.",
|
|
235
|
+
"successTitle": "Thank you",
|
|
236
|
+
"successTitlePending": "Check your inbox",
|
|
237
|
+
"sendAnother": "Send another",
|
|
238
|
+
"richTextTableLabel": "Table"
|
|
239
|
+
},
|
|
209
240
|
"video": {
|
|
210
241
|
"play": "Play video: {title}",
|
|
211
242
|
"playWithDuration": "Play video: {title}, {duration}",
|
package/template/i18n/is-IS.json
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"itemHintHelp": "Tilvitnun, nafn viðskiptavinar og staðsetning, eða veldu umsagnir úr vörulistanum."
|
|
31
31
|
},
|
|
32
32
|
"breadcrumbs": {
|
|
33
|
+
"home": "Heim",
|
|
33
34
|
"hintLabel": "Leiðarslóðin fyllist út sjálfkrafa.",
|
|
34
35
|
"hintHelp": "Hún birtist þegar þessi síða er undir annarri síðu."
|
|
35
36
|
},
|
|
@@ -202,10 +203,40 @@
|
|
|
202
203
|
"summaryTitleOne": "Einn reit þarf að skoða",
|
|
203
204
|
"summaryTitleMany": "{count} reiti þarf að skoða",
|
|
204
205
|
"serverError": "Ekki tókst að senda skilaboðin. Sendu tölvupóst á {email} í staðinn.",
|
|
205
|
-
"
|
|
206
|
-
"
|
|
206
|
+
"serverErrorGeneric": "Ekki tókst að senda skilaboðin. Reyndu aftur eftir smá stund.",
|
|
207
|
+
"successTitle": "Takk fyrir! Skilaboðin þín hafa borist okkur.",
|
|
208
|
+
"successTextDefault": "Við svörum innan eins virks dags, oftast fyrr.",
|
|
207
209
|
"sendAnother": "Senda önnur skilaboð"
|
|
208
210
|
},
|
|
211
|
+
"form": {
|
|
212
|
+
"headingHintLabel": "Bættu við fyrirsögn",
|
|
213
|
+
"formHintLabel": "Veldu eyðublað",
|
|
214
|
+
"formHintHelp": "Settu lykil eyðublaðsins af eyðublaðasíðunni, til dæmis \"contact\".",
|
|
215
|
+
"submit": "Senda",
|
|
216
|
+
"submitting": "Sendi…",
|
|
217
|
+
"selectPlaceholder": "Veldu valkost",
|
|
218
|
+
"loading": "Hleð eyðublaðinu…",
|
|
219
|
+
"loadFailed": "Ekki er hægt að sýna þetta eyðublað núna.",
|
|
220
|
+
"required": "{field} er nauðsynlegt.",
|
|
221
|
+
"requiredCheckbox": "Hakaðu í reitinn: {field}",
|
|
222
|
+
"invalidEmail": "Sláðu inn fullt netfang, eins og nafn{'@'}example.is",
|
|
223
|
+
"invalidNumber": "Sláðu inn tölu, t.d. 12 eða 3,5",
|
|
224
|
+
"invalidUrl": "Sláðu inn fullt veffang, t.d. https://example.is",
|
|
225
|
+
"tooShort": "Notaðu að minnsta kosti {min} stafi.",
|
|
226
|
+
"tooLong": "Notaðu í mesta lagi {max} stafi.",
|
|
227
|
+
"invalidFormat": "Athugaðu snið svarsins.",
|
|
228
|
+
"invalidForm": "Athugaðu svörin og reyndu aftur.",
|
|
229
|
+
"rateLimited": "Of margar tilraunir. Bíddu í eina mínútu og reyndu aftur.",
|
|
230
|
+
"tooLarge": "Þetta er meira en við getum tekið við. Styttu svörin.",
|
|
231
|
+
"unavailable": "Ekki tókst að senda þetta núna. Reyndu aftur eftir smá stund.",
|
|
232
|
+
"unsupported": "Þetta eyðublað er ekki tengt ennþá.",
|
|
233
|
+
"turnstileRequired": "Kláraðu ruslpóstsvörnina áður en þú sendir.",
|
|
234
|
+
"turnstileFailed": "Ekki tókst að hlaða ruslpóstsvörninni. Endurhlaðið síðuna og reyndu aftur.",
|
|
235
|
+
"successTitle": "Takk fyrir",
|
|
236
|
+
"successTitlePending": "Kíktu í pósthólfið",
|
|
237
|
+
"sendAnother": "Senda annað",
|
|
238
|
+
"richTextTableLabel": "Tafla"
|
|
239
|
+
},
|
|
209
240
|
"video": {
|
|
210
241
|
"play": "Spila myndband: {title}",
|
|
211
242
|
"playWithDuration": "Spila myndband: {title}, {duration}",
|