@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
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// GENERATED FILE — do not edit by hand.
|
|
2
|
+
// Regenerated by scripts/generate-stories.mjs (run automatically by
|
|
3
|
+
// `storybook dev` / `build-storybook`, or directly with
|
|
4
|
+
// `node scripts/generate-stories.mjs`) from blocks/*/block.json + mock.json
|
|
5
|
+
// (+ preview.json, when the block has one).
|
|
6
|
+
import type { Meta, StoryObj } from '@storybook/vue3-vite';
|
|
7
|
+
import Block from '../../blocks/form/Block.vue';
|
|
8
|
+
import mock from '../../blocks/form/mock.json';
|
|
9
|
+
|
|
10
|
+
const meta: Meta<typeof Block> = {
|
|
11
|
+
title: "Blocks/form",
|
|
12
|
+
component: Block,
|
|
13
|
+
};
|
|
14
|
+
export default meta;
|
|
15
|
+
|
|
16
|
+
type Story = StoryObj<typeof Block>;
|
|
17
|
+
|
|
18
|
+
const base = mock;
|
|
19
|
+
|
|
20
|
+
export const Default: Story = {
|
|
21
|
+
args: { entry: { id: "form", data: base } },
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const Inserted: Story = {
|
|
25
|
+
args: { entry: { id: "form", data: mock } },
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const PresetDefault: Story = {
|
|
29
|
+
args: {
|
|
30
|
+
entry: { id: "form", data: { ...base, "preset": "default" } },
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const PresetInline: Story = {
|
|
35
|
+
args: {
|
|
36
|
+
entry: { id: "form", data: { ...base, "preset": "inline" } },
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const SectionBackgroundNone: Story = {
|
|
41
|
+
args: {
|
|
42
|
+
entry: { id: "form", data: { ...base, "sectionBackground": "none" } },
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export const SectionBackgroundSurface: Story = {
|
|
47
|
+
args: {
|
|
48
|
+
entry: { id: "form", data: { ...base, "sectionBackground": "surface" } },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const SectionBackgroundSurfaceStrong: Story = {
|
|
53
|
+
args: {
|
|
54
|
+
entry: { id: "form", data: { ...base, "sectionBackground": "surface-strong" } },
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const SectionBackgroundPrimary: Story = {
|
|
59
|
+
args: {
|
|
60
|
+
entry: { id: "form", data: { ...base, "sectionBackground": "primary" } },
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const SectionBackgroundAccent: Story = {
|
|
65
|
+
args: {
|
|
66
|
+
entry: { id: "form", data: { ...base, "sectionBackground": "accent" } },
|
|
67
|
+
},
|
|
68
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { validateField } from '../blocks/form/validate';
|
|
3
|
+
import type { StorefrontFormField } from '../app/storefront/types';
|
|
4
|
+
|
|
5
|
+
const t = (key: string): string => key;
|
|
6
|
+
const text = (validation: StorefrontFormField['validation']): StorefrontFormField => ({
|
|
7
|
+
id: 'code',
|
|
8
|
+
type: 'text',
|
|
9
|
+
required: false,
|
|
10
|
+
label: 'Code',
|
|
11
|
+
validation,
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
describe('validateField', () => {
|
|
15
|
+
it('matches a pattern against the whole value, as the platform does', () => {
|
|
16
|
+
const field = text({ pattern: '[0-9]{3}' });
|
|
17
|
+
expect(validateField(field, '123', t)).toBeNull();
|
|
18
|
+
expect(validateField(field, 'abc123def', t)).toBe('form.invalidFormat');
|
|
19
|
+
expect(validateField(field, '1234', t)).toBe('form.invalidFormat');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('keeps an alternation inside the whole-value match', () => {
|
|
23
|
+
const field = text({ pattern: 'ab|cd' });
|
|
24
|
+
expect(validateField(field, 'cd', t)).toBeNull();
|
|
25
|
+
expect(validateField(field, 'abcd', t)).toBe('form.invalidFormat');
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('accepts only a finite number in a number field', () => {
|
|
29
|
+
const field: StorefrontFormField = { id: 'qty', type: 'number', required: true, label: 'Qty' };
|
|
30
|
+
for (const ok of ['12', '-3.5', '.5', '1e3', '3,5']) {
|
|
31
|
+
expect(validateField(field, ok, t)).toBeNull();
|
|
32
|
+
}
|
|
33
|
+
for (const bad of ['abc', '1,2,3', '1e999', '12px']) {
|
|
34
|
+
expect(validateField(field, bad, t)).toBe('form.invalidNumber');
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('accepts only an absolute http(s) address in a url field', () => {
|
|
39
|
+
const field: StorefrontFormField = { id: 'site', type: 'url', required: false, label: 'Site' };
|
|
40
|
+
expect(validateField(field, 'https://example.com/a?b=1', t)).toBeNull();
|
|
41
|
+
expect(validateField(field, '', t)).toBeNull();
|
|
42
|
+
for (const bad of ['example.com', 'javascript:alert(1)', 'ftp://x.test']) {
|
|
43
|
+
expect(validateField(field, bad, t)).toBe('form.invalidUrl');
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -81,7 +81,7 @@ describe('a prerendered route whose resolution failed', () => {
|
|
|
81
81
|
symlinkSync(join(templateDir, 'node_modules'), join(root, 'node_modules'), 'dir');
|
|
82
82
|
const run = await execa(nuxi, ['generate'], {
|
|
83
83
|
cwd: root,
|
|
84
|
-
env: { ELDRA_GATEWAY_URL: gateway.url, ELDRA_ORG_ID: ORG_ID },
|
|
84
|
+
env: { ELDRA_GATEWAY_URL: gateway.url, ELDRA_ORG_ID: ORG_ID, ELDRA_BUILD_TARGET: 'preview' },
|
|
85
85
|
reject: false,
|
|
86
86
|
timeout: 600_000,
|
|
87
87
|
});
|
|
@@ -395,7 +395,7 @@ describe('prerendered commerce data on the generated static site', () => {
|
|
|
395
395
|
);
|
|
396
396
|
const generated = await execa(nuxi, ['generate'], {
|
|
397
397
|
cwd: root,
|
|
398
|
-
env: { ELDRA_GATEWAY_URL: gateway.url, ELDRA_ORG_ID: ORG_ID },
|
|
398
|
+
env: { ELDRA_GATEWAY_URL: gateway.url, ELDRA_ORG_ID: ORG_ID, ELDRA_BUILD_TARGET: 'preview' },
|
|
399
399
|
reject: false,
|
|
400
400
|
timeout: 600_000,
|
|
401
401
|
});
|
|
@@ -1017,6 +1017,10 @@ describe('prerendered commerce data on the generated static site', () => {
|
|
|
1017
1017
|
'storefront:catalog.collectionProducts:[null,{"page":1,"pageSize":8}]',
|
|
1018
1018
|
'storefront:catalog.product:["ash-glaze-mug"]',
|
|
1019
1019
|
'storefront:catalog.related:["ash-glaze-mug",8]',
|
|
1020
|
+
// The footer's sign-up spam guard (`useFormSpam`): a footer with no newsletter zone names no
|
|
1021
|
+
// form, so the read is keyed `""`, resolves `null` without a request and is in the payload
|
|
1022
|
+
// because it exists.
|
|
1023
|
+
'storefront:forms.definition:["","en-US"]',
|
|
1020
1024
|
'storefront:search.run:[""]',
|
|
1021
1025
|
]);
|
|
1022
1026
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { SEEDED_PAGE_SLUGS } from '../app/seededPages';
|
|
3
|
+
import { starterPages } from '../app/templates';
|
|
4
|
+
|
|
5
|
+
describe('SEEDED_PAGE_SLUGS', () => {
|
|
6
|
+
it('lists exactly the pages the theme seeds', () => {
|
|
7
|
+
expect([...SEEDED_PAGE_SLUGS].sort()).toEqual(
|
|
8
|
+
starterPages()
|
|
9
|
+
.map((seed) => seed.page.slug)
|
|
10
|
+
.sort()
|
|
11
|
+
);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { seoInput, type SeoInputParts } from '../app/utils/seoInput';
|
|
3
|
+
|
|
4
|
+
const base: SeoInputParts = {
|
|
5
|
+
isNotFound: false,
|
|
6
|
+
notFoundTitle: 'Page not found',
|
|
7
|
+
catalog: null,
|
|
8
|
+
entry: null,
|
|
9
|
+
page: null,
|
|
10
|
+
template: null,
|
|
11
|
+
path: '/',
|
|
12
|
+
locales: [],
|
|
13
|
+
formatPrice: (amount) => `${amount} kr.`,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe('seoInput', () => {
|
|
17
|
+
it('builds the product variables, the lowest price and the first image', () => {
|
|
18
|
+
const input = seoInput({
|
|
19
|
+
...base,
|
|
20
|
+
path: '/products/mug',
|
|
21
|
+
catalog: { kind: 'product', slug: 'mug' },
|
|
22
|
+
template: { data: { title: 'Product' } },
|
|
23
|
+
entry: {
|
|
24
|
+
data: {
|
|
25
|
+
title: 'Mug',
|
|
26
|
+
description: {
|
|
27
|
+
type: 'doc',
|
|
28
|
+
content: [{ type: 'paragraph', content: [{ type: 'text', text: 'Hand thrown.' }] }],
|
|
29
|
+
},
|
|
30
|
+
variants: [
|
|
31
|
+
{ sku: 'M-1', price: 3000 },
|
|
32
|
+
{ sku: 'M-2', price: 2800 },
|
|
33
|
+
],
|
|
34
|
+
images: [
|
|
35
|
+
{
|
|
36
|
+
url: 'https://media.example/public/11111111-1111-1111-1111-111111111111/assets/22222222-2222-2222-2222-222222222222/sm',
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
expect(input.context).toBe('catalog:product');
|
|
43
|
+
expect(input.data).toMatchObject({
|
|
44
|
+
'page.title': 'Mug',
|
|
45
|
+
'product.name': 'Mug',
|
|
46
|
+
'product.sku': 'M-1',
|
|
47
|
+
'product.price': '2800 kr.',
|
|
48
|
+
'product.shortDescription': 'Hand thrown.',
|
|
49
|
+
});
|
|
50
|
+
expect(input.options.contentImage).toMatch(/\/lg$/);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('sets product.brand from the projection and product.category from the resolved name', () => {
|
|
54
|
+
const input = seoInput({
|
|
55
|
+
...base,
|
|
56
|
+
catalog: { kind: 'product', slug: 'mug' },
|
|
57
|
+
productCategory: 'Mugs',
|
|
58
|
+
entry: { data: { title: 'Mug', brand: 'Acme', variants: [] } },
|
|
59
|
+
});
|
|
60
|
+
expect(input.data).toMatchObject({ 'product.brand': 'Acme', 'product.category': 'Mugs' });
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('leaves product.brand and product.category empty when the product has none', () => {
|
|
64
|
+
const input = seoInput({
|
|
65
|
+
...base,
|
|
66
|
+
catalog: { kind: 'product', slug: 'mug' },
|
|
67
|
+
entry: { data: { title: 'Mug' } },
|
|
68
|
+
});
|
|
69
|
+
expect(input.data).toMatchObject({ 'product.brand': '', 'product.category': '' });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('leaves a missing price empty instead of inventing one', () => {
|
|
73
|
+
const input = seoInput({
|
|
74
|
+
...base,
|
|
75
|
+
catalog: { kind: 'product', slug: 'x' },
|
|
76
|
+
entry: { data: { title: 'X', variants: [{ sku: 'a', price: null }] } },
|
|
77
|
+
});
|
|
78
|
+
expect(input.data['product.price']).toBe('');
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('builds collection and category variables', () => {
|
|
82
|
+
const collection = seoInput({
|
|
83
|
+
...base,
|
|
84
|
+
catalog: { kind: 'collection', slug: 'mugs' },
|
|
85
|
+
entry: { data: { title: 'Mugs', description: 'All mugs', productCount: 12 } },
|
|
86
|
+
});
|
|
87
|
+
expect(collection.context).toBe('catalog:collection');
|
|
88
|
+
expect(collection.data).toMatchObject({
|
|
89
|
+
'collection.name': 'Mugs',
|
|
90
|
+
'collection.description': 'All mugs',
|
|
91
|
+
'collection.productCount': 12,
|
|
92
|
+
});
|
|
93
|
+
const category = seoInput({
|
|
94
|
+
...base,
|
|
95
|
+
catalog: { kind: 'category', slug: 'chairs' },
|
|
96
|
+
entry: { data: { title: 'Chairs' } },
|
|
97
|
+
});
|
|
98
|
+
expect(category.data['category.name']).toBe('Chairs');
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('knows the home page under a locale prefix', () => {
|
|
102
|
+
expect(seoInput({ ...base, path: '/is-IS/', locales: ['en-US', 'is-IS'] }).context).toBe(
|
|
103
|
+
'home'
|
|
104
|
+
);
|
|
105
|
+
expect(seoInput({ ...base, path: '/is-IS/about', locales: ['en-US', 'is-IS'] }).context).toBe(
|
|
106
|
+
'page'
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('ignores a blank title and a non-object seo value', () => {
|
|
111
|
+
const input = seoInput({
|
|
112
|
+
...base,
|
|
113
|
+
path: '/about',
|
|
114
|
+
page: { data: { title: ' ', seo: 'nope' } },
|
|
115
|
+
});
|
|
116
|
+
expect(input.data['page.title']).toBe('');
|
|
117
|
+
expect(input.options.entry).toBeNull();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @vitest-environment jsdom
|
|
2
2
|
//
|
|
3
3
|
// `app/pages/[...slug].vue` reads `useEldraPage()`, `useRoute()`, and
|
|
4
|
-
// `
|
|
4
|
+
// `useEldraSeo()` as bare Nuxt-auto-imported globals (no imports in the source
|
|
5
5
|
// file — see test/useEldraIcon.test.ts for the same pattern). Outside a
|
|
6
6
|
// Nuxt build we install them ourselves with `vi.stubGlobal` before mounting,
|
|
7
7
|
// the same technique used there. `NuxtLink` is stubbed via `global.stubs` so
|
|
@@ -71,7 +71,11 @@ describe('[...slug].vue not-found vs. error branch priority', () => {
|
|
|
71
71
|
|
|
72
72
|
it('renders the not-found shell, not the error alert, for /404 even when useEldraPage reports an error', () => {
|
|
73
73
|
vi.stubGlobal('useRoute', () => ({ path: '/404' }));
|
|
74
|
-
vi.stubGlobal('
|
|
74
|
+
vi.stubGlobal('useEldraSeo', () => {});
|
|
75
|
+
vi.stubGlobal('usePageStructuredData', () => {});
|
|
76
|
+
vi.stubGlobal('useStorefront', () => ({
|
|
77
|
+
catalog: { product: () => ({ data: { value: null } }) },
|
|
78
|
+
}));
|
|
75
79
|
vi.stubGlobal('useEldraPage', () => ({
|
|
76
80
|
page: ref(null),
|
|
77
81
|
template: ref(null),
|
|
@@ -93,7 +97,11 @@ describe('[...slug].vue not-found vs. error branch priority', () => {
|
|
|
93
97
|
|
|
94
98
|
it('renders the error alert, not the not-found shell, for a real route with an error', () => {
|
|
95
99
|
vi.stubGlobal('useRoute', () => ({ path: '/some-real-page' }));
|
|
96
|
-
vi.stubGlobal('
|
|
100
|
+
vi.stubGlobal('useEldraSeo', () => {});
|
|
101
|
+
vi.stubGlobal('usePageStructuredData', () => {});
|
|
102
|
+
vi.stubGlobal('useStorefront', () => ({
|
|
103
|
+
catalog: { product: () => ({ data: { value: null } }) },
|
|
104
|
+
}));
|
|
97
105
|
vi.stubGlobal('useEldraPage', () => ({
|
|
98
106
|
page: ref(null),
|
|
99
107
|
template: ref(null),
|
|
@@ -120,7 +128,11 @@ describe('[...slug].vue not-found vs. error branch priority', () => {
|
|
|
120
128
|
// above the navigation it exists to skip. The rule itself is `app/utils/pageStructure.ts`.
|
|
121
129
|
it('renders the header blocks before <main> and a trailing footer after it', () => {
|
|
122
130
|
vi.stubGlobal('useRoute', () => ({ path: '/' }));
|
|
123
|
-
vi.stubGlobal('
|
|
131
|
+
vi.stubGlobal('useEldraSeo', () => {});
|
|
132
|
+
vi.stubGlobal('usePageStructuredData', () => {});
|
|
133
|
+
vi.stubGlobal('useStorefront', () => ({
|
|
134
|
+
catalog: { product: () => ({ data: { value: null } }) },
|
|
135
|
+
}));
|
|
124
136
|
const blocks = [
|
|
125
137
|
{ id: 'b1', schemaApiId: 'announcement-bar' },
|
|
126
138
|
{ id: 'b2', schemaApiId: 'navigation' },
|
|
@@ -173,7 +185,11 @@ describe('[...slug].vue not-found vs. error branch priority', () => {
|
|
|
173
185
|
// also render the blocks `EldraLayout` is already rendering.
|
|
174
186
|
it('renders a layout-driven page through EldraLayout alone, with no extra zones', () => {
|
|
175
187
|
vi.stubGlobal('useRoute', () => ({ path: '/' }));
|
|
176
|
-
vi.stubGlobal('
|
|
188
|
+
vi.stubGlobal('useEldraSeo', () => {});
|
|
189
|
+
vi.stubGlobal('usePageStructuredData', () => {});
|
|
190
|
+
vi.stubGlobal('useStorefront', () => ({
|
|
191
|
+
catalog: { product: () => ({ data: { value: null } }) },
|
|
192
|
+
}));
|
|
177
193
|
vi.stubGlobal('useEldraPage', () => ({
|
|
178
194
|
page: ref({ data: { title: 'Home' } }),
|
|
179
195
|
template: ref(null),
|
|
@@ -197,18 +213,22 @@ describe('[...slug].vue not-found vs. error branch priority', () => {
|
|
|
197
213
|
});
|
|
198
214
|
});
|
|
199
215
|
|
|
200
|
-
describe('[...slug].vue
|
|
216
|
+
describe('[...slug].vue SEO input', () => {
|
|
201
217
|
afterEach(() => {
|
|
202
218
|
vi.unstubAllGlobals();
|
|
203
219
|
});
|
|
204
220
|
|
|
205
|
-
/** `
|
|
206
|
-
function
|
|
207
|
-
let
|
|
208
|
-
vi.stubGlobal('useRoute', () => ({ path
|
|
209
|
-
vi.stubGlobal('
|
|
210
|
-
|
|
221
|
+
/** `useEldraSeo` is called with getters, so the resolved input is read back by calling them. */
|
|
222
|
+
function seoFor(page: Record<string, unknown>, path = '/products/ash-glaze-mug') {
|
|
223
|
+
let args: unknown[] = [];
|
|
224
|
+
vi.stubGlobal('useRoute', () => ({ path }));
|
|
225
|
+
vi.stubGlobal('useEldraSeo', (...received: unknown[]) => {
|
|
226
|
+
args = received;
|
|
211
227
|
});
|
|
228
|
+
vi.stubGlobal('usePageStructuredData', () => {});
|
|
229
|
+
vi.stubGlobal('useStorefront', () => ({
|
|
230
|
+
catalog: { product: () => ({ data: { value: null } }) },
|
|
231
|
+
}));
|
|
212
232
|
vi.stubGlobal('useEldraPage', () => ({
|
|
213
233
|
page: ref(null),
|
|
214
234
|
template: ref(null),
|
|
@@ -222,23 +242,39 @@ describe('[...slug].vue document title', () => {
|
|
|
222
242
|
...page,
|
|
223
243
|
}));
|
|
224
244
|
mount(SlugPage, { global: mountGlobal });
|
|
225
|
-
|
|
245
|
+
const [context, data, options] = args as [() => unknown, () => unknown, () => unknown];
|
|
246
|
+
return { context: context(), data: data() as Record<string, unknown>, options: options() };
|
|
226
247
|
}
|
|
227
248
|
|
|
228
|
-
it('
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
).
|
|
249
|
+
it('names a catalog route after the product, not the template, and uses the template’s seo', () => {
|
|
250
|
+
const seo = seoFor({
|
|
251
|
+
template: ref({ data: { title: 'Product', seo: { noindex: true } } }),
|
|
252
|
+
entry: ref({ data: { title: 'Ash glaze mug' } }),
|
|
253
|
+
catalog: computed(() => ({ kind: 'product', slug: 'ash-glaze-mug' })),
|
|
254
|
+
blocks: computed(() => [{ id: 'b1', schemaApiId: 'product-detail' }]),
|
|
255
|
+
});
|
|
256
|
+
expect(seo.context).toBe('catalog:product');
|
|
257
|
+
expect(seo.data['page.title']).toBe('Ash glaze mug');
|
|
258
|
+
expect(seo.data['product.name']).toBe('Ash glaze mug');
|
|
259
|
+
expect(seo.options).toMatchObject({ entry: null, template: { noindex: true } });
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('passes an ordinary page’s own title and seo field', () => {
|
|
263
|
+
const seo = seoFor(
|
|
264
|
+
{ page: ref({ data: { title: 'About us', seo: { description: 'Who we are' } } }) },
|
|
265
|
+
'/about'
|
|
266
|
+
);
|
|
267
|
+
expect(seo.context).toBe('page');
|
|
268
|
+
expect(seo.data['page.title']).toBe('About us');
|
|
269
|
+
expect(seo.options).toMatchObject({ entry: { description: 'Who we are' } });
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('treats / as the home page', () => {
|
|
273
|
+
expect(seoFor({ page: ref({ data: { title: 'Home' } }) }, '/').context).toBe('home');
|
|
239
274
|
});
|
|
240
275
|
|
|
241
|
-
it('titles
|
|
242
|
-
|
|
276
|
+
it('titles the not-found shell itself and keeps it out of the index', () => {
|
|
277
|
+
const seo = seoFor({}, '/404');
|
|
278
|
+
expect(seo.options).toMatchObject({ entry: { title: 'Page not found', noindex: true } });
|
|
243
279
|
});
|
|
244
280
|
});
|
|
@@ -116,7 +116,11 @@ const projection = {
|
|
|
116
116
|
function stubTemplateRoute(options: { layout?: unknown; projection?: unknown } = {}): void {
|
|
117
117
|
const layout = options.layout ?? previewLayout;
|
|
118
118
|
vi.stubGlobal('useRoute', () => ({ path: '/products/ash-glaze-mug' }));
|
|
119
|
-
vi.stubGlobal('
|
|
119
|
+
vi.stubGlobal('useEldraSeo', () => {});
|
|
120
|
+
vi.stubGlobal('usePageStructuredData', () => {});
|
|
121
|
+
vi.stubGlobal('useStorefront', () => ({
|
|
122
|
+
catalog: { product: () => ({ data: { value: null } }) },
|
|
123
|
+
}));
|
|
120
124
|
vi.stubGlobal('useEldraPage', () => ({
|
|
121
125
|
page: ref(null),
|
|
122
126
|
template: ref({ id: 'rt-product', data: { title: 'Product', layout } }),
|
|
@@ -8,6 +8,7 @@ import { execa } from 'execa';
|
|
|
8
8
|
import { scanTheme } from '@eldrajs/vite-plugin-theme/scan';
|
|
9
9
|
import { encodeStega } from '@eldrajs/theme-core/stega';
|
|
10
10
|
import { safeHref } from '../app/utils/links';
|
|
11
|
+
import { starterFormSeeds } from '../app/formSeeds';
|
|
11
12
|
import { starterSeeds, starterTemplateRoles, stripSeedMedia } from '../app/templates';
|
|
12
13
|
|
|
13
14
|
const templateDir = fileURLToPath(new URL('..', import.meta.url));
|
|
@@ -35,6 +36,7 @@ const expectedBlocks = [
|
|
|
35
36
|
'faq',
|
|
36
37
|
'feature-grid',
|
|
37
38
|
'footer',
|
|
39
|
+
'form',
|
|
38
40
|
'gallery',
|
|
39
41
|
'hero',
|
|
40
42
|
'image',
|
|
@@ -102,7 +104,7 @@ describe('starter theme', () => {
|
|
|
102
104
|
])
|
|
103
105
|
);
|
|
104
106
|
const expectedFields: Record<string, string[]> = {
|
|
105
|
-
// Every one of the
|
|
107
|
+
// Every one of the 35 blocks has its field list here — the map used to cover 31, leaving
|
|
106
108
|
// `announcement-bar` and `newsletter` with only the manifest version rule behind a field
|
|
107
109
|
// rename or reorder, not the explicit list every sibling block has.
|
|
108
110
|
'announcement-bar': ['variant', 'message', 'linkLabel', 'linkHref', 'dismissable'],
|
|
@@ -118,7 +120,17 @@ describe('starter theme', () => {
|
|
|
118
120
|
'consentCheckboxLabel',
|
|
119
121
|
'successTitle',
|
|
120
122
|
'successText',
|
|
121
|
-
'
|
|
123
|
+
'formKey',
|
|
124
|
+
'sectionBackground',
|
|
125
|
+
],
|
|
126
|
+
form: [
|
|
127
|
+
'preset',
|
|
128
|
+
'formKey',
|
|
129
|
+
'heading',
|
|
130
|
+
'text',
|
|
131
|
+
'buttonLabel',
|
|
132
|
+
'consent',
|
|
133
|
+
'successTitle',
|
|
122
134
|
'sectionBackground',
|
|
123
135
|
],
|
|
124
136
|
hero: [
|
|
@@ -297,7 +309,6 @@ describe('starter theme', () => {
|
|
|
297
309
|
'formTitle',
|
|
298
310
|
'topics',
|
|
299
311
|
'showOrderNumber',
|
|
300
|
-
'recipient',
|
|
301
312
|
'successText',
|
|
302
313
|
],
|
|
303
314
|
'video-embed': [
|
|
@@ -875,6 +886,8 @@ describe('seeded templates and pages (app/templates.ts)', () => {
|
|
|
875
886
|
// page seeds in one list, exactly as `eldra.templates` takes them.
|
|
876
887
|
templates: starterSeeds(),
|
|
877
888
|
templateRoles: starterTemplateRoles(),
|
|
889
|
+
// What `nuxt.config.ts` passes as `eldra.formSeeds`.
|
|
890
|
+
formSeeds: starterFormSeeds(),
|
|
878
891
|
});
|
|
879
892
|
|
|
880
893
|
/** The blocks of one `pages/<name>.page.json` fixture in order, minus the two role blocks. */
|
|
@@ -887,6 +900,31 @@ describe('seeded templates and pages (app/templates.ts)', () => {
|
|
|
887
900
|
.filter((block) => block.apiId !== 'navigation' && block.apiId !== 'footer')
|
|
888
901
|
.map((block) => `${block.apiId}#${block.id}`);
|
|
889
902
|
|
|
903
|
+
/**
|
|
904
|
+
* The forms the blocks submit to must exist on a fresh site: `contact` (the contact block) and
|
|
905
|
+
* `newsletter` (the newsletter block's default and the footer's sign-up zone). A block that
|
|
906
|
+
* names a form no seed creates renders "this form can't be shown" until a merchant builds it.
|
|
907
|
+
*/
|
|
908
|
+
it('seeds the contact and newsletter forms the starter blocks submit to', () => {
|
|
909
|
+
expect(scanned.errors).toEqual([]);
|
|
910
|
+
const forms = scanned.manifest!.formSeeds!;
|
|
911
|
+
expect(forms.map((form) => form.key)).toEqual(['contact', 'newsletter']);
|
|
912
|
+
// The newsletter carries its consent sentence in both shipped locales, with the shop placeholder.
|
|
913
|
+
expect(forms[1]!.actions.subscribe?.list).toBe('newsletter');
|
|
914
|
+
expect(Object.keys(forms[1]!.actions.subscribe?.consentText ?? {})).toEqual(['en-US', 'is-IS']);
|
|
915
|
+
for (const text of Object.values(forms[1]!.actions.subscribe?.consentText ?? {})) {
|
|
916
|
+
expect(text).toContain('{shop}');
|
|
917
|
+
}
|
|
918
|
+
// The contact block sends exactly these values (`blocks/contact/Block.vue`).
|
|
919
|
+
expect(forms[0]!.fields.map((field) => field.id)).toEqual([
|
|
920
|
+
'name',
|
|
921
|
+
'email',
|
|
922
|
+
'topic',
|
|
923
|
+
'orderNumber',
|
|
924
|
+
'message',
|
|
925
|
+
]);
|
|
926
|
+
});
|
|
927
|
+
|
|
890
928
|
/**
|
|
891
929
|
* The emitted page-seed wire shape, which Core decodes strictly — an unknown key fails the whole
|
|
892
930
|
* manifest ingest, so this asserts the *exact* object rather than a subset.
|