@eldrajs/theme-cli 0.2.0 → 0.2.2
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/package.json +3 -3
- package/template/.eldra/block-types.d.ts +12 -3
- package/template/.eldra/manifest.json +315 -25
- package/template/.eldra/previews.json +35 -34
- package/template/.github/workflows/eldra-deploy.yml +31 -2
- package/template/.gitlab-ci.yml +37 -8
- package/template/.storybook/main.ts +3 -0
- package/template/README.md +25 -13
- package/template/app/components/FormHoneypot.vue +21 -0
- package/template/app/composables/useFormSpam.ts +56 -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 +22 -2
- 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/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 +25 -3
- 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 +66 -9
- package/template/blocks/footer/__tests__/Block.spec.ts +136 -17
- 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/i18n/en-US.json +33 -2
- package/template/i18n/is-IS.json +33 -2
- package/template/nuxt.config.ts +6 -0
- package/template/stories/generated/form.stories.ts +68 -0
- package/template/test/formValidate.spec.ts +46 -0
- package/template/test/prerenderFailure.spec.ts +1 -1
- package/template/test/prerenderRefresh.browser.spec.ts +5 -1
- 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 +41 -3
- package/template/test/storefront/analytics.spec.ts +283 -0
- package/template/test/storefront/forms.spec.ts +385 -0
- 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/app/utils/pageTitle.ts +0 -37
- package/template/test/pageTitle.spec.ts +0 -49
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
|
+
import { computed } from 'vue';
|
|
2
3
|
import { flushPromises, mount } from '@vue/test-utils';
|
|
3
|
-
import { describe, expect, it, vi } from 'vitest';
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
4
5
|
import { ELDRA_KEY, type EldraLocaleState } from '@eldrajs/theme-vue';
|
|
5
6
|
import { EditorPlaceholder } from '@eldrajs/ui';
|
|
6
7
|
import { axe } from '../../../test/support/axe';
|
|
@@ -8,11 +9,23 @@ import Block from '../Block.vue';
|
|
|
8
9
|
import mock from '../mock.json';
|
|
9
10
|
import { mountOptions } from '../../../test/support/mountBlock';
|
|
10
11
|
import { STOREFRONT_KEY } from '../../../app/storefront/types';
|
|
11
|
-
import type {
|
|
12
|
+
import type {
|
|
13
|
+
StorefrontCommerce,
|
|
14
|
+
StorefrontFormSubmitResult,
|
|
15
|
+
StorefrontSource,
|
|
16
|
+
StorefrontForms,
|
|
17
|
+
} from '../../../app/storefront/types';
|
|
12
18
|
import { createDemoStorefront } from '../../../app/storefront/demo';
|
|
13
19
|
import { currencyLabel } from '../../../app/storefront/money';
|
|
14
20
|
import enUS from '../../../i18n/en-US.json';
|
|
15
21
|
import isIS from '../../../i18n/is-IS.json';
|
|
22
|
+
import {
|
|
23
|
+
cleanUpTurnstile,
|
|
24
|
+
storefrontWithTurnstile,
|
|
25
|
+
stubTurnstile,
|
|
26
|
+
} from '../../../test/support/turnstileForms';
|
|
27
|
+
|
|
28
|
+
afterEach(cleanUpTurnstile);
|
|
16
29
|
|
|
17
30
|
/**
|
|
18
31
|
* `mock.json` names a collection or product by handle, because a theme cannot know an
|
|
@@ -67,7 +80,11 @@ function mountFooter(
|
|
|
67
80
|
data: Record<string, unknown>,
|
|
68
81
|
options: {
|
|
69
82
|
failForms?: boolean;
|
|
70
|
-
subscribe?: StorefrontForms['
|
|
83
|
+
subscribe?: StorefrontForms['submit'];
|
|
84
|
+
/** A whole storefront, for a spec that needs a form definition the demo does not have. */
|
|
85
|
+
storefront?: StorefrontSource;
|
|
86
|
+
/** Turn Cloudflare Turnstile on for the sign-up form (with `subscribe` as its submit). */
|
|
87
|
+
turnstile?: boolean;
|
|
71
88
|
/** Studio's edit mode — what `useEditing()` reads, and the only state that shows hints. */
|
|
72
89
|
editing?: boolean;
|
|
73
90
|
/** The content locale — `@eldrajs/ui`'s number locale follows it (`mountOptions`). */
|
|
@@ -99,12 +116,16 @@ function mountFooter(
|
|
|
99
116
|
context.preview.active = true;
|
|
100
117
|
context.preview.mode = 'edit';
|
|
101
118
|
}
|
|
102
|
-
const storefront =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
119
|
+
const storefront =
|
|
120
|
+
options.storefront ??
|
|
121
|
+
(options.subscribe && options.turnstile
|
|
122
|
+
? storefrontWithTurnstile(options.subscribe)
|
|
123
|
+
: options.subscribe
|
|
124
|
+
? (() => {
|
|
125
|
+
const demo = createDemoStorefront();
|
|
126
|
+
return { ...demo, forms: { ...demo.forms, submit: options.subscribe! } };
|
|
127
|
+
})()
|
|
128
|
+
: undefined);
|
|
108
129
|
return mount(Block, {
|
|
109
130
|
...base,
|
|
110
131
|
// Real focus tracking (`document.activeElement`, and `Select`'s own focus-return behaviour)
|
|
@@ -300,7 +321,79 @@ describe('footer block', () => {
|
|
|
300
321
|
const label = wrapper.find(`label[for="${id}"]`);
|
|
301
322
|
expect(label.exists()).toBe(true);
|
|
302
323
|
expect(label.text()).toBe(enUS.footer.emailLabel);
|
|
303
|
-
expect(label.classes()).toContain('sr-only');
|
|
324
|
+
expect(label.classes()).not.toContain('sr-only');
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it("labels the email field with the form definition's own label", async () => {
|
|
328
|
+
const demo = createDemoStorefront();
|
|
329
|
+
const storefront = {
|
|
330
|
+
...demo,
|
|
331
|
+
forms: {
|
|
332
|
+
...demo.forms,
|
|
333
|
+
definition: (key: string) => {
|
|
334
|
+
const result = demo.forms.definition(key);
|
|
335
|
+
return {
|
|
336
|
+
...result,
|
|
337
|
+
data: computed(() =>
|
|
338
|
+
result.data.value === null
|
|
339
|
+
? null
|
|
340
|
+
: {
|
|
341
|
+
...result.data.value,
|
|
342
|
+
fields: result.data.value.fields.map((field) =>
|
|
343
|
+
field.type === 'email' ? { ...field, label: 'Where should we write?' } : field
|
|
344
|
+
),
|
|
345
|
+
}
|
|
346
|
+
) as typeof result.data,
|
|
347
|
+
};
|
|
348
|
+
},
|
|
349
|
+
},
|
|
350
|
+
};
|
|
351
|
+
const wrapper = mountFooter(mock, { storefront });
|
|
352
|
+
await flushPromises();
|
|
353
|
+
const input = wrapper.get('input[type="email"]');
|
|
354
|
+
expect(wrapper.get(`label[for="${input.attributes('id')}"]`).text()).toBe(
|
|
355
|
+
'Where should we write?'
|
|
356
|
+
);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it("shows the placeholder the form's email field carries, not its label", async () => {
|
|
360
|
+
const wrapper = mountFooter(mock);
|
|
361
|
+
await flushPromises();
|
|
362
|
+
expect(wrapper.get('input[type="email"]').attributes('placeholder')).toBe('name@example.com');
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('keeps the email error in the field cell, directly under the input', async () => {
|
|
366
|
+
const wrapper = mountFooter(mock);
|
|
367
|
+
await flushPromises();
|
|
368
|
+
// The field wrapper is `display: contents` by default, which turns its error into a flex item of
|
|
369
|
+
// its own that lands after the button row; a real block keeps the two together.
|
|
370
|
+
const cell = wrapper.get('input[type="email"]').element.closest('.content-start');
|
|
371
|
+
expect(cell?.parentElement?.classList.contains('block')).toBe(true);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it('keeps the sign-up button and its consent sentence in one column as wide as the form', async () => {
|
|
375
|
+
const wrapper = mountFooter(mock);
|
|
376
|
+
await flushPromises();
|
|
377
|
+
// The library's actions row is `shrink-0` and the grid's auto column follows the sentence's
|
|
378
|
+
// max-content, so both pushed the button past the footer column; happy-dom has no layout,
|
|
379
|
+
// so this guards the two classes that prevent it.
|
|
380
|
+
const actions = wrapper.get('[data-part="consent-sentence"]').element.parentElement;
|
|
381
|
+
expect(actions?.classList.contains('grid-cols-[minmax(0,1fr)]')).toBe(true);
|
|
382
|
+
expect(actions?.parentElement?.classList.contains('w-full')).toBe(true);
|
|
383
|
+
// The form's own 0.25rem row gap leaves the button touching the field; the row adds the rest.
|
|
384
|
+
expect(actions?.parentElement?.classList.contains('mt-3')).toBe(true);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it('shows the platform consent sentence under the sign-up button, tied to it with aria-describedby', async () => {
|
|
388
|
+
const wrapper = mountFooter(mock);
|
|
389
|
+
await flushPromises();
|
|
390
|
+
const sentence = wrapper.get('[data-part="consent-sentence"]');
|
|
391
|
+
expect(sentence.text()).toBe(
|
|
392
|
+
'I want to receive the newsletter from Northwind Goods. I can unsubscribe at any time.'
|
|
393
|
+
);
|
|
394
|
+
expect(wrapper.get('button[type="submit"]').attributes('aria-describedby')).toBe(
|
|
395
|
+
sentence.attributes('id')
|
|
396
|
+
);
|
|
304
397
|
});
|
|
305
398
|
|
|
306
399
|
it('an invalid (malformed) email submit sets aria-invalid, shows the error linked by aria-describedby, and keeps focus in the field', async () => {
|
|
@@ -330,7 +423,7 @@ describe('footer block', () => {
|
|
|
330
423
|
expect(wrapper.text()).toContain(enUS.footer.emailInvalid);
|
|
331
424
|
});
|
|
332
425
|
|
|
333
|
-
it('a valid submit calls forms.
|
|
426
|
+
it('a valid submit calls forms.submit and announces success through role="status"', async () => {
|
|
334
427
|
const wrapper = mountFooter(mock);
|
|
335
428
|
const input = wrapper.find('input[type="email"]');
|
|
336
429
|
await input.setValue('reader@example.com');
|
|
@@ -345,6 +438,30 @@ describe('footer block', () => {
|
|
|
345
438
|
expect(wrapper.find('form').exists()).toBe(false);
|
|
346
439
|
});
|
|
347
440
|
|
|
441
|
+
it('with Turnstile on, renders the widget and honeypot, refuses to send before the check, then sends the token and honeypot', async () => {
|
|
442
|
+
const turnstile = stubTurnstile();
|
|
443
|
+
const subscribe = vi.fn(async () => ({ ok: true as const, pending: false }));
|
|
444
|
+
const wrapper = mountFooter(mock, { subscribe, turnstile: true });
|
|
445
|
+
await flushPromises();
|
|
446
|
+
expect(turnstile.render).toHaveBeenCalledOnce();
|
|
447
|
+
|
|
448
|
+
await wrapper.find('input[type="email"]').setValue('reader@example.com');
|
|
449
|
+
await wrapper.find('form').trigger('submit');
|
|
450
|
+
await flushPromises();
|
|
451
|
+
expect(subscribe).not.toHaveBeenCalled();
|
|
452
|
+
expect(wrapper.text()).toContain(enUS.form.turnstileRequired);
|
|
453
|
+
|
|
454
|
+
turnstile.solve('token-1');
|
|
455
|
+
await wrapper.find('input[name="website"]').setValue('bot');
|
|
456
|
+
await wrapper.find('form').trigger('submit');
|
|
457
|
+
await flushPromises();
|
|
458
|
+
expect(subscribe).toHaveBeenCalledWith('newsletter', {
|
|
459
|
+
values: { email: 'reader@example.com' },
|
|
460
|
+
turnstileToken: 'token-1',
|
|
461
|
+
hp: 'bot',
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
|
|
348
465
|
it('a subscribe failure (backend ok:false) shows an error and keeps focus in the field', async () => {
|
|
349
466
|
const wrapper = mountFooter(mock, { failForms: true });
|
|
350
467
|
const input = wrapper.find('input[type="email"]');
|
|
@@ -367,8 +484,11 @@ describe('footer block', () => {
|
|
|
367
484
|
// removing `@invalid="onNewsletterInvalid"` (or `retryable.value = serviceFailed` in
|
|
368
485
|
// `onNewsletterSubmit`) makes `subscribe` stay called once and the field stay marked invalid
|
|
369
486
|
// forever — confirmed by temporarily reverting each change and observing this test fail.
|
|
370
|
-
const results = [
|
|
371
|
-
|
|
487
|
+
const results: StorefrontFormSubmitResult[] = [
|
|
488
|
+
{ ok: false, reason: 'unavailable' },
|
|
489
|
+
{ ok: true, pending: true },
|
|
490
|
+
];
|
|
491
|
+
const subscribe = vi.fn(async () => results.shift() ?? { ok: true as const, pending: true });
|
|
372
492
|
const wrapper = mountFooter(mock, { subscribe });
|
|
373
493
|
const input = wrapper.find('input[type="email"]');
|
|
374
494
|
await input.setValue('reader@example.com');
|
|
@@ -383,9 +503,8 @@ describe('footer block', () => {
|
|
|
383
503
|
await flushPromises();
|
|
384
504
|
|
|
385
505
|
expect(subscribe).toHaveBeenCalledTimes(2);
|
|
386
|
-
expect(subscribe).toHaveBeenLastCalledWith({
|
|
387
|
-
email: 'reader@example.com',
|
|
388
|
-
list: 'footer-newsletter',
|
|
506
|
+
expect(subscribe).toHaveBeenLastCalledWith('newsletter', {
|
|
507
|
+
values: { email: 'reader@example.com' },
|
|
389
508
|
});
|
|
390
509
|
expect(wrapper.find('form').exists()).toBe(false);
|
|
391
510
|
expect(wrapper.find('[role="status"]').text()).toContain(enUS.footer.subscribed);
|
|
@@ -393,7 +512,7 @@ describe('footer block', () => {
|
|
|
393
512
|
|
|
394
513
|
it('a backend {ok:false, reason:"invalid"} shows the exact same invalid-email message (not the retryable one)', async () => {
|
|
395
514
|
const wrapper = mountFooter(mock, {
|
|
396
|
-
subscribe: async () => ({ ok: false, reason: 'invalid' }),
|
|
515
|
+
subscribe: async () => ({ ok: false, reason: 'invalid', errors: {}, form: [] }),
|
|
397
516
|
});
|
|
398
517
|
const input = wrapper.find('input[type="email"]');
|
|
399
518
|
await input.setValue('reader@example.com');
|
|
Binary file
|