@eldrajs/theme-cli 0.2.9 → 0.2.11

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 (169) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/package.json +3 -3
  3. package/template/.eldra/block-types.d.ts +4 -6
  4. package/template/.eldra/manifest.json +228 -246
  5. package/template/.eldra/previews.json +35 -35
  6. package/template/.storybook/eldra.ts +7 -2
  7. package/template/app/assets/main.css +5 -0
  8. package/template/app/composables/useBlockData.ts +9 -2
  9. package/template/app/composables/usePriceTokens.ts +150 -0
  10. package/template/app/composables/useQuickAdd.ts +95 -0
  11. package/template/app/composables/useRegionalFormat.ts +94 -0
  12. package/template/app/icons.ts +4 -0
  13. package/template/app/plugins/eldra-storefront.ts +2 -0
  14. package/template/app/plugins/eldra-ui-messages.ts +22 -8
  15. package/template/app/storefront/demo.ts +188 -16
  16. package/template/app/storefront/gateway.ts +19 -0
  17. package/template/app/storefront/productCardLook.ts +76 -0
  18. package/template/app/storefront/productReference.ts +17 -0
  19. package/template/app/storefront/toProductCard.ts +12 -8
  20. package/template/app/storefront/types.ts +17 -0
  21. package/template/blocks/announcement-bar/__tests__/Block.spec.ts +19 -7
  22. package/template/blocks/announcement-bar/block.json +2 -1
  23. package/template/blocks/announcement-bar/mock.json +1 -1
  24. package/template/blocks/announcement-bar/preview.png +0 -0
  25. package/template/blocks/article/Block.vue +8 -18
  26. package/template/blocks/article/block.json +3 -1
  27. package/template/blocks/article/preview.png +0 -0
  28. package/template/blocks/article-list/block.json +10 -1
  29. package/template/blocks/article-list/preview.png +0 -0
  30. package/template/blocks/breadcrumbs/Block.vue +15 -3
  31. package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +13 -0
  32. package/template/blocks/breadcrumbs/block.json +1 -0
  33. package/template/blocks/breadcrumbs/preview.png +0 -0
  34. package/template/blocks/cart/Block.vue +15 -5
  35. package/template/blocks/cart/__tests__/Block.spec.ts +53 -10
  36. package/template/blocks/cart/__tests__/ShippingBar.spec.ts +10 -8
  37. package/template/blocks/cart/block.json +8 -5
  38. package/template/blocks/cart/mock.json +2 -2
  39. package/template/blocks/cart/parts/ShippingBar.vue +24 -30
  40. package/template/blocks/cart/parts/notSold.ts +4 -3
  41. package/template/blocks/collection-grid/Block.vue +168 -85
  42. package/template/blocks/collection-grid/__tests__/Block.spec.ts +101 -23
  43. package/template/blocks/collection-grid/preview.png +0 -0
  44. package/template/blocks/collection-header/Block.vue +51 -17
  45. package/template/blocks/collection-header/__tests__/Block.spec.ts +80 -4
  46. package/template/blocks/collection-header/block.json +2 -0
  47. package/template/blocks/collection-header/preview.png +0 -0
  48. package/template/blocks/contact/block.json +4 -0
  49. package/template/blocks/contact/preview.png +0 -0
  50. package/template/blocks/cta/block.json +2 -0
  51. package/template/blocks/faq/Block.vue +5 -10
  52. package/template/blocks/faq/block.json +2 -1
  53. package/template/blocks/faq/mock.json +12 -1
  54. package/template/blocks/faq/preview.png +0 -0
  55. package/template/blocks/feature-grid/__tests__/Block.spec.ts +30 -7
  56. package/template/blocks/feature-grid/block.json +3 -2
  57. package/template/blocks/feature-grid/mock.json +1 -1
  58. package/template/blocks/feature-grid/preview.png +0 -0
  59. package/template/blocks/footer/Block.vue +64 -21
  60. package/template/blocks/footer/__tests__/Block.spec.ts +97 -1
  61. package/template/blocks/footer/block.json +5 -2
  62. package/template/blocks/footer/mock.json +1 -1
  63. package/template/blocks/footer/preview.png +0 -0
  64. package/template/blocks/form/block.json +1 -0
  65. package/template/blocks/gallery/preview.png +0 -0
  66. package/template/blocks/hero/Block.vue +38 -9
  67. package/template/blocks/hero/__tests__/Block.spec.ts +71 -19
  68. package/template/blocks/hero/block.json +16 -22
  69. package/template/blocks/hero/preview.json +1 -3
  70. package/template/blocks/hero/preview.png +0 -0
  71. package/template/blocks/image/block.json +2 -1
  72. package/template/blocks/image/preview.png +0 -0
  73. package/template/blocks/logo-cloud/block.json +1 -0
  74. package/template/blocks/logo-cloud/preview.png +0 -0
  75. package/template/blocks/navigation/Block.vue +405 -159
  76. package/template/blocks/navigation/__tests__/Block.spec.ts +816 -172
  77. package/template/blocks/navigation/__tests__/currentItem.spec.ts +90 -0
  78. package/template/blocks/navigation/block.json +2 -11
  79. package/template/blocks/navigation/mock.json +3 -3
  80. package/template/blocks/navigation/parts/LocalePicker.vue +103 -0
  81. package/template/blocks/navigation/parts/currentItem.ts +82 -0
  82. package/template/blocks/navigation/preview.json +7 -1
  83. package/template/blocks/navigation/preview.png +0 -0
  84. package/template/blocks/newsletter/Block.vue +6 -2
  85. package/template/blocks/newsletter/block.json +2 -0
  86. package/template/blocks/newsletter/preview.png +0 -0
  87. package/template/blocks/order-status/Block.vue +8 -17
  88. package/template/blocks/order-status/block.json +3 -0
  89. package/template/blocks/order-status/preview.png +0 -0
  90. package/template/blocks/pricing-table/__tests__/Block.spec.ts +12 -4
  91. package/template/blocks/pricing-table/block.json +2 -0
  92. package/template/blocks/pricing-table/mock.json +6 -6
  93. package/template/blocks/pricing-table/preview.png +0 -0
  94. package/template/blocks/product-carousel/Block.vue +36 -126
  95. package/template/blocks/product-carousel/__tests__/Block.spec.ts +88 -0
  96. package/template/blocks/product-carousel/block.json +1 -0
  97. package/template/blocks/product-carousel/preview.png +0 -0
  98. package/template/blocks/product-detail/Block.vue +84 -31
  99. package/template/blocks/product-detail/__tests__/Block.spec.ts +86 -0
  100. package/template/blocks/product-detail/__tests__/specs.spec.ts +79 -0
  101. package/template/blocks/product-detail/block.json +3 -1
  102. package/template/blocks/product-detail/mock.json +54 -4
  103. package/template/blocks/product-detail/parts/Gallery.vue +8 -2
  104. package/template/blocks/product-detail/preview.png +0 -0
  105. package/template/blocks/product-detail/specs.ts +75 -0
  106. package/template/blocks/quote/block.json +1 -0
  107. package/template/blocks/rich-text/preview.png +0 -0
  108. package/template/blocks/search/Block.vue +6 -1
  109. package/template/blocks/search/TypeSection.vue +8 -1
  110. package/template/blocks/search/__tests__/Block.spec.ts +24 -1
  111. package/template/blocks/search/block.json +1 -0
  112. package/template/blocks/search/preview.png +0 -0
  113. package/template/blocks/split-content/Block.vue +12 -5
  114. package/template/blocks/split-content/__tests__/Block.spec.ts +13 -0
  115. package/template/blocks/split-content/block.json +4 -2
  116. package/template/blocks/split-content/preview.png +0 -0
  117. package/template/blocks/stats/preview.png +0 -0
  118. package/template/blocks/tabs/Block.vue +3 -4
  119. package/template/blocks/tabs/block.json +1 -1
  120. package/template/blocks/tabs/preview.png +0 -0
  121. package/template/blocks/team/block.json +3 -1
  122. package/template/blocks/team/preview.png +0 -0
  123. package/template/blocks/testimonials/block.json +2 -0
  124. package/template/blocks/testimonials/preview.png +0 -0
  125. package/template/blocks/timeline/block.json +2 -1
  126. package/template/blocks/timeline/preview.png +0 -0
  127. package/template/blocks/trust-strip/Block.vue +2 -2
  128. package/template/blocks/trust-strip/__tests__/Block.spec.ts +38 -9
  129. package/template/blocks/trust-strip/block.json +1 -1
  130. package/template/blocks/trust-strip/mock.json +1 -1
  131. package/template/blocks/trust-strip/preview.json +1 -1
  132. package/template/blocks/trust-strip/preview.png +0 -0
  133. package/template/blocks/video-embed/block.json +2 -0
  134. package/template/blocks/video-embed/preview.png +0 -0
  135. package/template/blocks/wishlist/Block.vue +2 -2
  136. package/template/blocks/wishlist/preview.png +0 -0
  137. package/template/i18n/en-US.json +13 -5
  138. package/template/i18n/is-IS.json +12 -4
  139. package/template/pages/article.page.json +1 -3
  140. package/template/pages/cart.page.json +1 -3
  141. package/template/pages/category.page.json +2 -4
  142. package/template/pages/collection.page.json +1 -3
  143. package/template/pages/home.page.json +7 -18
  144. package/template/pages/product.page.json +62 -131
  145. package/template/pages/products.page.json +1 -3
  146. package/template/pages/search.page.json +1 -3
  147. package/template/pages/wishlist.page.json +1 -3
  148. package/template/stories/generated/footer.stories.ts +6 -0
  149. package/template/stories/generated/navigation.stories.ts +0 -18
  150. package/template/test/inlineEditable.spec.ts +10 -2
  151. package/template/test/localePrefix.spec.ts +2 -19
  152. package/template/test/pages/article.spec.ts +0 -2
  153. package/template/test/pages/category.spec.ts +35 -13
  154. package/template/test/pages/home.spec.ts +33 -17
  155. package/template/test/pages/product.spec.ts +64 -44
  156. package/template/test/pages/ssr.spec.ts +3 -1
  157. package/template/test/prerenderRefresh.browser.spec.ts +30 -25
  158. package/template/test/previewParity.browser.spec.ts +36 -2
  159. package/template/test/priceTokens.spec.ts +309 -0
  160. package/template/test/regionalFormat.spec.ts +80 -0
  161. package/template/test/starter.spec.ts +23 -7
  162. package/template/test/storefront/demo.spec.ts +19 -18
  163. package/template/test/storefront/toProductCard.spec.ts +17 -2
  164. package/template/test/structuredData.generate.spec.ts +4 -2
  165. package/template/test/support/mockGateway.ts +21 -1
  166. package/template/test/support/mountBlock.ts +25 -4
  167. package/template/test/support/priceTokens.ts +20 -0
  168. package/template/test/uiMessagesPlugin.spec.ts +34 -1
  169. package/template/tokens.json +8 -8
