@eldrajs/theme-cli 0.2.2 → 0.2.4
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/dist/cli.js +2 -3
- package/dist/index.d.ts +0 -12
- package/dist/index.js +1 -1
- package/dist/{validate-DprFpjV7.js → validate-FjQ-5_ne.js} +9 -18
- package/package.json +3 -3
- package/template/.eldra/previews.json +35 -35
- package/template/app/plugins/chunk-reload.client.ts +29 -0
- package/template/app/plugins/eldra-storefront.ts +5 -0
- package/template/app/storefront/gateway.ts +34 -14
- package/template/app/storefront/sharedRead.ts +34 -0
- package/template/app/storefront/structuredData.ts +19 -2
- package/template/app/storefront/types.ts +0 -5
- package/template/app/utils/chunkReload.ts +11 -0
- package/template/app/utils/seoInput.ts +0 -1
- 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 +146 -94
- package/template/blocks/collection-grid/__tests__/Block.spec.ts +116 -2
- package/template/blocks/collection-grid/preview.png +0 -0
- package/template/blocks/collection-header/preview.png +0 -0
- package/template/blocks/navigation/Block.vue +125 -541
- package/template/blocks/navigation/__tests__/Block.spec.ts +172 -73
- package/template/blocks/navigation/parts/MenuLink.vue +15 -0
- package/template/blocks/product-detail/preview.png +0 -0
- package/template/blocks/search/preview.png +0 -0
- package/template/blocks/team/preview.png +0 -0
- package/template/blocks/video-embed/preview.png +0 -0
- package/template/package.json +1 -1
- package/template/test/chunkReload.spec.ts +20 -0
- package/template/test/imageFraming.browser.spec.ts +125 -0
- package/template/test/pages/article.spec.ts +1 -1
- package/template/test/pages/collection.spec.ts +1 -1
- package/template/test/pages/home.spec.ts +1 -1
- package/template/test/pages/product.spec.ts +1 -1
- package/template/test/prerenderRefresh.browser.spec.ts +58 -13
- package/template/test/seoInput.spec.ts +5 -4
- package/template/test/storefront/gateway.spec.ts +6 -0
- package/template/test/storefront/gatewayPrerender.spec.ts +26 -1
- package/template/test/storefront/sharedRead.spec.ts +43 -0
- package/template/test/storefront/structuredData.spec.ts +34 -6
- package/template/test/structuredData.generate.spec.ts +1 -1
- package/template/test/support/mockGateway.ts +8 -3
- package/template/blocks/navigation/useMegaMenuKeys.ts +0 -276
|
@@ -189,6 +189,16 @@ function countPill(control: DOMWrapper<Element>): Element | null {
|
|
|
189
189
|
return siblings.find((element) => element !== control.element) ?? null;
|
|
190
190
|
}
|
|
191
191
|
|
|
192
|
+
/** A mouse pointer entering or leaving an element; `NavMenu` ignores touch and pen. */
|
|
193
|
+
function mouse(target: Element, type: 'pointerenter' | 'pointerleave'): void {
|
|
194
|
+
target.dispatchEvent(new PointerEvent(type, { pointerType: 'mouse' }));
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/** `NavMenu`'s root, the Menu button's parent: the element a pointer leaves when it leaves the menu. */
|
|
198
|
+
function menuRoot(wrapper: { get: (selector: string) => DOMWrapper<Element> }): Element {
|
|
199
|
+
return wrapper.get('[data-part="toggle"]').element.parentElement!;
|
|
200
|
+
}
|
|
201
|
+
|
|
192
202
|
describe('header block (navigation apiId)', () => {
|
|
193
203
|
afterEach(() => {
|
|
194
204
|
window.history.pushState({}, '', '/');
|
|
@@ -250,7 +260,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
250
260
|
{ kind: 'url', url: '/pages/visit', label: 'Visit' },
|
|
251
261
|
],
|
|
252
262
|
});
|
|
253
|
-
const rows = wrapper.findAll('
|
|
263
|
+
const rows = wrapper.findAll('[data-part="item"]');
|
|
254
264
|
expect(rows).toHaveLength(1);
|
|
255
265
|
expect(rows[0]!.text()).toBe('Visit');
|
|
256
266
|
});
|
|
@@ -311,13 +321,13 @@ describe('header block (navigation apiId)', () => {
|
|
|
311
321
|
});
|
|
312
322
|
|
|
313
323
|
it('labels the primary navigation landmark', () => {
|
|
314
|
-
//
|
|
315
|
-
// `<div>`/`<ul>` with no `nav` landmark of its own: with no real stylesheet loaded, jsdom/axe
|
|
316
|
-
// cannot tell "hidden below 64rem" from "visible", so a second identically-labelled `nav`
|
|
317
|
-
// would trip axe's `landmark-unique` rule the moment both exist in the same render.
|
|
324
|
+
// One landmark in the bar; the drawer's copy stays out of the page inside the closed `<dialog>`.
|
|
318
325
|
const wrapper = mountBlock(resolved.data);
|
|
319
326
|
const navs = wrapper.findAll('nav[aria-label="Primary navigation"]');
|
|
320
|
-
expect(navs).toHaveLength(1);
|
|
327
|
+
expect(navs.filter((nav) => nav.element.closest('dialog') === null)).toHaveLength(1);
|
|
328
|
+
for (const nav of navs.filter((nav) => nav.element.closest('dialog') !== null)) {
|
|
329
|
+
expect((nav.element.closest('dialog') as HTMLDialogElement).open).toBe(false);
|
|
330
|
+
}
|
|
321
331
|
});
|
|
322
332
|
|
|
323
333
|
it('establishes its own @container context on the root, so @tablet:/@content: classes measure the block’s own width', () => {
|
|
@@ -354,27 +364,29 @@ describe('header block (navigation apiId)', () => {
|
|
|
354
364
|
});
|
|
355
365
|
|
|
356
366
|
describe('mega-menu keyboard', () => {
|
|
357
|
-
|
|
367
|
+
// Enter/Space are a native button's click, which jsdom never synthesises; `@eldrajs/ui`'s browser spec presses them.
|
|
368
|
+
it('a trigger toggles on activation; hover alone never opens it; opening one closes the other', async () => {
|
|
358
369
|
const wrapper = mountBlock(resolved.data, { attachTo: document.body });
|
|
359
370
|
// Locate the two mega-menu triggers by their accessible label text.
|
|
360
371
|
const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
|
|
361
372
|
const ceramics = wrapper.findAll('button').find((b) => b.text().includes('Ceramics'))!;
|
|
362
373
|
|
|
363
374
|
expect(knitwear.attributes('aria-expanded')).toBe('false');
|
|
364
|
-
|
|
375
|
+
mouse(knitwear.element, 'pointerenter');
|
|
376
|
+
await nextTick();
|
|
365
377
|
expect(knitwear.attributes('aria-expanded')).toBe('false'); // nothing opens on hover alone (no wait)
|
|
366
|
-
|
|
378
|
+
mouse(knitwear.element, 'pointerleave');
|
|
367
379
|
|
|
368
|
-
await knitwear.trigger('
|
|
380
|
+
await knitwear.trigger('click');
|
|
369
381
|
expect(knitwear.attributes('aria-expanded')).toBe('true');
|
|
370
382
|
|
|
371
383
|
// Opening the other one closes the first.
|
|
372
|
-
await ceramics.trigger('
|
|
384
|
+
await ceramics.trigger('click');
|
|
373
385
|
expect(ceramics.attributes('aria-expanded')).toBe('true');
|
|
374
386
|
expect(knitwear.attributes('aria-expanded')).toBe('false');
|
|
375
387
|
|
|
376
388
|
// Toggling the same trigger again closes it.
|
|
377
|
-
await ceramics.trigger('
|
|
389
|
+
await ceramics.trigger('click');
|
|
378
390
|
expect(ceramics.attributes('aria-expanded')).toBe('false');
|
|
379
391
|
|
|
380
392
|
wrapper.unmount();
|
|
@@ -387,29 +399,32 @@ describe('header block (navigation apiId)', () => {
|
|
|
387
399
|
const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
|
|
388
400
|
const panel = () => wrapper.find(`#${knitwear.attributes('aria-controls')}`);
|
|
389
401
|
|
|
390
|
-
|
|
402
|
+
mouse(knitwear.element, 'pointerenter');
|
|
391
403
|
vi.advanceTimersByTime(160);
|
|
392
404
|
await nextTick();
|
|
393
405
|
expect(knitwear.attributes('aria-expanded')).toBe('true');
|
|
394
406
|
|
|
395
|
-
//
|
|
396
|
-
|
|
397
|
-
|
|
407
|
+
// Trigger to panel never leaves the menu; straying out and back within the grace keeps it open.
|
|
408
|
+
mouse(knitwear.element, 'pointerleave');
|
|
409
|
+
mouse(menuRoot(wrapper), 'pointerleave');
|
|
410
|
+
vi.advanceTimersByTime(100);
|
|
411
|
+
mouse(menuRoot(wrapper), 'pointerenter');
|
|
398
412
|
vi.advanceTimersByTime(300);
|
|
399
413
|
await nextTick();
|
|
414
|
+
expect(panel().isVisible()).toBe(true);
|
|
400
415
|
expect(knitwear.attributes('aria-expanded')).toBe('true');
|
|
401
416
|
|
|
402
|
-
// Leaving the
|
|
403
|
-
|
|
417
|
+
// Leaving the menu closes what hover opened.
|
|
418
|
+
mouse(menuRoot(wrapper), 'pointerleave');
|
|
404
419
|
vi.advanceTimersByTime(160);
|
|
405
420
|
await nextTick();
|
|
406
421
|
expect(knitwear.attributes('aria-expanded')).toBe('false');
|
|
407
422
|
|
|
408
|
-
// A panel opened by
|
|
409
|
-
await knitwear.trigger('
|
|
423
|
+
// A panel opened by a click is not hover-owned: the pointer leaving does not close it.
|
|
424
|
+
await knitwear.trigger('click');
|
|
410
425
|
expect(knitwear.attributes('aria-expanded')).toBe('true');
|
|
411
|
-
|
|
412
|
-
|
|
426
|
+
mouse(knitwear.element, 'pointerenter');
|
|
427
|
+
mouse(menuRoot(wrapper), 'pointerleave');
|
|
413
428
|
vi.advanceTimersByTime(300);
|
|
414
429
|
await nextTick();
|
|
415
430
|
expect(knitwear.attributes('aria-expanded')).toBe('true');
|
|
@@ -446,7 +461,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
446
461
|
expect(spacer.classes()).toContain('border-b');
|
|
447
462
|
expect(spacer.classes()).toContain('border-transparent');
|
|
448
463
|
const reserved = spacer.get('div');
|
|
449
|
-
const bar = wrapper.get('header
|
|
464
|
+
const bar = wrapper.get('[data-eldra-header-bar]');
|
|
450
465
|
for (const height of ['h-16', '@content:h-[4.5rem]']) {
|
|
451
466
|
expect(bar.classes()).toContain(height);
|
|
452
467
|
expect(reserved.classes()).toContain(height);
|
|
@@ -490,7 +505,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
490
505
|
|
|
491
506
|
// In use: an open mega-menu keeps the bar on screen through a scroll-down …
|
|
492
507
|
const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
|
|
493
|
-
await knitwear.trigger('
|
|
508
|
+
await knitwear.trigger('click');
|
|
494
509
|
await scrollTo(900);
|
|
495
510
|
expect(header.classes()).not.toContain('-translate-y-full');
|
|
496
511
|
await knitwear.trigger('keydown', { key: 'Escape' });
|
|
@@ -975,7 +990,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
975
990
|
panelLinks(wrapper, knitwear)[0]!.element.focus();
|
|
976
991
|
|
|
977
992
|
// The pointer has come to rest on the next trigger: its 150ms open is armed, not fired.
|
|
978
|
-
|
|
993
|
+
mouse(ceramics.element, 'pointerenter');
|
|
979
994
|
// Focus leaves the header's menus, which closes the open panel…
|
|
980
995
|
wrapper.get('a[data-eldra-header-focus]').element.focus();
|
|
981
996
|
await nextTick();
|
|
@@ -997,7 +1012,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
997
1012
|
const wrapper = mountBlock(resolved.data, { attachTo: document.body });
|
|
998
1013
|
const knitwear = triggerFor(wrapper, 'Knitwear');
|
|
999
1014
|
|
|
1000
|
-
|
|
1015
|
+
mouse(knitwear.element, 'pointerenter');
|
|
1001
1016
|
vi.advanceTimersByTime(160);
|
|
1002
1017
|
await nextTick();
|
|
1003
1018
|
expect(knitwear.attributes('aria-expanded')).toBe('true');
|
|
@@ -1005,7 +1020,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1005
1020
|
// Focus has arrived inside what hover opened, so the pointer no longer owns it: closing
|
|
1006
1021
|
// on the way out would strand that focus on a link the panel has just hidden.
|
|
1007
1022
|
panelLinks(wrapper, knitwear)[0]!.element.focus();
|
|
1008
|
-
|
|
1023
|
+
mouse(menuRoot(wrapper), 'pointerleave');
|
|
1009
1024
|
vi.advanceTimersByTime(300);
|
|
1010
1025
|
await nextTick();
|
|
1011
1026
|
expect(knitwear.attributes('aria-expanded')).toBe('true');
|
|
@@ -1045,8 +1060,10 @@ describe('header block (navigation apiId)', () => {
|
|
|
1045
1060
|
|
|
1046
1061
|
const dialog = wrapper.get('dialog');
|
|
1047
1062
|
expect(dialog.attributes('open')).toBe('');
|
|
1048
|
-
// The first row of the drawer's own list —
|
|
1049
|
-
const firstRow = wrapper.get(
|
|
1063
|
+
// The first row of the drawer's own list — an accordion row (Knitwear has a mega-menu).
|
|
1064
|
+
const firstRow = wrapper.get(
|
|
1065
|
+
'dialog ul li:first-child summary, dialog ul li:first-child button, dialog ul li:first-child a'
|
|
1066
|
+
);
|
|
1050
1067
|
expect(document.activeElement).toBe(firstRow.element);
|
|
1051
1068
|
wrapper.unmount();
|
|
1052
1069
|
});
|
|
@@ -1347,6 +1364,92 @@ describe('header block (navigation apiId)', () => {
|
|
|
1347
1364
|
expect(other.attributes('aria-current')).toBeUndefined();
|
|
1348
1365
|
});
|
|
1349
1366
|
|
|
1367
|
+
it('marks a current page inside a mega-menu on its link and on the trigger that holds it', async () => {
|
|
1368
|
+
window.history.pushState({}, '', '/collections/womens-sweaters');
|
|
1369
|
+
const wrapper = mountBlock(resolved.data, { attachTo: document.body });
|
|
1370
|
+
const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
|
|
1371
|
+
expect(knitwear.attributes('data-current')).toBe('');
|
|
1372
|
+
const panel = wrapper.get(`#${knitwear.attributes('aria-controls')}`);
|
|
1373
|
+
const current = panel.findAll('[aria-current="page"]');
|
|
1374
|
+
expect(current).toHaveLength(1);
|
|
1375
|
+
expect(current[0]!.attributes('href')).toBe('/collections/womens-sweaters');
|
|
1376
|
+
wrapper.unmount();
|
|
1377
|
+
});
|
|
1378
|
+
|
|
1379
|
+
it('routes a same-site row and leaves an external one a plain anchor, opening a new tab when asked', () => {
|
|
1380
|
+
const wrapper = mountBlock({
|
|
1381
|
+
...resolved.data,
|
|
1382
|
+
links: [
|
|
1383
|
+
{ kind: 'url', url: '/journal', label: 'Journal' },
|
|
1384
|
+
{
|
|
1385
|
+
kind: 'url',
|
|
1386
|
+
url: 'https://example.com/stockists',
|
|
1387
|
+
label: 'Stockists',
|
|
1388
|
+
openInNewTab: true,
|
|
1389
|
+
},
|
|
1390
|
+
],
|
|
1391
|
+
});
|
|
1392
|
+
const routed = wrapper
|
|
1393
|
+
.findAllComponents({ name: 'NuxtLink' })
|
|
1394
|
+
.map((link) => link.props('to') as string);
|
|
1395
|
+
expect(routed).toContain('/journal');
|
|
1396
|
+
expect(routed).not.toContain('https://example.com/stockists');
|
|
1397
|
+
const external = wrapper.get('[data-part="link"][href="https://example.com/stockists"]');
|
|
1398
|
+
expect(external.attributes('target')).toBe('_blank');
|
|
1399
|
+
expect(external.attributes('rel')).toBe('noopener noreferrer');
|
|
1400
|
+
});
|
|
1401
|
+
|
|
1402
|
+
it('takes no room for the View all row under a heading that goes nowhere', async () => {
|
|
1403
|
+
const wrapper = mountBlock({
|
|
1404
|
+
...resolved.data,
|
|
1405
|
+
links: [
|
|
1406
|
+
{
|
|
1407
|
+
kind: 'none',
|
|
1408
|
+
label: 'Workshop',
|
|
1409
|
+
children: [{ kind: 'url', url: '/journal', label: 'Journal' }],
|
|
1410
|
+
},
|
|
1411
|
+
],
|
|
1412
|
+
});
|
|
1413
|
+
const trigger = wrapper.findAll('button').find((b) => b.text().includes('Workshop'))!;
|
|
1414
|
+
// Ungrouped children still make a sheet across the header, not a dropdown under the trigger.
|
|
1415
|
+
expect(wrapper.get(`#${trigger.attributes('aria-controls')}`).classes()).toContain('inset-x-0');
|
|
1416
|
+
const footer = wrapper.get(`#${trigger.attributes('aria-controls')} [data-part="footer"]`);
|
|
1417
|
+
// `:empty` as a browser reads it (jsdom counts Vue's empty anchors; `@eldrajs/ui`'s browser spec proves it).
|
|
1418
|
+
expect(footer.element.children).toHaveLength(0);
|
|
1419
|
+
expect(footer.element.textContent).toBe('');
|
|
1420
|
+
expect(footer.classes()).toContain('empty:hidden');
|
|
1421
|
+
});
|
|
1422
|
+
|
|
1423
|
+
it('is axe-clean in every variant with the drawer open, and with a mega-menu open where the bar has one', async () => {
|
|
1424
|
+
for (const variant of ['default', 'centered', 'minimal']) {
|
|
1425
|
+
const wrapper = mountBlock({ ...resolved.data, variant }, { attachTo: document.body });
|
|
1426
|
+
const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'));
|
|
1427
|
+
if (variant !== 'minimal') {
|
|
1428
|
+
await knitwear!.trigger('click');
|
|
1429
|
+
expect(knitwear!.attributes('aria-expanded'), variant).toBe('true');
|
|
1430
|
+
expect(await axe(wrapper.element), variant).toHaveNoViolations();
|
|
1431
|
+
await knitwear!.trigger('click');
|
|
1432
|
+
}
|
|
1433
|
+
await wrapper.get('[data-part="toggle"]').trigger('click');
|
|
1434
|
+
const dialog = wrapper.get('dialog[open]');
|
|
1435
|
+
expect(dialog.attributes('aria-label'), variant).toBe('Menu');
|
|
1436
|
+
// The open drawer is modal: everything behind it is inert, so the dialog is what is checked.
|
|
1437
|
+
expect(await axe(dialog.element), variant).toHaveNoViolations();
|
|
1438
|
+
wrapper.unmount();
|
|
1439
|
+
}
|
|
1440
|
+
});
|
|
1441
|
+
|
|
1442
|
+
it('minimal variant shows the Menu button, word and all, at every width and no bar of links', () => {
|
|
1443
|
+
const wrapper = mountBlock({ ...resolved.data, variant: 'minimal' });
|
|
1444
|
+
expect(wrapper.find('[data-part="nav"]').exists()).toBe(false);
|
|
1445
|
+
const toggle = wrapper.get('[data-part="toggle"]');
|
|
1446
|
+
expect(toggle.text()).toBe('Menu');
|
|
1447
|
+
expect(toggle.classes().some((token) => token.endsWith(':hidden'))).toBe(false);
|
|
1448
|
+
// The default variant hides it once the bar has room for its links.
|
|
1449
|
+
const bar = mountBlock(resolved.data).get('[data-part="toggle"]');
|
|
1450
|
+
expect(bar.classes()).toContain('@content:hidden');
|
|
1451
|
+
});
|
|
1452
|
+
|
|
1350
1453
|
it('renders 8 links with no overflow markup errors', async () => {
|
|
1351
1454
|
const eightLinks = [
|
|
1352
1455
|
...resolved.data.links,
|
|
@@ -1376,49 +1479,53 @@ describe('header block (navigation apiId)', () => {
|
|
|
1376
1479
|
// jsdom computes no layout, so the proof that the panel really lands on the brand's left edge
|
|
1377
1480
|
// and the actions' right edge is the browser case in `test/prerenderRefresh.browser.spec.ts`.
|
|
1378
1481
|
// What is checkable here is the arrangement that produces it: the panel is pinned to the
|
|
1379
|
-
// header's own content box — the
|
|
1482
|
+
// header's own content box — the bar's grid — rather than to the item that opened it, and its
|
|
1380
1483
|
// columns are the container's 12-column grid.
|
|
1381
1484
|
it('pins the panel to the header container, not to the trigger that opened it', async () => {
|
|
1382
1485
|
const wrapper = mountBlock(resolved.data, { attachTo: document.body });
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
expect(
|
|
1486
|
+
// The bar's grid is the panel's positioning box; the menu's own root takes no box at all.
|
|
1487
|
+
expect(wrapper.get('[data-eldra-header-bar]').classes()).toContain('relative');
|
|
1488
|
+
const root = [...menuRoot(wrapper).classList];
|
|
1489
|
+
expect(root).toContain('contents');
|
|
1490
|
+
expect(root).not.toContain('relative');
|
|
1387
1491
|
// …and no row of the bar may reclaim it, or the panel would hang under its own item again.
|
|
1388
|
-
for (const row of wrapper.findAll('
|
|
1492
|
+
for (const row of wrapper.findAll('[data-part="item"]')) {
|
|
1389
1493
|
expect(row.classes()).not.toContain('relative');
|
|
1390
1494
|
}
|
|
1391
1495
|
|
|
1392
1496
|
const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
|
|
1393
1497
|
await knitwear.trigger('click');
|
|
1394
1498
|
const panel = wrapper.get(`#${knitwear.attributes('aria-controls')}`);
|
|
1395
|
-
|
|
1396
|
-
for (const token of ['absolute', 'top-full', '
|
|
1499
|
+
// Flush under the bar: no offset of its own.
|
|
1500
|
+
for (const token of ['absolute', 'top-full', 'inset-x-0', 'pt-0']) {
|
|
1397
1501
|
expect(panel.classes()).toContain(token);
|
|
1398
1502
|
}
|
|
1399
1503
|
// A width of its own is exactly what the old panel had, and what made it feel arbitrary.
|
|
1400
1504
|
expect(panel.classes()).not.toContain('w-screen');
|
|
1401
1505
|
expect(panel.classes().some((token) => token.startsWith('max-w-'))).toBe(false);
|
|
1402
|
-
// The
|
|
1403
|
-
|
|
1404
|
-
// are rounded, and the shadow falls below.
|
|
1506
|
+
// The bar's own bottom border is the sheet's top edge, so only the other three sides and corners are drawn.
|
|
1507
|
+
const sheet = panel.get('[data-part="content"]').classes();
|
|
1405
1508
|
for (const token of [
|
|
1406
1509
|
'border',
|
|
1407
1510
|
'border-t-0',
|
|
1408
1511
|
'border-border',
|
|
1512
|
+
'rounded-none',
|
|
1409
1513
|
'rounded-b-lg',
|
|
1410
|
-
'shadow-float',
|
|
1514
|
+
'shadow-(--eldra-shadow-float)',
|
|
1515
|
+
'p-6',
|
|
1516
|
+
'@wide:p-8',
|
|
1411
1517
|
]) {
|
|
1412
|
-
expect(
|
|
1518
|
+
expect(sheet).toContain(token);
|
|
1413
1519
|
}
|
|
1414
1520
|
|
|
1415
1521
|
// The container's grid: 12 columns, 24px gutters, and an inset that keeps every column off
|
|
1416
1522
|
// the panel's own edges — 24px, 32px once the container passes `wide`. The browser case
|
|
1417
1523
|
// measures what this produces; here it is only the arrangement.
|
|
1418
|
-
|
|
1419
|
-
|
|
1524
|
+
const columns = panel.get('[data-part="columns"]').classes();
|
|
1525
|
+
for (const token of ['grid', 'grid-cols-12', 'gap-6']) {
|
|
1526
|
+
expect(columns).toContain(token);
|
|
1420
1527
|
}
|
|
1421
|
-
expect(
|
|
1528
|
+
expect(sheet).not.toContain('py-8');
|
|
1422
1529
|
wrapper.unmount();
|
|
1423
1530
|
});
|
|
1424
1531
|
|
|
@@ -1448,10 +1555,12 @@ describe('header block (navigation apiId)', () => {
|
|
|
1448
1555
|
expect(viewAll.text()).toBe('View all');
|
|
1449
1556
|
// Self-descriptive out of context (2.4.4), opening with the visible text (2.5.3).
|
|
1450
1557
|
expect(viewAll.attributes('aria-label')).toBe('View all Knitwear');
|
|
1451
|
-
// Right-aligned under a rule
|
|
1452
|
-
|
|
1453
|
-
|
|
1558
|
+
// Right-aligned under a rule across the content width: it follows the columns, outside their grid.
|
|
1559
|
+
const row = viewAll.element.parentElement!;
|
|
1560
|
+
for (const token of ['justify-end', 'border-t', 'border-border', 'pt-4']) {
|
|
1561
|
+
expect([...row.classList]).toContain(token);
|
|
1454
1562
|
}
|
|
1563
|
+
expect(row.previousElementSibling?.getAttribute('data-part')).toBe('columns');
|
|
1455
1564
|
// The trailing arrow the theme's other "view all" links carry, drawn outside the label so
|
|
1456
1565
|
// the underline runs under the words only.
|
|
1457
1566
|
expect(viewAll.find('[data-part="arrow"]').exists()).toBe(true);
|
|
@@ -1472,18 +1581,15 @@ describe('header block (navigation apiId)', () => {
|
|
|
1472
1581
|
|
|
1473
1582
|
const knitwear = wrapper.findAll('button').find((b) => b.text().includes('Knitwear'))!;
|
|
1474
1583
|
await knitwear.trigger('click');
|
|
1475
|
-
const
|
|
1476
|
-
expect(
|
|
1584
|
+
const sheet = wrapper.get(`#${knitwear.attributes('aria-controls')} [data-part="content"]`);
|
|
1585
|
+
expect(sheet.classes()).toContain('bg-(--eldra-header-surface)');
|
|
1477
1586
|
// And no ground token of its own left behind to drift away from the bar's.
|
|
1478
|
-
expect(
|
|
1587
|
+
expect(sheet.classes()).not.toContain('bg-background');
|
|
1479
1588
|
wrapper.unmount();
|
|
1480
1589
|
});
|
|
1481
1590
|
|
|
1482
|
-
it('eases the panel in and out,
|
|
1483
|
-
//
|
|
1484
|
-
// panel, one frame before the to-classes land, so this is the frame they can be read in.
|
|
1485
|
-
// jsdom computes no transition at all, which is also why the leave's own duration is proven in
|
|
1486
|
-
// the browser spec instead; what is checkable here is the wiring and the numbers on it.
|
|
1591
|
+
it('eases the panel in and fades it out, both on the motion tokens', async () => {
|
|
1592
|
+
// Leave classes land in the patch that closes the panel; the browser spec proves the fade itself.
|
|
1487
1593
|
//
|
|
1488
1594
|
// `stubs: { transition: false }` is the one thing this test needs that no other does:
|
|
1489
1595
|
// `@vue/test-utils` stubs `<Transition>` by default, and a stub applies no classes at all.
|
|
@@ -1504,25 +1610,18 @@ describe('header block (navigation apiId)', () => {
|
|
|
1504
1610
|
|
|
1505
1611
|
await knitwear.trigger('click');
|
|
1506
1612
|
expect(knitwear.attributes('aria-expanded')).toBe('true');
|
|
1507
|
-
|
|
1508
|
-
'
|
|
1509
|
-
|
|
1510
|
-
'transition-[opacity,transform]',
|
|
1511
|
-
'duration-[150ms]',
|
|
1512
|
-
'ease-out',
|
|
1513
|
-
]) {
|
|
1514
|
-
expect(panel().classes(), 'enter').toContain(token);
|
|
1515
|
-
}
|
|
1613
|
+
expect(panel().get('[data-part="content"]').classes(), 'enter').toContain(
|
|
1614
|
+
'animate-eldra-popover-in'
|
|
1615
|
+
);
|
|
1516
1616
|
|
|
1517
1617
|
await knitwear.trigger('click');
|
|
1518
1618
|
// The panel is still there, and still addressable, while it leaves — that is the whole point
|
|
1519
|
-
// of a `<Transition>` over a bare `v-show` — but
|
|
1520
|
-
// crossing it on its way out never clears the close timer and pulls it back open.
|
|
1619
|
+
// of a `<Transition>` over a bare `v-show` — but a click on the fading sheet goes through it.
|
|
1521
1620
|
expect(knitwear.attributes('aria-expanded')).toBe('false');
|
|
1522
1621
|
for (const token of [
|
|
1523
1622
|
'pointer-events-none',
|
|
1524
|
-
'transition-
|
|
1525
|
-
'duration-
|
|
1623
|
+
'transition-opacity',
|
|
1624
|
+
'duration-fast',
|
|
1526
1625
|
'ease-in',
|
|
1527
1626
|
]) {
|
|
1528
1627
|
expect(panel().classes(), 'leave').toContain(token);
|
|
@@ -1778,9 +1877,9 @@ describe('header block (navigation apiId)', () => {
|
|
|
1778
1877
|
// together.
|
|
1779
1878
|
it('puts one 0.25rem gap everywhere in the bar’s grid — never a larger one between columns', () => {
|
|
1780
1879
|
const wrapper = mountBlock(resolved.data);
|
|
1781
|
-
const
|
|
1782
|
-
expect(
|
|
1783
|
-
expect(
|
|
1880
|
+
const bar = wrapper.get('[data-eldra-header-bar]');
|
|
1881
|
+
expect(bar.classes()).toContain('gap-1');
|
|
1882
|
+
expect(bar.classes().some((cls) => cls.includes('gap-4'))).toBe(false);
|
|
1784
1883
|
|
|
1785
1884
|
const actions = wrapper.get('[data-eldra-header-actions]');
|
|
1786
1885
|
expect(actions.classes()).toContain('gap-1');
|
|
@@ -1789,7 +1888,7 @@ describe('header block (navigation apiId)', () => {
|
|
|
1789
1888
|
it('gives the call to action its own 0.75rem from the cart, not only the row’s 0.25rem gap', () => {
|
|
1790
1889
|
const wrapper = mountBlock(resolved.data);
|
|
1791
1890
|
const actions = wrapper.get('[data-eldra-header-actions]');
|
|
1792
|
-
const cta =
|
|
1891
|
+
const cta = actions.findAll('a, button').find((el) => el.text() === mock.ctaLabel)!;
|
|
1793
1892
|
// 0.5rem of margin on top of the row's own 0.25rem `gap-1` — spec "Header" -> Layout, "From
|
|
1794
1893
|
// 64rem": the call to action "sits 0.75rem after the cart".
|
|
1795
1894
|
expect(cta.classes()).toContain('@content:ml-2');
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed } from 'vue';
|
|
3
|
+
import EldraRouterLink from '../../../app/components/EldraRouterLink.vue';
|
|
4
|
+
import { isInternalHref } from '../../../app/utils/links';
|
|
5
|
+
|
|
6
|
+
/** `NavMenu`'s `linkAs`: a same-site destination routes, anything else is a plain anchor. */
|
|
7
|
+
const props = defineProps<{ to: string }>();
|
|
8
|
+
|
|
9
|
+
const internal = computed(() => isInternalHref(props.to));
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<EldraRouterLink v-if="internal" :to="to"><slot /></EldraRouterLink>
|
|
14
|
+
<a v-else :href="to"><slot /></a>
|
|
15
|
+
</template>
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/template/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { isChunkError, shouldReload } from '../app/utils/chunkReload';
|
|
3
|
+
|
|
4
|
+
describe('chunk reload', () => {
|
|
5
|
+
it('recognises the browsers’ messages for a chunk that is gone', () => {
|
|
6
|
+
expect(
|
|
7
|
+
isChunkError(
|
|
8
|
+
new TypeError('Failed to fetch dynamically imported module: https://x/_nuxt/a.js')
|
|
9
|
+
)
|
|
10
|
+
).toBe(true);
|
|
11
|
+
expect(isChunkError(new Error('Importing a module script failed.'))).toBe(true);
|
|
12
|
+
expect(isChunkError(new Error('Cannot read properties of undefined'))).toBe(false);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('reloads once, then not again within the window', () => {
|
|
16
|
+
expect(shouldReload(1_000, null)).toBe(true);
|
|
17
|
+
expect(shouldReload(10_000, 1_000)).toBe(false);
|
|
18
|
+
expect(shouldReload(40_000, 1_000)).toBe(true);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { chromium, type Browser, type Page } from '@playwright/test';
|
|
5
|
+
import { compile } from '@tailwindcss/node';
|
|
6
|
+
import { mount } from '@vue/test-utils';
|
|
7
|
+
import { imageFramingStyle, type ImageFraming } from '@eldrajs/theme-vue';
|
|
8
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
|
9
|
+
import UiImage from '../app/components/ui/UiImage.vue';
|
|
10
|
+
|
|
11
|
+
// Studio previews a framing with theme-core's imageFramingStyle; UiImage must draw the same pixels, out-of-band framings too.
|
|
12
|
+
|
|
13
|
+
const assetsDir = `${join(import.meta.dirname, '../app/assets')}/`;
|
|
14
|
+
const PICTURE = 'https://picture.test/frame.png';
|
|
15
|
+
|
|
16
|
+
const FRAMINGS: Array<ImageFraming | null> = [
|
|
17
|
+
null,
|
|
18
|
+
{ x: 0.5, y: 0.5, zoom: 1.6 },
|
|
19
|
+
{ x: 0.2, y: 0.6, zoom: 2 },
|
|
20
|
+
{ x: 0.05, y: 0.95, zoom: 3.5 },
|
|
21
|
+
{ x: 1, y: 0, zoom: 4 },
|
|
22
|
+
{ x: 0, y: 1, zoom: 2.5 },
|
|
23
|
+
];
|
|
24
|
+
const ASPECTS = ['16/9', '1/1', '4/5'];
|
|
25
|
+
const CASES = ASPECTS.flatMap((aspect) => FRAMINGS.map((framing) => ({ aspect, framing })));
|
|
26
|
+
|
|
27
|
+
const styleText = (style: Record<string, string>) =>
|
|
28
|
+
Object.entries(style)
|
|
29
|
+
.map(([property, value]) => `${property}:${value}`)
|
|
30
|
+
.join(';');
|
|
31
|
+
|
|
32
|
+
describe('a page-builder framing through UiImage, in a real browser', () => {
|
|
33
|
+
let browser: Browser;
|
|
34
|
+
let page: Page;
|
|
35
|
+
|
|
36
|
+
beforeAll(async () => {
|
|
37
|
+
const rendered = CASES.map(({ aspect, framing }) => {
|
|
38
|
+
const wrapper = mount(UiImage, { props: { src: PICTURE, alt: '', aspect, framing } });
|
|
39
|
+
const html = wrapper.html();
|
|
40
|
+
wrapper.unmount();
|
|
41
|
+
return html;
|
|
42
|
+
});
|
|
43
|
+
const candidates = [...rendered.join('').matchAll(/class="([^"]*)"/g)].flatMap((match) =>
|
|
44
|
+
match[1]!.split(/\s+/).filter(Boolean)
|
|
45
|
+
);
|
|
46
|
+
const compiler = await compile(readFileSync(`${assetsDir}main.css`, 'utf8'), {
|
|
47
|
+
base: assetsDir,
|
|
48
|
+
onDependency() {},
|
|
49
|
+
});
|
|
50
|
+
const css = compiler.build([...new Set(candidates)]);
|
|
51
|
+
const columns = CASES.map(({ aspect, framing }, i) => {
|
|
52
|
+
const reference =
|
|
53
|
+
`<div class="ref" style="position:relative;overflow:hidden;aspect-ratio:${aspect}">` +
|
|
54
|
+
`<img src="${PICTURE}" alt="" style="display:block;width:100%;height:100%;${styleText(imageFramingStyle(framing))}"></div>`;
|
|
55
|
+
return `<div class="case">${rendered[i]}${reference}</div>`;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
browser = await chromium.launch();
|
|
59
|
+
page = await browser.newPage({ viewport: { width: 1200, height: 900 } });
|
|
60
|
+
await page.route(PICTURE, async (route) => {
|
|
61
|
+
const png = await page.evaluate(() => {
|
|
62
|
+
const canvas = Object.assign(document.createElement('canvas'), {
|
|
63
|
+
width: 1600,
|
|
64
|
+
height: 900,
|
|
65
|
+
});
|
|
66
|
+
const ctx = canvas.getContext('2d')!;
|
|
67
|
+
const gradient = ctx.createLinearGradient(0, 0, 1600, 900);
|
|
68
|
+
gradient.addColorStop(0, '#1d3557');
|
|
69
|
+
gradient.addColorStop(0.5, '#e9c46a');
|
|
70
|
+
gradient.addColorStop(1, '#e63946');
|
|
71
|
+
ctx.fillStyle = gradient;
|
|
72
|
+
ctx.fillRect(0, 0, 1600, 900);
|
|
73
|
+
ctx.strokeStyle = '#fff';
|
|
74
|
+
for (let x = 0; x < 1600; x += 37) ctx.strokeRect(x, (x * 7) % 900, 23, 23);
|
|
75
|
+
return canvas.toDataURL('image/png').split(',')[1]!;
|
|
76
|
+
});
|
|
77
|
+
await route.fulfill({ body: Buffer.from(png, 'base64'), contentType: 'image/png' });
|
|
78
|
+
});
|
|
79
|
+
await page.setContent(
|
|
80
|
+
`<style>${css} body{margin:0} .case{display:flex;gap:20px;height:400px;align-items:flex-start}` +
|
|
81
|
+
`.case>*{flex:none;width:300px}</style>` +
|
|
82
|
+
`<main>${columns.join('')}</main>`
|
|
83
|
+
);
|
|
84
|
+
await page.evaluate(() =>
|
|
85
|
+
Promise.all([...document.images].map((img) => ((img.loading = 'eager'), img.decode())))
|
|
86
|
+
);
|
|
87
|
+
}, 120_000);
|
|
88
|
+
|
|
89
|
+
// theme-core prints percentages to 4 places and UiImage passes x * 100 as is, so an edge pixel can differ by a few levels.
|
|
90
|
+
const largestDifference = (a: Buffer, b: Buffer) =>
|
|
91
|
+
page.evaluate(
|
|
92
|
+
async ([a, b]) => {
|
|
93
|
+
const pixels = async (data: string) => {
|
|
94
|
+
const bitmap = await createImageBitmap(
|
|
95
|
+
await (await fetch(`data:image/png;base64,${data}`)).blob()
|
|
96
|
+
);
|
|
97
|
+
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
|
|
98
|
+
const ctx = canvas.getContext('2d')!;
|
|
99
|
+
ctx.drawImage(bitmap, 0, 0);
|
|
100
|
+
return ctx.getImageData(0, 0, bitmap.width, bitmap.height);
|
|
101
|
+
};
|
|
102
|
+
const [pa, pb] = await Promise.all([pixels(a!), pixels(b!)]);
|
|
103
|
+
if (pa.width !== pb.width || pa.height !== pb.height) return Number.POSITIVE_INFINITY;
|
|
104
|
+
let largest = 0;
|
|
105
|
+
for (let i = 0; i < pa.data.length; i++)
|
|
106
|
+
largest = Math.max(largest, Math.abs(pa.data[i]! - pb.data[i]!));
|
|
107
|
+
return largest;
|
|
108
|
+
},
|
|
109
|
+
[a.toString('base64'), b.toString('base64')]
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
afterAll(async () => {
|
|
113
|
+
await browser?.close();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it.each(CASES.map((c, i) => [c.aspect, JSON.stringify(c.framing), i] as const))(
|
|
117
|
+
'draws %s at %s exactly as Studio previews it',
|
|
118
|
+
async (_aspect, _framing, i) => {
|
|
119
|
+
const item = page.locator('.case').nth(i);
|
|
120
|
+
const site = await item.locator('[data-part="frame"]').screenshot();
|
|
121
|
+
const studio = await item.locator('.ref').screenshot();
|
|
122
|
+
expect(await largestDifference(site, studio)).toBeLessThanOrEqual(8);
|
|
123
|
+
}
|
|
124
|
+
);
|
|
125
|
+
});
|
|
@@ -31,7 +31,7 @@ describe('article sample page', () => {
|
|
|
31
31
|
|
|
32
32
|
// Tag + landmark identity, in document order.
|
|
33
33
|
expect(headerEl!.tagName).toBe('HEADER');
|
|
34
|
-
expect(headerEl!.querySelector('
|
|
34
|
+
expect(headerEl!.querySelector('[data-eldra-header-focus]')).not.toBeNull();
|
|
35
35
|
expect(breadcrumbsEl!.tagName).toBe('DIV');
|
|
36
36
|
expect(breadcrumbsEl!.querySelector('nav[aria-label]')).not.toBeNull();
|
|
37
37
|
expect(articleEl!.querySelector('article')).not.toBeNull();
|
|
@@ -109,7 +109,7 @@ describe('collection sample page', () => {
|
|
|
109
109
|
const [navEl, breadcrumbsEl, headerEl, gridEl, ctaEl, footerEl] = children;
|
|
110
110
|
|
|
111
111
|
expect(navEl!.tagName).toBe('HEADER');
|
|
112
|
-
expect(navEl!.querySelector('
|
|
112
|
+
expect(navEl!.querySelector('[data-eldra-header-focus]')).not.toBeNull();
|
|
113
113
|
expect(breadcrumbsEl!.tagName).toBe('DIV');
|
|
114
114
|
expect(breadcrumbsEl!.querySelector('nav[aria-label]')).not.toBeNull();
|
|
115
115
|
expect(headerEl!.tagName).toBe('HEADER');
|