gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain4099e64aMerge branch 'font-segoe-ui' into mainAtlasmain/tests/e2e-menu-current.mjs

10.2 KB

  1. // usage: node tests/e2e-menu-current.mjs <base url> <shot prefix> [CDP port, default 9223]
  2. // mission 009 real-Chrome e2e (lisbeth's Chrome through CDP): ONE existing page tab (picked fresh from /json), real mouse clicks,
  3. // 390 (phone: sidebar + main menu) and 1280. The current marker moves with each page: aria-current, the bar, contrast >= 3:1 for every accent,
  4. // the count badge and current=true on the tracker demo. Leaves the tab at about:blank. Hold the lock: flock lisbeth.lock.
  5. import { writeFileSync } from 'node:fs';
  6. const [BASE, PREFIX, CDP = '9223'] = process.argv.slice(2);
  7. const SH = '/media/STORAGE/claude-scratch/atlas/D3/shots/';
  8. const tabs = await (await fetch(`http://127.0.0.1:${CDP}/json`)).json();
  9. const tab = tabs.find(t => t.type === 'page');
  10. if (!tab) throw new Error('no page tab');
  11. const ws = new WebSocket(tab.webSocketDebuggerUrl.replace(/ws:\/\/[^/]+/, `ws://127.0.0.1:${CDP}`));
  12. await new Promise(r => ws.onopen = r);
  13. let id = 0; const pend = new Map();
  14. ws.onmessage = (m) => { const d = JSON.parse(m.data); if (d.id && pend.has(d.id)) { pend.get(d.id)(d); pend.delete(d.id); } };
  15. const send = (method, params = {}) => new Promise((res, rej) => { const i = ++id; pend.set(i, (d) => d.error ? rej(new Error(method + ': ' + JSON.stringify(d.error))) : res(d.result)); ws.send(JSON.stringify({ id: i, method, params })); });
  16. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  17. const ev = async (e) => { const r = await send('Runtime.evaluate', { expression: e, returnByValue: true, awaitPromise: true }); if (r.exceptionDetails) throw new Error(JSON.stringify(r.exceptionDetails).slice(0, 300)); return r.result.value; };
  18. const shot = async (n) => { const { data } = await send('Page.captureScreenshot', { format: 'png' }); writeFileSync(SH + `e2e-${PREFIX}-${n}.png`, Buffer.from(data, 'base64')); };
  19. const results = [];
  20. const check = (l, ok, d = '') => { results.push(ok); console.log((ok ? 'ok ' : 'FAIL ') + l + (ok ? '' : ' — ' + d)); };
  21. const waitFor = async (e, ms = 15000) => { const t = Date.now(); while (Date.now() - t < ms) { try { if (await ev(e)) return true; } catch {} await sleep(150); } return false; };
  22. const open = async (p) => { await send('Page.navigate', { url: BASE + p }); await sleep(600); await waitFor('document.readyState === "complete" && !!document.querySelector("application-header")', 30000); await sleep(500); };
  23. const click = async (sel) => { await ev(`document.querySelector(${JSON.stringify(sel)}).scrollIntoView({ block: 'nearest' })`); await sleep(120); const b = await ev(`(() => { const r = document.querySelector(${JSON.stringify(sel)}).getBoundingClientRect(); return [r.left + r.width / 2, r.top + r.height / 2]; })()`); for (const type of ['mouseMoved', 'mousePressed', 'mouseReleased']) await send('Input.dispatchMouseEvent', { type, x: b[0], y: b[1], button: 'left', clickCount: 1, buttons: type === 'mousePressed' ? 1 : 0 }); await sleep(150); };
  24. const waitPath = (p) => waitFor(`location.pathname === ${JSON.stringify(p)}`, 15000);
  25. const size = (w) => send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 600 });
  26. const lum = (c) => { const v = c.map(x => { x /= 255; return x <= 0.03928 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4); }); return 0.2126 * v[0] + 0.7152 * v[1] + 0.0722 * v[2]; };
  27. const ratio = (a, b) => { const x = lum(a), y = lum(b); return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05); };
  28. const rgbOf = (s) => (String(s).match(/rgba?\(([^)]+)\)/) || [0, '0,0,0'])[1].split(',').slice(0, 3).map(Number);
  29. const marks = (root) => ev(`[...document.querySelectorAll(${JSON.stringify(root + ' a')})].filter(a => a.getAttribute('aria-current') === 'page').map(a => a.firstChild.textContent.trim())`);
  30. const J = JSON.stringify;
  31. const style = (sel) => ev(`(() => { const a = document.querySelector(${J(sel)}); if (!a) return null; const c = getComputedStyle(a); const r = a.getBoundingClientRect(); return { color: c.color, bg: c.backgroundColor, shadow: c.boxShadow, h: r.height }; })()`);
  32. // the marker: a bar (box-shadow) that is not none, bar >= 3:1 and text >= 3:1 against the link's own background (which is the surface)
  33. const barOk = (m) => !!m && m.shadow !== 'none' && ratio(rgbOf(m.shadow), rgbOf(m.bg)) >= 3 && ratio(rgbOf(m.color), rgbOf(m.bg)) >= 3;
  34. const barCr = (m) => m ? `bar ${ratio(rgbOf(m.shadow), rgbOf(m.bg)).toFixed(2)} text ${ratio(rgbOf(m.color), rgbOf(m.bg)).toFixed(2)}` : 'none';
  35. const accentTest = async (w, sel) => {
  36. const accents = ['blue-dark', 'green-dark', 'yellow', 'orange', 'red', 'purple', 'blue-light', 'green-light'];
  37. const seen = {};
  38. for (const a of accents) {
  39. await click(`accent-switcher button[value="${a}"]`);
  40. await sleep(200);
  41. const m = await style(sel);
  42. seen[a] = barCr(m);
  43. check(`${w} accent ${a}: the marked link has a bar and contrast >= 3:1 (${seen[a]})`, barOk(m), J(m));
  44. }
  45. await click('accent-switcher button.reset'); await sleep(150);
  46. };
  47. await send('Page.bringToFront');
  48. try {
  49. console.log('tab', tab.id, 'base', BASE);
  50. // ---------------- 1280 ----------------
  51. await size(1280);
  52. await open('/components');
  53. const H = 'application-header main-menu';
  54. check('1280 /components: only Components has aria-current="page"', J(await marks(H)) === '["Components"]', J(await marks(H)));
  55. const m0 = await style(H + ' a.current');
  56. check('1280 the visible bar: box-shadow set, contrast >= 3:1 (blue-dark ' + barCr(m0) + ')', barOk(m0), J(m0));
  57. await shot('1280-1-components');
  58. await click(H + ' a[href="/shells"]'); await waitPath('/shells'); await sleep(400);
  59. check('1280 mouse click Shells: marker moved to Shells (aria-current)', J(await marks(H)) === '["Shells"]', J(await marks(H)));
  60. check('1280 the old link no longer has the class current', (await ev(`document.querySelectorAll(${J(H + ' a.current')}).length`)) === 1);
  61. await shot('1280-2-shells');
  62. await click(H + ' a[href="/docs"]'); await waitPath('/docs'); await sleep(400);
  63. check('1280 click Docs: marker moved to Docs', J(await marks(H)) === '["Docs"]', J(await marks(H)));
  64. await click(H + ' a[href="/components"]'); await waitPath('/components'); await sleep(400);
  65. check('1280 click Components: marker back on Components', J(await marks(H)) === '["Components"]');
  66. await open('/components/pagination');
  67. check('1280 a page below Components: Components marked in the menu, Pagination in the sidebar', J(await marks(H)) === '["Components"]' && J(await marks('#sidebar nav:not(main-menu nav)')).includes('Pagination'), J([await marks(H), await marks('#sidebar')]));
  68. await shot('1280-3-pagination');
  69. await accentTest(1280, H + ' a.current');
  70. await open('/shells/content-first');
  71. check('1280 tracker demo: current = true on Series (no path match) → Series marked', J(await marks(H)) === '["Series"]', J(await marks(H)));
  72. const badge = await ev(`(() => { const a = document.querySelector(${J(H + ' a[href="/shells/content-first/show"]')}); const b = a && a.querySelector('span.count'); if (!b) return null; const c = getComputedStyle(b); return { label: a.firstChild.textContent.trim(), count: b.textContent, color: c.color, bg: c.backgroundColor }; })()`);
  73. check('1280 tracker demo: Shows carries the count badge 12, label plain, text >= 4.5:1', !!badge && badge.label === 'Shows' && badge.count === '12' && ratio(rgbOf(badge.color), rgbOf(badge.bg)) >= 4.5, J(badge));
  74. await shot('1280-4-tracker-badge');
  75. await click(H + ' a[href="/shells/content-first/movie"]'); await waitPath('/shells/content-first/movie'); await sleep(400);
  76. check('1280 click Movies in the tracker demo: marker moved from Series to Movies', J(await marks(H)) === '["Movies"]', J(await marks(H)));
  77. // ---------------- 390 ----------------
  78. await size(390);
  79. const S = '#sidebar main-menu';
  80. const openSide = async () => { await click('application-header .menu-toggle'); await waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, 8000); await sleep(300); };
  81. await open('/components');
  82. await openSide();
  83. check('390 sidebar menu: Components marked (aria-current)', J(await marks(S)) === '["Components"]', J(await marks(S)));
  84. const p0 = await style(S + ' a.current');
  85. check('390 the bar + contrast (blue-dark ' + barCr(p0) + ')', barOk(p0), J(p0));
  86. await shot('390-1-components');
  87. await click(S + ' a[href="/shells"]'); await waitPath('/shells'); await sleep(500);
  88. await openSide();
  89. check('390 tap Shells, reopen: marker moved to Shells', J(await marks(S)) === '["Shells"]', J(await marks(S)));
  90. await shot('390-2-shells');
  91. await click(S + ' a[href="/docs"]'); await waitPath('/docs'); await sleep(500);
  92. await openSide();
  93. check('390 tap Docs, reopen: marker moved to Docs', J(await marks(S)) === '["Docs"]', J(await marks(S)));
  94. await accentTest(390, S + ' a.current');
  95. await shot('390-3-docs-red-after-reset');
  96. await ev(`(() => { const s = document.querySelector('#sidebar'); if (s && s.matches(':popover-open')) s.hidePopover(); return location.pathname; })()`);
  97. await open('/shells/content-first');
  98. await openSide();
  99. check('390 tracker demo, phone menu: Series marked by current = true', J(await marks(S)) === '["Series"]', J(await marks(S)));
  100. const b2 = await ev(`(() => { const a = document.querySelector(${J(S + ' a[href="/shells/content-first/show"]')}); const b = a && a.querySelector('span.count'); if (!b) return null; const c = getComputedStyle(b); const r = a.getBoundingClientRect(); return { count: b.textContent, h: r.height, color: c.color, bg: c.backgroundColor }; })()`);
  101. check('390 tracker demo: the badge 12 in the phone menu, tap target >= 44, text >= 4.5:1', !!b2 && b2.count === '12' && b2.h >= 44 && ratio(rgbOf(b2.color), rgbOf(b2.bg)) >= 4.5, J(b2));
  102. await shot('390-4-tracker-badge');
  103. await click(S + ' a[href="/shells/content-first/movie"]'); await waitPath('/shells/content-first/movie'); await sleep(500);
  104. await openSide();
  105. check('390 tap Movies, reopen: marker on Movies', J(await marks(S)) === '["Movies"]', J(await marks(S)));
  106. await shot('390-5-tracker-movies');
  107. await ev(`(() => { const s = document.querySelector('#sidebar'); if (s && s.matches(':popover-open')) s.hidePopover(); return location.pathname; })()`);
  108. } catch (e) { console.log('ERROR', e.message); results.push(false); }
  109. console.log(PREFIX, results.filter(Boolean).length, 'ok', results.filter(x => !x).length, 'FAIL');
  110. try { await ev(`localStorage.removeItem('layouts-accent')`); await send('Emulation.clearDeviceMetricsOverride'); await send('Page.navigate', { url: 'about:blank' }); } catch {}
  111. ws.close();