@@ -0,0 +1,309 @@
1
+ // @vitest-environment jsdom
2
+ import { flushPromises, mount } from '@vue/test-utils';
3
+ import { describe, expect, it, vi } from 'vitest';
4
+ import { decodeStega, encodeStega } from '@eldrajs/theme-core/stega';
5
+ import { resolveBlockTokens } from '../app/composables/usePriceTokens';
6
+ import { formatMoney } from '../app/storefront/money';
7
+ import AnnouncementBar from '../blocks/announcement-bar/Block.vue';
8
+ import Faq from '../blocks/faq/Block.vue';
9
+ import PricingTable from '../blocks/pricing-table/Block.vue';
10
+ import Navigation from '../blocks/navigation/Block.vue';
11
+ import announcementMock from '../blocks/announcement-bar/mock.json';
12
+ import faqMock from '../blocks/faq/mock.json';
13
+ import pricingMock from '../blocks/pricing-table/mock.json';
14
+ import { mountOptions } from './support/mountBlock';
15
+ import { STOREFRONT_KEY, type StorefrontSource } from '../app/storefront/types';
16
+
17
+ /**
18
+ * Price tokens (WS-1474, WS-1473) resolve in one place, `useBlockData`, for every block: these specs
19
+ * mount real blocks whose seeds carry tokens and read what a shopper sees.
20
+ */
21
+
22
+ const ISK = {
23
+ currency: 'ISK',
24
+ taxInclusivePricing: true,
25
+ defaultTaxRate: 0.24,
26
+ };
27
+ const EUR = {
28
+ currency: 'EUR',
29
+ taxInclusivePricing: true,
30
+ defaultTaxRate: 0.21,
31
+ };
32
+
33
+ describe('price tokens in block data', () => {
34
+ it("writes a store setting in the shopper's currency, from the store's own amounts", async () => {
35
+ const wrapper = mount(
36
+ AnnouncementBar,
37
+ mountOptions({ entry: { id: 'a1', data: { ...announcementMock } } })
38
+ );
39
+ await flushPromises();
40
+ expect(wrapper.text()).toContain('Free shipping on orders over $80.00');
41
+ expect(wrapper.text()).not.toContain('⟦');
42
+ });
43
+
44
+ it('follows the store currency and the regional format, never converting', async () => {
45
+ const wrapper = mount(
46
+ AnnouncementBar,
47
+ mountOptions(
48
+ { entry: { id: 'a1', data: { ...announcementMock } } },
49
+ {
50
+ commerce: ISK,
51
+ region: {
52
+ countryCode: 'IS',
53
+ formatLocale: 'is-IS',
54
+ timeZone: 'Atlantic/Reykjavik',
55
+ },
56
+ }
57
+ )
58
+ );
59
+ await flushPromises();
60
+ expect(wrapper.text()).toContain(
61
+ `Free shipping on orders over ${formatMoney(15000, 'ISK', 'is-IS')}`
62
+ );
63
+ expect(formatMoney(15000, 'ISK', 'is-IS')).toMatch(/^15\.000\skr\.$/);
64
+ });
65
+
66
+ it('drops a header info item whose only sentence names a missing amount, icon and all', async () => {
67
+ const data = {
68
+ infoItems: [
69
+ {
70
+ text: encodeStega('Free delivery over ⟦store freeShippingThreshold⟧', {
71
+ entryId: 'n1',
72
+ fieldPath: 'infoItems.0.text',
73
+ locale: 'en-US',
74
+ }),
75
+ icon: 'truck',
76
+ placement: 'start',
77
+ },
78
+ { text: '30-day returns', icon: 'arrow-back-up', placement: 'start' },
79
+ ],
80
+ };
81
+ // The preview carries the editing payload; a store with no thresholds leaves the item empty.
82
+ const wrapper = mount(
83
+ Navigation,
84
+ mountOptions({ entry: { id: 'n1', data } }, { storeAmounts: null })
85
+ );
86
+ await flushPromises();
87
+ const strip = wrapper.get('[aria-label="Store information"]');
88
+ expect(strip.findAll('li')).toHaveLength(1);
89
+ expect(strip.text()).toContain('30-day returns');
90
+ });
91
+
92
+ it("follows the shopper's chosen currency, not the store's base one", async () => {
93
+ const options = mountOptions(
94
+ { entry: { id: 'a1', data: { ...announcementMock } } },
95
+ {
96
+ commerce: { ...ISK, currencies: ['ISK', 'EUR', 'USD'] },
97
+ region: { countryCode: 'IS', formatLocale: 'is-IS', timeZone: 'Atlantic/Reykjavik' },
98
+ }
99
+ );
100
+ const storefront = options.global.provide[STOREFRONT_KEY] as StorefrontSource;
101
+ storefront.currency.started.value = true;
102
+ const wrapper = mount(AnnouncementBar, options);
103
+ await flushPromises();
104
+ expect(wrapper.text()).toContain(formatMoney(15000, 'ISK', 'is-IS'));
105
+ // The shopper picks euros: the store's own euro threshold (€75), never 15.000 kr. converted.
106
+ storefront.currency.choose('EUR');
107
+ await vi.waitFor(() => expect(storefront.currency.active.value).toBe('EUR'));
108
+ await flushPromises();
109
+ expect(wrapper.text()).toContain(formatMoney(75, 'EUR', 'is-IS'));
110
+ expect(wrapper.text()).not.toContain('kr.');
111
+ });
112
+
113
+ it('leaves the sentence out when the store has no amount for the currency', async () => {
114
+ const wrapper = mount(
115
+ AnnouncementBar,
116
+ mountOptions({ entry: { id: 'a1', data: { ...announcementMock } } }, { storeAmounts: null })
117
+ );
118
+ await flushPromises();
119
+ expect(wrapper.text()).not.toContain('Free shipping');
120
+ expect(wrapper.text()).not.toContain('⟦');
121
+ });
122
+
123
+ it('writes each plan price from its own amount in that currency', async () => {
124
+ const wrapper = mount(
125
+ PricingTable,
126
+ mountOptions({ entry: { id: 'p1', data: { ...pricingMock } } }, { commerce: EUR })
127
+ );
128
+ await flushPromises();
129
+ const text = wrapper.text();
130
+ // EUR=3500 on the monthly plan: the merchant's euro amount, not $38 converted.
131
+ expect(text).toContain(formatMoney(35, 'EUR', 'en-US'));
132
+ expect(text).toContain(`${formatMoney(32, 'EUR', 'en-US')} a box, billed each season.`);
133
+ expect(text).not.toContain('⟦');
134
+ });
135
+
136
+ it("writes a rich-text price node, and drops only its paragraph when it can't be", async () => {
137
+ const answer = (faqMock.items as { answer?: unknown }[]).find((item) =>
138
+ JSON.stringify(item.answer).includes('"price"')
139
+ );
140
+ expect(answer).toBeDefined();
141
+ const data = { ...faqMock, items: [answer] };
142
+ const usd = mount(Faq, mountOptions({ entry: { id: 'f1', data } }));
143
+ await flushPromises();
144
+ expect(usd.text()).toContain('Add a handwritten card at checkout for $4.00, and');
145
+
146
+ const sek = mount(
147
+ Faq,
148
+ mountOptions(
149
+ { entry: { id: 'f1', data } },
150
+ {
151
+ commerce: {
152
+ currency: 'SEK',
153
+ taxInclusivePricing: true,
154
+ defaultTaxRate: 0.25,
155
+ },
156
+ }
157
+ )
158
+ );
159
+ await flushPromises();
160
+ // The paragraph stays in the tree (the builder's rich-text positions count it) but is hidden.
161
+ const paragraph = sek.findAll('p').find((p) => p.text().includes('handwritten card'));
162
+ expect(paragraph?.attributes('hidden')).toBeDefined();
163
+ expect(sek.text()).not.toContain('⟦');
164
+ expect(
165
+ usd
166
+ .findAll('p')
167
+ .find((p) => p.text().includes('handwritten card'))
168
+ ?.attributes('hidden')
169
+ ).toBeUndefined();
170
+ });
171
+ });
172
+
173
+ describe('resolveBlockTokens', () => {
174
+ const options = {
175
+ currency: 'USD',
176
+ locale: 'en-US',
177
+ storeAmounts: null,
178
+ format: formatMoney,
179
+ };
180
+
181
+ it('returns the very same data when nothing holds a token', () => {
182
+ const data = {
183
+ title: 'Hello',
184
+ items: [{ text: 'a' }],
185
+ doc: { type: 'doc', content: [] },
186
+ };
187
+ expect(resolveBlockTokens(data, options)).toBe(data);
188
+ });
189
+
190
+ it('resolves at any depth and copies only the path that changed', () => {
191
+ const untouched = { text: 'plain' };
192
+ const data = {
193
+ items: [untouched, { text: 'Card ⟦price#card USD=400⟧.' }],
194
+ };
195
+ const out = resolveBlockTokens(data, options);
196
+ expect(out.items[1]).toEqual({ text: 'Card $4.00.' });
197
+ expect(out.items[0]).toBe(untouched);
198
+ expect(data.items[1]!.text).toBe('Card ⟦price#card USD=400⟧.');
199
+ });
200
+
201
+ it('gives the builder the stored text to edit on the canvas, each price as a chip', () => {
202
+ const meta = { entryId: 'e1', fieldPath: 'message', locale: 'en-US' };
203
+ const out = resolveBlockTokens(encodeStega('Card ⟦price#card USD=400⟧.', meta), options);
204
+ // The page shows the written price; the payload carries the stored text the canvas edits.
205
+ expect(decodeStega(out)).toEqual({
206
+ cleaned: 'Card $4.00.',
207
+ meta: {
208
+ ...meta,
209
+ parts: ['Card ', { token: '⟦price#card USD=400⟧', label: '$4.00' }, '.'],
210
+ },
211
+ });
212
+ // A price with no amount in the shopper's currency is a chip the operator can still fix.
213
+ const missing = resolveBlockTokens(
214
+ encodeStega('Hi. Card ⟦price#card EUR=400⟧.', meta),
215
+ options
216
+ );
217
+ expect(decodeStega(missing).meta?.parts).toEqual([
218
+ 'Hi. Card ',
219
+ { token: '⟦price#card EUR=400⟧', label: 'No USD price', missing: true },
220
+ '.',
221
+ ]);
222
+ // Every sentence left out: empty, with no payload, so a block's own `trim() === ''` sees it.
223
+ expect(
224
+ resolveBlockTokens(
225
+ encodeStega('Free delivery over ⟦store freeShippingThreshold⟧', meta),
226
+ options
227
+ )
228
+ ).toBe('');
229
+ // A field without a token keeps its payload exactly as Studio sent it.
230
+ const plain = encodeStega('Hello', meta);
231
+ expect(resolveBlockTokens(plain, options)).toBe(plain);
232
+ });
233
+ });
234
+
235
+ describe('price opt-outs (allowPrices: false)', () => {
236
+ interface FieldDef {
237
+ fieldId: string;
238
+ type: string;
239
+ allowPrices?: boolean;
240
+ metadata?: { item?: FieldDef; fields?: FieldDef[] };
241
+ }
242
+ const definitions = import.meta.glob<{ default: { apiId: string; fields: FieldDef[] } }>(
243
+ '../blocks/*/block.json',
244
+ { eager: true }
245
+ );
246
+ const seeds = import.meta.glob<{ default: Record<string, unknown> }>(
247
+ ['../blocks/*/mock.json', '../blocks/*/preview.json'],
248
+ { eager: true }
249
+ );
250
+ const pages = import.meta.glob<{
251
+ default: { blocks: { apiId: string; data: Record<string, unknown> }[] };
252
+ }>('../pages/*.page.json', { eager: true });
253
+
254
+ /** A field's own children: a list's item (or the item composite's fields), a composite's fields. */
255
+ const childrenOf = (field: FieldDef): FieldDef[] => {
256
+ const item = field.metadata?.item;
257
+ if (item !== undefined)
258
+ return item.type === 'composite' ? (item.metadata?.fields ?? []) : [item];
259
+ return field.metadata?.fields ?? [];
260
+ };
261
+ const isUrlLike = (id: string): boolean => id === 'href' || /(Href|Url)$/.test(id);
262
+
263
+ it('opts out every URL field: a written price there would break the link', () => {
264
+ const missing: string[] = [];
265
+ const walk = (fields: FieldDef[], at: string): void => {
266
+ for (const field of fields) {
267
+ const where = `${at}.${field.fieldId}`;
268
+ if ((field.type === 'string' || field.type === 'text') && isUrlLike(field.fieldId)) {
269
+ if (field.allowPrices !== false) missing.push(where);
270
+ }
271
+ walk(childrenOf(field), where);
272
+ }
273
+ };
274
+ for (const d of Object.values(definitions)) walk(d.default.fields, d.default.apiId);
275
+ expect(missing).toEqual([]);
276
+ });
277
+
278
+ it('never seeds a price into a field that opted out, which Core would refuse', () => {
279
+ const found: string[] = [];
280
+ const walk = (value: unknown, field: FieldDef | null, at: string): void => {
281
+ if (typeof value === 'string') {
282
+ if (value.includes('⟦') && field?.allowPrices === false) found.push(at);
283
+ return;
284
+ }
285
+ if (Array.isArray(value)) {
286
+ value.forEach((v, i) => walk(v, field, `${at}.${i}`));
287
+ return;
288
+ }
289
+ if (value === null || typeof value !== 'object' || field?.type === 'rich-text') return;
290
+ for (const [key, v] of Object.entries(value)) {
291
+ const children = field === null ? [] : childrenOf(field);
292
+ walk(v, children.find((f) => f.fieldId === key) ?? null, `${at}.${key}`);
293
+ }
294
+ };
295
+ const check = (apiId: string, data: Record<string, unknown>, where: string): void => {
296
+ const fields = Object.values(definitions).find((d) => d.default.apiId === apiId)!.default
297
+ .fields;
298
+ for (const [key, value] of Object.entries(data)) {
299
+ walk(value, fields.find((f) => f.fieldId === key) ?? null, `${where}:${key}`);
300
+ }
301
+ };
302
+ for (const [path, seed] of Object.entries(seeds))
303
+ check(path.split('/')[2]!, seed.default, path);
304
+ for (const [path, page] of Object.entries(pages)) {
305
+ for (const block of page.default.blocks) check(block.apiId, block.data, path);
306
+ }
307
+ expect(found).toEqual([]);
308
+ });
309
+ });
@@ -0,0 +1,80 @@
1
+ // @vitest-environment jsdom
2
+ import { mount } from '@vue/test-utils';
3
+ import { defineComponent, h } from 'vue';
4
+ import { describe, expect, it } from 'vitest';
5
+ import { formatDate } from '@eldrajs/ui';
6
+ import ArticleBlock from '../blocks/article/Block.vue';
7
+ import articleMock from '../blocks/article/mock.json';
8
+ import { calendarDayIn, useFormatDate } from '../app/composables/useRegionalFormat';
9
+ import { useMoney } from '../app/storefront/money';
10
+ import { mountOptions } from './support/mountBlock';
11
+
12
+ /**
13
+ * The organisation's regional format (`runtimeConfig.public.eldra.region`, read at build by
14
+ * `@eldrajs/theme-nuxt`) decides how money, numbers and dates are written; the content locale
15
+ * decides only the words. An English-language Icelandic store prints "4.790 kr." and an Icelandic
16
+ * date under English copy — the defect this guards was "ISK 4,790" on such a store.
17
+ */
18
+
19
+ const ICELAND = { countryCode: 'IS', formatLocale: 'is-IS', timeZone: 'Atlantic/Reykjavik' };
20
+ const ISK = { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 };
21
+
22
+ /** A component that prints one amount and one timestamp the way every block does. */
23
+ const Probe = defineComponent({
24
+ props: { entry: { type: Object, required: true } },
25
+ setup() {
26
+ const money = useMoney();
27
+ const formatRegionalDate = useFormatDate();
28
+ return () =>
29
+ h('p', [
30
+ h('span', { class: 'price' }, money.format(4790)),
31
+ h('span', { class: 'date' }, formatRegionalDate('2026-11-26T12:00:00Z') ?? ''),
32
+ ]);
33
+ },
34
+ });
35
+
36
+ const entry = { id: 'probe', data: {} };
37
+
38
+ describe('the regional format', () => {
39
+ it('writes an Icelandic store’s prices and dates in Icelandic under English content', () => {
40
+ const wrapper = mount(
41
+ Probe,
42
+ mountOptions({ entry }, { locale: 'en-US', commerce: ISK, region: ICELAND })
43
+ );
44
+
45
+ expect(wrapper.get('.price').text()).toBe('4.790 kr.');
46
+ expect(wrapper.get('.date').text()).toBe(formatDate('2026-11-26', 'is-IS'));
47
+ expect(wrapper.get('.date').text()).not.toBe(formatDate('2026-11-26', 'en-US'));
48
+ });
49
+
50
+ it('falls back to the content locale with no regional format', () => {
51
+ const wrapper = mount(Probe, mountOptions({ entry }, { locale: 'en-US', commerce: ISK }));
52
+
53
+ expect(wrapper.get('.price').text()).toBe('ISK 4,790');
54
+ expect(wrapper.get('.date').text()).toBe(formatDate('2026-11-26', 'en-US'));
55
+ });
56
+
57
+ it('dates an article in the regional format, while its words stay English', () => {
58
+ const wrapper = mount(
59
+ ArticleBlock,
60
+ mountOptions(
61
+ { entry: { id: 'article', data: articleMock } },
62
+ { locale: 'en-US', region: ICELAND }
63
+ )
64
+ );
65
+ const spans = wrapper.get('time').findAll('span');
66
+
67
+ expect(spans[0]!.text()).toBe(formatDate(articleMock.publishedAt, 'is-IS'));
68
+ expect(spans[1]!.text()).toBe(formatDate(articleMock.publishedAt, 'is-IS', { month: 'long' }));
69
+ });
70
+
71
+ it('dates a timestamp on its calendar day in the organisation’s time zone', () => {
72
+ // 02:30 UTC on the 27th is still the evening of the 26th in New York; a bare date is a day
73
+ // already and is left alone, as is anything with no zone to convert to.
74
+ expect(calendarDayIn('2026-11-27T02:30:00Z', 'America/New_York')).toBe('2026-11-26');
75
+ expect(calendarDayIn('2026-11-27T02:30:00Z', 'Atlantic/Reykjavik')).toBe('2026-11-27');
76
+ expect(calendarDayIn('2026-11-27', 'America/New_York')).toBe('2026-11-27');
77
+ expect(calendarDayIn('2026-11-27T02:30:00Z', undefined)).toBe('2026-11-27T02:30:00Z');
78
+ expect(calendarDayIn('not-a-dateTnope', 'America/New_York')).toBe('not-a-dateTnope');
79
+ });
80
+ });
@@ -143,9 +143,8 @@ describe('starter theme', () => {
143
143
  'subheading',
144
144
  'image',
145
145
  'slides',
146
+ 'captionProduct',
146
147
  'captionLabel',
147
- 'captionDetail',
148
- 'captionHref',
149
148
  'spacing',
150
149
  'primaryCtaLabel',
151
150
  'primaryCtaHref',
@@ -182,7 +181,6 @@ describe('starter theme', () => {
182
181
  'drawerLayout',
183
182
  'account',
184
183
  'showSearch',
185
- 'searchStyle',
186
184
  'ctaLabel',
187
185
  'cta',
188
186
  'sticky',
@@ -434,7 +432,7 @@ describe('starter theme', () => {
434
432
  ],
435
433
  cart: [
436
434
  'variant',
437
- 'freeShippingThreshold',
435
+ 'showShippingBar',
438
436
  'showDiscountField',
439
437
  'showPaymentIcons',
440
438
  'note',
@@ -1152,7 +1150,8 @@ describe('seeded templates and pages (app/templates.ts)', () => {
1152
1150
  // Real data, not an empty stub: the home fixture's own header and footer settings.
1153
1151
  expect(roles.header?.data.brandText).toBe('Northwind Goods');
1154
1152
  expect(roles.header?.data.showSearch).toBe(true);
1155
- expect(roles.footer?.data.description).toEqual(expect.stringContaining('small workshops'));
1153
+ expect(roles.footer?.data.brandText).toBe('Northwind Goods');
1154
+ expect(roles.footer?.data.background).toBe('dark');
1156
1155
  });
1157
1156
 
1158
1157
  it('seeds a header and footer with no destinations at all', () => {
@@ -1197,8 +1196,9 @@ describe('seeded templates and pages (app/templates.ts)', () => {
1197
1196
  it('ships no showAccount field, at a version that tells Core to retire it', () => {
1198
1197
  const navigation = scanned.manifest!.blocks.find((block) => block.apiId === 'navigation')!;
1199
1198
  expect(navigation.fields.map((field) => field.fieldId)).not.toContain('showAccount');
1200
- // Version 5 is the `groupsToSections` step (WS-1362); the retirement happened at 4 and stays.
1201
- expect(navigation.version).toBe(5);
1199
+ // Version 5 is the `groupsToSections` step (WS-1362) and 6 retires `searchStyle`; the
1200
+ // retirement happened at 4 and stays.
1201
+ expect(navigation.version).toBe(6);
1202
1202
  expect(navigation.migrations?.at(-1)).toEqual({
1203
1203
  version: 5,
1204
1204
  groupsToSections: [{ field: 'links' }],
@@ -1211,6 +1211,22 @@ describe('seeded templates and pages (app/templates.ts)', () => {
1211
1211
  expect(named).not.toContain('showAccount');
1212
1212
  });
1213
1213
 
1214
+ /**
1215
+ * Search is the labelled Search tool at every width, so the pill/inline choice is gone. Like
1216
+ * `showAccount`, it is retired by the version bump alone (6): no step names it, and Core keeps
1217
+ * what an entry held as `searchStyle__v5`.
1218
+ */
1219
+ it('ships no searchStyle field, retired at version 6 with no step naming it', () => {
1220
+ const navigation = scanned.manifest!.blocks.find((block) => block.apiId === 'navigation')!;
1221
+ expect(navigation.fields.map((field) => field.fieldId)).not.toContain('searchStyle');
1222
+ expect(navigation.version).toBe(6);
1223
+ const named = (navigation.migrations ?? []).flatMap((step) => [
1224
+ ...(step.renames ?? []).map((rename) => rename.from),
1225
+ ...(step.convertToLink ?? []).map((conversion) => conversion.from),
1226
+ ]);
1227
+ expect(named).not.toContain('searchStyle');
1228
+ });
1229
+
1214
1230
  it('seeds Core-valid data: every seed block and both roles pass the mock.json rules', () => {
1215
1231
  // `scanTheme` runs `templates[].blocks[].data` and `templateRoles.*.data` through exactly the
1216
1232
  // walk it applies to every block's `mock.json` — the rule `eldra-theme validate` enforces —
@@ -32,7 +32,7 @@ async function settle(): Promise<void> {
32
32
  describe('createDemoStorefront', () => {
33
33
  it('the catalogue satisfies StorefrontProductListItem — real under pnpm typecheck', () => {
34
34
  expectTypeOf(PRODUCTS).toEqualTypeOf<StorefrontProductListItem[]>();
35
- expect(PRODUCTS).toHaveLength(12);
35
+ expect(PRODUCTS).toHaveLength(16);
36
36
  });
37
37
 
38
38
  it('contains the spec Northwind products with their prices, in major units', () => {
@@ -52,7 +52,7 @@ describe('createDemoStorefront', () => {
52
52
  expect(byTitle.get('Stonewashed linen throw')?.price.amount).toBe(118);
53
53
  });
54
54
 
55
- it('"Linen tea towels, pair" is sold out; everything else defaults to in stock', () => {
55
+ it('"Linen tea towels, pair" and the enamel camp cups are sold out; everything else defaults to in stock', () => {
56
56
  const byTitle = new Map(PRODUCTS.map((product) => [product.title, product]));
57
57
  const soldOut = byTitle.get('Linen tea towels, pair')!;
58
58
  expect(soldOut.stock).toBe('out');
@@ -298,10 +298,10 @@ describe('createDemoStorefront', () => {
298
298
  });
299
299
 
300
300
  it('narrows both the items and the total for a category filter', async () => {
301
- // 5 of the 12 products are knitwear, each appearing 4 times in the 48-item collection.
301
+ // 5 of the 16 products are knitwear, each appearing 3 times in the 48-item collection.
302
302
  const response = await collection({ filters: { category: ['knitwear'] } });
303
- expect(response.items).toHaveLength(20);
304
- expect(response.total).toBe(20);
303
+ expect(response.items).toHaveLength(15);
304
+ expect(response.total).toBe(15);
305
305
  });
306
306
 
307
307
  it('ORs values inside one source and ANDs across sources', async () => {
@@ -313,16 +313,16 @@ describe('createDemoStorefront', () => {
313
313
  const andACross = await collection({
314
314
  filters: { category: ['knitwear'], 'option:size': ['m'] },
315
315
  });
316
- // Only the three apparel products are made in M, and all three are knitwear.
317
- expect(andACross.total).toBe(12);
316
+ // Only the three apparel products are made in M, and all three are knitwear: 3 × 3 copies.
317
+ expect(andACross.total).toBe(9);
318
318
  });
319
319
 
320
320
  it('filters by size, colour and availability', async () => {
321
- expect((await collection({ filters: { 'option:size': ['m'] } })).total).toBe(12);
322
- // Oat is only the merino crew sweater's colour, four times over.
323
- expect((await collection({ filters: { 'option:colour': ['oat'] } })).total).toBe(4);
324
- // Everything but the sold-out linen tea towels.
325
- expect((await collection({ filters: { availability: ['in-stock'] } })).total).toBe(44);
321
+ expect((await collection({ filters: { 'option:size': ['m'] } })).total).toBe(9);
322
+ // Oat is only the merino crew sweater's colour, three times over.
323
+ expect((await collection({ filters: { 'option:colour': ['oat'] } })).total).toBe(3);
324
+ // Everything but the sold-out linen tea towels and enamel camp cups, three copies of each.
325
+ expect((await collection({ filters: { availability: ['in-stock'] } })).total).toBe(42);
326
326
  });
327
327
 
328
328
  it('filters by a price range in whole dollars, with either end open', async () => {
@@ -367,11 +367,11 @@ describe('createDemoStorefront', () => {
367
367
 
368
368
  it('leads `best-selling` with the best-seller list, clones included', async () => {
369
369
  const response = await collection({ sort: 'best-selling' });
370
- // The demo's best-seller list names 6 products; each appears 4 times in the 48-item
371
- // collection, so the first 24 items are exactly those six (identified by title — a clone
370
+ // The demo's best-seller list names 6 products; each appears 3 times in the 48-item
371
+ // collection, so the first 18 items are exactly those six (identified by title — a clone
372
372
  // carries a suffixed handle but the same title), and the merino crew sweater leads.
373
373
  expect(response.items[0]!.title).toBe('Merino crew sweater');
374
- const leading = new Set(response.items.slice(0, 24).map((item) => item.title));
374
+ const leading = new Set(response.items.slice(0, 18).map((item) => item.title));
375
375
  expect([...leading].sort()).toEqual(
376
376
  [
377
377
  'Hand-thrown serving bowl',
@@ -391,8 +391,9 @@ describe('createDemoStorefront', () => {
391
391
  sort: 'price-asc',
392
392
  filters: { category: ['knitwear'] },
393
393
  });
394
- expect(response.total).toBe(20);
395
- expect(response.items).toHaveLength(8);
394
+ // 15 knitwear items, so page 2 of 8 holds the last 7.
395
+ expect(response.total).toBe(15);
396
+ expect(response.items).toHaveLength(7);
396
397
  const prices = response.items.map((item) => item.price.amount);
397
398
  expect(prices).toEqual([...prices].sort((a, b) => a - b));
398
399
  });
@@ -443,7 +444,7 @@ describe('createDemoStorefront', () => {
443
444
  const facets = (await collection({})).facets!;
444
445
  const bySlug = new Map(facets.collections.map((term) => [term.slug, term]));
445
446
  expect(bySlug.get('the-winter-edit')?.count).toBe(48);
446
- expect(bySlug.get('best-sellers')?.count).toBe(24);
447
+ expect(bySlug.get('best-sellers')?.count).toBe(18);
447
448
  expect(bySlug.get('the-winter-edit')?.title).toBe('The winter edit');
448
449
  // The id is the one a `reference` field carries, so a filter value and a picked collection
449
450
  // describe the same object.
@@ -28,17 +28,32 @@ function expectCard(...args: Parameters<typeof toProductCard>) {
28
28
  }
29
29
 
30
30
  describe('toProductCard', () => {
31
- it('maps title, url, featuredImage, rating, colours, stock and available straight through', () => {
31
+ it('maps title, url, featuredImage, rating, colours and available straight through', () => {
32
32
  const card = expectCard(baseItem());
33
33
  expect(card.title).toBe('Merino crew sweater');
34
34
  expect(card.url).toBe('/products/merino-crew-sweater');
35
35
  expect(card.featuredImage).toEqual({ src: '/demo/product-1.svg', alt: 'Merino crew sweater' });
36
36
  expect(card.rating).toEqual({ value: 4.5, count: 126 });
37
37
  expect(card.colours).toEqual([{ name: 'Oat', swatch: '#d8cbb0' }]);
38
- expect(card.stock).toBe('in');
39
38
  expect(card.available).toBe(true);
40
39
  });
41
40
 
41
+ it('carries no stock level: the theme card draws no stock line', () => {
42
+ expect(expectCard(baseItem({ stock: 'low' }))).not.toHaveProperty('stock');
43
+ });
44
+
45
+ it('maps the vendor through as the maker line, and leaves it out when there is none', () => {
46
+ expect(expectCard(baseItem({ vendor: 'Fell & Fleece' })).vendor).toBe('Fell & Fleece');
47
+ expect(expectCard(baseItem())).not.toHaveProperty('vendor');
48
+ });
49
+
50
+ it('derives badge: { variant: "new" } for an isNew item, and the sale badge wins over it', () => {
51
+ expect(expectCard(baseItem({ isNew: true })).badge).toEqual({ variant: 'new' });
52
+ expect(
53
+ expectCard(baseItem({ isNew: true, price: { amount: 96, compareAt: 128 } })).badge
54
+ ).toEqual({ variant: 'sale' });
55
+ });
56
+
42
57
  it('converts price.amount and compareAt into the minor units the card reads', () => {
43
58
  const card = expectCard(baseItem({ price: { amount: 96, compareAt: 128, from: true } }));
44
59
  expect(card.price).toEqual({ amount: 9600, compareAt: 12800, from: true });
@@ -7,6 +7,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest';
7
7
  import { formatMoney } from '../app/storefront/money';
8
8
  import {
9
9
  COLLECTION_HANDLE,
10
+ MOCK_REGION,
10
11
  ORG_ID,
11
12
  PRODUCT_HANDLE,
12
13
  startMockGateway,
@@ -123,9 +124,10 @@ describe('generated pages carry schema.org JSON-LD', () => {
123
124
  availability: 'https://schema.org/InStock',
124
125
  },
125
126
  });
126
- // The visible price is `formatMoney(42, 'ISK')`: same amount, same currency.
127
+ // The visible price is the same amount in the same currency, written in the organisation's
128
+ // regional format (`MOCK_REGION`), which is not the page's English.
127
129
  expect(html).toContain(
128
- formatMoney(product.offers.price, product.offers.priceCurrency, 'en-US')
130
+ formatMoney(product.offers.price, product.offers.priceCurrency, MOCK_REGION.formatLocale)
129
131
  );
130
132
  });
131
133
 
@@ -821,9 +821,27 @@ export interface MockGateway {
821
821
  close(): Promise<void>;
822
822
  }
823
823
 
824
+ /**
825
+ * The organisation's regional format the mock publishes: Icelandic, because Northwind sells in ISK
826
+ * and this is the shape the defect it guards came from — an English-language Icelandic store must
827
+ * print "42 kr." on its English pages too, not "ISK 42". `@eldrajs/theme-nuxt` reads it once per
828
+ * build onto `runtimeConfig.public.eldra.region`.
829
+ */
830
+ export const MOCK_REGION = {
831
+ countryCode: 'IS',
832
+ formatLocale: 'is-IS',
833
+ timeZone: 'Atlantic/Reykjavik',
834
+ } as const;
835
+
824
836
  export function startMockGateway(
825
- options: { catalogContract?: MockCatalogContract; failPath?: string } = {}
837
+ options: {
838
+ catalogContract?: MockCatalogContract;
839
+ failPath?: string;
840
+ /** `null` publishes no `region`, as a gateway older than the field does. */
841
+ region?: { countryCode: string; formatLocale: string; timeZone: string } | null;
842
+ } = {}
826
843
  ): Promise<MockGateway> {
844
+ const region = options.region === undefined ? MOCK_REGION : options.region;
827
845
  setMockCatalogContract(options.catalogContract ?? '3.8.0');
828
846
  return new Promise((resolve) => {
829
847
  const requests: string[] = [];
@@ -930,6 +948,8 @@ export function startMockGateway(
930
948
  ],
931
949
  commerce: { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 },
932
950
  locales: { default: DEFAULT_LOCALE, supported: [DEFAULT_LOCALE, PREFIXED_LOCALE] },
951
+ // How money and dates are written, whatever the content locale (`MOCK_REGION`).
952
+ ...(region === null ? {} : { region }),
933
953
  });
934
954
  } else if (url.pathname === '/cms/v1/schema/page/entry') {
935
955
  answer(listResponse(pages));