@eldrajs/theme-cli 0.2.7 → 0.2.9
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 +2 -0
- package/package.json +3 -3
- package/template/.eldra/block-types.d.ts +28 -7
- package/template/.eldra/manifest.json +1152 -445
- package/template/.eldra/previews.json +35 -35
- package/template/README.md +32 -0
- package/template/app/assets/main.css +23 -0
- package/template/app/plugins/eldra-storefront.ts +3 -0
- package/template/app/storefront/demo.ts +75 -24
- package/template/app/storefront/gateway.ts +16 -2
- package/template/blocks/announcement-bar/preview.png +0 -0
- package/template/blocks/article/preview.json +4 -4
- package/template/blocks/article/preview.png +0 -0
- package/template/blocks/article-list/Block.vue +48 -19
- package/template/blocks/article-list/__tests__/Block.spec.ts +15 -0
- package/template/blocks/article-list/preview.json +43 -43
- package/template/blocks/article-list/preview.png +0 -0
- package/template/blocks/breadcrumbs/preview.png +0 -0
- package/template/blocks/cart/preview.png +0 -0
- package/template/blocks/collection-grid/Block.vue +260 -9
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +202 -0
- package/template/blocks/collection-grid/block.json +3 -3
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/Block.vue +65 -52
- package/template/blocks/collection-header/preview.json +4 -4
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/contact/preview.png +0 -0
- package/template/blocks/cta/preview.json +4 -4
- package/template/blocks/cta/preview.png +0 -0
- package/template/blocks/faq/preview.png +0 -0
- package/template/blocks/feature-grid/Block.vue +73 -4
- package/template/blocks/feature-grid/__tests__/Block.spec.ts +43 -1
- package/template/blocks/feature-grid/block.json +2 -2
- package/template/blocks/feature-grid/preview.json +49 -24
- package/template/blocks/feature-grid/preview.png +0 -0
- package/template/blocks/footer/Block.vue +186 -71
- package/template/blocks/footer/__tests__/Block.spec.ts +127 -32
- package/template/blocks/footer/block.json +42 -4
- package/template/blocks/footer/mock.json +31 -34
- package/template/blocks/footer/preview.png +0 -0
- package/template/blocks/form/preview.png +0 -0
- package/template/blocks/gallery/preview.json +24 -24
- package/template/blocks/gallery/preview.png +0 -0
- package/template/blocks/hero/Block.vue +117 -19
- package/template/blocks/hero/__tests__/Block.spec.ts +46 -0
- package/template/blocks/hero/block.json +36 -1
- package/template/blocks/hero/preview.json +33 -25
- package/template/blocks/hero/preview.png +0 -0
- package/template/blocks/image/preview.json +4 -4
- package/template/blocks/image/preview.png +0 -0
- package/template/blocks/logo-cloud/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +665 -184
- package/template/blocks/navigation/__tests__/Block.spec.ts +496 -75
- package/template/blocks/navigation/__tests__/fixtures/menu.json +182 -0
- package/template/blocks/navigation/block.json +110 -6
- package/template/blocks/navigation/mock.json +372 -140
- package/template/blocks/navigation/preview.json +311 -0
- package/template/blocks/navigation/preview.png +0 -0
- package/template/blocks/newsletter/Block.vue +248 -144
- package/template/blocks/newsletter/__tests__/Block.spec.ts +42 -0
- package/template/blocks/newsletter/block.json +61 -2
- package/template/blocks/newsletter/preview.json +35 -0
- package/template/blocks/newsletter/preview.png +0 -0
- package/template/blocks/order-status/preview.png +0 -0
- package/template/blocks/pricing-table/preview.png +0 -0
- package/template/blocks/product-carousel/Block.vue +272 -26
- package/template/blocks/product-carousel/__tests__/Block.spec.ts +90 -0
- package/template/blocks/product-carousel/block.json +61 -0
- package/template/blocks/product-carousel/preview.json +12 -0
- package/template/blocks/product-carousel/preview.png +0 -0
- package/template/blocks/product-detail/Block.vue +148 -96
- package/template/blocks/product-detail/__tests__/Block.spec.ts +98 -74
- package/template/blocks/product-detail/block.json +11 -4
- package/template/blocks/product-detail/mock.json +53 -22
- package/template/blocks/product-detail/parts/Gallery.vue +52 -103
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/quote/preview.png +0 -0
- package/template/blocks/rich-text/preview.png +0 -0
- package/template/blocks/search/Block.vue +1 -0
- package/template/blocks/search/TypeSection.vue +1 -0
- package/template/blocks/search/__tests__/Block.spec.ts +23 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/split-content/Block.vue +98 -20
- package/template/blocks/split-content/__tests__/Block.spec.ts +57 -18
- package/template/blocks/split-content/block.json +72 -6
- package/template/blocks/split-content/preview.json +34 -13
- package/template/blocks/split-content/preview.png +0 -0
- package/template/blocks/stats/preview.png +0 -0
- package/template/blocks/tabs/preview.json +16 -16
- package/template/blocks/tabs/preview.png +0 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/testimonials/preview.png +0 -0
- package/template/blocks/timeline/preview.png +0 -0
- package/template/blocks/trust-strip/Block.vue +67 -1
- package/template/blocks/trust-strip/__tests__/Block.spec.ts +30 -1
- package/template/blocks/trust-strip/block.json +4 -4
- package/template/blocks/trust-strip/preview.json +21 -0
- package/template/blocks/trust-strip/preview.png +0 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/blocks/wishlist/preview.png +0 -0
- package/template/i18n/en-US.json +16 -9
- package/template/i18n/is-IS.json +16 -9
- package/template/package.json +1 -1
- package/template/pages/article.page.json +19 -18
- package/template/pages/cart.page.json +3 -13
- package/template/pages/category.page.json +15 -7
- package/template/pages/collection.page.json +15 -14
- package/template/pages/home.page.json +217 -182
- package/template/pages/product.page.json +46 -36
- package/template/pages/products.page.json +3 -13
- package/template/pages/search.page.json +3 -13
- package/template/pages/wishlist.page.json +3 -13
- package/template/public/images/CREDITS.md +28 -0
- package/template/public/images/bowl.webp +0 -0
- package/template/public/images/clay-hands.webp +0 -0
- package/template/public/images/coffee-table.webp +0 -0
- package/template/public/images/cup.webp +0 -0
- package/template/public/images/enamel-cups.webp +0 -0
- package/template/public/images/hero.webp +0 -0
- package/template/public/images/kitchen.webp +0 -0
- package/template/public/images/mug.webp +0 -0
- package/template/public/images/northwind-mark.svg +1 -0
- package/template/public/images/planters.webp +0 -0
- package/template/public/images/plates.webp +0 -0
- package/template/public/images/reading.webp +0 -0
- package/template/public/images/sweater.webp +0 -0
- package/template/public/images/terracotta.webp +0 -0
- package/template/public/images/throws.webp +0 -0
- package/template/public/images/vase.webp +0 -0
- package/template/public/images/wheel.webp +0 -0
- package/template/public/images/yarn-tools.webp +0 -0
- package/template/public/images/yarn.webp +0 -0
- package/template/stories/generated/collection-grid.stories.ts +6 -0
- package/template/stories/generated/feature-grid.stories.ts +6 -0
- package/template/stories/generated/footer.stories.ts +4 -4
- package/template/stories/generated/hero.stories.ts +6 -0
- package/template/stories/generated/navigation.stories.ts +14 -1
- package/template/stories/generated/newsletter.stories.ts +2 -1
- package/template/stories/generated/product-carousel.stories.ts +12 -0
- package/template/stories/generated/split-content.stories.ts +12 -0
- package/template/stories/generated/trust-strip.stories.ts +8 -1
- package/template/stories/pages/article.stories.ts +2 -1
- package/template/stories/pages/cart.stories.ts +2 -1
- package/template/stories/pages/category.stories.ts +2 -1
- package/template/stories/pages/collection.stories.ts +2 -1
- package/template/stories/pages/home.stories.ts +2 -1
- package/template/stories/pages/product.stories.ts +2 -1
- package/template/stories/pages/products.stories.ts +2 -1
- package/template/stories/pages/search.stories.ts +2 -1
- package/template/stories/pages/wishlist.stories.ts +2 -1
- package/template/stories/support/demoChrome.ts +32 -0
- package/template/stories/support/pageBlocks.ts +2 -4
- package/template/test/countPill.browser.spec.ts +21 -13
- package/template/test/localePrefix.spec.ts +11 -6
- package/template/test/pages/article.spec.ts +1 -1
- package/template/test/pages/category.spec.ts +34 -11
- package/template/test/pages/collection.spec.ts +182 -148
- package/template/test/pages/home.spec.ts +35 -40
- package/template/test/pages/hydration.spec.ts +4 -4
- package/template/test/pages/product.spec.ts +17 -14
- package/template/test/pages/seededPages.spec.ts +11 -6
- package/template/test/prerenderFailure.spec.ts +4 -3
- package/template/test/prerenderRefresh.browser.spec.ts +36 -15
- package/template/test/previewParity.browser.spec.ts +1152 -0
- package/template/test/starter.spec.ts +37 -16
- package/template/test/storefront/gatewayPrerender.spec.ts +26 -0
- package/template/test/support/previewParity.ts +302 -0
- package/template/test/support/previewParityContent.ts +726 -0
- package/template/tokens.json +13 -13
|
@@ -6,7 +6,8 @@ import { Badge } from '@eldrajs/ui';
|
|
|
6
6
|
import { enUS as uiEnUS } from '@eldrajs/ui';
|
|
7
7
|
import { axe } from '../../../test/support/axe';
|
|
8
8
|
import Block from '../Block.vue';
|
|
9
|
-
import
|
|
9
|
+
import seed from '../mock.json';
|
|
10
|
+
import menuFixture from './fixtures/menu.json';
|
|
10
11
|
import { mountOptions } from '../../../test/support/mountBlock';
|
|
11
12
|
import { computed, nextTick, ref, type Ref } from 'vue';
|
|
12
13
|
import { STOREFRONT_KEY } from '../../../app/storefront/types';
|
|
@@ -21,6 +22,15 @@ import { createDemoStorefront } from '../../../app/storefront/demo';
|
|
|
21
22
|
// slug and a title before rendering. `resolveTargets` does both here, so a spec can assert the
|
|
22
23
|
// hrefs a real page produces; `mock` itself stays the unresolved seed, which is what a header
|
|
23
24
|
// looks like the moment it is inserted and nothing has resolved yet.
|
|
25
|
+
// The menu and keyboard specs below were written against a five-item bar — Knitwear and Ceramics
|
|
26
|
+
// as mega-menus, then Kitchen, Journal and Visit the studio as plain links — and they count
|
|
27
|
+
// triggers and walk panels by position. That menu is kept as a fixture (`fixtures/menu.json`, the
|
|
28
|
+
// seed's links before the Northwind redesign) so those specs keep measuring `NavMenu`'s behaviour
|
|
29
|
+
// rather than whichever demo menu the seed happens to ship; everything else is the real seed, info
|
|
30
|
+
// strip included. The redesigned seed's own menu (sections with cards, a badge, a dropdown) has its
|
|
31
|
+
// own specs under "the Northwind menu".
|
|
32
|
+
const mock = { ...seed, links: menuFixture.links, searchStyle: 'icon' as const };
|
|
33
|
+
|
|
24
34
|
const COLLECTION_TEMPLATE = {
|
|
25
35
|
id: 'rt-collection',
|
|
26
36
|
data: {
|
|
@@ -35,7 +45,14 @@ interface SeedTarget {
|
|
|
35
45
|
slug?: string;
|
|
36
46
|
id?: string;
|
|
37
47
|
}
|
|
48
|
+
interface SeedSection {
|
|
49
|
+
heading?: string;
|
|
50
|
+
links?: SeedLink[];
|
|
51
|
+
seeAll?: SeedLink;
|
|
52
|
+
headingLink?: SeedLink;
|
|
53
|
+
}
|
|
38
54
|
interface SeedLink {
|
|
55
|
+
sections?: SeedSection[];
|
|
39
56
|
kind: string;
|
|
40
57
|
target?: SeedTarget;
|
|
41
58
|
url?: string;
|
|
@@ -53,16 +70,22 @@ function resolveTargets<T extends Record<string, unknown>>(
|
|
|
53
70
|
const targets = new Map<string, unknown>();
|
|
54
71
|
const rewrite = (link: SeedLink): SeedLink => {
|
|
55
72
|
const slug = link.target?.slug;
|
|
56
|
-
|
|
57
|
-
return { ...link, ...(link.children ? { children: link.children.map(rewrite) } : {}) };
|
|
58
|
-
}
|
|
59
|
-
const id = `id-${slug}`;
|
|
60
|
-
targets.set(`${link.target._type}:${id}`, { slug, title: link.label });
|
|
61
|
-
return {
|
|
62
|
-
...link,
|
|
63
|
-
target: { _type: link.target._type, id },
|
|
73
|
+
const nested = {
|
|
64
74
|
...(link.children ? { children: link.children.map(rewrite) } : {}),
|
|
75
|
+
...(link.sections
|
|
76
|
+
? {
|
|
77
|
+
sections: link.sections.map((section) => ({
|
|
78
|
+
...section,
|
|
79
|
+
...(section.links ? { links: section.links.map(rewrite) } : {}),
|
|
80
|
+
...(section.seeAll ? { seeAll: rewrite(section.seeAll) } : {}),
|
|
81
|
+
})),
|
|
82
|
+
}
|
|
83
|
+
: {}),
|
|
65
84
|
};
|
|
85
|
+
if (link.target === undefined || slug === undefined) return { ...link, ...nested };
|
|
86
|
+
const id = `id-${slug}`;
|
|
87
|
+
targets.set(`${link.target._type}:${id}`, { slug, title: link.label });
|
|
88
|
+
return { ...link, target: { _type: link.target._type, id }, ...nested };
|
|
66
89
|
};
|
|
67
90
|
const next = { ...data } as Record<string, unknown>;
|
|
68
91
|
if (Array.isArray(next.links)) next.links = (next.links as SeedLink[]).map(rewrite);
|
|
@@ -94,6 +117,16 @@ function stubFocusVisible(matches: boolean): () => void {
|
|
|
94
117
|
};
|
|
95
118
|
}
|
|
96
119
|
|
|
120
|
+
/** The labelled Search tool: named by its visible label, so it carries no `aria-label` to find it by. */
|
|
121
|
+
function findSearchTool(wrapper: { findAll: (selector: string) => DOMWrapper<Element>[] }) {
|
|
122
|
+
return wrapper.findAll('button').find((button) => button.text().trim() === 'Search');
|
|
123
|
+
}
|
|
124
|
+
function searchTool(wrapper: { findAll: (selector: string) => DOMWrapper<Element>[] }) {
|
|
125
|
+
const button = findSearchTool(wrapper);
|
|
126
|
+
if (button === undefined) throw new Error('no Search tool in the bar');
|
|
127
|
+
return button;
|
|
128
|
+
}
|
|
129
|
+
|
|
97
130
|
function mountBlock(data: Record<string, unknown>, opts?: { attachTo?: Element }) {
|
|
98
131
|
const base = mountOptions({ entry: { id: 'e1', data } }, { links: resolved.links });
|
|
99
132
|
return mount(Block, {
|
|
@@ -277,6 +310,76 @@ describe('header block (navigation apiId)', () => {
|
|
|
277
310
|
wrapper.unmount();
|
|
278
311
|
});
|
|
279
312
|
|
|
313
|
+
it('draws a menu card with its picture at the declared aspect, its title and its price, axe-clean', async () => {
|
|
314
|
+
const targets = new Map(resolved.links.targets);
|
|
315
|
+
targets.set('product:p-1', {
|
|
316
|
+
slug: 'ash-mug',
|
|
317
|
+
title: 'Ash glaze mug',
|
|
318
|
+
image: 'https://media.test/mug-md.jpg',
|
|
319
|
+
price: 28,
|
|
320
|
+
});
|
|
321
|
+
targets.set('collection:c-1', {
|
|
322
|
+
slug: 'winter-knits',
|
|
323
|
+
title: 'Winter knits',
|
|
324
|
+
image: 'https://media.test/winter-md.jpg',
|
|
325
|
+
});
|
|
326
|
+
const wrapper = mount(Block, {
|
|
327
|
+
...mountOptions(
|
|
328
|
+
{
|
|
329
|
+
entry: {
|
|
330
|
+
id: 'e1',
|
|
331
|
+
data: {
|
|
332
|
+
...resolved.data,
|
|
333
|
+
links: [
|
|
334
|
+
{
|
|
335
|
+
kind: 'none',
|
|
336
|
+
label: 'Shop',
|
|
337
|
+
sections: [
|
|
338
|
+
{
|
|
339
|
+
heading: 'Featured',
|
|
340
|
+
display: 'card',
|
|
341
|
+
links: [
|
|
342
|
+
{ kind: 'product', target: { _type: 'product', id: 'p-1' } },
|
|
343
|
+
{ kind: 'collection', target: { _type: 'collection', id: 'c-1' } },
|
|
344
|
+
],
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
heading: 'Care',
|
|
348
|
+
links: [{ kind: 'url', url: '/care', label: 'Care guides' }],
|
|
349
|
+
},
|
|
350
|
+
],
|
|
351
|
+
},
|
|
352
|
+
],
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
{ links: { ...resolved.links, targets } }
|
|
357
|
+
),
|
|
358
|
+
attachTo: document.body,
|
|
359
|
+
});
|
|
360
|
+
const trigger = wrapper.findAll('button').find((b) => b.text().includes('Shop'))!;
|
|
361
|
+
await trigger.trigger('click');
|
|
362
|
+
const panel = wrapper.get(`#${trigger.attributes('aria-controls')}`);
|
|
363
|
+
const cards = panel.findAll('[data-part="card"]');
|
|
364
|
+
expect(cards).toHaveLength(2);
|
|
365
|
+
const image = cards[0]!.get('img');
|
|
366
|
+
expect(image.attributes('src')).toBe('https://media.test/mug-md.jpg');
|
|
367
|
+
expect((image.element as HTMLImageElement).style.aspectRatio).toBe('4 / 5');
|
|
368
|
+
expect(cards[0]!.get('[data-part="cardTitle"]').text()).toBe('Ash glaze mug');
|
|
369
|
+
expect(cards[0]!.get('[data-part="cardPrice"]').text()).toMatch(/28/);
|
|
370
|
+
expect(cards[1]!.get('img').attributes('src')).toBe('https://media.test/winter-md.jpg');
|
|
371
|
+
expect(cards[1]!.find('[data-part="cardPrice"]').exists()).toBe(false);
|
|
372
|
+
// The cards column is the wide one; the link column is one track.
|
|
373
|
+
const columns = panel.findAll('[data-part="group"]');
|
|
374
|
+
expect(columns[0]!.attributes('data-cards')).toBeDefined();
|
|
375
|
+
expect(columns[0]!.classes()).toContain('[[data-cards]>&[data-cards]]:col-span-2');
|
|
376
|
+
expect(columns[1]!.attributes('data-cards')).toBeUndefined();
|
|
377
|
+
// A plain link beside the cards is still a link.
|
|
378
|
+
expect(panel.findAll('a').some((a) => a.text() === 'Care guides')).toBe(true);
|
|
379
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
380
|
+
wrapper.unmount();
|
|
381
|
+
});
|
|
382
|
+
|
|
280
383
|
it('renders a heading-only mega-menu parent as a disclosure with no destination', async () => {
|
|
281
384
|
// `kind: "none"`: the trigger has a label and children and goes nowhere,
|
|
282
385
|
// which is what a mega-menu parent without its own page is.
|
|
@@ -460,11 +563,20 @@ describe('header block (navigation apiId)', () => {
|
|
|
460
563
|
expect(spacer.classes()).toContain('@container');
|
|
461
564
|
expect(spacer.classes()).toContain('border-b');
|
|
462
565
|
expect(spacer.classes()).toContain('border-transparent');
|
|
463
|
-
|
|
566
|
+
// The info strip's box first (the seed has one), then the bar's. The strip mirrors its own
|
|
567
|
+
// two boxes too: the hairline on the outer, the height on the inner, so the border adds to
|
|
568
|
+
// the height (36px + 1px) rather than eating into it (`border-box`).
|
|
569
|
+
const [strip, reserved] = spacer.findAll(':scope > div');
|
|
570
|
+
const info = wrapper.get('[data-eldra-header-info]');
|
|
571
|
+
expect(info.classes()).toContain('border-b');
|
|
572
|
+
expect(strip!.classes()).toContain('border-b');
|
|
573
|
+
expect(strip!.classes()).not.toContain('min-h-9');
|
|
574
|
+
expect(info.get(':scope > div').classes()).toContain('min-h-9');
|
|
575
|
+
expect(strip!.get(':scope > div').classes()).toContain('min-h-9');
|
|
464
576
|
const bar = wrapper.get('[data-eldra-header-bar]');
|
|
465
|
-
for (const height of ['h-
|
|
577
|
+
for (const height of ['min-h-[4.5rem]', '@max-[47.5625rem]:min-h-[3.75rem]']) {
|
|
466
578
|
expect(bar.classes()).toContain(height);
|
|
467
|
-
expect(reserved
|
|
579
|
+
expect(reserved!.classes()).toContain(height);
|
|
468
580
|
}
|
|
469
581
|
|
|
470
582
|
wrapper.unmount();
|
|
@@ -562,7 +674,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
562
674
|
window.dispatchEvent(new Event('scroll'));
|
|
563
675
|
await nextTick();
|
|
564
676
|
};
|
|
565
|
-
const searchButton = wrapper
|
|
677
|
+
const searchButton = searchTool(wrapper);
|
|
566
678
|
|
|
567
679
|
await searchButton.trigger('focusin');
|
|
568
680
|
await scrollTo(300);
|
|
@@ -1132,38 +1244,37 @@ describe('header block (navigation apiId)', () => {
|
|
|
1132
1244
|
});
|
|
1133
1245
|
|
|
1134
1246
|
/**
|
|
1135
|
-
*
|
|
1136
|
-
*
|
|
1137
|
-
*
|
|
1138
|
-
*
|
|
1139
|
-
*
|
|
1140
|
-
*
|
|
1141
|
-
* `min-h-6`/`text-badge` must not survive the merge — that overshoot (1.5rem tall, the wrong
|
|
1142
|
-
* type scale) was the original defect.
|
|
1247
|
+
* The Northwind design's corner badge on a labelled tool: 1.125rem tall, `0.6875rem` bold
|
|
1248
|
+
* figures, at the tool's top-right (`top-0.5 right-1.5`, `right-0.5` on a phone), no ring (a ring
|
|
1249
|
+
* separates a pill from what sits *beside* it; this one sits deliberately *on* the icon's
|
|
1250
|
+
* corner). `Badge`'s own `min-h-6`/`text-badge` must not survive the merge — that overshoot
|
|
1251
|
+
* (1.5rem tall, the wrong type scale) was the original defect. The real-browser measurement is
|
|
1252
|
+
* `test/countPill.browser.spec.ts`.
|
|
1143
1253
|
*/
|
|
1144
1254
|
it('sizes and positions the pill as a corner badge, with none of Badge’s own oversized defaults left behind', async () => {
|
|
1145
1255
|
const wrapper = mountWithCartCount(mock, 2);
|
|
1146
1256
|
await nextTick();
|
|
1147
1257
|
const badge = countPill(findCartButton(wrapper))!;
|
|
1148
1258
|
for (const token of [
|
|
1149
|
-
'min-h-
|
|
1150
|
-
'min-w-
|
|
1151
|
-
'h-
|
|
1259
|
+
'min-h-[1.125rem]',
|
|
1260
|
+
'min-w-[1.125rem]',
|
|
1261
|
+
'h-[1.125rem]',
|
|
1152
1262
|
'px-1',
|
|
1153
|
-
'text-[0.
|
|
1263
|
+
'text-[0.6875rem]',
|
|
1154
1264
|
'font-bold',
|
|
1155
1265
|
'tabular-nums',
|
|
1156
1266
|
'leading-none',
|
|
1157
|
-
'
|
|
1158
|
-
'
|
|
1267
|
+
'top-0.5',
|
|
1268
|
+
'right-1.5',
|
|
1269
|
+
'@max-[47.5625rem]:right-0.5',
|
|
1159
1270
|
]) {
|
|
1160
1271
|
expect([...badge.classList]).toContain(token);
|
|
1161
1272
|
}
|
|
1162
1273
|
for (const stale of [
|
|
1163
1274
|
'min-h-6',
|
|
1164
1275
|
'text-badge',
|
|
1165
|
-
'top-0.5',
|
|
1166
|
-
'right-0.5',
|
|
1276
|
+
'-top-0.5',
|
|
1277
|
+
'-right-0.5',
|
|
1167
1278
|
'ring-2',
|
|
1168
1279
|
'ring-background',
|
|
1169
1280
|
'min-h-5',
|
|
@@ -1235,7 +1346,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1235
1346
|
function findHeart(wrapper: ReturnType<typeof mountBlock>) {
|
|
1236
1347
|
return wrapper
|
|
1237
1348
|
.findAll('a, button')
|
|
1238
|
-
.find((control) => control.attributes('aria-label')?.startsWith('
|
|
1349
|
+
.find((control) => control.attributes('aria-label')?.startsWith('Saved'));
|
|
1239
1350
|
}
|
|
1240
1351
|
|
|
1241
1352
|
function saveInBrowser(...handles: string[]): void {
|
|
@@ -1247,7 +1358,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1247
1358
|
const heart = findHeart(wrapper)!;
|
|
1248
1359
|
// No number in the name, so the prerendered header reads the same for every visitor — and
|
|
1249
1360
|
// the destination is there from the first paint, not grown later.
|
|
1250
|
-
expect(heart.attributes('aria-label')).toBe('
|
|
1361
|
+
expect(heart.attributes('aria-label')).toBe('Saved');
|
|
1251
1362
|
expect(heart.attributes('href')).toBe('/wishlist');
|
|
1252
1363
|
expect(countPill(heart)).toBeNull();
|
|
1253
1364
|
// The bag's own pill is absent too (an empty cart), so this is the whole actions row: two
|
|
@@ -1278,7 +1389,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1278
1389
|
await nextTick();
|
|
1279
1390
|
|
|
1280
1391
|
const heart = findHeart(wrapper)!;
|
|
1281
|
-
expect(heart.attributes('aria-label')).toBe('
|
|
1392
|
+
expect(heart.attributes('aria-label')).toBe('Saved, 1 item');
|
|
1282
1393
|
expect(heart.element.tagName).toBe('A');
|
|
1283
1394
|
expect(heart.attributes('href')).toBe('/wishlist');
|
|
1284
1395
|
// It is a link to a page, so it claims no popup — the same rule the bag's link form follows.
|
|
@@ -1291,7 +1402,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1291
1402
|
await nextTick();
|
|
1292
1403
|
|
|
1293
1404
|
const heart = findHeart(wrapper)!;
|
|
1294
|
-
expect(heart.attributes('aria-label')).toBe('
|
|
1405
|
+
expect(heart.attributes('aria-label')).toBe('Saved, 2 items');
|
|
1295
1406
|
const badge = countPill(heart)!;
|
|
1296
1407
|
expect(badge.getAttribute('aria-hidden')).toBe('true');
|
|
1297
1408
|
expect(badge.textContent?.trim()).toBe('2');
|
|
@@ -1304,7 +1415,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1304
1415
|
await nextTick();
|
|
1305
1416
|
|
|
1306
1417
|
const heart = findHeart(wrapper)!;
|
|
1307
|
-
expect(heart.attributes('aria-label')).toBe('
|
|
1418
|
+
expect(heart.attributes('aria-label')).toBe('Saved, 120 items');
|
|
1308
1419
|
expect(countPill(heart)?.textContent?.trim()).toBe('99+');
|
|
1309
1420
|
});
|
|
1310
1421
|
|
|
@@ -1330,7 +1441,13 @@ describe('header block (navigation apiId)', () => {
|
|
|
1330
1441
|
expect(heartPill.className).toBe(cartPill.className);
|
|
1331
1442
|
// And the corner-badge classes are actually on it, not just shared with an equally-wrong
|
|
1332
1443
|
// sibling.
|
|
1333
|
-
for (const token of [
|
|
1444
|
+
for (const token of [
|
|
1445
|
+
'min-h-[1.125rem]',
|
|
1446
|
+
'min-w-[1.125rem]',
|
|
1447
|
+
'h-[1.125rem]',
|
|
1448
|
+
'top-0.5',
|
|
1449
|
+
'right-1.5',
|
|
1450
|
+
]) {
|
|
1334
1451
|
expect([...heartPill.classList]).toContain(token);
|
|
1335
1452
|
}
|
|
1336
1453
|
});
|
|
@@ -1348,7 +1465,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1348
1465
|
* control's own, which is the state every prerendered page is served in. */
|
|
1349
1466
|
it('is axe-clean with nothing saved, where the heart carries no pill', async () => {
|
|
1350
1467
|
const wrapper = mountBlock(resolved.data);
|
|
1351
|
-
expect(findHeart(wrapper)!.attributes('aria-label')).toBe('
|
|
1468
|
+
expect(findHeart(wrapper)!.attributes('aria-label')).toBe('Saved');
|
|
1352
1469
|
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
1353
1470
|
});
|
|
1354
1471
|
});
|
|
@@ -1478,15 +1595,15 @@ describe('header block (navigation apiId)', () => {
|
|
|
1478
1595
|
});
|
|
1479
1596
|
|
|
1480
1597
|
describe('mega-menu panel geometry', () => {
|
|
1481
|
-
// jsdom computes no layout
|
|
1482
|
-
//
|
|
1483
|
-
//
|
|
1484
|
-
//
|
|
1485
|
-
// columns are the container's 12-column grid.
|
|
1598
|
+
// jsdom computes no layout; what is checkable here is the arrangement. The Northwind panel is a
|
|
1599
|
+
// full-bleed sheet: pinned to the whole `<header>` (fixed when sticky, `relative` when not) rather
|
|
1600
|
+
// than to the item that opened it or to the bar's grid, with its columns held inside the same
|
|
1601
|
+
// wide container the bar uses.
|
|
1486
1602
|
it('pins the panel to the header container, not to the trigger that opened it', async () => {
|
|
1487
1603
|
const wrapper = mountBlock(resolved.data, { attachTo: document.body });
|
|
1488
|
-
// The
|
|
1489
|
-
expect(wrapper.get('
|
|
1604
|
+
// The header is the panel's positioning box; the bar's grid and the menu's own root take none.
|
|
1605
|
+
expect(wrapper.get('header').classes()).toContain('fixed');
|
|
1606
|
+
expect(wrapper.get('[data-eldra-header-bar]').classes()).not.toContain('relative');
|
|
1490
1607
|
const root = [...menuRoot(wrapper).classList];
|
|
1491
1608
|
expect(root).toContain('static');
|
|
1492
1609
|
expect(root).toContain('contents');
|
|
@@ -1506,30 +1623,34 @@ describe('header block (navigation apiId)', () => {
|
|
|
1506
1623
|
const panelTokens = panel.classes().map((token) => token.replace(/^eldra:/, ''));
|
|
1507
1624
|
expect(panelTokens).not.toContain('w-screen');
|
|
1508
1625
|
expect(panelTokens.some((token) => token.startsWith('max-w-'))).toBe(false);
|
|
1509
|
-
// The bar's own bottom border is the sheet's top edge
|
|
1626
|
+
// The bar's own bottom border is the sheet's top edge; the sheet draws only a bottom rule and
|
|
1627
|
+
// the float shadow, square-cornered, 2rem above and below, the page's own gutters at the sides.
|
|
1510
1628
|
const sheet = panel.get('[data-part="content"]').classes();
|
|
1511
1629
|
for (const token of [
|
|
1512
|
-
'eldra:border',
|
|
1513
|
-
'border-t-0',
|
|
1514
|
-
'eldra:border-border',
|
|
1515
1630
|
'rounded-none',
|
|
1516
|
-
'
|
|
1631
|
+
'border-0',
|
|
1632
|
+
'border-b',
|
|
1633
|
+
'border-border',
|
|
1517
1634
|
'shadow-(--eldra-shadow-float)',
|
|
1518
|
-
'
|
|
1519
|
-
'
|
|
1635
|
+
'py-8',
|
|
1636
|
+
'px-(--eldra-gutter-mobile)',
|
|
1637
|
+
'@tablet:px-(--eldra-gutter-tablet)',
|
|
1638
|
+
'@content:px-(--eldra-gutter-desktop)',
|
|
1520
1639
|
]) {
|
|
1521
1640
|
expect(sheet).toContain(token);
|
|
1522
1641
|
}
|
|
1523
1642
|
|
|
1524
|
-
// The
|
|
1525
|
-
// the panel's own edges — 24px, 32px once the container passes `wide`. The browser case
|
|
1526
|
-
// measures what this produces; here it is only the arrangement.
|
|
1643
|
+
// The columns: inside the wide container, 12 tracks with 2rem gutters.
|
|
1527
1644
|
const columns = panel.get('[data-part="columns"]').classes();
|
|
1528
|
-
for (const token of [
|
|
1645
|
+
for (const token of [
|
|
1646
|
+
'eldra:grid',
|
|
1647
|
+
'grid-cols-12',
|
|
1648
|
+
'gap-8',
|
|
1649
|
+
'mx-auto',
|
|
1650
|
+
'max-w-[calc(var(--eldra-container-wide)-2*var(--eldra-gutter-desktop))]',
|
|
1651
|
+
]) {
|
|
1529
1652
|
expect(columns).toContain(token);
|
|
1530
1653
|
}
|
|
1531
|
-
expect(sheet).not.toContain('eldra:py-8');
|
|
1532
|
-
expect(sheet).not.toContain('py-8');
|
|
1533
1654
|
wrapper.unmount();
|
|
1534
1655
|
});
|
|
1535
1656
|
|
|
@@ -1655,7 +1776,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1655
1776
|
|
|
1656
1777
|
it('the search control has aria-haspopup="dialog" and opens SearchModal', async () => {
|
|
1657
1778
|
const wrapper = mountBlock(resolved.data, { attachTo: document.body });
|
|
1658
|
-
const searchButton = wrapper
|
|
1779
|
+
const searchButton = searchTool(wrapper);
|
|
1659
1780
|
expect(searchButton.attributes('aria-haspopup')).toBe('dialog');
|
|
1660
1781
|
await searchButton.trigger('click');
|
|
1661
1782
|
const dialogs = wrapper.findAll('dialog');
|
|
@@ -1740,7 +1861,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1740
1861
|
}
|
|
1741
1862
|
|
|
1742
1863
|
async function openOverlay(wrapper: ReturnType<typeof mountWithSearch>) {
|
|
1743
|
-
await wrapper
|
|
1864
|
+
await searchTool(wrapper).trigger('click');
|
|
1744
1865
|
return wrapper.get('dialog[open] input[type="search"]');
|
|
1745
1866
|
}
|
|
1746
1867
|
|
|
@@ -1873,32 +1994,43 @@ describe('header block (navigation apiId)', () => {
|
|
|
1873
1994
|
});
|
|
1874
1995
|
|
|
1875
1996
|
describe('actions row spacing', () => {
|
|
1876
|
-
//
|
|
1877
|
-
// the
|
|
1878
|
-
// so
|
|
1879
|
-
|
|
1880
|
-
it('puts one 0.25rem gap everywhere in the bar’s grid — never a larger one between columns', () => {
|
|
1997
|
+
// Below 68.8125rem the brand is centred by symmetry alone: Menu and Search on one side, Saved
|
|
1998
|
+
// and Cart on the other, all one fixed width, with the grid's gap equal to the actions row's own
|
|
1999
|
+
// — so the two sides measure the same. A larger gap on either breaks the centring.
|
|
2000
|
+
it('puts the same 0.125rem gap in the bar’s grid and in the actions row, so the brand stays centred', () => {
|
|
1881
2001
|
const wrapper = mountBlock(resolved.data);
|
|
1882
2002
|
const bar = wrapper.get('[data-eldra-header-bar]');
|
|
1883
|
-
expect(bar.classes()).toContain('gap-
|
|
1884
|
-
expect(bar.classes()
|
|
1885
|
-
|
|
2003
|
+
expect(bar.classes()).toContain('gap-x-0.5');
|
|
2004
|
+
expect(bar.classes()).toContain(
|
|
2005
|
+
'grid-cols-[auto_auto_minmax(0,1fr)_minmax(0,auto)_minmax(0,1fr)_auto]'
|
|
2006
|
+
);
|
|
1886
2007
|
const actions = wrapper.get('[data-eldra-header-actions]');
|
|
1887
|
-
expect(actions.classes()).toContain('gap-
|
|
2008
|
+
expect(actions.classes()).toContain('gap-0.5');
|
|
2009
|
+
// Every tool on either side is the same fixed width.
|
|
2010
|
+
const menu = wrapper.get('button[aria-label="Menu"]');
|
|
2011
|
+
const saved = wrapper.get('[aria-label^="Saved"]');
|
|
2012
|
+
const tools = [menu, searchTool(wrapper), saved, findCartButtonIn(wrapper)!];
|
|
2013
|
+
for (const tool of tools) {
|
|
2014
|
+
expect(tool.classes()).toEqual(
|
|
2015
|
+
expect.arrayContaining(['w-14', '@max-[47.5625rem]:w-11', '@max-[22.5rem]:w-10'])
|
|
2016
|
+
);
|
|
2017
|
+
}
|
|
1888
2018
|
});
|
|
1889
2019
|
|
|
1890
2020
|
it('gives the call to action its own 0.75rem from the cart, not only the row’s 0.25rem gap', () => {
|
|
1891
2021
|
const wrapper = mountBlock(resolved.data);
|
|
1892
2022
|
const actions = wrapper.get('[data-eldra-header-actions]');
|
|
1893
2023
|
const cta = actions.findAll('a, button').find((el) => el.text() === mock.ctaLabel)!;
|
|
1894
|
-
// 0.
|
|
1895
|
-
//
|
|
1896
|
-
expect(cta.classes()).toContain('
|
|
2024
|
+
// 0.625rem of margin on top of the row's own 0.125rem gap: the call to action "sits 0.75rem
|
|
2025
|
+
// after the cart".
|
|
2026
|
+
expect(cta.classes()).toContain('ml-2.5');
|
|
1897
2027
|
// And the row's only hidden/visible pair lands on the button's own root — the flex item the
|
|
1898
2028
|
// row's `gap-1` actually counts — not on a wrapper around it. A wrapper carrying `hidden`
|
|
1899
2029
|
// while the button inside it carries the visible class would still occupy a gap slot: the
|
|
1900
2030
|
// parent check is what rules that out, not just the classes existing somewhere in the tree.
|
|
1901
|
-
expect(cta.classes()).toEqual(
|
|
2031
|
+
expect(cta.classes()).toEqual(
|
|
2032
|
+
expect.arrayContaining(['hidden', '@min-[68.8125rem]:inline-flex'])
|
|
2033
|
+
);
|
|
1902
2034
|
expect(cta.element.parentElement).toBe(actions.element);
|
|
1903
2035
|
});
|
|
1904
2036
|
});
|
|
@@ -1926,7 +2058,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1926
2058
|
// The bar's link list is not drawn at all with nothing in it, so no empty `<ul>` is left
|
|
1927
2059
|
// sitting in the grid.
|
|
1928
2060
|
expect(wrapper.find('ul.list-none.items-center').exists()).toBe(false);
|
|
1929
|
-
expect(wrapper
|
|
2061
|
+
expect(findSearchTool(wrapper)).toBeDefined();
|
|
1930
2062
|
expect(wrapper.find('[aria-label="Cart, empty"]').exists()).toBe(true);
|
|
1931
2063
|
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
1932
2064
|
});
|
|
@@ -1935,7 +2067,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1935
2067
|
// The drawer holds the links and the call to action. With neither there is nothing to open,
|
|
1936
2068
|
// and a Menu button that opens an empty sheet is a control that does nothing.
|
|
1937
2069
|
const wrapper = mountBlock(SEEDED);
|
|
1938
|
-
expect(wrapper.find('button[aria-label="
|
|
2070
|
+
expect(wrapper.find('button[aria-label="Menu"]').exists()).toBe(false);
|
|
1939
2071
|
// `dialog[aria-label="Menu"]` is the drawer itself; the search overlay's own `<dialog>`
|
|
1940
2072
|
// renders either way, so the drawer has to be named rather than counted.
|
|
1941
2073
|
expect(wrapper.find('dialog[aria-label="Menu"]').exists()).toBe(false);
|
|
@@ -1948,7 +2080,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1948
2080
|
{ ...SEEDED, ctaLabel: 'Shop', cta: { kind: 'url', url: '/collections/all' } },
|
|
1949
2081
|
]) {
|
|
1950
2082
|
const wrapper = mountBlock(data);
|
|
1951
|
-
expect(wrapper.find('button[aria-label="
|
|
2083
|
+
expect(wrapper.find('button[aria-label="Menu"]').exists()).toBe(true);
|
|
1952
2084
|
}
|
|
1953
2085
|
});
|
|
1954
2086
|
|
|
@@ -1966,7 +2098,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1966
2098
|
wrapper.findAll('a, button').some((control) => control.attributes('href') === '/account')
|
|
1967
2099
|
).toBe(false);
|
|
1968
2100
|
expect(wrapper.text()).not.toContain('Account');
|
|
1969
|
-
expect(wrapper.find('button[aria-label="
|
|
2101
|
+
expect(wrapper.find('button[aria-label="Menu"]').exists()).toBe(false);
|
|
1970
2102
|
expect(wrapper.find('dialog[aria-label="Menu"]').exists()).toBe(false);
|
|
1971
2103
|
}
|
|
1972
2104
|
});
|
|
@@ -2129,3 +2261,292 @@ describe('header block (navigation apiId)', () => {
|
|
|
2129
2261
|
});
|
|
2130
2262
|
});
|
|
2131
2263
|
});
|
|
2264
|
+
|
|
2265
|
+
/**
|
|
2266
|
+
* The redesigned seed: an info strip, labelled tools, a scalable brand, and a menu of sections with
|
|
2267
|
+
* cards, a badge and a dropdown — the Northwind design's header boards.
|
|
2268
|
+
*/
|
|
2269
|
+
describe('the Northwind menu (the seed’s own)', () => {
|
|
2270
|
+
const PRODUCT_TEMPLATE = {
|
|
2271
|
+
id: 'rt-product',
|
|
2272
|
+
data: { schemaApiId: 'catalog:product', routePattern: '/products/:slug', slugField: 'slug' },
|
|
2273
|
+
};
|
|
2274
|
+
const PRODUCT_TARGETS: Record<string, { image: string; price: number }> = {
|
|
2275
|
+
'speckled-latte-mug': { image: '/images/mug.webp', price: 28 },
|
|
2276
|
+
'merino-crew-sweater': { image: '/images/sweater.webp', price: 96 },
|
|
2277
|
+
'hand-thrown-serving-bowl': { image: '/images/bowl.webp', price: 64 },
|
|
2278
|
+
};
|
|
2279
|
+
const northwind = resolveTargets(seed);
|
|
2280
|
+
const links = {
|
|
2281
|
+
templates: [COLLECTION_TEMPLATE, PRODUCT_TEMPLATE] as (typeof COLLECTION_TEMPLATE)[],
|
|
2282
|
+
targets: new Map(
|
|
2283
|
+
[...northwind.links.targets].map(([key, info]) => {
|
|
2284
|
+
const slug = (info as { slug: string }).slug;
|
|
2285
|
+
const extra = key.startsWith('product:') ? PRODUCT_TARGETS[slug] : undefined;
|
|
2286
|
+
return [key, { ...(info as object), ...extra }];
|
|
2287
|
+
})
|
|
2288
|
+
),
|
|
2289
|
+
};
|
|
2290
|
+
function mountSeed(data: Record<string, unknown> = {}) {
|
|
2291
|
+
return mount(Block, {
|
|
2292
|
+
...mountOptions({ entry: { id: 'e1', data: { ...northwind.data, ...data } } }, { links }),
|
|
2293
|
+
attachTo: document.body,
|
|
2294
|
+
});
|
|
2295
|
+
}
|
|
2296
|
+
type Wrapper = ReturnType<typeof mountSeed>;
|
|
2297
|
+
const trigger = (wrapper: Wrapper, label: string) =>
|
|
2298
|
+
wrapper.findAll('button').find((button) => button.text().includes(label))!;
|
|
2299
|
+
const panel = (wrapper: Wrapper, label: string) =>
|
|
2300
|
+
wrapper.get(`#${trigger(wrapper, label).attributes('aria-controls')}`);
|
|
2301
|
+
|
|
2302
|
+
afterEach(() => {
|
|
2303
|
+
document.body.innerHTML = '';
|
|
2304
|
+
});
|
|
2305
|
+
|
|
2306
|
+
it('renders the seed axe-clean in every variant', async () => {
|
|
2307
|
+
for (const variant of ['default', 'centered', 'minimal']) {
|
|
2308
|
+
const wrapper = mountSeed({ variant });
|
|
2309
|
+
expect(await axe(wrapper.element), variant).toHaveNoViolations();
|
|
2310
|
+
wrapper.unmount();
|
|
2311
|
+
}
|
|
2312
|
+
});
|
|
2313
|
+
|
|
2314
|
+
describe('info strip', () => {
|
|
2315
|
+
it('is a named region: the start items with icons, the end items as links', async () => {
|
|
2316
|
+
const wrapper = mountSeed();
|
|
2317
|
+
const strip = wrapper.get('[data-eldra-header-info]');
|
|
2318
|
+
expect(strip.attributes('role')).toBe('region');
|
|
2319
|
+
expect(strip.attributes('aria-label')).toBe('Store information');
|
|
2320
|
+
const [start, end] = strip.findAll('ul');
|
|
2321
|
+
expect(start!.findAll('li').map((li) => li.text())).toEqual([
|
|
2322
|
+
'Free delivery over $80',
|
|
2323
|
+
'30-day returns',
|
|
2324
|
+
'Shop open today 10–18',
|
|
2325
|
+
]);
|
|
2326
|
+
const phone = end!.findAll('a').find((a) => a.text() === '(555) 014-2290')!;
|
|
2327
|
+
expect(phone.attributes('href')).toBe('tel:+15550142290');
|
|
2328
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2329
|
+
});
|
|
2330
|
+
|
|
2331
|
+
it('keeps only the first item on a phone, and moves the end of the strip into the drawer', () => {
|
|
2332
|
+
const wrapper = mountSeed();
|
|
2333
|
+
const [start, end] = wrapper.get('[data-eldra-header-info]').findAll('ul');
|
|
2334
|
+
const items = start!.findAll('li');
|
|
2335
|
+
expect(items[0]!.classes()).not.toContain('@max-[47.5625rem]:hidden');
|
|
2336
|
+
for (const item of items.slice(1))
|
|
2337
|
+
expect(item.classes()).toContain('@max-[47.5625rem]:hidden');
|
|
2338
|
+
expect(end!.classes()).toContain('@max-[68.8125rem]:hidden');
|
|
2339
|
+
// The drawer's footer repeats the end links the strip hides there.
|
|
2340
|
+
const drawerLinks = wrapper.get('[data-eldra-header-drawer-links]');
|
|
2341
|
+
expect(drawerLinks.text()).toContain('Order status');
|
|
2342
|
+
expect(drawerLinks.text()).toContain('(555) 014-2290');
|
|
2343
|
+
expect(drawerLinks.text()).toContain('Saved items');
|
|
2344
|
+
});
|
|
2345
|
+
|
|
2346
|
+
it('is not drawn with no items, and drops a javascript: link to plain text', () => {
|
|
2347
|
+
const empty = mountSeed({ infoItems: [] });
|
|
2348
|
+
expect(empty.find('[data-eldra-header-info]').exists()).toBe(false);
|
|
2349
|
+
empty.unmount();
|
|
2350
|
+
const wrapper = mountSeed({
|
|
2351
|
+
infoItems: [{ text: 'Call us', href: 'javascript:alert(1)' }],
|
|
2352
|
+
});
|
|
2353
|
+
const strip = wrapper.get('[data-eldra-header-info]');
|
|
2354
|
+
expect(strip.find('a').exists()).toBe(false);
|
|
2355
|
+
expect(strip.text()).toBe('Call us');
|
|
2356
|
+
});
|
|
2357
|
+
});
|
|
2358
|
+
|
|
2359
|
+
describe('labelled tools', () => {
|
|
2360
|
+
it('names every tool with its visible label first (WCAG 2.5.3)', async () => {
|
|
2361
|
+
const wrapper = mountSeed();
|
|
2362
|
+
const menu = wrapper.get('button[aria-label="Menu"]');
|
|
2363
|
+
expect(menu.text()).toBe('Menu');
|
|
2364
|
+
const search = wrapper
|
|
2365
|
+
.findAll('button')
|
|
2366
|
+
.filter((button) => button.text().trim() === 'Search');
|
|
2367
|
+
expect(search).toHaveLength(1);
|
|
2368
|
+
expect(search[0]!.attributes('aria-label')).toBeUndefined();
|
|
2369
|
+
// The design's pill field, from 80rem; the Search tool below it.
|
|
2370
|
+
const pill = wrapper.findAll('button').find((b) => b.text().trim() === 'Search the shop')!;
|
|
2371
|
+
expect(pill.classes()).toEqual(expect.arrayContaining(['hidden', '@wide:inline-flex']));
|
|
2372
|
+
expect(search[0]!.classes()).toContain('@wide:hidden');
|
|
2373
|
+
for (const tool of [
|
|
2374
|
+
wrapper.get('[aria-label^="Saved"]'),
|
|
2375
|
+
wrapper.get('[aria-label^="Cart"]'),
|
|
2376
|
+
]) {
|
|
2377
|
+
const label = tool.get('[data-part="label"]').text().trim();
|
|
2378
|
+
expect(tool.attributes('aria-label')!.startsWith(label)).toBe(true);
|
|
2379
|
+
}
|
|
2380
|
+
});
|
|
2381
|
+
|
|
2382
|
+
it('shows Account only when it is linked, as a tool and in the drawer', async () => {
|
|
2383
|
+
const bare = mountSeed();
|
|
2384
|
+
expect(bare.text()).not.toContain('Account');
|
|
2385
|
+
bare.unmount();
|
|
2386
|
+
const wrapper = mountSeed({ account: { kind: 'url', url: '/account' } });
|
|
2387
|
+
const tools = wrapper
|
|
2388
|
+
.get('[data-eldra-header-actions]')
|
|
2389
|
+
.findAll('a')
|
|
2390
|
+
.filter((a) => a.text().trim() === 'Account');
|
|
2391
|
+
expect(tools).toHaveLength(1);
|
|
2392
|
+
expect(tools[0]!.attributes('href')).toBe('/account');
|
|
2393
|
+
expect(tools[0]!.classes()).toContain('@max-[68.8125rem]:hidden');
|
|
2394
|
+
expect(wrapper.get('[data-eldra-header-drawer-links]').text()).toContain('Account');
|
|
2395
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2396
|
+
});
|
|
2397
|
+
});
|
|
2398
|
+
|
|
2399
|
+
describe('brand', () => {
|
|
2400
|
+
const logo = (width: number, height: number) => ({
|
|
2401
|
+
assetId: 'logo',
|
|
2402
|
+
url: '/logo.svg',
|
|
2403
|
+
altText: 'Northwind Goods',
|
|
2404
|
+
width,
|
|
2405
|
+
height,
|
|
2406
|
+
});
|
|
2407
|
+
const mark = { assetId: 'mark', url: '/mark.svg', altText: '', width: 64, height: 64 };
|
|
2408
|
+
const brand = (wrapper: Wrapper) => wrapper.get('[data-eldra-header-brand]');
|
|
2409
|
+
|
|
2410
|
+
it('names the link once, so whichever picture a width shows, it reads the same', async () => {
|
|
2411
|
+
const wrapper = mountSeed({ brandMark: mark, brandLogo: logo(300, 100) });
|
|
2412
|
+
expect(brand(wrapper).attributes('aria-label')).toBe('Northwind Goods, home');
|
|
2413
|
+
for (const img of brand(wrapper).findAll('img')) expect(img.attributes('alt')).toBe('');
|
|
2414
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2415
|
+
});
|
|
2416
|
+
|
|
2417
|
+
it('draws a mark beside the wordmark, and the mark alone below 400px', () => {
|
|
2418
|
+
const wrapper = mountSeed({ brandMark: mark });
|
|
2419
|
+
const [img] = brand(wrapper).findAll('img');
|
|
2420
|
+
expect(img!.classes()).not.toContain('hidden');
|
|
2421
|
+
expect(brand(wrapper).get('span span').classes()).toContain('@max-[25.0625rem]:hidden');
|
|
2422
|
+
});
|
|
2423
|
+
|
|
2424
|
+
it('swaps a logo for its mark below 400px', () => {
|
|
2425
|
+
const wrapper = mountSeed({ brandMark: mark, brandLogo: logo(300, 100) });
|
|
2426
|
+
const [markImg, logoImg] = brand(wrapper).findAll('img');
|
|
2427
|
+
expect(markImg!.classes()).toEqual(
|
|
2428
|
+
expect.arrayContaining(['hidden', '@max-[25.0625rem]:block'])
|
|
2429
|
+
);
|
|
2430
|
+
expect(logoImg!.classes()).toContain('@max-[25.0625rem]:hidden');
|
|
2431
|
+
expect(brand(wrapper).text()).toBe('');
|
|
2432
|
+
});
|
|
2433
|
+
|
|
2434
|
+
it('prints the store name below 400px for a logo wider than 4:1 with no mark', () => {
|
|
2435
|
+
const wrapper = mountSeed({ brandLogo: logo(1000, 100) });
|
|
2436
|
+
const [logoImg] = brand(wrapper).findAll('img');
|
|
2437
|
+
expect(logoImg!.classes()).toContain('@max-[25.0625rem]:hidden');
|
|
2438
|
+
const name = brand(wrapper).get('span span');
|
|
2439
|
+
expect(name.text()).toBe('Northwind Goods');
|
|
2440
|
+
expect(name.classes()).toEqual(expect.arrayContaining(['hidden', '@max-[25.0625rem]:block']));
|
|
2441
|
+
});
|
|
2442
|
+
|
|
2443
|
+
it('keeps a logo of 4:1 or narrower at every width, sized by height', () => {
|
|
2444
|
+
const wrapper = mountSeed({ brandLogo: logo(400, 100) });
|
|
2445
|
+
const [logoImg] = brand(wrapper).findAll('img');
|
|
2446
|
+
expect(logoImg!.classes()).toEqual(
|
|
2447
|
+
expect.arrayContaining(['h-9', 'w-auto', 'max-w-60', '@max-[47.5625rem]:max-h-8'])
|
|
2448
|
+
);
|
|
2449
|
+
expect(logoImg!.classes()).not.toContain('@max-[25.0625rem]:hidden');
|
|
2450
|
+
expect(brand(wrapper).text()).toBe('');
|
|
2451
|
+
});
|
|
2452
|
+
|
|
2453
|
+
it('wraps a text-only wordmark onto two centred lines below 360px', () => {
|
|
2454
|
+
const wrapper = mountSeed();
|
|
2455
|
+
const name = brand(wrapper).get('span span');
|
|
2456
|
+
expect(name.classes()).toEqual(
|
|
2457
|
+
expect.arrayContaining([
|
|
2458
|
+
'@max-[22.5rem]:whitespace-normal',
|
|
2459
|
+
'@max-[22.5rem]:text-center',
|
|
2460
|
+
'@max-[22.5rem]:max-w-[5.75rem]',
|
|
2461
|
+
])
|
|
2462
|
+
);
|
|
2463
|
+
});
|
|
2464
|
+
});
|
|
2465
|
+
|
|
2466
|
+
describe('panels', () => {
|
|
2467
|
+
it('draws column headings, linked or plain, a badge and a see-all link', async () => {
|
|
2468
|
+
const wrapper = mountSeed();
|
|
2469
|
+
await trigger(wrapper, 'Ceramics').trigger('click');
|
|
2470
|
+
const ceramics = panel(wrapper, 'Ceramics');
|
|
2471
|
+
const headings = ceramics.findAll('[data-part="groupHeading"]');
|
|
2472
|
+
expect(headings.map((heading) => heading.text())).toEqual([
|
|
2473
|
+
'By type',
|
|
2474
|
+
'By glaze',
|
|
2475
|
+
'Makers',
|
|
2476
|
+
'Best sellers',
|
|
2477
|
+
]);
|
|
2478
|
+
expect(headings[0]!.find('a').exists()).toBe(true);
|
|
2479
|
+
expect(headings[1]!.find('a').exists()).toBe(false);
|
|
2480
|
+
const vases = ceramics.findAll('a').find((a) => a.text().startsWith('Vases'))!;
|
|
2481
|
+
expect(vases.get('[data-part="label"]').text()).toBe('New');
|
|
2482
|
+
const seeAll = ceramics.get('[data-see-all]');
|
|
2483
|
+
expect(seeAll.text()).toBe('All ceramics');
|
|
2484
|
+
expect(seeAll.attributes('href')).toBe('/categories/home/ceramics');
|
|
2485
|
+
// A column's own see-all link stands in for the panel's "View all" row.
|
|
2486
|
+
expect(ceramics.find('[data-eldra-mega-view-all]').exists()).toBe(false);
|
|
2487
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2488
|
+
});
|
|
2489
|
+
|
|
2490
|
+
it('draws product cards with their picture, title and price', async () => {
|
|
2491
|
+
const wrapper = mountSeed();
|
|
2492
|
+
await trigger(wrapper, 'Shop').trigger('click');
|
|
2493
|
+
const cards = panel(wrapper, 'Shop').findAll('[data-part="card"]');
|
|
2494
|
+
expect(cards).toHaveLength(2);
|
|
2495
|
+
expect(cards[0]!.get('img').attributes('src')).toBe('/images/mug.webp');
|
|
2496
|
+
expect(cards[0]!.get('[data-part="cardTitle"]').text()).toBe('Speckled latte mug');
|
|
2497
|
+
expect(cards[0]!.find('[data-part="cardPrice"]').exists()).toBe(true);
|
|
2498
|
+
expect(cards[0]!.element.closest('a')!.getAttribute('href')).toBe(
|
|
2499
|
+
'/products/speckled-latte-mug'
|
|
2500
|
+
);
|
|
2501
|
+
});
|
|
2502
|
+
|
|
2503
|
+
it('hangs a one-column panel with no heading under its trigger, descriptions under the links', async () => {
|
|
2504
|
+
const wrapper = mountSeed();
|
|
2505
|
+
await trigger(wrapper, 'Journal').trigger('click');
|
|
2506
|
+
const journal = panel(wrapper, 'Journal');
|
|
2507
|
+
expect(journal.get('[data-part="content"]').classes()).toContain(
|
|
2508
|
+
'eldra:eldra-nav-menu-dropdown'
|
|
2509
|
+
);
|
|
2510
|
+
expect(journal.findAll('[data-part="description"]').map((d) => d.text())).toEqual([
|
|
2511
|
+
'Washing linen, seasoning boards, storing wool',
|
|
2512
|
+
'Mornings with the people who make our goods',
|
|
2513
|
+
'Small rituals and slow mornings',
|
|
2514
|
+
]);
|
|
2515
|
+
expect(await axe(wrapper.element)).toHaveNoViolations();
|
|
2516
|
+
});
|
|
2517
|
+
|
|
2518
|
+
it('opens the dropdown from the keyboard and walks its links', async () => {
|
|
2519
|
+
const wrapper = mountSeed();
|
|
2520
|
+
const journal = trigger(wrapper, 'Journal');
|
|
2521
|
+
(journal.element as HTMLElement).focus();
|
|
2522
|
+
await journal.trigger('keydown', { key: 'ArrowDown' });
|
|
2523
|
+
await nextTick();
|
|
2524
|
+
expect(journal.attributes('aria-expanded')).toBe('true');
|
|
2525
|
+
const rows = panel(wrapper, 'Journal').findAll('a');
|
|
2526
|
+
expect(document.activeElement).toBe(rows[0]!.element);
|
|
2527
|
+
await rows[0]!.trigger('keydown', { key: 'ArrowDown' });
|
|
2528
|
+
expect(document.activeElement).toBe(rows[1]!.element);
|
|
2529
|
+
await rows[1]!.trigger('keydown', { key: 'Escape' });
|
|
2530
|
+
await nextTick();
|
|
2531
|
+
expect(journal.attributes('aria-expanded')).toBe('false');
|
|
2532
|
+
expect(document.activeElement).toBe(journal.element);
|
|
2533
|
+
});
|
|
2534
|
+
|
|
2535
|
+
it('lays the drawer out as an accordion by default, and as open sections on request', async () => {
|
|
2536
|
+
const accordion = mountSeed();
|
|
2537
|
+
expect(accordion.find('[data-part="drawerSectionHeading"]').exists()).toBe(false);
|
|
2538
|
+
accordion.unmount();
|
|
2539
|
+
const sections = mountSeed({ drawerLayout: 'sections' });
|
|
2540
|
+
const headings = sections.findAll('[data-part="drawerSectionHeading"]');
|
|
2541
|
+
expect(headings.map((heading) => heading.text())).toEqual(['Shop', 'Ceramics', 'Journal']);
|
|
2542
|
+
expect(await axe(sections.element)).toHaveNoViolations();
|
|
2543
|
+
});
|
|
2544
|
+
});
|
|
2545
|
+
|
|
2546
|
+
it('pads the fixed bar by the scrollbar width an open overlay takes away', () => {
|
|
2547
|
+
expect(mountSeed().get('header').classes()).toContain('pr-(--eldra-scrollbar-width,0px)');
|
|
2548
|
+
expect(mountSeed({ sticky: false }).get('header').classes()).not.toContain(
|
|
2549
|
+
'pr-(--eldra-scrollbar-width,0px)'
|
|
2550
|
+
);
|
|
2551
|
+
});
|
|
2552
|
+
});
|