@eldrajs/theme-cli 0.2.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.
Files changed (66) hide show
  1. package/package.json +3 -3
  2. package/template/.eldra/block-types.d.ts +12 -3
  3. package/template/.eldra/manifest.json +315 -25
  4. package/template/.eldra/previews.json +35 -34
  5. package/template/.github/workflows/eldra-deploy.yml +2 -0
  6. package/template/.gitlab-ci.yml +2 -0
  7. package/template/.storybook/main.ts +3 -0
  8. package/template/README.md +22 -10
  9. package/template/app/components/FormHoneypot.vue +21 -0
  10. package/template/app/composables/useFormSpam.ts +55 -0
  11. package/template/app/composables/usePageStructuredData.ts +112 -0
  12. package/template/app/composables/useTurnstile.ts +111 -0
  13. package/template/app/formSeeds.ts +93 -0
  14. package/template/app/pages/[...slug].vue +48 -12
  15. package/template/app/plugins/eldra-storefront.ts +19 -2
  16. package/template/app/seededPages.ts +7 -0
  17. package/template/app/storefront/analytics.ts +202 -0
  18. package/template/app/storefront/cart.ts +7 -0
  19. package/template/app/storefront/demo.ts +48 -2
  20. package/template/app/storefront/forms.ts +133 -0
  21. package/template/app/storefront/gateway.ts +113 -7
  22. package/template/app/storefront/structuredData.ts +161 -0
  23. package/template/app/storefront/types.ts +101 -2
  24. package/template/app/utils/seoInput.ts +172 -0
  25. package/template/bitbucket-pipelines.yml +3 -1
  26. package/template/blocks/breadcrumbs/Block.vue +1 -0
  27. package/template/blocks/cart/Block.vue +1 -0
  28. package/template/blocks/cart/parts/Summary.vue +1 -0
  29. package/template/blocks/contact/Block.vue +50 -21
  30. package/template/blocks/contact/__tests__/Block.spec.ts +89 -8
  31. package/template/blocks/contact/block.json +2 -9
  32. package/template/blocks/contact/mock.json +1 -2
  33. package/template/blocks/footer/Block.vue +56 -6
  34. package/template/blocks/footer/__tests__/Block.spec.ts +70 -16
  35. package/template/blocks/footer/preview.png +0 -0
  36. package/template/blocks/form/Block.vue +614 -0
  37. package/template/blocks/form/__tests__/Block.spec.ts +536 -0
  38. package/template/blocks/form/block.json +69 -0
  39. package/template/blocks/form/mock.json +25 -0
  40. package/template/blocks/form/preview.png +0 -0
  41. package/template/blocks/form/validate.ts +68 -0
  42. package/template/blocks/newsletter/Block.vue +57 -3
  43. package/template/blocks/newsletter/__tests__/Block.spec.ts +89 -31
  44. package/template/blocks/newsletter/block.json +4 -5
  45. package/template/blocks/newsletter/mock.json +1 -1
  46. package/template/blocks/newsletter/preview.png +0 -0
  47. package/template/i18n/en-US.json +33 -2
  48. package/template/i18n/is-IS.json +33 -2
  49. package/template/nuxt.config.ts +6 -0
  50. package/template/stories/generated/form.stories.ts +68 -0
  51. package/template/test/formValidate.spec.ts +46 -0
  52. package/template/test/prerenderFailure.spec.ts +1 -1
  53. package/template/test/prerenderRefresh.browser.spec.ts +5 -1
  54. package/template/test/seededPages.spec.ts +13 -0
  55. package/template/test/seoInput.spec.ts +119 -0
  56. package/template/test/slugPage.spec.ts +62 -26
  57. package/template/test/slugPageTemplate.spec.ts +5 -1
  58. package/template/test/starter.spec.ts +41 -3
  59. package/template/test/storefront/analytics.spec.ts +283 -0
  60. package/template/test/storefront/forms.spec.ts +385 -0
  61. package/template/test/storefront/structuredData.spec.ts +138 -0
  62. package/template/test/structuredData.generate.spec.ts +159 -0
  63. package/template/test/support/mockGateway.ts +29 -1
  64. package/template/test/support/turnstileForms.ts +53 -0
  65. package/template/app/utils/pageTitle.ts +0 -37
  66. package/template/test/pageTitle.spec.ts +0 -49
