@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
@@ -1,16 +1,17 @@
1
1
  // @vitest-environment jsdom
2
2
  //
3
3
  // The product sample page (`pages/product.page.json`): header, breadcrumbs, the product-detail
4
- // buy box for "Merino crew sweater", a related-products carousel, an FAQ and the footer, rendered
4
+ // buy box for "Merino crew sweater", the related products as a grid on a `surface` band ("Goes well
5
+ // with") and the footer, rendered
5
6
  // together through `mountPage` exactly as `app/pages/[...slug].vue` renders a real page: the
6
7
  // leading structure block (the header, which carries its own info strip) before `<main id="main">`,
7
8
  // everything else inside it, the footer after it — see `app/utils/pageStructure.ts`.
8
9
  //
9
- // Carousel counts are read off the real demo storefront (`app/storefront/demo.ts`), not assumed:
10
+ // Related counts are read off the real demo storefront (`app/storefront/demo.ts`), not assumed:
10
11
  // `RELATED_HANDLES` lists 7 handles including "merino-crew-sweater" itself; `product-carousel`'s
11
12
  // `related` variant filters out the product being viewed and any sold-out item (see that block's
12
- // own module doc comment), leaving the other 6 — all in stock in the demo catalogue — which is
13
- // where `RELATED_COUNT` below comes from. The product's own gallery has 2 images
13
+ // own module doc comment), leaving 6, and the fixture's `limit` of 4 shows the first four — which
14
+ // is where `RELATED_COUNT` below comes from. The product's own gallery has 2 images
14
15
  // (`buildFullProduct`: `[demoImage(index + 1, …), demoImage(index + 7, …)]`), and its `colour`
15
16
  // option carries one unavailable value ("Moss") used below to reach the back-in-stock dialog.
16
17
  import { flushPromises } from '@vue/test-utils';
@@ -31,7 +32,7 @@ import { createDemoStorefront } from '../../app/storefront/demo';
31
32
  const fixture = productPage as unknown as PageFixture;
32
33
 
33
34
  /** From `app/storefront/demo.ts` — see the module comment above. */
34
- const RELATED_COUNT = 6;
35
+ const RELATED_COUNT = 4;
35
36
 
36
37
  /** The product-detail block's own "no fake urgency" guard (`blocks/product-detail/__tests__/Block.spec.ts`), applied
37
38
  * here over the whole rendered page rather than one block. */
@@ -57,7 +58,6 @@ describe('product sample page', () => {
57
58
  'breadcrumbs',
58
59
  'product-detail',
59
60
  'product-carousel',
60
- 'faq',
61
61
  'footer',
62
62
  ]);
63
63
  });
