@eldrajs/theme-cli 0.2.10 → 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 (168) hide show
  1. package/CHANGELOG.md +11 -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 +34 -11
  45. package/template/blocks/collection-header/__tests__/Block.spec.ts +3 -3
  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 +404 -159
  76. package/template/blocks/navigation/__tests__/Block.spec.ts +806 -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/priceTokens.spec.ts +309 -0
  159. package/template/test/regionalFormat.spec.ts +80 -0
  160. package/template/test/starter.spec.ts +23 -7
  161. package/template/test/storefront/demo.spec.ts +19 -18
  162. package/template/test/storefront/toProductCard.spec.ts +17 -2
  163. package/template/test/structuredData.generate.spec.ts +4 -2
  164. package/template/test/support/mockGateway.ts +21 -1
  165. package/template/test/support/mountBlock.ts +25 -4
  166. package/template/test/support/priceTokens.ts +20 -0
  167. package/template/test/uiMessagesPlugin.spec.ts +34 -1
  168. package/template/tokens.json +8 -8
@@ -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));
@@ -29,7 +29,11 @@ import {
29
29
  } from '@eldrajs/theme-vue';
30
30
  import { CURRENCY_KEY, LOCALE_KEY, MESSAGES_KEY, enUS as uiEnUS } from '@eldrajs/ui';
31
31
  import { isIS as uiIsIS } from '@eldrajs/ui/messages/is-IS';
32
- import { createDemoStorefront } from '../../app/storefront/demo';
32
+ import type { StoreRegion } from '@eldrajs/theme-nuxt/region';
33
+ import { REGION_KEY, regionalFormatLocale } from '../../app/composables/useRegionalFormat';
34
+ import { createDemoStorefront, DEMO_STORE_AMOUNTS } from '../../app/storefront/demo';
35
+ import { STORE_AMOUNTS_KEY } from '../../app/composables/usePriceTokens';
36
+ import type { StoreAmounts } from '@eldrajs/sdk/tokens';
33
37
  import { STOREFRONT_KEY, type StorefrontCommerce } from '../../app/storefront/types';
34
38
  import enUSMessages from '../../i18n/en-US.json';
35
39
  import isISMessages from '../../i18n/is-IS.json';
@@ -82,6 +86,15 @@ export function mountOptions(
82
86
  * same way the two plugins take both from one runtime-config read on a real page.
83
87
  */
84
88
  commerce?: StorefrontCommerce | null;
89
+ /**
90
+ * The organisation's regional format, for a spec about how numbers and dates are written:
91
+ * none by default (the content locale formats), as on a site whose build learned none. Wired
92
+ * the way `app/plugins/eldra-ui-messages.ts` wires it: `LOCALE_KEY` and `REGION_KEY`.
93
+ */
94
+ region?: StoreRegion | null;
95
+ /** The store's amounts for `⟦store …⟧` price tokens; the demo store's by default, `null` for a
96
+ * store whose thresholds could not be read. */
97
+ storeAmounts?: StoreAmounts | null;
85
98
  } = {}