@@ -1,19 +1,34 @@
1
1
  // @vitest-environment jsdom
2
2
  import { flushPromises, mount } from '@vue/test-utils';
3
- import { describe, expect, it } from 'vitest';
3
+ import { afterEach, describe, expect, it, vi } from 'vitest';
4
4
  import { axe } from '../../../test/support/axe';
5
5
  import Block from '../Block.vue';
6
6
  import mock from '../mock.json';
7
7
  import preview from '../preview.json';
8
8
  import { mountOptions } from '../../../test/support/mountBlock';
9
9
  import { STOREFRONT_KEY } from '../../../app/storefront/types';
10
+ import type { StorefrontSource } from '../../../app/storefront/types';
10
11
  import { createDemoStorefront } from '../../../app/storefront/demo';
11
12
  import enUS from '../../../i18n/en-US.json';
12
13
  import { renderedMessage } from '../../../test/support/i18nText';
14
+ import {
15
+ cleanUpTurnstile,
16
+ storefrontWithTurnstile,
17
+ stubTurnstile,
18
+ } from '../../../test/support/turnstileForms';
19
+
20
+ afterEach(cleanUpTurnstile);
13
21
 
14
22
  const merged = { ...mock, ...preview };
15
23
 
16
- function mountContact(data: Record<string, unknown>, options: { failForms?: boolean } = {}) {
24
+ function mountContact(
25
+ data: Record<string, unknown>,
26
+ options: {
27
+ failForms?: boolean;
28
+ submit?: StorefrontSource['forms']['submit'];
29
+ storefront?: StorefrontSource;
30
+ } = {}
31
+ ) {
17
32
  const base = mountOptions({ entry: { id: 'e1', data } });
18
33
  return mount(Block, {
19
34
  ...base,
@@ -28,6 +43,15 @@ function mountContact(data: Record<string, unknown>, options: { failForms?: bool
28
43
  ...(options.failForms
29
44
  ? { [STOREFRONT_KEY]: createDemoStorefront({ failForms: true }) }
30
45
  : {}),
46
+ ...(options.submit
47
+ ? {
48
+ [STOREFRONT_KEY]: (() => {
49
+ const base = createDemoStorefront();
50
+ return { ...base, forms: { ...base.forms, submit: options.submit } };
51
+ })(),
52
+ }
53
+ : {}),
54
+ ...(options.storefront ? { [STOREFRONT_KEY]: options.storefront } : {}),
31
55
  },
32
56
  },
33
57
  });
@@ -177,18 +201,50 @@ describe('contact block', () => {
177
201
  expect(document.activeElement).toBe(messageField.element);
178
202
  });
179
203
 
180
- it('a valid submit calls forms.sendMessage and shows a role="status" success panel that receives focus, replacing the form', async () => {
181
- const wrapper = mountContact(mock);
204
+ it('a valid submit posts the seeded contact form’s fields to forms.submit and shows a role="status" success panel that receives focus, replacing the form', async () => {
205
+ const submit = vi.fn(async () => ({ ok: true as const, pending: false }));
206
+ const wrapper = mountContact(mock, { submit });
182
207
  await submitValid(wrapper);
183
208
 
209
+ expect(submit).toHaveBeenCalledWith('contact', {
210
+ values: {
211
+ name: 'Hannah Reyes',
212
+ email: 'hannah@example.com',
213
+ topic: mock.topics[0]!.label,
214
+ message: 'Do you carry the moss glaze in stock right now?',
215
+ },
216
+ });
184
217
  expect(wrapper.find('form').exists()).toBe(false);
185
218
  const status = wrapper.find('[role="status"]');
186
219
  expect(status.exists()).toBe(true);
187
- expect(status.text()).toContain('Hannah');
188
- expect(status.text()).toContain('hannah@example.com');
220
+ // A receipt never echoes what the visitor typed.
221
+ expect(status.text()).not.toContain('Hannah');
222
+ expect(status.text()).not.toContain('hannah@example.com');
189
223
  expect(document.activeElement).toBe(status.element);
190
224
  });
191
225
 
226
+ it('with Turnstile on, renders the widget and honeypot, refuses to send before the check, then sends the token and honeypot', async () => {
227
+ const turnstile = stubTurnstile();
228
+ const submit = vi.fn(async () => ({ ok: true as const, pending: false }));
229
+ const wrapper = mountContact(mock, { storefront: storefrontWithTurnstile(submit) });
230
+ await flushPromises();
231
+ expect(turnstile.render).toHaveBeenCalledOnce();
232
+
233
+ await submitValid(wrapper);
234
+ expect(submit).not.toHaveBeenCalled();
235
+ expect(wrapper.text()).toContain(enUS.form.turnstileRequired);
236
+
237
+ turnstile.solve('token-1');
238
+ await wrapper.find('input[name="website"]').setValue('bot');
239
+ await wrapper.find('form').trigger('submit');
240
+ await flushPromises();
241
+ expect(submit).toHaveBeenCalledWith(
242
+ 'contact',
243
+ expect.objectContaining({ turnstileToken: 'token-1', hp: 'bot' })
244
+ );
245
+ expect(turnstile.reset).toHaveBeenCalled();
246
+ });
247
+
192
248
  it('"Send another message" restores an empty form and focuses the Name field', async () => {
193
249
  const wrapper = mountContact(mock);
194
250
  await submitValid(wrapper);
@@ -206,12 +262,37 @@ describe('contact block', () => {
206
262
  expect(document.activeElement).toBe(name.element);
207
263
  });
208
264
 
209
- it('a server failure (forms.sendMessage ok:false) shows the summary again and keeps the form', async () => {
265
+ it('a server failure (forms.submit ok:false) shows the summary again and keeps the form', async () => {
210
266
  const wrapper = mountContact(mock, { failForms: true });
211
267
  await submitValid(wrapper);
212
268
 
213
269
  expect(wrapper.find('form').exists()).toBe(true);
214
- expect(wrapper.find('[role="alert"]').text()).toContain(mock.recipient);
270
+ expect(wrapper.find('[role="alert"]').text()).toContain(mock.email);
271
+ });
272
+
273
+ it('a server failure with no contact email on the block still says what happened', async () => {
274
+ const { email: _omit, ...withoutEmail } = mock;
275
+ const wrapper = mountContact(withoutEmail, { failForms: true });
276
+ await submitValid(wrapper);
277
+
278
+ expect(wrapper.find('[role="alert"]').text()).toBe(enUS.contact.serverErrorGeneric);
279
+ });
280
+
281
+ it('a 422 marks the field the platform names, with its own message, and focuses the summary', async () => {
282
+ const submit = vi.fn(async () => ({
283
+ ok: false as const,
284
+ reason: 'invalid' as const,
285
+ errors: { email: ['That domain does not accept mail.'] },
286
+ form: [],
287
+ }));
288
+ const wrapper = mountContact(mock, { submit });
289
+ await submitValid(wrapper);
290
+
291
+ expect(wrapper.find('form').exists()).toBe(true);
292
+ expect(wrapper.find('input[type="email"]').attributes('aria-invalid')).toBe('true');
293
+ expect(wrapper.text()).toContain('That domain does not accept mail.');
294
+ expect(wrapper.find('input[autocomplete="name"]').attributes('aria-invalid')).toBeUndefined();
295
+ expect(await axe(wrapper.element)).toHaveNoViolations();
215
296
  });
216
297
 
217
298
  it.each(['Enter', ' ', 'ArrowDown'])(
@@ -4,7 +4,7 @@
4
4
  "description": "The shop's address, opening hours, phone and email beside a short enquiry form, with a map that always offers an \"Open in maps\" link outside any embed.",
5
5
  "icon": "map-pin",
6
6
  "category": "marketing",
7
- "version": 1,
7
+ "version": 2,
8
8
  "fields": [
9
9
  {
10
10
  "fieldId": "variant",
@@ -156,19 +156,12 @@
156
156
  "type": "bool",
157
157
  "default": false
158
158
  },
159
- {
160
- "fieldId": "recipient",
161
- "name": "Recipient",
162
- "type": "string",
163
- "helpText": "Where submissions go. Not shown.",
164
- "validators": { "required": true }
165
- },
166
159
  {
167
160
  "fieldId": "successText",
168
161
  "name": "Success text",
169
162
  "type": "text",
170
163
  "localized": true,
171
- "helpText": "Shown after a successful submit. {email} is replaced with the sender's own address."
164
+ "helpText": "Shown after a successful submit. It never echoes what the visitor typed."
172
165
  }
173
166
  ]
174
167
  }
@@ -23,6 +23,5 @@
23
23
  { "label": "Something else" }
24
24
  ],
25
25
  "showOrderNumber": true,
26
- "recipient": "hello@northwind.example",
27
- "successText": "We reply within one business day, usually sooner. A copy is on its way to {email}."
26
+ "successText": "We reply within one business day, usually sooner."
28
27
  }
@@ -57,7 +57,8 @@
57
57
  * slot renders nothing. The `Select` branch stays for the day the derived list carries two or more
58
58
  * entries; which branch renders is driven by that list's length, not by a separate flag.
59
59
  *
60
- * The newsletter zone posts through `useStorefront().forms.subscribe`. Email format is validated
60
+ * The newsletter zone posts through `useStorefront().forms.submit('newsletter', …)` — the platform's
61
+ * seeded `newsletter` form, the same one the newsletter block defaults to. Email format is validated
61
62
  * locally (empty/malformed never reaches the storefront); a backend `{ ok: false }` shows the same
62
63
  * error slot. Both failure paths return focus to the email field — `FormLayout`'s own submit
63
64
  * handler only refuses a *second* submit while a field is already marked invalid, so the first
@@ -96,8 +97,10 @@ import { useBlockData } from '../../app/composables/useBlockData';
96
97
  import { useEditing } from '../../app/composables/useEditing';
97
98
  import { useI18n } from 'vue-i18n';
98
99
  import { useUiId } from '../../app/composables/useUiId';
100
+ import { useFormSpam } from '../../app/composables/useFormSpam';
99
101
  import { useStorefront } from '../../app/composables/useStorefront';
100
102
  import EldraIcon from '../../app/components/EldraIcon.vue';
103
+ import FormHoneypot from '../../app/components/FormHoneypot.vue';
101
104
  import EldraRouterLink from '../../app/components/EldraRouterLink.vue';
102
105
  import type { ThemeIconName } from '../../app/icons';
103
106
  import { currencyLabel, useMoney } from '../../app/storefront/money';
@@ -109,6 +112,9 @@ type FooterLink = {
109
112
  as: typeof EldraRouterLink | undefined;
110
113
  };
111
114
 
115
+ /** The seeded form the footer's sign-up zone submits to (`app/formSeeds.ts`). */
116
+ const NEWSLETTER_FORM_KEY = 'newsletter';
117
+
112
118
  const props = defineProps<{ entry: EldraBlockEntry<'footer'> }>();
113
119
  const { data } = useBlockData(props, 'footer');
114
120
  const { t } = useI18n();
@@ -308,6 +314,18 @@ const emailFieldRoot = ref<HTMLElement | null>(null);
308
314
  const showNewsletter = computed(
309
315
  () => variant.value === 'default' && (data.value.showNewsletter ?? true)
310
316
  );
317
+ // Only a footer that shows the sign-up reads the form's definition (its honeypot and Turnstile).
318
+ const {
319
+ honeypot,
320
+ honeypotField,
321
+ siteKey,
322
+ consentSentence,
323
+ turnstileRoot,
324
+ challenge,
325
+ signals,
326
+ reset,
327
+ } = useFormSpam(computed(() => (showNewsletter.value ? NEWSLETTER_FORM_KEY : '')));
328
+ const consentSentenceId = `footer-consent-sentence-${useUiId()}`;
311
329
 
312
330
  /** Mirrors `blocks/newsletter/Block.vue`'s own comment: an error has to clear itself the moment
313
331
  * its own condition is fixed (the visitor edits the address), not only inside a later successful
@@ -353,9 +371,23 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
353
371
  return;
354
372
  }
355
373
 
374
+ // Turnstile is on and not passed: nothing about the address is wrong, so a retry is welcome.
375
+ const blocked = challenge();
376
+ if (blocked !== null) {
377
+ retryable.value = true;
378
+ emailError.value = blocked;
379
+ await focusEmailField();
380
+ return;
381
+ }
382
+
356
383
  emailError.value = null;
357
384
  newsletterState.value = 'submitting';
358
- const result = await storefront.forms.subscribe({ email: value, list: 'footer-newsletter' });
385
+ const result = await storefront.forms.submit(NEWSLETTER_FORM_KEY, {
386
+ values: { email: value },
387
+ ...signals(),
388
+ });
389
+ // A Turnstile token is single-use, whatever the outcome.
390
+ reset();
359
391
 
360
392
  if (result.ok) {
361
393
  newsletterState.value = 'success';
@@ -365,7 +397,9 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
365
397
  newsletterState.value = 'idle';
366
398
  const serviceFailed = result.reason !== 'invalid';
367
399
  retryable.value = serviceFailed;
368
- emailError.value = serviceFailed ? t('footer.emailError') : t('footer.emailInvalid');
400
+ emailError.value = serviceFailed
401
+ ? t('footer.emailError')
402
+ : (result.errors.email?.[0] ?? t('footer.emailInvalid'));
369
403
  await focusEmailField();
370
404
  }
371
405
  </script>
@@ -511,10 +545,26 @@ async function onNewsletterSubmit(payload: FormLayoutSubmitPayload): Promise<voi
511
545
  />
512
546
  </FieldWrapper>
513
547
  </div>
548
+ <FormHoneypot v-model="honeypot" :name="honeypotField" />
549
+ <div v-if="siteKey" ref="turnstileRoot" class="w-full" />
514
550
  <template #actions>
515
- <Button type="submit" variant="primary" :label="t('footer.subscribing')">{{
516
- t('footer.subscribe')
517
- }}</Button>
551
+ <div class="grid w-full gap-2">
552
+ <Button
553
+ type="submit"
554
+ variant="primary"
555
+ :label="t('footer.subscribing')"
556
+ :aria-describedby="consentSentence ? consentSentenceId : undefined"
557
+ >{{ t('footer.subscribe') }}</Button
558
+ >
559
+ <p
560
+ v-if="consentSentence"
561
+ :id="consentSentenceId"
562
+ data-part="consent-sentence"
563
+ class="text-muted text-body-sm"
564
+ >
565
+ {{ consentSentence }}
566
+ </p>
567
+ </div>
518
568
  </template>
519
569
  </FormLayout>
520
570
  </template>
@@ -1,6 +1,6 @@
1
1
  // @vitest-environment jsdom
2
2
  import { flushPromises, mount } from '@vue/test-utils';
3
- import { describe, expect, it, vi } from 'vitest';
3
+ import { afterEach, describe, expect, it, vi } from 'vitest';
4
4
  import { ELDRA_KEY, type EldraLocaleState } from '@eldrajs/theme-vue';
5
5
  import { EditorPlaceholder } from '@eldrajs/ui';
6
6
  import { axe } from '../../../test/support/axe';
@@ -8,11 +8,22 @@ import Block from '../Block.vue';
8
8
  import mock from '../mock.json';
9
9
  import { mountOptions } from '../../../test/support/mountBlock';
10
10
  import { STOREFRONT_KEY } from '../../../app/storefront/types';
11
- import type { StorefrontCommerce, StorefrontForms } from '../../../app/storefront/types';
11
+ import type {
12
+ StorefrontCommerce,
13
+ StorefrontFormSubmitResult,
14
+ StorefrontForms,
15
+ } from '../../../app/storefront/types';
12
16
  import { createDemoStorefront } from '../../../app/storefront/demo';
13
17
  import { currencyLabel } from '../../../app/storefront/money';
14
18
  import enUS from '../../../i18n/en-US.json';
15
19
  import isIS from '../../../i18n/is-IS.json';
20
+ import {
21
+ cleanUpTurnstile,
22
+ storefrontWithTurnstile,
23
+ stubTurnstile,
24
+ } from '../../../test/support/turnstileForms';
25
+
26
+ afterEach(cleanUpTurnstile);
16
27
 
17
28
  /**
18
29
  * `mock.json` names a collection or product by handle, because a theme cannot know an
@@ -67,7 +78,9 @@ function mountFooter(
67
78
  data: Record<string, unknown>,
68
79
  options: {
69
80
  failForms?: boolean;
70
- subscribe?: StorefrontForms['subscribe'];
81
+ subscribe?: StorefrontForms['submit'];
82
+ /** Turn Cloudflare Turnstile on for the sign-up form (with `subscribe` as its submit). */
83
+ turnstile?: boolean;
71
84
  /** Studio's edit mode — what `useEditing()` reads, and the only state that shows hints. */
72
85
  editing?: boolean;
73
86
  /** The content locale — `@eldrajs/ui`'s number locale follows it (`mountOptions`). */
@@ -99,12 +112,15 @@ function mountFooter(
99
112
  context.preview.active = true;
100
113
  context.preview.mode = 'edit';
101
114
  }
102
- const storefront = options.subscribe
103
- ? (() => {
104
- const demo = createDemoStorefront();
105
- return { ...demo, forms: { ...demo.forms, subscribe: options.subscribe! } };
106
- })()
107
- : undefined;
115
+ const storefront =
116
+ options.subscribe && options.turnstile
117
+ ? storefrontWithTurnstile(options.subscribe)
118
+ : options.subscribe
119
+ ? (() => {
120
+ const demo = createDemoStorefront();
121
+ return { ...demo, forms: { ...demo.forms, submit: options.subscribe! } };
122
+ })()
123
+ : undefined;
108
124
  return mount(Block, {
109
125
  ...base,
110
126
  // Real focus tracking (`document.activeElement`, and `Select`'s own focus-return behaviour)
@@ -303,6 +319,18 @@ describe('footer block', () => {
303
319
  expect(label.classes()).toContain('sr-only');
304
320
  });
305
321
 
322
+ it('shows the platform consent sentence under the sign-up button, tied to it with aria-describedby', async () => {
323
+ const wrapper = mountFooter(mock);
324
+ await flushPromises();
325
+ const sentence = wrapper.get('[data-part="consent-sentence"]');
326
+ expect(sentence.text()).toBe(
327
+ 'I want to receive the newsletter from Northwind Goods. I can unsubscribe at any time.'
328
+ );
329
+ expect(wrapper.get('button[type="submit"]').attributes('aria-describedby')).toBe(
330
+ sentence.attributes('id')
331
+ );
332
+ });
333
+
306
334
  it('an invalid (malformed) email submit sets aria-invalid, shows the error linked by aria-describedby, and keeps focus in the field', async () => {
307
335
  const wrapper = mountFooter(mock);
308
336
  const input = wrapper.find('input[type="email"]');
@@ -330,7 +358,7 @@ describe('footer block', () => {
330
358
  expect(wrapper.text()).toContain(enUS.footer.emailInvalid);
331
359
  });
332
360
 
333
- it('a valid submit calls forms.subscribe and announces success through role="status"', async () => {
361
+ it('a valid submit calls forms.submit and announces success through role="status"', async () => {
334
362
  const wrapper = mountFooter(mock);
335
363
  const input = wrapper.find('input[type="email"]');
336
364
  await input.setValue('reader@example.com');
@@ -345,6 +373,30 @@ describe('footer block', () => {
345
373
  expect(wrapper.find('form').exists()).toBe(false);
346
374
  });
347
375
 
376
+ it('with Turnstile on, renders the widget and honeypot, refuses to send before the check, then sends the token and honeypot', async () => {
377
+ const turnstile = stubTurnstile();
378
+ const subscribe = vi.fn(async () => ({ ok: true as const, pending: false }));
379
+ const wrapper = mountFooter(mock, { subscribe, turnstile: true });
380
+ await flushPromises();
381
+ expect(turnstile.render).toHaveBeenCalledOnce();
382
+
383
+ await wrapper.find('input[type="email"]').setValue('reader@example.com');
384
+ await wrapper.find('form').trigger('submit');
385
+ await flushPromises();
386
+ expect(subscribe).not.toHaveBeenCalled();
387
+ expect(wrapper.text()).toContain(enUS.form.turnstileRequired);
388
+
389
+ turnstile.solve('token-1');
390
+ await wrapper.find('input[name="website"]').setValue('bot');
391
+ await wrapper.find('form').trigger('submit');
392
+ await flushPromises();
393
+ expect(subscribe).toHaveBeenCalledWith('newsletter', {
394
+ values: { email: 'reader@example.com' },
395
+ turnstileToken: 'token-1',
396
+ hp: 'bot',
397
+ });
398
+ });
399
+
348
400
  it('a subscribe failure (backend ok:false) shows an error and keeps focus in the field', async () => {
349
401
  const wrapper = mountFooter(mock, { failForms: true });
350
402
  const input = wrapper.find('input[type="email"]');
@@ -367,8 +419,11 @@ describe('footer block', () => {
367
419
  // removing `@invalid="onNewsletterInvalid"` (or `retryable.value = serviceFailed` in
368
420
  // `onNewsletterSubmit`) makes `subscribe` stay called once and the field stay marked invalid
369
421
  // forever — confirmed by temporarily reverting each change and observing this test fail.
370
- const results = [{ ok: false as const, reason: 'failed' as const }, { ok: true as const }];
371
- const subscribe = vi.fn(async () => results.shift() ?? { ok: true as const });
422
+ const results: StorefrontFormSubmitResult[] = [
423
+ { ok: false, reason: 'unavailable' },
424
+ { ok: true, pending: true },
425
+ ];
426
+ const subscribe = vi.fn(async () => results.shift() ?? { ok: true as const, pending: true });
372
427
  const wrapper = mountFooter(mock, { subscribe });
373
428
  const input = wrapper.find('input[type="email"]');
374
429
  await input.setValue('reader@example.com');
@@ -383,9 +438,8 @@ describe('footer block', () => {
383
438
  await flushPromises();
384
439
 
385
440
  expect(subscribe).toHaveBeenCalledTimes(2);
386
- expect(subscribe).toHaveBeenLastCalledWith({
387
- email: 'reader@example.com',
388
- list: 'footer-newsletter',
441
+ expect(subscribe).toHaveBeenLastCalledWith('newsletter', {
442
+ values: { email: 'reader@example.com' },
389
443
  });
390
444
  expect(wrapper.find('form').exists()).toBe(false);
391
445
  expect(wrapper.find('[role="status"]').text()).toContain(enUS.footer.subscribed);
@@ -393,7 +447,7 @@ describe('footer block', () => {
393
447
 
394
448
  it('a backend {ok:false, reason:"invalid"} shows the exact same invalid-email message (not the retryable one)', async () => {
395
449
  const wrapper = mountFooter(mock, {
396
- subscribe: async () => ({ ok: false, reason: 'invalid' }),
450
+ subscribe: async () => ({ ok: false, reason: 'invalid', errors: {}, form: [] }),
397
451
  });
398
452
  const input = wrapper.find('input[type="email"]');
399
453
  await input.setValue('reader@example.com');
Binary file