@eldrajs/theme-cli 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/package.json +3 -3
  2. package/template/.eldra/previews.json +35 -35
  3. package/template/app/plugins/chunk-reload.client.ts +29 -0
  4. package/template/app/plugins/eldra-storefront.ts +5 -0
  5. package/template/app/storefront/gateway.ts +34 -11
  6. package/template/app/storefront/sharedRead.ts +34 -0
  7. package/template/app/storefront/structuredData.ts +17 -0
  8. package/template/app/utils/chunkReload.ts +11 -0
  9. package/template/blocks/announcement-bar/preview.png +0 -0
  10. package/template/blocks/article/preview.png +0 -0
  11. package/template/blocks/article-list/preview.png +0 -0
  12. package/template/blocks/breadcrumbs/preview.png +0 -0
  13. package/template/blocks/cart/preview.png +0 -0
  14. package/template/blocks/collection-grid/Block.vue +146 -94
  15. package/template/blocks/collection-grid/__tests__/Block.spec.ts +116 -2
  16. package/template/blocks/collection-grid/preview.png +0 -0
  17. package/template/blocks/collection-header/preview.png +0 -0
  18. package/template/blocks/contact/preview.png +0 -0
  19. package/template/blocks/cta/preview.png +0 -0
  20. package/template/blocks/faq/preview.png +0 -0
  21. package/template/blocks/feature-grid/preview.png +0 -0
  22. package/template/blocks/footer/preview.png +0 -0
  23. package/template/blocks/form/preview.png +0 -0
  24. package/template/blocks/gallery/preview.png +0 -0
  25. package/template/blocks/hero/preview.png +0 -0
  26. package/template/blocks/image/preview.png +0 -0
  27. package/template/blocks/logo-cloud/preview.png +0 -0
  28. package/template/blocks/navigation/Block.vue +125 -541
  29. package/template/blocks/navigation/__tests__/Block.spec.ts +172 -73
  30. package/template/blocks/navigation/parts/MenuLink.vue +15 -0
  31. package/template/blocks/navigation/preview.png +0 -0
  32. package/template/blocks/newsletter/preview.png +0 -0
  33. package/template/blocks/order-status/preview.png +0 -0
  34. package/template/blocks/pricing-table/preview.png +0 -0
  35. package/template/blocks/product-carousel/preview.png +0 -0
  36. package/template/blocks/product-detail/preview.png +0 -0
  37. package/template/blocks/quote/preview.png +0 -0
  38. package/template/blocks/rich-text/preview.png +0 -0
  39. package/template/blocks/search/preview.png +0 -0
  40. package/template/blocks/split-content/preview.png +0 -0
  41. package/template/blocks/stats/preview.png +0 -0
  42. package/template/blocks/tabs/preview.png +0 -0
  43. package/template/blocks/team/preview.png +0 -0
  44. package/template/blocks/testimonials/preview.png +0 -0
  45. package/template/blocks/timeline/preview.png +0 -0
  46. package/template/blocks/trust-strip/preview.png +0 -0
  47. package/template/blocks/video-embed/preview.png +0 -0
  48. package/template/blocks/wishlist/preview.png +0 -0
  49. package/template/test/chunkReload.spec.ts +20 -0
  50. package/template/test/imageFraming.browser.spec.ts +125 -0
  51. package/template/test/pages/article.spec.ts +1 -1
  52. package/template/test/pages/collection.spec.ts +1 -1
  53. package/template/test/pages/home.spec.ts +1 -1
  54. package/template/test/pages/product.spec.ts +1 -1
  55. package/template/test/prerenderRefresh.browser.spec.ts +8 -13
  56. package/template/test/storefront/gateway.spec.ts +6 -0
  57. package/template/test/storefront/gatewayPrerender.spec.ts +26 -1
  58. package/template/test/storefront/sharedRead.spec.ts +43 -0
  59. package/template/test/storefront/structuredData.spec.ts +31 -0
  60. 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('nav ul li');
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
- // Exactly one `<nav>` — the bar's own row. The drawer's copy of the link list is a plain
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
- it('Enter/Space toggles the trigger; hover alone never opens it; opening one closes the other', async () => {
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
- await knitwear.trigger('mouseenter');
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
- await knitwear.trigger('mouseleave');
378
+ mouse(knitwear.element, 'pointerleave');
367
379
 
368
- await knitwear.trigger('keydown', { key: 'Enter' });
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('keydown', { key: ' ' });
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('keydown', { key: 'Enter' });
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
- await knitwear.trigger('mouseenter');
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
- // Crossing from the trigger into the panel keeps it open.
396
- await knitwear.trigger('mouseleave');
397
- await panel().trigger('mouseenter');
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 panel closes what hover opened.
403
- await panel().trigger('mouseleave');
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 Enter is not hover-owned: the pointer leaving does not close it.
409
- await knitwear.trigger('keydown', { key: 'Enter' });
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
- await knitwear.trigger('mouseenter');
412
- await knitwear.trigger('mouseleave');
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 nav');
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('keydown', { key: 'Enter' });
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
- await ceramics.trigger('mouseenter');
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
- await knitwear.trigger('mouseenter');
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
- await knitwear.trigger('mouseleave');
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 — a disclosure button (Knitwear has a mega-menu).
1049
- const firstRow = wrapper.get('dialog ul li:first-child button, dialog ul li:first-child a');
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 `<nav>` — rather than to the item that opened it, and its
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
- const nav = wrapper.get('nav');
1384
- // The positioning context: the panel's `left-0 right-0` only means "the header container"
1385
- // because this is the nearest positioned ancestor.
1386
- expect(nav.classes()).toContain('relative');
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('nav > ul > li')) {
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
- expect(panel.attributes('data-eldra-mega-panel')).toBe('');
1396
- for (const token of ['absolute', 'top-full', 'left-0', 'right-0']) {
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 hairline above the panel is the bar's own full-bleed bottom border, so the panel takes
1403
- // no top border of its own; the other three sides are the border token, the bottom corners
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(panel.classes()).toContain(token);
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
- for (const token of ['grid', 'grid-cols-12', 'gap-6', 'p-6', '@wide:p-8']) {
1419
- expect(panel.classes()).toContain(token);
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(panel.classes()).not.toContain('py-8');
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 that spans the panel's content width, 16px above it.
1452
- for (const token of ['justify-end', 'border-t', 'border-border', 'pt-4', 'col-span-12']) {
1453
- expect([...viewAll.element.parentElement!.classList]).toContain(token);
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 panel = wrapper.get(`#${knitwear.attributes('aria-controls')}`);
1476
- expect(panel.attributes('style')).toContain('background: var(--eldra-header-surface)');
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(panel.classes()).not.toContain('bg-background');
1587
+ expect(sheet.classes()).not.toContain('bg-background');
1479
1588
  wrapper.unmount();
1480
1589
  });
1481
1590
 
1482
- it('eases the panel in and out, with the rise dropped under reduced motion', async () => {
1483
- // A `<Transition>` applies its from/active classes in the same patch that opens or closes the
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
- for (const token of [
1508
- 'opacity-0',
1509
- 'motion-safe:-translate-y-1',
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 it can no longer be pointed at, so a pointer
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-[opacity,transform]',
1525
- 'duration-[120ms]',
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 nav = wrapper.get('nav[aria-label="Primary navigation"]');
1782
- expect(nav.classes()).toContain('gap-1');
1783
- expect(nav.classes().some((cls) => cls.includes('gap-4'))).toBe(false);
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 = wrapper.findAll('a, button').find((el) => el.text() === mock.ctaLabel)!;
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
Binary file
@@ -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
+ });