@@ -74,8 +74,7 @@ describe('product sample page', () => {
74
74
  'data-eldra-header-focus', // navigation
75
75
  'aria-label="Breadcrumb"', // breadcrumbs
76
76
  'aria-label="Product images"', // product-detail (gallery)
77
- 'You may also like', // product-carousel
78
- 'Shipping &amp; care', // faq
77
+ 'Goes well with', // product-carousel
79
78
  '<footer', // footer
80
79
  ];
81
80
  const indices = markers.map((marker) => html.indexOf(marker));
@@ -124,7 +123,7 @@ describe('product sample page', () => {
124
123
  wrapper.unmount();
125
124
  });
126
125
 
127
- it('tab order runs header → breadcrumbs → product-detail → carousel → faq → footer', async () => {
126
+ it('tab order runs header → breadcrumbs → product-detail → related → footer', async () => {
128
127
  const wrapper = await mountProductPage();
129
128
  const html = wrapper.html();
130
129
  // The header's first focusable control. It used to be the Menu button, which the seeded header
@@ -133,10 +132,9 @@ describe('product sample page', () => {
133
132
  const header = html.indexOf('data-eldra-header-focus');
134
133
  const breadcrumb = html.indexOf('aria-label="Breadcrumb"');
135
134
  const gallery = html.indexOf('aria-label="Product images"');
136
- const carousel = html.indexOf('You may also like');
137
- const faqHeading = html.indexOf('Shipping &amp; care');
135
+ const related = html.indexOf('Goes well with');
138
136
  const footer = html.indexOf('<footer');
139
- const order = [header, breadcrumb, gallery, carousel, faqHeading, footer];
137
+ const order = [header, breadcrumb, gallery, related, footer];
140
138
  expect(order.every((i) => i >= 0)).toBe(true);
141
139
  for (let i = 1; i < order.length; i += 1) {
142
140
  expect(order[i]).toBeGreaterThan(order[i - 1]!);
@@ -144,43 +142,64 @@ describe('product sample page', () => {
144
142
  wrapper.unmount();
145
143
  });
146
144
 
147
- describe('related-products carousel', () => {
148
- it(`excludes the current product and shows the other ${RELATED_COUNT} demo related items`, async () => {
145
+ /**
146
+ * The design's "Goes well with": every related product at once in a four-across grid (the
147
+ * `grid` layout), never a sideways carousel with arrows, and no FAQ section after it — the design
148
+ * has none on the product page.
149
+ */
150
+ describe('related products ("Goes well with")', () => {
151
+ it(`shows ${RELATED_COUNT} related products as a grid, not a carousel, without the current product`, async () => {
149
152
  const wrapper = await mountProductPage();
150
- const carousel = wrapper.get('section[aria-roledescription="carousel"]');
151
- const slides = carousel.findAll('[data-part="slide"]');
152
- expect(slides).toHaveLength(RELATED_COUNT);
153
- for (const slide of slides) {
154
- expect(slide.text()).not.toContain('Merino crew sweater');
155
- }
153
+ const [, , , related] = pageBlockRoots(wrapper);
154
+ expect(related!.querySelector('h2')?.textContent).toContain('Goes well with');
155
+ expect(related!.querySelector('[aria-roledescription="carousel"]')).toBeNull();
156
+ const cards = related!.querySelectorAll('ul[role="list"] > li');
157
+ expect(cards).toHaveLength(RELATED_COUNT);
158
+ for (const card of cards) expect(card.textContent).not.toContain('Merino crew sweater');
159
+ // "Shop all knitwear →" on its own at the right of a plain heading.
160
+ expect(related!.querySelector('h2 a')).toBeNull();
161
+ expect(related!.querySelector('a[data-view-all]')?.textContent?.trim()).toBe(
162
+ 'Shop all knitwear'
163
+ );
156
164
  wrapper.unmount();
157
165
  });
158
166
 
159
- it(`labels slides "n of ${RELATED_COUNT}" and renders no counter`, async () => {
167
+ it('has no FAQ section on the page', async () => {
160
168
  const wrapper = await mountProductPage();
161
- const carousel = wrapper.get('section[aria-roledescription="carousel"]');
162
- const slides = carousel.findAll('[data-part="slide"]');
163
- expect(slides[0]!.attributes('aria-label')).toBe(`1 of ${RELATED_COUNT}`);
164
- expect(slides[RELATED_COUNT - 1]!.attributes('aria-label')).toBe(
165
- `${RELATED_COUNT} of ${RELATED_COUNT}`
166
- );
167
- // A product row shows several cards at once, so no "n / total" counter (spec "Carousel" →
168
- // Product row); the slides' own labels carry the position for assistive technology.
169
- expect(carousel.find('[data-part="counter"]').exists()).toBe(false);
169
+ expect(wrapper.text()).not.toContain('Shipping & care');
170
+ expect(wrapper.find('[data-block="faq"]').exists()).toBe(false);
170
171
  wrapper.unmount();
171
172
  });
172
173
  });
173
174
 
174
- it('shares the same ground across product-detail, the carousel and the FAQ, with only the footer changing it', async () => {
175
+ it('sets the related products on a `surface` band between the product and the footer', async () => {
175
176
  const wrapper = await mountProductPage();
176
- const [, , productDetail, carousel, faq, footer] = pageBlockRoots(wrapper);
177
+ const [, , productDetail, related, footer] = pageBlockRoots(wrapper);
177
178
  expect(productDetail!.getAttribute('data-section-bg')).toBe('none');
178
- expect(carousel!.getAttribute('data-section-bg')).toBe('none');
179
- expect(faq!.getAttribute('data-section-bg')).toBe('none');
179
+ expect(related!.getAttribute('data-section-bg')).toBe('surface');
180
180
  expect(footer!.getAttribute('data-section-bg')).toBe('primary');
181
- // Adjacency (not just value) is what the package's CSS rule keys off:
182
- expect(productDetail!.nextElementSibling).toBe(carousel);
183
- expect(carousel!.nextElementSibling).toBe(faq);
181
+ expect(productDetail!.nextElementSibling).toBe(related);
182
+ wrapper.unmount();
183
+ });
184
+
185
+ it('names the maker above the title, as a link to a search for their other products', async () => {
186
+ const wrapper = await mountProductPage();
187
+ const maker = wrapper.get('[data-product-maker] a');
188
+ expect(maker.text()).toBe('Fell & Fleece');
189
+ expect(maker.attributes('href')).toBe('/search?q=Fell%20%26%20Fleece');
190
+ const html = wrapper.html();
191
+ expect(html.indexOf('data-product-maker')).toBeLessThan(html.indexOf('<h1'));
192
+ wrapper.unmount();
193
+ });
194
+
195
+ it('draws the Details tab as a definition list of label and value pairs, open', async () => {
196
+ const wrapper = await mountProductPage();
197
+ const details = wrapper.findAll('details').find((d) => d.text().startsWith('Details'))!;
198
+ expect((details.element as HTMLDetailsElement).open).toBe(true);
199
+ const terms = details.findAll('dl > dt').map((dt) => dt.text());
200
+ expect(terms).toEqual(['Material', 'Fit', 'Weight', 'Made in']);
201
+ expect(details.findAll('dl > dd')).toHaveLength(4);
202
+ expect(details.find('ul').exists()).toBe(false);
184
203
  wrapper.unmount();
185
204
  });
186
205
 
@@ -215,19 +234,21 @@ describe('product sample page', () => {
215
234
  });
216
235
 
217
236
  describe('modals', () => {
218
- it('menu drawer: opens as a dialog and Esc returns focus to the menu button', async () => {
237
+ it('menu drawer: opens under the header and Esc returns focus to the menu button', async () => {
219
238
  const wrapper = await mountProductPageWithHeaderLink();
220
239
  const menuButton = wrapper.get('button[aria-label="Menu"]');
221
240
  menuButton.element.focus();
222
241
  await menuButton.trigger('click');
223
- const dialog = wrapper.get('dialog[open]');
224
- expect(dialog.attributes('open')).toBe('');
242
+ // The design's inline drawer: a disclosure under the bar, its button now reading Close.
243
+ expect(menuButton.attributes('aria-expanded')).toBe('true');
244
+ expect(menuButton.attributes('aria-label')).toBe('Close');
245
+ expect(wrapper.findAll('dialog[open]')).toHaveLength(0);
225
246
 
226
247
  document.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
227
248
  await new Promise((resolve) => setTimeout(resolve));
228
249
  await wrapper.vm.$nextTick();
229
250
 
230
- expect(wrapper.findAll('dialog[open]')).toHaveLength(0);
251
+ expect(menuButton.attributes('aria-expanded')).toBe('false');
231
252
  expect(document.activeElement).toBe(menuButton.element);
232
253
  wrapper.unmount();
233
254
  });
@@ -303,14 +324,13 @@ describe('product sample page', () => {
303
324
  wrapper.unmount();
304
325
  });
305
326
 
306
- it('carries the shared policy facts (Portland, 2 business days, over $80, free US returns, 400°F)', async () => {
327
+ it('carries the shared policy facts (Portland, 2 business days, over $80, 30-day returns)', async () => {
307
328
  const wrapper = await mountProductPage();
308
329
  const text = wrapper.text();
309
330
  expect(text).toContain('Portland');
310
331
  expect(text).toContain('2 business days');
311
332
  expect(text).toContain('$80');
312
- expect(text).toContain('US returns are free');
313
- expect(text).toContain('400°F');
333
+ expect(text).toContain('30-day returns');
314
334
  wrapper.unmount();
315
335
  });
316
336
 
@@ -377,7 +377,9 @@ describe('server rendering', () => {
377
377
 
378
378
  expect(html).toContain('Fisherman rib cardigan');
379
379
  expect(html).toContain('$164.00');
380
- expect(html).toContain('In stock, ships in 1–2 days');
380
+ // The maker line, not a stock line: the theme's card draws none (`toProductCard`).
381
+ expect(html).toContain('Fell &amp; Fleece');
382
+ expect(html).not.toContain('In stock, ships in 1–2 days');
381
383
  expect(html).not.toContain('eldra-skeleton');
382
384
  expect(html).not.toContain('eldra-revalidating');
383
385
  expect(html).not.toContain('aria-busy="true"');
@@ -13,6 +13,7 @@ import {
13
13
  DEFAULT_LOCALE,
14
14
  HOME_PAGE_PATH,
15
15
  LINKED_HEADER_LABELS,
16
+ MOCK_REGION,
16
17
  PREFIXED_LOCALE,
17
18
  PRODUCT_HANDLE,
18
19
  SEEDED_CART_ID,
@@ -613,13 +614,16 @@ describe('prerendered commerce data on the generated static site', () => {
613
614
  );
614
615
  }
615
616
 
616
- // The store still sells in ISK; only the formatting follows the page.
617
+ // The store still sells in ISK, and its prices are written in the organisation's regional
618
+ // format (`MOCK_REGION`, Icelandic) on **both** pages — the content locale changes the words,
619
+ // never how money is written. The English page printing "ISK 42" was the defect.
617
620
  const product = staticHtml(`/${PREFIXED_LOCALE}/products/${PRODUCT_HANDLE}`);
618
- expect(product).toContain(formatMoney(42, 'ISK', PREFIXED_LOCALE));
619
- expect(staticHtml(`/products/${PRODUCT_HANDLE}`)).toContain(
620
- formatMoney(42, 'ISK', DEFAULT_LOCALE)
621
- );
622
- expect(formatMoney(42, 'ISK', PREFIXED_LOCALE)).not.toBe(
621
+ const english = staticHtml(`/products/${PRODUCT_HANDLE}`);
622
+ expect(product).toContain(formatMoney(42, 'ISK', MOCK_REGION.formatLocale));
623
+ expect(english).toContain(formatMoney(42, 'ISK', MOCK_REGION.formatLocale));
624
+ expect(english).not.toContain(formatMoney(42, 'ISK', DEFAULT_LOCALE));
625
+ expect(english).toContain(`region:{countryCode:"IS",formatLocale:"is-IS"`);
626
+ expect(formatMoney(42, 'ISK', MOCK_REGION.formatLocale)).not.toBe(
623
627
  formatMoney(42, 'ISK', DEFAULT_LOCALE)
624
628
  );
625
629
  });
@@ -689,8 +693,8 @@ describe('prerendered commerce data on the generated static site', () => {
689
693
  // case would keep passing while quietly testing nothing.
690
694
  expect(visited.url).toBe(`${statics.origin}${productPage}/`);
691
695
  const instances = blockInstances(visited);
692
- // The page's own six, plus the shell's hosted cart drawer (see the control above).
693
- expect(Object.keys(instances.created).length).toBe(7);
696
+ // The page's own five, plus the shell's hosted cart drawer (see the control above).
697
+ expect(Object.keys(instances.created).length).toBe(6);
694
698
  // The page is served at `/products/ash-glaze-mug/` and prerendered at
695
699
  // `/products/ash-glaze-mug` (`startStaticServer`'s 308 is the deployed host's). Nuxt therefore
696
700
  // re-navigates between the two while the page hydrates, and unless the route key and the page
@@ -709,7 +713,7 @@ describe('prerendered commerce data on the generated static site', () => {
709
713
  // (`test/support/mockGateway.ts` publishes ISK — and says why it is not dollars). A page that
710
714
  // fell back to `@eldrajs/ui`'s ambient default would read `$42.00` here instead.
711
715
  expect(html, path).toContain('commerce:{currency:"ISK"');
712
- expect(html, path).toContain(formatMoney(42, 'ISK'));
716
+ expect(html, path).toContain(formatMoney(42, 'ISK', MOCK_REGION.formatLocale));
713
717
  expect(html, path).not.toContain('$42.00');
714
718
  expect(html, path).toContain('Ash glaze mug');
715
719
  expect(html, path).not.toContain('eldra-skeleton');
@@ -808,9 +812,10 @@ describe('prerendered commerce data on the generated static site', () => {
808
812
  // real claim rather than a coincidence of where this item sits.
809
813
  expect(edges.trigger.left).toBeGreaterThan(edges.panel.left + 1);
810
814
  expect(edges.trigger.right).toBeLessThan(edges.panel.right - 1);
811
- // And nothing inside the panel sits flush against its edges: the page's own gutters at least.
812
- expect(edges.firstColumn.left).toBeGreaterThanOrEqual(edges.panel.left + 24);
813
- expect(edges.viewAll.right).toBeLessThanOrEqual(edges.panel.right - 24);
815
+ // And nothing inside the panel sits flush against its edges: the page's own gutter at least,
816
+ // which is the design's 1rem (`tokens.json` containers, via `--eldra-gutter-*` in main.css).
817
+ expect(edges.firstColumn.left).toBeGreaterThanOrEqual(edges.panel.left + 16);
818
+ expect(edges.viewAll.right).toBeLessThanOrEqual(edges.panel.right - 16);
814
819
  } finally {
815
820
  await page.close();
816
821
  }
@@ -1027,12 +1032,12 @@ describe('prerendered commerce data on the generated static site', () => {
1027
1032
  // it, a null-sourced result makes no request and carries no data; it is in the payload
1028
1033
  // because it exists, and the browser computes the same key for it.
1029
1034
  'storefront:catalog.category:[null]',
1030
- 'storefront:catalog.collectionProducts:[null,{"page":1,"pageSize":8}]',
1035
+ 'storefront:catalog.collectionProducts:[null,{"page":1,"pageSize":4}]',
1031
1036
  'storefront:catalog.product:["ash-glaze-mug"]',
1032
- // `product-carousel`'s quick-add read, keyed `null` until a shopper presses Quick add: no
1037
+ // The shared quick-add read (`useQuickAdd`), keyed `null` until a shopper presses Add: no
1033
1038
  // request and no data, in the payload because it exists, like the category read above.
1034
1039
  'storefront:catalog.product:[null]',
1035
- 'storefront:catalog.related:["ash-glaze-mug",8]',
1040
+ 'storefront:catalog.related:["ash-glaze-mug",4]',
1036
1041
  // The footer's sign-up spam guard (`useFormSpam`): a footer with no newsletter zone names no
1037
1042
  // form, so the read is keyed `""`, resolves `null` without a request and is in the payload
1038
1043
  // because it exists.
@@ -1045,13 +1050,12 @@ describe('prerendered commerce data on the generated static site', () => {
1045
1050
  const visited = await visit(productPage);
1046
1051
  // The **full** log, duplicates included, not a set of unique URLs. `product-detail` re-reads
1047
1052
  // its own product (only that read knows the variant-level inventory the products list cannot
1048
- // answer about), and every card on the page — the carousel's six — is one batched `id:in` read.
1053
+ // answer about), and every card on the page — "Goes well with"'s four — is one batched `id:in` read.
1049
1054
  // Nothing else: no re-run of a prerendered non-volatile read, and nothing twice.
1050
1055
  expect(visited.requests).toEqual([
1051
1056
  `/catalog/v1/products/${PRODUCT_HANDLE}`,
1052
- '/catalog/v1/products/list?pageSize=6&filter=id:in:prod-cedar-serving-board,' +
1053
- 'prod-flax-tea-towel,prod-stoneware-bowl,prod-brass-candle-holder,prod-linen-napkin-set,' +
1054
- 'prod-walnut-spoon',
1057
+ '/catalog/v1/products/list?pageSize=4&filter=id:in:prod-cedar-serving-board,' +
1058
+ 'prod-flax-tea-towel,prod-stoneware-bowl,prod-brass-candle-holder',
1055
1059
  // The detail read's second half: the product's own inventory, which the list read has none of.
1056
1060
  '/inventory/v1/stock/availability',
1057
1061
  ]);
@@ -1062,9 +1066,10 @@ describe('prerendered commerce data on the generated static site', () => {
1062
1066
  it('draws the refresh treatment on every value it is re-reading, then clears it', async () => {
1063
1067
  const visited = await visit(productPage);
1064
1068
  const peak = peakOf(visited.samples);
1065
- // Two values on the product itself (price, stock line) and two on each of the six cards.
1066
- expect(peak.spinners).toBe(14);
1067
- expect(peak.dimmed).toBeGreaterThanOrEqual(14);
1069
+ // Two values on the product itself (price, stock line) and one, the price, on each of the four
1070
+ // cards: the design's card has no stock line.
1071
+ expect(peak.spinners).toBe(6);
1072
+ expect(peak.dimmed).toBeGreaterThanOrEqual(6);
1068
1073
  expect(peak.busy).toBeGreaterThan(0);
1069
1074
  // Something says so out loud — the carousel's one row-level region, plus the product's own
1070
1075
  // price and stock line, which announce for themselves. How many regions each block owns is
@@ -1072,8 +1077,8 @@ describe('prerendered commerce data on the generated static site', () => {
1072
1077
  expect(peak.announced).toBeGreaterThanOrEqual(1);
1073
1078
  // …and it is gone once the refresh has answered, with the prerendered values still on screen.
1074
1079
  expect(visited.samples[visited.samples.length - 1]).toEqual(NOTHING);
1075
- expect(visited.prices).toContain(formatMoney(42, 'ISK'));
1076
- expect(visited.prices).toContain(formatMoney(68, 'ISK'));
1080
+ expect(visited.prices).toContain(formatMoney(42, 'ISK', MOCK_REGION.formatLocale));
1081
+ expect(visited.prices).toContain(formatMoney(68, 'ISK', MOCK_REGION.formatLocale));
1077
1082
  });
1078
1083
 
1079
1084
  /**
@@ -1095,7 +1100,7 @@ describe('prerendered commerce data on the generated static site', () => {
1095
1100
  // Both blocks still draw the treatment and both end up showing the refreshed values: the block
1096
1101
  // that arrived second folds in the answer the first one's read had already brought back.
1097
1102
  const peak = peakOf(visited.samples);
1098
- expect(peak.spinners).toBe(28); // seven cards in the grid, seven in the carousel, two each
1103
+ expect(peak.spinners).toBe(14); // seven cards in the grid, seven in the carousel, a price each
1099
1104
  expect(peak.busy).toBeGreaterThan(0);
1100
1105
  expect(peak.announced).toBe(2); // one row-level region per block
1101
1106
  expect(visited.samples[visited.samples.length - 1]).toEqual(NOTHING);
@@ -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
+ });