@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
package/template/nuxt.config.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, copyFileSync } from 'node:fs';
|
|
|
2
2
|
import { dirname, join } from 'node:path';
|
|
3
3
|
import { fileURLToPath } from 'node:url';
|
|
4
4
|
import tailwindcss from '@tailwindcss/vite';
|
|
5
|
+
import { starterFormSeeds } from './app/formSeeds';
|
|
5
6
|
import { starterSeeds, starterTemplateRoles } from './app/templates';
|
|
6
7
|
|
|
7
8
|
const rootDir = dirname(fileURLToPath(import.meta.url));
|
|
@@ -97,8 +98,16 @@ export default defineNuxtConfig({
|
|
|
97
98
|
// Keep these exact origins: they are also emitted into the Pages CSP header. More than one
|
|
98
99
|
// (comma-separated in `ELDRA_STUDIO_ORIGIN`) lets one build serve a Studio whose origin is
|
|
99
100
|
// changing — the old and the new origin both allowed until the old one is retired.
|
|
101
|
+
//
|
|
102
|
+
// Defaults to production Studio (`https://eldra.app`), not a local dev origin: a build that
|
|
103
|
+
// forgets to set `ELDRA_STUDIO_ORIGIN` is far more likely to be a staging/production deploy than
|
|
104
|
+
// someone's local theme dev server, and the old `https://localhost:4311` default made that
|
|
105
|
+
// mistake fail silently — the static page still rendered, so nothing looked wrong, but the
|
|
106
|
+
// preview bridge would never connect and the editor would just report "Preview disconnected"
|
|
107
|
+
// with inline editing dead. Local theme development against a local Studio must set
|
|
108
|
+
// `ELDRA_STUDIO_ORIGIN` explicitly.
|
|
100
109
|
eldra: {
|
|
101
|
-
studioOrigins: (process.env.ELDRA_STUDIO_ORIGIN ?? 'https://
|
|
110
|
+
studioOrigins: (process.env.ELDRA_STUDIO_ORIGIN ?? 'https://eldra.app')
|
|
102
111
|
.split(',')
|
|
103
112
|
.map((origin) => origin.trim())
|
|
104
113
|
.filter((origin) => origin.length > 0),
|
|
@@ -127,6 +136,11 @@ export default defineNuxtConfig({
|
|
|
127
136
|
// header and one footer.
|
|
128
137
|
templates: starterSeeds(),
|
|
129
138
|
templateRoles: starterTemplateRoles(),
|
|
139
|
+
// The forms Core creates on the first deploy (only when their key is absent, and never over a
|
|
140
|
+
// merchant's own edits): `contact` and `newsletter`, which the `contact`, `newsletter`,
|
|
141
|
+
// `footer` and `form` blocks submit to. The build also reads each one's definition from the
|
|
142
|
+
// platform and bakes it into the site (`app/formSeeds.ts`, "Forms" in `docs/starter-kit.md`).
|
|
143
|
+
formSeeds: starterFormSeeds(),
|
|
130
144
|
},
|
|
131
145
|
typescript: {
|
|
132
146
|
tsConfig: {
|
package/template/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
@@ -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
|
+
});
|
|
@@ -70,7 +70,8 @@ const mockModules = import.meta.glob<{ default: Record<string, unknown> }>(
|
|
|
70
70
|
registerBlockFields(
|
|
71
71
|
Object.fromEntries(
|
|
72
72
|
manifest.blocks.map((block) => [block.apiId, block.fields])
|
|
73
|
-
) as unknown as BlockFieldsMap
|
|
73
|
+
) as unknown as BlockFieldsMap,
|
|
74
|
+
manifest.theme.id
|
|
74
75
|
);
|
|
75
76
|
|
|
76
77
|
const blocks = Object.entries(blockModules)
|
|
@@ -9,11 +9,7 @@ import { formatMoney } from '../app/storefront/money';
|
|
|
9
9
|
* One formatter for every currency on the storefront, and it is the public one.
|
|
10
10
|
*
|
|
11
11
|
* `@eldrajs/ui`'s `formatCurrency` (and the `<Price>`/`<ProductCard>`/`<CurrencyInput>` components
|
|
12
|
-
* that format through it)
|
|
13
|
-
* `2.800 kr.` on an Icelandic one. A hand-built `Intl.NumberFormat({ style: 'currency' })` writes
|
|
14
|
-
* the *wide* sign instead (`ISK 2,800`), and the two look nothing alike on the same page: that is
|
|
15
|
-
* exactly how this theme came to show `ISK 2,800` in an Add-to-cart label beside a `<Price>`
|
|
16
|
-
* reading `kr 2,800` for the same money.
|
|
12
|
+
* that format through it) is the one formatter, so every price on a page writes the same sign.
|
|
17
13
|
*
|
|
18
14
|
* So no block and no app module may build a currency formatter of its own. `app/storefront/money.ts`
|
|
19
15
|
* is the single exception — it is the module that calls the public util — and it builds only a
|
|
@@ -78,12 +74,12 @@ describe('money is formatted in exactly one place', () => {
|
|
|
78
74
|
expect(offenders).toEqual([]);
|
|
79
75
|
});
|
|
80
76
|
|
|
81
|
-
it('formats through the public util, which is what gives every price the
|
|
77
|
+
it('formats through the public util, which is what gives every price the same sign', () => {
|
|
82
78
|
// The module under the exception, held to the util it exists to call.
|
|
83
79
|
expect(formatMoney(2800, 'ISK', 'en-US')).toBe(
|
|
84
|
-
formatCurrency(2800, 'en-US', 'ISK',
|
|
80
|
+
formatCurrency(2800, 'en-US', 'ISK', false, 0, 0)
|
|
85
81
|
);
|
|
86
|
-
expect(formatMoney(2800, 'ISK', 'en-US')).toBe('
|
|
82
|
+
expect(formatMoney(2800, 'ISK', 'en-US')).toBe('ISK\u00a02,800');
|
|
87
83
|
expect(formatMoney(2800, 'ISK', 'is-IS')).toBe('2.800\u00a0kr.');
|
|
88
84
|
});
|
|
89
85
|
});
|
|
@@ -353,14 +353,9 @@ describe('server rendering', () => {
|
|
|
353
353
|
});
|
|
354
354
|
|
|
355
355
|
/**
|
|
356
|
-
* And the sign is the
|
|
357
|
-
* later. `is-IS` writes `kr.` either way, so the sign is only a choice on a page in another
|
|
358
|
-
* locale: an English page of the same krónur store must prerender `kr 96`, never `ISK 96`.
|
|
359
|
-
* The wide sign is what a hand-built `{ style: 'currency' }` formatter writes, and it reached
|
|
360
|
-
* the HTML of every price on the page — both the `<Price>` elements and the formatted labels
|
|
361
|
-
* beside them.
|
|
356
|
+
* And the sign is the wide one on an English page (`ISK 96`), in every price and label alike.
|
|
362
357
|
*/
|
|
363
|
-
it('server-renders the store’s currency in its
|
|
358
|
+
it('server-renders the store’s currency in its wide sign, never a bare "kr"', async () => {
|
|
364
359
|
const commerce = { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 };
|
|
365
360
|
const html = await renderPageToString(productPage as unknown as PageFixture, {
|
|
366
361
|
[CURRENCY_KEY]: commerce.currency,
|
|
@@ -369,10 +364,9 @@ describe('server rendering', () => {
|
|
|
369
364
|
});
|
|
370
365
|
|
|
371
366
|
expect(html).toContain(formatMoney(96, 'ISK', 'en-US'));
|
|
372
|
-
expect(formatMoney(96, 'ISK', 'en-US')).toBe('
|
|
373
|
-
// Not the
|
|
374
|
-
|
|
375
|
-
expect(html).not.toMatch(/ISK(\s| )\d/);
|
|
367
|
+
expect(formatMoney(96, 'ISK', 'en-US')).toBe('ISK\u00a096');
|
|
368
|
+
// Not the narrow sign in front of an amount, anywhere: not in a price, not in a button label.
|
|
369
|
+
expect(html).not.toMatch(/\bkr(\s| )\d/);
|
|
376
370
|
});
|
|
377
371
|
|
|
378
372
|
it('server-renders product-carousel with real cards, and no skeleton', async () => {
|
|
@@ -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
|
});
|
|
@@ -49,14 +49,17 @@ const body = {
|
|
|
49
49
|
* not the test's invention.
|
|
50
50
|
*/
|
|
51
51
|
function registerArticleFields(): void {
|
|
52
|
-
registerBlockFields(
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
registerBlockFields(
|
|
53
|
+
{
|
|
54
|
+
article: blockManifest.fields.map((field) => ({
|
|
55
|
+
fieldId: field.fieldId,
|
|
56
|
+
type: field.type,
|
|
57
|
+
...(field.localized === true ? { localized: true } : {}),
|
|
58
|
+
...(field.metadata === undefined ? {} : { metadata: field.metadata }),
|
|
59
|
+
})),
|
|
60
|
+
},
|
|
61
|
+
'starter'
|
|
62
|
+
);
|
|
60
63
|
}
|
|
61
64
|
|
|
62
65
|
/** A preview bridge attached with an active content locale. */
|
|
@@ -84,7 +87,7 @@ function mountArticle(context?: unknown, doc: unknown = body) {
|
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
afterEach(() => {
|
|
87
|
-
registerBlockFields({});
|
|
90
|
+
registerBlockFields({}, 'starter');
|
|
88
91
|
});
|
|
89
92
|
|
|
90
93
|
describe('article body renders through EldraRichText', () => {
|
|
@@ -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 } }),
|