86
99
  ): {
87
100
  props: { entry: { id: string; data: Record<string, unknown> } };
@@ -118,8 +131,11 @@ export function mountOptions(
118
131
  // platform's answer there, the demo source's own here — never from the
119
132
  // locale.
120
133
  [MESSAGES_KEY]: uiMessagesFor(effectiveLocale),
121
- [LOCALE_KEY]: effectiveLocale,
134
+ [LOCALE_KEY]: regionalFormatLocale(options.region ?? null, effectiveLocale),
135
+ [REGION_KEY]: options.region ?? null,
122
136
  [CURRENCY_KEY]: storefront.commerce?.currency,
137
+ [STORE_AMOUNTS_KEY]:
138
+ options.storeAmounts === undefined ? DEMO_STORE_AMOUNTS : options.storeAmounts,
123
139
  // The same wiring `app/plugins/eldra-storefront.ts` does on a real page: a commerce block
124
140
  // reads `useStorefront()`, never the client directly, so every block test sees the
125
141
  // Northwind demo catalogue (`app/storefront/demo.ts`) instead of a live gateway.
@@ -169,7 +185,10 @@ function createTestEldraContext(
169
185
  }
170
186
 
171
187
  function createTestEldraClient(): EldraClient {
172
- return createEldraClient({ gatewayUrl: 'https://vitest.invalid', orgId: 'vitest' });
188
+ return createEldraClient({
189
+ gatewayUrl: 'https://vitest.invalid',
190
+ orgId: 'vitest',
191
+ });
173
192
  }
174
193
 
175
194
  /**
@@ -187,7 +206,9 @@ const NuxtLinkStub = defineComponent({
187
206
  return () =>
188
207
  h(
189
208
  'a',
190
- { href: typeof props.to === 'string' ? props.to : JSON.stringify(props.to) },
209
+ {
210
+ href: typeof props.to === 'string' ? props.to : JSON.stringify(props.to),
211
+ },
191
212
  slots.default?.()
192
213
  );
193
214
  },
@@ -0,0 +1,20 @@
1
+ import { resolveBlockTokens } from '../../app/composables/usePriceTokens';
2
+ import { DEMO_STORE_AMOUNTS } from '../../app/storefront/demo';
3
+ import { formatMoney } from '../../app/storefront/money';
4
+
5
+ /** How `mountOptions` resolves price tokens: the demo store's dollars and thresholds. */
6
+ export const DEMO_PRICE_OPTIONS = {
7
+ currency: 'USD',
8
+ locale: 'en-US',
9
+ storeAmounts: DEMO_STORE_AMOUNTS,
10
+ format: formatMoney,
11
+ };
12
+
13
+ /**
14
+ * A seed value as a block mounted by `mountOptions` shows it: every price token written out in the
15
+ * demo store's currency (`useBlockData`). A spec comparing page text with `mock.json` compares with
16
+ * this, since a seed's `⟦store freeShippingThreshold⟧` reads "$80.00" on the page.
17
+ */
18
+ export function shown<T>(value: T): T {
19
+ return resolveBlockTokens(value, DEMO_PRICE_OPTIONS);
20
+ }
@@ -1,5 +1,12 @@
1
1
  import { afterEach, describe, expect, it, vi } from 'vitest';
2
- import { CURRENCY_KEY, LOCALE_KEY, MESSAGES_KEY } from '@eldrajs/ui';
2
+ import {
3
+ CURRENCY_KEY,
4
+ LOCALE_KEY,
5
+ MESSAGES_KEY,
6
+ enUS as uiEnUS,
7
+ type UiMessages,
8
+ } from '@eldrajs/ui';
9
+ import { REGION_KEY } from '../app/composables/useRegionalFormat';
3
10
 
4
11
  /**
5
12
  * `app/plugins/eldra-ui-messages.ts` is the one place the store's currency reaches `@eldrajs/ui` —
@@ -20,6 +27,8 @@ vi.mock('nuxt/app', () => ({
20
27
 
21
28
  const { default: plugin } = await import('../app/plugins/eldra-ui-messages');
22
29
 
30
+ const ICELAND = { countryCode: 'IS', formatLocale: 'is-IS', timeZone: 'Atlantic/Reykjavik' };
31
+
23
32
  const ISK = { currency: 'ISK', taxInclusivePricing: true, defaultTaxRate: 0.24 };
24
33
 
25
34
  /** Runs the plugin against one `runtimeConfig.public`, and reports what it provided. */
@@ -101,4 +110,28 @@ describe('eldra-ui-messages', () => {
101
110
 
102
111
  expect(eldraWarnings(warn)).toEqual([]);
103
112
  });
113
+
114
+ it('formats in the organisation’s regional format, while its strings stay on the content locale', () => {
115
+ const provided = provideWith({ commerce: ISK, region: ICELAND });
116
+
117
+ expect((provided.get(LOCALE_KEY) as () => string | undefined)()).toBe('is-IS');
118
+ expect(provided.get(REGION_KEY)).toEqual(ICELAND);
119
+ // No content locale here (no theme context), so the strings are the English defaults — the
120
+ // regional format must not have pulled them to Icelandic.
121
+ const messages = provided.get(MESSAGES_KEY) as UiMessages;
122
+ const plainKey = (Object.keys(uiEnUS) as (keyof UiMessages)[]).find(
123
+ (key) => typeof uiEnUS[key] === 'string'
124
+ )!;
125
+ expect(messages[plainKey]).toBe(uiEnUS[plainKey]);
126
+ });
127
+
128
+ it('falls back to the content locale when the build learned no regional format', () => {
129
+ // Absent, the `''` Nuxt serialises a null as, and a record `Intl` would throw on all read the
130
+ // same: no regional format, so `LOCALE_KEY` answers the content locale (none here).
131
+ for (const region of [undefined, null, '', { ...ICELAND, timeZone: 'Mars/Olympus_Mons' }]) {
132
+ const provided = provideWith({ commerce: ISK, region });
133
+ expect((provided.get(LOCALE_KEY) as () => string | undefined)()).toBeUndefined();
134
+ expect(provided.get(REGION_KEY)).toBeNull();
135
+ }
136
+ });
104
137
  });
@@ -108,8 +108,8 @@
108
108
  "label": "Narrow",
109
109
  "maxWidth": "40rem",
110
110
  "gutter": {
111
- "normal": "2rem",
112
- "tablet": "1.5rem",
111
+ "normal": "1rem",
112
+ "tablet": "1rem",
113
113
  "mobile": "1rem"
114
114
  },
115
115
  "allowSiteOverride": true
@@ -118,8 +118,8 @@
118
118
  "label": "Content",
119
119
  "maxWidth": "64rem",
120
120
  "gutter": {
121
- "normal": "2rem",
122
- "tablet": "1.5rem",
121
+ "normal": "1rem",
122
+ "tablet": "1rem",
123
123
  "mobile": "1rem"
124
124
  },
125
125
  "allowSiteOverride": true
@@ -128,8 +128,8 @@
128
128
  "label": "Wide",
129
129
  "maxWidth": "78rem",
130
130
  "gutter": {
131
- "normal": "2rem",
132
- "tablet": "1.5rem",
131
+ "normal": "1rem",
132
+ "tablet": "1rem",
133
133
  "mobile": "1rem"
134
134
  },
135
135
  "allowSiteOverride": true
@@ -138,8 +138,8 @@
138
138
  "label": "Full",
139
139
  "maxWidth": "none",
140
140
  "gutter": {
141
- "normal": "2rem",
142
- "tablet": "1.5rem",
141
+ "normal": "1rem",
142
+ "tablet": "1rem",
143
143
  "mobile": "1rem"
144
144
  },
145
145
  "allowSiteOverride": true