@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.
- package/CHANGELOG.md +12 -1
- package/package.json +3 -3
- package/template/.eldra/block-types.d.ts +4 -6
- package/template/.eldra/manifest.json +228 -246
- package/template/.eldra/previews.json +35 -35
- package/template/.storybook/eldra.ts +7 -2
- package/template/app/assets/main.css +5 -0
- package/template/app/composables/useBlockData.ts +9 -2
- package/template/app/composables/usePriceTokens.ts +150 -0
- package/template/app/composables/useQuickAdd.ts +95 -0
- package/template/app/composables/useRegionalFormat.ts +94 -0
- package/template/app/icons.ts +4 -0
- package/template/app/plugins/eldra-storefront.ts +2 -0
- package/template/app/plugins/eldra-ui-messages.ts +22 -8
- package/template/app/storefront/demo.ts +188 -16
- package/template/app/storefront/gateway.ts +19 -0
- package/template/app/storefront/productCardLook.ts +76 -0
- package/template/app/storefront/productReference.ts +17 -0
- package/template/app/storefront/toProductCard.ts +12 -8
- package/template/app/storefront/types.ts +17 -0
- package/template/blocks/announcement-bar/__tests__/Block.spec.ts +19 -7
- package/template/blocks/announcement-bar/block.json +2 -1
- package/template/blocks/announcement-bar/mock.json +1 -1
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/Block.vue +8 -18
- package/template/blocks/article/block.json +3 -1
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/block.json +10 -1
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/Block.vue +15 -3
- package/template/blocks/breadcrumbs/__tests__/Block.spec.ts +13 -0
- package/template/blocks/breadcrumbs/block.json +1 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/Block.vue +15 -5
- package/template/blocks/cart/__tests__/Block.spec.ts +53 -10
- package/template/blocks/cart/__tests__/ShippingBar.spec.ts +10 -8
- package/template/blocks/cart/block.json +8 -5
- package/template/blocks/cart/mock.json +2 -2
- package/template/blocks/cart/parts/ShippingBar.vue +24 -30
- package/template/blocks/cart/parts/notSold.ts +4 -3
- package/template/blocks/collection-grid/Block.vue +168 -85
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +101 -23
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +51 -17
- package/template/blocks/collection-header/__tests__/Block.spec.ts +80 -4
- package/template/blocks/collection-header/block.json +2 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/block.json +4 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/block.json +2 -0
- package/template/blocks/faq/Block.vue +5 -10
- package/template/blocks/faq/block.json +2 -1
- package/template/blocks/faq/mock.json +12 -1
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +30 -7
- package/template/blocks/feature-grid/block.json +3 -2
- package/template/blocks/feature-grid/mock.json +1 -1
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +64 -21
- package/template/blocks/footer/__tests__/Block.spec.ts +97 -1
- package/template/blocks/footer/block.json +5 -2
- package/template/blocks/footer/mock.json +1 -1
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/form/block.json +1 -0
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +38 -9
- package/template/blocks/hero/__tests__/Block.spec.ts +71 -19
- package/template/blocks/hero/block.json +16 -22
- package/template/blocks/hero/preview.json +1 -3
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/block.json +2 -1
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/block.json +1 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +405 -159
- package/template/blocks/navigation/__tests__/Block.spec.ts +816 -172
- package/template/blocks/navigation/__tests__/currentItem.spec.ts +90 -0
- package/template/blocks/navigation/block.json +2 -11
- package/template/blocks/navigation/mock.json +3 -3
- package/template/blocks/navigation/parts/LocalePicker.vue +103 -0
- package/template/blocks/navigation/parts/currentItem.ts +82 -0
- package/template/blocks/navigation/preview.json +7 -1
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/newsletter/Block.vue +6 -2
- package/template/blocks/newsletter/block.json +2 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/Block.vue +8 -17
- package/template/blocks/order-status/block.json +3 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/__tests__/Block.spec.ts +12 -4
- package/template/blocks/pricing-table/block.json +2 -0
- package/template/blocks/pricing-table/mock.json +6 -6
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +36 -126
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +88 -0
- package/template/blocks/product-carousel/block.json +1 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +84 -31
- package/template/blocks/product-detail/__tests__/Block.spec.ts +86 -0
- package/template/blocks/product-detail/__tests__/specs.spec.ts +79 -0
- package/template/blocks/product-detail/block.json +3 -1
- package/template/blocks/product-detail/mock.json +54 -4
- package/template/blocks/product-detail/parts/Gallery.vue +8 -2
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/product-detail/specs.ts +75 -0
- package/template/blocks/quote/block.json +1 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +6 -1
- package/template/blocks/search/TypeSection.vue +8 -1
- package/template/blocks/search/__tests__/Block.spec.ts +24 -1
- package/template/blocks/search/block.json +1 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/split-content/Block.vue +12 -5
- package/template/blocks/split-content/__tests__/Block.spec.ts +13 -0
- package/template/blocks/split-content/block.json +4 -2
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/Block.vue +3 -4
- package/template/blocks/tabs/block.json +1 -1
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/block.json +3 -1
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/block.json +2 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/block.json +2 -1
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +2 -2
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +38 -9
- package/template/blocks/trust-strip/block.json +1 -1
- package/template/blocks/trust-strip/mock.json +1 -1
- package/template/blocks/trust-strip/preview.json +1 -1
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/block.json +2 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/Block.vue +2 -2
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +13 -5
- package/template/i18n/is-IS.json +12 -4
- package/template/pages/article.page.json +1 -3
- package/template/pages/cart.page.json +1 -3
- package/template/pages/category.page.json +2 -4
- package/template/pages/collection.page.json +1 -3
- package/template/pages/home.page.json +7 -18
- package/template/pages/product.page.json +62 -131
- package/template/pages/products.page.json +1 -3
- package/template/pages/search.page.json +1 -3
- package/template/pages/wishlist.page.json +1 -3
- package/template/stories/generated/footer.stories.ts +6 -0
- package/template/stories/generated/navigation.stories.ts +0 -18
- package/template/test/inlineEditable.spec.ts +10 -2
- package/template/test/localePrefix.spec.ts +2 -19
- package/template/test/pages/article.spec.ts +0 -2
- package/template/test/pages/category.spec.ts +35 -13
- package/template/test/pages/home.spec.ts +33 -17
- package/template/test/pages/product.spec.ts +64 -44
- package/template/test/pages/ssr.spec.ts +3 -1
- package/template/test/prerenderRefresh.browser.spec.ts +30 -25
- package/template/test/previewParity.browser.spec.ts +36 -2
- package/template/test/priceTokens.spec.ts +309 -0
- package/template/test/regionalFormat.spec.ts +80 -0
- package/template/test/starter.spec.ts +23 -7
- package/template/test/storefront/demo.spec.ts +19 -18
- package/template/test/storefront/toProductCard.spec.ts +17 -2
- package/template/test/structuredData.generate.spec.ts +4 -2
- package/template/test/support/mockGateway.ts +21 -1
- package/template/test/support/mountBlock.ts +25 -4
- package/template/test/support/priceTokens.ts +20 -0
- package/template/test/uiMessagesPlugin.spec.ts +34 -1
- 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",
|
|
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
|
-
//
|
|
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
|
|
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 =
|
|
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
|
-
'
|
|
78
|
-
'Shipping & 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 →
|
|
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
|
|
137
|
-
const faqHeading = html.indexOf('Shipping & care');
|
|
135
|
+
const related = html.indexOf('Goes well with');
|
|
138
136
|
const footer = html.indexOf('<footer');
|
|
139
|
-
const order = [header, breadcrumb, gallery,
|
|
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
|
-
|
|
148
|
-
|
|
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
|
|
151
|
-
|
|
152
|
-
expect(
|
|
153
|
-
|
|
154
|
-
|
|
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(
|
|
167
|
+
it('has no FAQ section on the page', async () => {
|
|
160
168
|
const wrapper = await mountProductPage();
|
|
161
|
-
|
|
162
|
-
|
|
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('
|
|
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,
|
|
177
|
+
const [, , productDetail, related, footer] = pageBlockRoots(wrapper);
|
|
177
178
|
expect(productDetail!.getAttribute('data-section-bg')).toBe('none');
|
|
178
|
-
expect(
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
|
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
|
-
|
|
224
|
-
expect(
|
|
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(
|
|
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,
|
|
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('
|
|
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
|
-
|
|
380
|
+
// The maker line, not a stock line: the theme's card draws none (`toProductCard`).
|
|
381
|
+
expect(html).toContain('Fell & 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
|
|
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
|
-
|
|
619
|
-
expect(
|
|
620
|
-
|
|
621
|
-
);
|
|
622
|
-
expect(
|
|
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
|
|
693
|
-
expect(Object.keys(instances.created).length).toBe(
|
|
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
|
|
812
|
-
|
|
813
|
-
expect(edges.
|
|
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":
|
|
1035
|
+
'storefront:catalog.collectionProducts:[null,{"page":1,"pageSize":4}]',
|
|
1031
1036
|
'storefront:catalog.product:["ash-glaze-mug"]',
|
|
1032
|
-
//
|
|
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",
|
|
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 —
|
|
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=
|
|
1053
|
-
'prod-flax-tea-towel,prod-stoneware-bowl,prod-brass-candle-holder,
|
|
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
|
|
1066
|
-
|
|
1067
|
-
expect(peak.
|
|
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(
|
|
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);
|
|
@@ -567,7 +567,22 @@ function capture(origin: string, path: string, width: number, session: boolean):
|
|
|
567
567
|
});
|
|
568
568
|
}
|
|
569
569
|
|
|
570
|
-
/**
|
|
570
|
+
/**
|
|
571
|
+
* A full-page screenshot, after the same normalisation as the DOM.
|
|
572
|
+
*
|
|
573
|
+
* Captured beyond the viewport, as `fullPage: true` does, but only once the viewport already is the
|
|
574
|
+
* document's height and the page has settled at that size. A capture beyond the viewport draws the
|
|
575
|
+
* page afresh, which is what keeps a session's paint history (a block re-rendered from the draft)
|
|
576
|
+
* out of the pixels. But Playwright's `fullPage: true` grows the view in that same capture, and the
|
|
577
|
+
* taller view changes the layer tree: on `/` at 1280 the open search popover needed its own layer
|
|
578
|
+
* only because the page scrolled under it. The frame is drawn before or after that change lands, a
|
|
579
|
+
* race decided on every load, and the popover's suggestion chips sit on a fractional pixel, so
|
|
580
|
+
* their rounded borders came out a step of anti-aliasing apart, about 60 pixels, on whichever page
|
|
581
|
+
* lost the race (WS-1450). Grown first, the capture changes nothing about the page it draws.
|
|
582
|
+
*
|
|
583
|
+
* What `animations: 'disabled'` and `caret: 'hide'` did is done here: a finite animation is
|
|
584
|
+
* finished, an infinite one cancelled, and the caret made transparent, the same on both pages.
|
|
585
|
+
*/
|
|
571
586
|
function screenshot(
|
|
572
587
|
origin: string,
|
|
573
588
|
path: string,
|
|
@@ -577,7 +592,26 @@ function screenshot(
|
|
|
577
592
|
return open(origin, path, width, session, async (page) => {
|
|
578
593
|
await normalise(page, session);
|
|
579
594
|
await settle(page, true);
|
|
580
|
-
|
|
595
|
+
const height = await page.evaluate(() => document.documentElement.scrollHeight);
|
|
596
|
+
await page.setViewportSize({ width, height });
|
|
597
|
+
await settle(page, true);
|
|
598
|
+
await page.addStyleTag({
|
|
599
|
+
content: '*, *::before, *::after { caret-color: transparent !important; }',
|
|
600
|
+
});
|
|
601
|
+
await page.evaluate(async () => {
|
|
602
|
+
for (const animation of document.getAnimations()) {
|
|
603
|
+
if (animation.effect?.getComputedTiming().endTime === Infinity) animation.cancel();
|
|
604
|
+
else animation.finish();
|
|
605
|
+
}
|
|
606
|
+
await new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve)));
|
|
607
|
+
});
|
|
608
|
+
const cdp = await page.context().newCDPSession(page);
|
|
609
|
+
const { data } = await cdp.send('Page.captureScreenshot', {
|
|
610
|
+
format: 'png',
|
|
611
|
+
clip: { x: 0, y: 0, width, height, scale: 1 },
|
|
612
|
+
captureBeyondViewport: true,
|
|
613
|
+
});
|
|
614
|
+
return Buffer.from(data, 'base64');
|
|
581
615
|
});
|
|
582
616
|
}
|
|
583
617
|
|