Branches

Latest commits

  • 4099e64aMerge branch 'font-segoe-ui' into mainAtlas
  • e14fb795|||PR Theme font: Segoe UI first (his choice 2026-11-19)Atlas
  • 44071d2cMerge branch 'hl-standard-5' into mainAtlas
  • 5ea64202|||PR Gate: count the new-tab check's console errors tooAtlas
  • 2752ceddMerge branch 'hl-standard-4' into mainAtlas
  • ac552b81|||PR Gate: keyboard (Tab/Enter/Space) and Back/Forward/reload/new-tab checks (HL-STANDARD F5, F21)Atlas
  • 8cddcaa9Merge branch 'hl-standard-2' into mainAtlas
  • 2b480a64|||PR Type the route parameter of main-menu build (HL-STANDARD L10)Atlas
  • ab54a39dMerge branch 'hl-standard' into mainAtlas
  • 04d36fcf|||PR Type function parameters and drop unneeded let (HL-STANDARD L2, L10)Atlas
  • 220c8fa4Merge branch 'readme-audit' into mainAtlas
  • b78fb85a|||PR README matches the codemre
  • 9f351699Preserve comments and nest supported selectors without changing rendered outputmre
  • 97110ad9WIP: nest accepted layout selectors; stopped at startup parse failuremre
  • ce4a0baeKeep caller slot styles whole so minimal shell apps startmre
  • 12cd3992Re-vendor complete Hybriel plugins and runtime to day44mre
  • b05c20feBackup tar: --hard-dereference, so mpackdb sidecars are never stored as hard links (Tracker's finding)mre
  • 8d9ed0b8Re-vendor complete Hybriel plugins and runtime to day39mre
  • ebd00b6cNest caller slot styles in three-panemre
  • 009991efNest caller slot styles in list-firstmre