gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitf4ad7eecf4ad7eecsync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mref4ad7eec/tests/browser.mjs

64.9 KB

  1. // tests/browser.mjs — THE GATE of layouts.worldapi.org: its own server, real headless Chrome, real clicks.
  2. // node tests/browser.mjs (LAYOUTS_GATE_PORT server, default 8760; LAYOUTS_GATE_CHROME "8761-8764" = Chrome debug ports;
  3. // 8765/8766 are foreign on Loreana — never use them)
  4. // What it proves, at 390 and 1280 px: the three shells and their states (list-first item → detail → back; three-pane all three
  5. // on desktop, list → detail on the phone; the sidebar overlay and the search + user menu popovers open and close), the header
  6. // flush with the content column, no sideways scroll, the themed components without decorative frames, the accent switcher,
  7. // the theme gate helper, and no console errors. Screenshots land in .scratch/gate-*.png — LOOK at them.
  8. import { spawn, execFileSync } from 'node:child_process';
  9. import { writeFileSync, existsSync, mkdirSync, rmSync } from 'node:fs';
  10. import { dirname, join, resolve } from 'node:path';
  11. import { fileURLToPath } from 'node:url';
  12. import { launchBrowser } from './cdp.mjs';
  13. import { AUDIT } from './taps-audit.mjs';
  14. import { DISPLAY } from './display-audit.mjs';
  15. import { mdShowcase } from './md-showcase.mjs';
  16. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  17. const APP = resolve(dirname(fileURLToPath(import.meta.url)), '..');
  18. const PORT = Number(process.env.LAYOUTS_GATE_PORT || 8760);
  19. const [CH_FROM, CH_TO] = (process.env.LAYOUTS_GATE_CHROME || '8761-8764').split('-').map(Number);
  20. const BASE = `http://127.0.0.1:${PORT}`;
  21. const SCRATCH = join(APP, '.scratch');
  22. mkdirSync(SCRATCH, { recursive: true });
  23. for (const f of ['gate-shots']) rmSync(join(SCRATCH, f), { recursive: true, force: true });
  24. const SHOTS = join(SCRATCH, 'gate-shots');
  25. mkdirSync(SHOTS, { recursive: true });
  26. let failures = 0, passes = 0;
  27. function check(label, ok, detail = '') {
  28. console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`);
  29. if (ok) passes++; else failures++;
  30. }
  31. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  32. let log = '', server = null, browser = null;
  33. async function startServer() {
  34. server = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, env: { ...process.env, LAYOUTS_PORT: String(PORT), LAYOUTS_WATCH: '0' }, stdio: ['ignore', 'pipe', 'pipe'] });
  35. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  36. for (let i = 0; ; i++) {
  37. try { if ((await fetch(BASE + '/')).ok) break; } catch {}
  38. if (i > 1600) throw new Error('server did not come up\n' + log);
  39. await sleep(250);
  40. }
  41. }
  42. async function stop() {
  43. if (browser) { try { await browser.close(); } catch {} browser = null; }
  44. if (server) {
  45. try { server.kill('SIGTERM'); } catch {}
  46. await new Promise(r => { if (server.exitCode !== null || server.signalCode !== null) return r(); server.once('exit', r); setTimeout(r, 3000); });
  47. server = null;
  48. }
  49. }
  50. async function main() {
  51. // ---- the theme gate helper (no server needed) -----------------------------------------------------------------
  52. const helper = (args) => { try { return { code: 0, out: execFileSync('node', [join(APP, 'theme/check-theme.mjs'), ...args], { encoding: 'utf8' }) }; } catch (e) { return { code: e.status, out: String(e.stdout) }; } };
  53. const own = helper([APP]);
  54. check('check-theme on this app: 0 problems (exit 0)', own.code === 0 && /0 problems/.test(own.out), own.out.slice(-600));
  55. const fx = join(SCRATCH, 'gate-check-fixture');
  56. rmSync(fx, { recursive: true, force: true });
  57. mkdirSync(fx, { recursive: true });
  58. writeFileSync(join(fx, 'styles.hl'), [
  59. "a { color = '#ff0000' }",
  60. "'.card' { border = '1px solid ' + colorBorder }",
  61. "'.box' { background = 'white' }",
  62. "details { border = '1px solid ' + colorBorder }",
  63. "'.zone' { border = '2px dashed ' + colorBorder } // functional: a drop zone",
  64. "'.x' { color = 'var(--color-text, #c3c8cd)' border = '0' }",
  65. "'.r1' { padding = '0' borderRadius = '.4rem' }",
  66. "'.r2' { borderRadius = 'var(--layout-radius)' }",
  67. "'.r3' { borderRadius = radiusSmall borderTopLeftRadius = 'var(--radius-large, 10px)' }",
  68. "'.r4' { borderRadius = radiusLarge + ' ' + radiusLarge + ' 0 0' }",
  69. "'.r5' { borderRadius = '50%' } // an avatar",
  70. "'.r6' { borderRadius = radiusLarge + ' 3px' }",
  71. ].join('\n'));
  72. writeFileSync(join(fx, 'extra.css'), '.a { border-radius: var(--radius-small); }\n.b { border-top-left-radius: 4px; border-radius: 0 }\n');
  73. const bad = helper([fx]);
  74. check('check-theme flags a hard-coded #hex, a decorative border and a named colour', bad.code === 1 && /styles.hl:1: hard-coded colour/.test(bad.out) && /styles.hl:2: decorative border/.test(bad.out) && /styles.hl:3: named colour/.test(bad.out), bad.out);
  75. const radiusLines = bad.out.split('\n').filter(l => /corner radius/.test(l)).map(l => l.split(':').slice(0, 2).join(':')).sort().join(' ');
  76. check('check-theme flags every corner radius but radiusSmall / radiusLarge / 50% (hl and css; 7 problems in all)', bad.code === 1 && /7 problems/.test(bad.out) && radiusLines === 'extra.css:2 styles.hl:12 styles.hl:7 styles.hl:8', radiusLines + '\n' + bad.out);
  77. // ---- the server ---------------------------------------------------------------------------------------------------
  78. await startServer();
  79. const routes = ['/', '/elements', '/components', '/shells', '/docs', '/components/month-view', '/components/date-picker', '/components/range-picker', '/components/pagination', '/components/md-editor', '/components/code-editor', '/components/file-upload', '/components/modal', '/components/comments', '/components/files-upload', '/components/files-upload-pick', '/shells/content-first', '/shells/content-first/movie', '/shells/list-first', '/shells/list-first/trip', '/shells/three-pane', '/shells/three-pane/m2', '/search/modal'];
  80. const codes = await Promise.all(routes.map(async r => [r, (await fetch(BASE + r)).status]));
  81. check(`all ${routes.length} pages answer 200`, codes.every(([, c]) => c === 200), JSON.stringify(codes.filter(([, c]) => c !== 200)));
  82. // mission 007: no link of the app may leave it or land on a raw file (the Settings link once opened a .md file)
  83. const crawl = [];
  84. for (const r of [...routes, '/settings', '/read/using-the-theme', '/read/readme-modal', '/read/layouts-app-header', '/search/zzzz']) {
  85. const html = await (await fetch(BASE + r)).text();
  86. for (const m of html.matchAll(/<a [^>]*href="([^"]*)"/g)) crawl.push([r, m[1]]);
  87. }
  88. const rawLinks = crawl.filter(([, h]) => /\.md(#|$)/.test(h)).map(([r, h]) => r + ' -> ' + h);
  89. check(`no link of any page opens a raw .md file (${crawl.length} links crawled; docs and READMEs open in the app: /read/…)`, rawLinks.length === 0, [...new Set(rawLinks)].slice(0, 8).join('\n'));
  90. const internal = [...new Set(crawl.map(([, h]) => h.split('#')[0]).filter(h => h.startsWith('/') && !h.startsWith('//')))];
  91. const badLinks = [];
  92. for (const h of internal) { const res = await fetch(BASE + h); if (res.status !== 200 || !/text\/html/.test(res.headers.get('content-type') || '')) badLinks.push(h + ' ' + res.status + ' ' + res.headers.get('content-type')); }
  93. check(`all ${internal.length} distinct internal links answer 200 as HTML pages (no 404, no raw file)`, badLinks.length === 0, badLinks.slice(0, 8).join('\n'));
  94. const external = [...new Set(crawl.map(([, h]) => h).filter(h => /^(https?:)?\/\//.test(h)))];
  95. check('the only link that leaves the app is the sibling components.hybriel.worldapi.org', external.every(h => h === 'https://components.hybriel.worldapi.org/'), external.join(' '));
  96. const settings = await fetch(BASE + '/settings');
  97. const sHtml = await settings.text();
  98. check('the user menu\'s Settings is /settings, a page of the app (not a file)', /<a [^>]*href="\/settings"[^>]*>Settings<\/a>/.test(await (await fetch(BASE + '/')).text()) && settings.ok && /text\/html/.test(settings.headers.get('content-type')) && /application-header|applicationHeader/i.test(sHtml));
  99. const readme = await fetch(BASE + '/components/modal/README.md');
  100. check('a component README is served as Markdown', readme.ok && /markdown/.test(readme.headers.get('content-type')));
  101. const doc = await fetch(BASE + '/docs/layouts/list-first.md');
  102. check('a layout doc is served as Markdown', doc.ok && /markdown/.test(doc.headers.get('content-type')) && (await doc.text()).includes('# ListFirst'));
  103. const sr = await fetch(BASE + '/search?q=Date+Pick', { redirect: 'manual' });
  104. check('the header search GET /search?q= redirects to /search/<words>', sr.status === 302 && sr.headers.get('location') === '/search/date-pick', sr.status + ' ' + sr.headers.get('location'));
  105. const css = await (await fetch(BASE + '/__hl/app.css')).text();
  106. check('the stylesheet carries the theme: tokens (incl. the two radii), type slots and the html-prefixed component rules', /--color-accent:/.test(css) && /--color-type1:/.test(css) && /--layout-column:/.test(css) && css.includes('html pagination button{border:0;border-radius:var(--radius-small);min-width:var(--layout-tap);}') && /--radius-small:5px;--radius-large:10px;/.test(css) && css.includes('html md-editor{border:0'), css.slice(0, 300));
  107. check('the theme comes BEFORE the components\' own Style (cascade: theme rules win by the html prefix)', css.indexOf('html pagination button') < css.indexOf('pagination button{'), 'order');
  108. check('no style rule dropped at boot', !/style DROPPED/.test(log), log.split('\n').filter(l => /DROPPED/.test(l)).join('\n'));
  109. browser = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });
  110. const page = await browser.newPage();
  111. const ev = (e) => page.evaluate(e);
  112. const shot = async (name) => { const { data } = await page.send('Page.captureScreenshot', { format: 'png' }); writeFileSync(join(SHOTS, `gate-${name}.png`), Buffer.from(data, 'base64')); };
  113. const size = (w) => page.send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 600 });
  114. const open = async (path) => {
  115. await page.goto(BASE + path, { timeout: 45000 });
  116. await hydrated('hydrated ' + path);
  117. await sleep(300);
  118. };
  119. const shown = (sel) => ev(`(() => { const el = document.querySelector(${JSON.stringify(sel)}); if (!el) return false; const r = el.getBoundingClientRect(); return getComputedStyle(el).display !== 'none' && r.width > 0 && r.height > 0; })()`);
  120. const rect = (sel) => ev(`(() => { const el = document.querySelector(${JSON.stringify(sel)}); if (!el) return null; const r = el.getBoundingClientRect(); return { x: Math.round(r.left), r: Math.round(r.right), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height) }; })()`);
  121. const noSideways = async (label) => { const o = await ev('({ sw: document.documentElement.scrollWidth, w: window.innerWidth })'); check(`${label}: no sideways scroll`, o.sw <= o.w, JSON.stringify(o)); };
  122. // a link click may be a full page load (server-rendered HTML first): the next click waits for the page to be live, or it is lost
  123. const hydrated = (label = 'page hydrated') => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 30000, label });
  124. const waitPath = async (p) => { await page.waitFor(`location.pathname === ${JSON.stringify(p)}`, { timeout: 15000, label: 'path ' + p }); await hydrated('hydrated after ' + p); };
  125. const press = async (key) => {
  126. const vk = key === 'Escape' ? 27 : 13;
  127. await page.send('Input.dispatchKeyEvent', { type: 'keyDown', key, code: key, windowsVirtualKeyCode: vk });
  128. if (key === 'Enter') await page.send('Input.dispatchKeyEvent', { type: 'char', text: '\r' });
  129. await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key, code: key, windowsVirtualKeyCode: vk });
  130. };
  131. const popOpen = (sel) => ev(`document.querySelector(${JSON.stringify(sel)}).matches(':popover-open')`);
  132. // ================================== PHONE (390) ==================================
  133. await size(390);
  134. // content-first (the showcase site itself): content shown, sidebar hidden until the toggle
  135. await open('/elements');
  136. check('390 content-first: main shown, sidebar hidden, toggle shown', await shown('content-first > main') && !(await shown('#sidebar')) && await shown('application-header .menu-toggle'));
  137. check('390 header: main menu hidden, loupe + user icon shown', !(await shown('application-header main-menu')) && await shown('application-header .search-toggle') && await shown('user-menu .user-toggle'));
  138. await noSideways('390 /elements');
  139. await shot('390-content-first');
  140. await page.click('application-header .menu-toggle');
  141. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'sidebar opens' });
  142. await sleep(250);
  143. const sb = await rect('#sidebar');
  144. check('390 toggle opens the sidebar overlay from the left, over the page', sb && sb.x === 0 && sb.w > 250 && sb.w < 390 && sb.h >= 800, JSON.stringify(sb));
  145. check('390 the sidebar holds the main menu (the header has no room for it)', await shown('#sidebar main-menu') && (await ev(`document.querySelector('#sidebar main-menu a.current').textContent`)) === 'Elements');
  146. await shot('390-sidebar-open');
  147. await press('Escape');
  148. await page.waitFor(`!document.querySelector('#sidebar').matches(':popover-open')`, { label: 'Esc closes the sidebar' });
  149. check('390 Esc closes the sidebar', !(await shown('#sidebar')));
  150. await page.click('application-header .menu-toggle');
  151. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'sidebar opens again' });
  152. await page.click('#sidebar nav a[href="/components/pagination"]');
  153. await waitPath('/components/pagination');
  154. await page.waitFor(`!!document.querySelector('pagination')`, { label: 'pagination page' });
  155. await sleep(300);
  156. check('390 a link in the sidebar navigates and the overlay is closed after it', !(await popOpen('#sidebar')) && !(await shown('#sidebar')));
  157. // search: the loupe opens the field under the bar, focused; Enter searches
  158. await open('/');
  159. await page.click('application-header .search-toggle');
  160. await page.waitFor(`document.querySelector('#app-search').matches(':popover-open')`, { label: 'search opens' });
  161. await sleep(200);
  162. const sf = await rect('#app-search');
  163. check('390 loupe opens the search field full width under the header, focused', sf && sf.x === 0 && sf.w === 390 && sf.y >= 50 && (await ev(`document.activeElement === document.querySelector('#app-search input')`)), JSON.stringify(sf));
  164. await shot('390-search-open');
  165. await page.type('#app-search input', 'modal');
  166. await press('Enter');
  167. await waitPath('/search/modal');
  168. await page.waitForSelector('ul.pages a[href="/components/modal"]', { timeout: 15000 });
  169. check('390 the search lands on /search/modal and finds the Modal page', true);
  170. // user menu: the icon opens the dropdown; Esc closes it
  171. await open('/');
  172. await page.click('user-menu .user-toggle');
  173. await page.waitFor(`document.querySelector('#user-menu').matches(':popover-open')`, { label: 'user menu opens' });
  174. await sleep(200);
  175. const um = await rect('#user-menu');
  176. const items = await ev(`[...document.querySelectorAll('#user-menu a')].map(a => a.textContent)`);
  177. check('390 user icon opens the dropdown at the right edge, Settings then Logout last', um && um.r <= 390 && um.r >= 370 && items.join('|') === 'Settings|Logout', JSON.stringify({ um, items }));
  178. await shot('390-user-menu');
  179. await press('Escape');
  180. await page.waitFor(`!document.querySelector('#user-menu').matches(':popover-open')`, { label: 'Esc closes the user menu' });
  181. check('390 Esc closes the user menu', true);
  182. // list-first: the list first; an item replaces it; back returns
  183. await open('/shells/list-first');
  184. check('390 list-first /: the list shown, the welcome text never', await shown('list-first > aside') && !(await shown('list-first > main')));
  185. check('390 list-first: no sidebar toggle (no overlay in this shell)', !(await shown('application-header .menu-toggle')));
  186. await noSideways('390 list-first');
  187. await shot('390-list-first-list');
  188. await page.click('list-first > aside a[href="/shells/list-first/trip"]');
  189. await waitPath('/shells/list-first/trip');
  190. await page.waitFor(`document.querySelector('list-first').classList.contains('detail')`, { label: 'detail state' });
  191. await sleep(300);
  192. check('390 list-first item → only the note shows (list gone), with its long title', !(await shown('list-first > aside')) && await shown('list-first > main') && /Helsinki trip/.test(await ev(`document.querySelector('list-first > main h1').textContent`)));
  193. check('390 list-first detail: a back link to the list', await shown('list-first a.back'));
  194. await noSideways('390 list-first detail (long title)');
  195. await shot('390-list-first-detail');
  196. await page.click('list-first a.back');
  197. await waitPath('/shells/list-first');
  198. await page.waitFor(`document.querySelector('list-first').classList.contains('list')`, { label: 'back to the list' });
  199. check('390 back → the list again', await shown('list-first > aside'));
  200. // three-pane: list first; folders are the overlay; an item shows with its actions
  201. await open('/shells/three-pane');
  202. check('390 three-pane: the message list first, no message, folders hidden', await shown('three-pane > aside') && !(await shown('three-pane > main')) && !(await shown('#sidebar')));
  203. await page.click('application-header .menu-toggle');
  204. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'folders open' });
  205. await sleep(250);
  206. check('390 three-pane: the toggle slides the folders in', /Inbox/.test(await ev(`document.querySelector('#sidebar').textContent`)) && await shown('#sidebar'));
  207. await shot('390-three-pane-folders');
  208. await page.click('#sidebar .sidebar-close');
  209. await page.waitFor(`!document.querySelector('#sidebar').matches(':popover-open')`, { label: '× closes the folders' });
  210. check('390 three-pane: the × closes the folders', true);
  211. await page.click('three-pane > aside a[href="/shells/three-pane/m3"]');
  212. await waitPath('/shells/three-pane/m3');
  213. await page.waitFor(`document.querySelector('three-pane').classList.contains('detail')`, { label: 'mail detail' });
  214. await sleep(300);
  215. check('390 three-pane item → the message with its actions, the list gone', !(await shown('three-pane > aside')) && await shown('three-pane > main > menu') && /tracker#32/.test(await ev(`document.querySelector('three-pane > main h1').textContent`)));
  216. await noSideways('390 three-pane detail');
  217. await page.click('three-pane > main > menu button[value="Archived"]');
  218. await page.waitFor(`/Archived/.test(document.querySelector('three-pane > main output').textContent)`, { label: 'action answered' });
  219. check('390 three-pane: an action button answers (mock)', true);
  220. await shot('390-three-pane-detail');
  221. // content-first demo (signed out): the phone-only sidebar holds the main menu
  222. await open('/shells/content-first');
  223. check('390 tracker demo: signed out, a login where the user menu would be', await shown('application-header a.button.primary') && !(await ev(`!!document.querySelector('user-menu')`)));
  224. await page.click('application-header .menu-toggle');
  225. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'tracker sidebar' });
  226. await page.click('#sidebar main-menu a[href="/shells/content-first/movie"]');
  227. await waitPath('/shells/content-first/movie');
  228. await page.waitFor(`document.querySelector('main h1').textContent === 'Movie'`, { label: 'movies' });
  229. check('390 tracker demo: Movies from the sidebar menu → only movies, overlay closed', (await ev(`[...document.querySelectorAll('ul.titles .pill')].every(p => p.textContent === 'Movie')`)) && !(await popOpen('#sidebar')));
  230. await noSideways('390 tracker demo');
  231. await shot('390-tracker-demo');
  232. // every other page at 390: no sideways scroll
  233. for (const r of ['/components/month-view', '/components/date-picker', '/components/range-picker', '/components/md-editor', '/components/code-editor', '/components/file-upload', '/components/modal', '/components/comments', '/components/files-upload', '/components/files-upload-pick', '/components/pagination', '/docs']) {
  234. await open(r);
  235. await noSideways('390 ' + r);
  236. if (/comments|files-upload|pagination/.test(r)) await shot('390' + r.replace(/\//g, '-'));
  237. }
  238. // ================================== DESKTOP (1280) ==================================
  239. await size(1280);
  240. await open('/elements');
  241. check('1280 content-first: sidebar and main side by side, no toggle, no loupe', await shown('#sidebar') && await shown('content-first > main') && !(await shown('application-header .menu-toggle')) && !(await shown('application-header .search-toggle')));
  242. const [brand, um2, sideR, mainR, colR] = [await rect('application-header > a.brand'), await rect('user-menu .user-toggle svg'), await rect('#sidebar > nav a'), await rect('content-first > main'), await rect('content-first')];
  243. check('1280 header contents flush with the content column (brand text = sidebar text left, user icon right = column right)', Math.abs(brand.x - (sideR.x + 12)) <= 1 && Math.abs(um2.r - mainR.r) <= 1, JSON.stringify({ brand, um2, sideR, mainR, colR }));
  244. check('1280 the header shows the main menu with the page marked, and the search field', await shown('application-header main-menu') && (await ev(`document.querySelector('application-header main-menu a.current').textContent`)) === 'Elements' && await shown('#app-search input'));
  245. check('1280 the sidebar does not repeat the main menu', !(await shown('#sidebar main-menu')));
  246. await shot('1280-content-first');
  247. // themed plain elements: borderless except the foldable and the drop zone
  248. const b = await ev(`(() => { const s = (q, p) => getComputedStyle(document.querySelector(q))[p]; return {
  249. button: s('elements-page button.primary', 'borderTopStyle'), input: s('#el-title', 'borderTopStyle'),
  250. details: s('elements-page details', 'borderTopStyle'), drop: s('drop-zone', 'borderTopStyle'),
  251. td: s('elements-page td', 'borderTopStyle'), h1: s('elements-page h1', 'color'), strong: s('elements-page strong', 'color') }; })()`);
  252. check('1280 elements: buttons, fields, table cells have no border; the foldable solid, the drop zone dashed', b.button === 'none' && b.input === 'none' && b.td === 'none' && b.details === 'solid' && b.drop === 'dashed', JSON.stringify(b));
  253. check('1280 elements: titles white (text-strong)', b.h1 === 'rgb(245, 250, 255)' && b.strong === 'rgb(245, 250, 255)', JSON.stringify(b));
  254. await page.click('elements-page details:nth-of-type(2) summary');
  255. check('1280 elements: a foldable opens on its summary', await ev(`document.querySelectorAll('elements-page details')[1].open`));
  256. // the accent switcher: a palette colour becomes --color-accent, survives a reload, Reset returns the default
  257. const accentOf = () => ev(`getComputedStyle(document.querySelector('application-header main-menu a.current')).color`);
  258. const before = await accentOf();
  259. await page.click('accent-switcher button[value="purple"]');
  260. await sleep(200);
  261. check('1280 accent switcher: purple → the marked menu link is purple', (await accentOf()) === 'rgb(197, 134, 192)', await accentOf());
  262. await open('/shells');
  263. check('1280 accent switcher: the accent stays on the next page (localStorage)', (await accentOf()) === 'rgb(197, 134, 192)', await accentOf());
  264. await shot('1280-accent-purple');
  265. await page.click('accent-switcher button.reset');
  266. await sleep(200);
  267. check('1280 accent switcher: Reset → the theme default again', (await accentOf()) === before, `${await accentOf()} vs ${before}`);
  268. // themed components: no decorative frames left, functional ones kept
  269. await open('/components/pagination');
  270. check('1280 pagination: no frames, the current page is the accent', (await ev(`getComputedStyle(document.querySelector('pagination li.current button')).borderTopStyle`)) === 'none' && (await ev(`getComputedStyle(document.querySelector('pagination li:not(.current) button')).borderTopStyle`)) === 'none');
  271. await page.click('pagination li:nth-child(3) button');
  272. await page.waitFor(`document.querySelector('pagination li.current button').textContent === '3'`, { label: 'page 3' });
  273. check('1280 pagination still works themed (page 3)', true);
  274. await open('/components/md-editor');
  275. check('1280 md-editor: no outer frame, no line under the toolbar', (await ev(`getComputedStyle(document.querySelector('md-editor')).borderTopStyle`)) === 'none' && (await ev(`getComputedStyle(document.querySelector('md-editor nav')).borderBottomStyle`)) === 'none');
  276. await shot('1280-md-editor');
  277. await open('/components/code-editor');
  278. check('1280 code-editor: no frame, no gutter line', (await ev(`getComputedStyle(document.querySelector('code-editor')).borderTopStyle`)) === 'none' && (await ev(`getComputedStyle(document.querySelector('code-editor code-gutter')).borderRightStyle`)) === 'none');
  279. await open('/components/month-view');
  280. check('1280 month-view: day cells without grid lines, today still marked', (await ev(`getComputedStyle(document.querySelector('#month-days li')).borderTopStyle`)) === 'none' && (await ev(`document.querySelectorAll('#month-days li.today').length`)) === 1);
  281. await shot('1280-month-view');
  282. await open('/components/date-picker');
  283. await page.click('date-picker input');
  284. await page.waitFor(`getComputedStyle(document.querySelector('date-picker picker-popup')).display !== 'none'`, { label: 'date popup' });
  285. await sleep(300);
  286. check('1280 date-picker: borderless field, the popup a raised surface without frame', (await ev(`getComputedStyle(document.querySelector('date-picker input')).borderTopStyle`)) === 'none' && (await ev(`getComputedStyle(document.querySelector('date-picker month-view')).borderTopStyle`)) === 'none');
  287. await shot('1280-date-picker-open');
  288. await open('/components/file-upload');
  289. check('1280 file-upload: the drop zone keeps its dashed border, the choose button has none', (await ev(`getComputedStyle(document.querySelector('file-upload drop-zone')).borderTopStyle`)) === 'dashed' && (await ev(`getComputedStyle(document.querySelector('file-upload label.choose')).borderTopStyle`)) === 'none');
  290. await open('/components/modal');
  291. await page.click('#open-confirm');
  292. await page.waitFor(`document.querySelector('#confirm').open`, { label: 'modal open' });
  293. await sleep(300);
  294. check('1280 modal: the window has no frame, no line under the title', (await ev(`getComputedStyle(document.querySelector('#confirm')).borderTopStyle`)) === 'none' && (await ev(`getComputedStyle(document.querySelector('#confirm header')).borderBottomStyle`)) === 'none');
  295. await shot('1280-modal-open');
  296. await page.click('#confirm footer button[value="delete"]');
  297. await page.waitFor(`document.querySelector('#modal-last').textContent === 'confirm: delete'`, { label: 'modal closed' });
  298. check('1280 modal still reports how it closed (confirm: delete)', true);
  299. // ---- mission 005: pagination tells the page (onPage), md-editor readonly, the two new components: comments, files-upload ----------
  300. const key = async (k, code, vk, text, modifiers = 0) => { await page.send('Input.dispatchKeyEvent', { type: 'keyDown', key: k, code, windowsVirtualKeyCode: vk, text, modifiers }); await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key: k, code, windowsVirtualKeyCode: vk, modifiers }); await sleep(15); };
  301. const typeText = async (t) => { for (const ch of t) await key(ch, '', undefined, ch); };
  302. await open('/components/pagination');
  303. check('1280 pagination: before any click the page says "none yet"', (await ev(`document.querySelector('#pagination-heard').textContent`)) === 'none yet');
  304. await page.click('pagination li:nth-child(4) button');
  305. check('1280 pagination: a click on 4 tells the page "page 4" (onPage)', (await ev(`document.querySelector('#pagination-heard').textContent`)) === 'page 4', await ev(`document.querySelector('#pagination-heard').textContent`));
  306. await page.click('pagination li:last-child button');
  307. await sleep(400);
  308. check('1280 pagination: Next tells the page the page after it', /^page [0-9]+$/.test(await ev(`document.querySelector('#pagination-heard').textContent`)) && (await ev(`document.querySelector('#pagination-heard').textContent`)) !== 'page 4', await ev(`document.querySelector('#pagination-heard').textContent`));
  309. await shot('1280-pagination');
  310. await open('/components/md-editor');
  311. const ro = await ev(`(() => { const ed = [...document.querySelectorAll('md-editor')].find(m => m.querySelector('input[name=shown]')); if (!ed) return null; const a = ed.querySelector('article'); return { toolbar: getComputedStyle(ed.querySelector('nav')).display !== 'none', editable: a.isContentEditable, strong: !!a.querySelector('strong'), li: a.querySelectorAll('li').length, h1: !!a.querySelector('h1') }; })()`);
  312. check('1280 md-editor readonly: the Markdown shown formatted (h1, bold, list), not editable, no toolbar', ro && ro.h1 && ro.strong && ro.li === 2 && !ro.editable && !ro.toolbar, JSON.stringify(ro));
  313. await ev(`[...document.querySelectorAll('md-editor')].find(m => m.querySelector('input[name=shown]')).scrollIntoView()`);
  314. await shot('1280-md-editor-readonly');
  315. // ---- mission 010: real keys on the showcase md-editor page (a table typed after a list is a table), 390 and 1280 ----
  316. for (const w of [390, 1280]) {
  317. await size(w); await open('/components/md-editor');
  318. await mdShowcase(page, { check, sleep, label: String(w), shot: (n) => shot(`${w}-${n}`) });
  319. }
  320. await size(1280);
  321. // ---- comments ----
  322. await open('/components/comments');
  323. const R = (id) => `document.querySelector('comments-block li.comment[data-id="${id}"]')`;
  324. const art = (id) => ev(`(${R(id)}.querySelector('md-editor article') || {}).innerHTML`);
  325. const ids = () => ev(`[...document.querySelectorAll('comments-block li.comment')].map(li => li.dataset.id).join(',')`);
  326. const count = () => ev(`document.querySelector('comments-block .comments-count').textContent`);
  327. const told = () => ev(`document.querySelector('#comments-told').textContent`);
  328. const btns = (id) => ev(`[...${R(id)}.querySelectorAll('comment-actions button')].map(b => b.textContent).join('|')`);
  329. await page.waitFor(`!!${R('c1')}.querySelector('md-editor article ul')`, { label: 'comment Markdown drawn' }).catch(() => {});
  330. check('1280 comments: "3 comments", the three comments, the texts drawn as formatted Markdown (bold, code, link, list)', (await count()) === '3 comments' && (await ids()) === 'c1,c2,c3' && /<strong>Markdown<\/strong>/.test(await art('c1')) && /<code>code<\/code>/.test(await art('c1')) && /<ul><li>one<\/li><li>two<\/li><\/ul>/.test(await art('c1')), (await count()) + ' ' + (await art('c1')));
  331. check('1280 comments: a shown text is not editable and has no toolbar', await ev(`!${R('c1')}.querySelector('md-editor article').isContentEditable && getComputedStyle(${R('c1')}.querySelector('md-editor nav')).display === 'none'`));
  332. check('1280 comments: as alice, Edit / Delete only on alice\'s comments (c1, c3), the like on every one', (await btns('c1')) === '♡ 2|Edit|Delete' && (await btns('c2')) === '♥ 1' && (await btns('c3')) === '♡ 0|Edit|Delete', [await btns('c1'), await btns('c2'), await btns('c3')].join(' / '));
  333. check('1280 comments: avatar initial, name, time, "edited" only on the edited one', await ev(`(() => { const li = ${R('c2')}; return li.querySelector('comment-avatar').textContent === 'B' && li.querySelector('.comment-author').textContent === 'bob' && li.querySelector('time').textContent === 'Oct 17, 10:40' && !!li.querySelector('details.comment-history') && !${R('c3')}.querySelector('details.comment-history'); })()`));
  334. await shot('1280-comments');
  335. await page.click('comments-block li.comment[data-id="c1"] .comment-like');
  336. await page.waitFor(`${R('c1')}.querySelector('.comment-like').textContent === '♥ 3' && document.querySelector('#comments-told').textContent === 'like c1'`, { label: 'liked' }).catch(() => {});
  337. check('1280 comments: a click on the like → ♥ 3, pressed, the page told "like c1"', (await ev(`${R('c1')}.querySelector('.comment-like').textContent`)) === '♥ 3' && (await ev(`${R('c1')}.querySelector('.comment-like').getAttribute('aria-pressed')`)) === 'true' && (await told()) === 'like c1', await told());
  338. await page.click('comments-block form.comment-form md-editor article');
  339. await typeText('Hello **world** by keys');
  340. await sleep(200);
  341. check('1280 comments: typing in the form formats (**world** → bold) as in the editor', /<strong>world<\/strong>/.test(await ev(`document.querySelector('comments-block form.comment-form article').innerHTML`)));
  342. await key('Enter', 'Enter', 13, '\r', 2);
  343. await page.waitFor(`document.querySelectorAll('comments-block li.comment').length === 4 && !!${R('n1')}.querySelector('md-editor article p')`, { label: 'posted by Ctrl+Enter' }).catch(() => {});
  344. check('1280 comments: Ctrl+Enter posts — "4 comments", the new one last by alice, formatted, the form empty again, page told "post"', (await ids()) === 'c1,c2,c3,n1' && (await count()) === '4 comments' && /Hello <strong>world<\/strong> by keys/.test(await art('n1')) && (await told()) === 'post' && (await ev(`document.querySelector('comments-block form.comment-form article').textContent`)) === '', (await ids()) + ' ' + (await count()) + ' ' + (await told()));
  345. await page.click('comments-block li.comment[data-id="n1"] .comment-edit-start');
  346. await page.waitFor(`!!${R('n1')}.querySelector('form.comment-edit article p')`, { label: 'edit form' }).catch(() => {});
  347. await page.click('comments-block li.comment[data-id="n1"] form.comment-edit article');
  348. await key('End', 'End', 35, undefined, 2);
  349. await typeText(' and more');
  350. await page.click('comments-block li.comment[data-id="n1"] .comment-save');
  351. await page.waitFor(`!!${R('n1')}.querySelector('details.comment-history') && /by keys and more/.test((${R('n1')}.querySelector('md-editor article') || {}).innerHTML || '')`, { label: 'edited' }).catch(() => {});
  352. check('1280 comments: Edit, type, Save → the text changed, "edited" appears, the page told "edit n1"', /by keys and more/.test(await art('n1') || '') && (await told()) === 'edit n1' && (await ev(`!!${R('n1')}.querySelector('details.comment-history')`)), (await art('n1')) + ' ' + (await told()));
  353. await page.click('comments-block li.comment[data-id="n1"] .comment-delete');
  354. await page.waitFor(`!!${R('n1')}.querySelector('.comment-delete-yes')`, { label: 'asks' }).catch(() => {});
  355. check('1280 comments: Delete asks first ("Delete this comment?") and nothing is gone yet', (await ids()) === 'c1,c2,c3,n1' && /Delete this comment\?/.test(await ev(`${R('n1')}.querySelector('comment-ask').textContent`)));
  356. await page.click('comments-block li.comment[data-id="n1"] .comment-delete-yes');
  357. await page.waitFor(`!${R('n1')}`, { label: 'deleted' }).catch(() => {});
  358. check('1280 comments: Delete again removes it — "3 comments", the page told "delete n1"', (await ids()) === 'c1,c2,c3' && (await count()) === '3 comments' && (await told()) === 'delete n1', (await ids()) + ' ' + (await told()));
  359. await page.click('#as-bob');
  360. await page.waitFor(`document.querySelector('#comments-me').textContent === 'bob' && ${R('c2')}.querySelector('.comment-edit-start')`, { label: 'bob' }).catch(() => {});
  361. check('1280 comments: as bob, Edit / Delete only on bob\'s c2 (alice\'s c1 liked by alice stays ♥ 3)', (await btns('c1')) === '♥ 3' && (await btns('c2')) === '♥ 1|Edit|Delete' && (await btns('c3')) === '♡ 0', [await btns('c1'), await btns('c2'), await btns('c3')].join(' / '));
  362. await page.click('#as-nobody');
  363. await page.waitFor(`document.querySelector('#comments-me').textContent === ''`, { label: 'nobody' }).catch(() => {});
  364. await sleep(300);
  365. check('1280 comments: as nobody, no form, no Edit / Delete, the sign-in text instead', !(await ev(`!!document.querySelector('comments-block form.comment-form')`)) && (await ev(`document.querySelectorAll('comments-block .comment-edit-start, comments-block .comment-delete').length`)) === 0 && /Choose a user above/.test(await ev(`document.querySelector('comments-block .comments-sign-in').textContent`)));
  366. await page.click('#as-alice');
  367. await page.waitFor(`!!document.querySelector('comments-block form.comment-form')`, { label: 'alice again' }).catch(() => {});
  368. await ev('scrollTo(0, 0)');
  369. // the look: the bubble is a surface without a frame, the avatar round, the post button not framed
  370. const look = await ev(`(() => { const s = (q, p) => getComputedStyle(document.querySelector(q))[p]; return { bubble: s('comments-block comment-bubble', 'borderTopStyle'), avatar: s('comments-block comment-avatar', 'borderTopLeftRadius'), post: s('comments-block button.comment-post', 'borderTopStyle'), details: s('comments-block details.comment-history', 'borderTopStyle') }; })()`);
  371. check('1280 comments: the bubble and the Comment button have no frame, the avatar is round (50%)', look.bubble === 'none' && look.post === 'none' && look.avatar === '50%', JSON.stringify(look));
  372. // ---- files-upload ----
  373. const UP = join(SCRATCH, 'up');
  374. mkdirSync(UP, { recursive: true });
  375. writeFileSync(join(UP, 'a.txt'), 'hello a');
  376. writeFileSync(join(UP, 'b.txt'), 'hello b, a bit longer');
  377. writeFileSync(join(UP, 'c.bin'), Buffer.alloc(1536 * 1024, 7));
  378. await open('/components/files-upload', '/components/files-upload-pick');
  379. const rows = () => ev(`[...document.querySelectorAll('files-upload ul.files li')].map(li => [li.querySelector('.name').textContent, li.querySelector('.state').textContent].join('|'))`);
  380. const summary = () => ev(`(document.querySelector('files-upload output.summary') || {}).textContent`);
  381. check('1280 files-upload: the drop zone keeps its dashed border, the choose button has none, the input takes several', (await ev(`getComputedStyle(document.querySelector('files-upload drop-zone')).borderTopStyle`)) === 'dashed' && (await ev(`getComputedStyle(document.querySelector('files-upload label.choose')).borderTopStyle`)) === 'none' && (await ev(`document.querySelector('files-upload input[type=file]').multiple`)));
  382. await shot('1280-files-upload');
  383. const zone = await page.box('files-upload drop-zone');
  384. const dropData = { items: [], files: [join(UP, 'a.txt'), join(UP, 'b.txt'), join(UP, 'c.bin')], dragOperationsMask: 1 };
  385. for (const type of ['dragEnter', 'dragOver', 'drop']) await page.send('Input.dispatchDragEvent', { type, x: Math.round(zone.x), y: Math.round(zone.y), data: dropData });
  386. await page.waitFor(`document.querySelectorAll('files-upload li.done').length === 3`, { timeout: 60000, label: 'three uploaded' }).catch(() => {});
  387. const r1 = await rows();
  388. check('1280 files-upload: a real drop of three files → three rows in drop order, all Uploaded, "3 of 3 uploaded"', r1.join(',') === 'a.txt|Uploaded,b.txt|Uploaded,c.bin|Uploaded' && /3 of 3/.test(await summary()), r1.join(',') + ' / ' + await summary());
  389. const { root } = await page.send('DOM.getDocument');
  390. const { nodeId } = await page.send('DOM.querySelector', { nodeId: root.nodeId, selector: 'files-upload input[type=file]' });
  391. await page.send('DOM.setFileInputFiles', { files: [join(UP, 'a.txt'), join(UP, 'b.txt')], nodeId });
  392. await page.waitFor(`document.querySelectorAll('files-upload li.done').length === 5`, { timeout: 30000, label: 'five uploaded' }).catch(() => {});
  393. check('1280 files-upload: choosing two more files adds two rows → "5 of 5 uploaded"', (await ev(`document.querySelectorAll('files-upload ul.files li').length`)) === 5 && /5 of 5/.test(await summary()), await summary());
  394. await ev('scrollTo(0, 0)');
  395. await shot('1280-files-upload-done');
  396. // ---- mission 008: components 1442e58 — pick mode, comments with attachments, md-editor rows / files="off" / md-empty ----------
  397. const PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==';
  398. writeFileSync(join(UP, 'pic.png'), Buffer.from(PNG, 'base64'));
  399. writeFileSync(join(UP, 'doc.pdf'), '%PDF-1.4 test');
  400. writeFileSync(join(UP, 'big.bin'), Buffer.alloc(2200 * 1024, 1));
  401. const fileInput = async (sel, files) => {
  402. const { root: rt } = await page.send('DOM.getDocument');
  403. const { nodeId: nid } = await page.send('DOM.querySelector', { nodeId: rt.nodeId, selector: sel });
  404. await page.send('DOM.setFileInputFiles', { files, nodeId: nid });
  405. };
  406. // a real paste event carrying a file (never the system clipboard): the target is the focused text field
  407. const pasteFile = (sel, name, type) => ev(`(() => { const dt = new DataTransfer(); const b = Uint8Array.from(atob(${JSON.stringify(PNG)}), c => c.charCodeAt(0)); dt.items.add(new File([b], ${JSON.stringify(name)}, { type: ${JSON.stringify(type)} })); const t = document.querySelector(${JSON.stringify(sel)}); t.focus(); t.dispatchEvent(new ClipboardEvent('paste', { clipboardData: dt, bubbles: true, cancelable: true })); return true; })()`);
  408. for (const w of [1280, 390]) {
  409. await size(w);
  410. await open('/components/files-upload-pick');
  411. const pk = () => ev(`[...document.querySelectorAll('files-upload li.picked, files-upload li.refused')].map(li => (li.className.includes('refused') ? '!' : '') + li.querySelector('.name').textContent).join(',')`);
  412. check(w + ' pick: the page has a pick area, the chat form inside it, no upload rows, no files yet', await ev(`!!document.querySelector('files-upload pick-area form#chat-form') && document.querySelectorAll('files-upload li').length === 0`));
  413. await shot('pick-' + w + '-before');
  414. await fileInput('files-upload input[type=file]', [join(UP, 'pic.png'), join(UP, 'doc.pdf')]);
  415. await page.waitFor(`document.querySelectorAll('files-upload li.picked').length === 2`, { label: 'picked 2' }).catch(() => {});
  416. check(w + ' pick: choosing a picture and a pdf → two rows in order, the picture as a thumbnail (img.thumb), the pdf with its kind', (await pk()) === 'pic.png,doc.pdf' && await ev(`!!document.querySelector('files-upload li.picked img.thumb') && /PDF/i.test(document.querySelectorAll('files-upload li.picked')[1].querySelector('.kind').textContent)`), await pk());
  417. await page.click('#chat-text');
  418. await pasteFile('#chat-text', 'pasted.png', 'image/png');
  419. await page.waitFor(`document.querySelectorAll('files-upload li.picked').length === 3`, { label: 'paste' }).catch(() => {});
  420. check(w + ' pick: a paste of a file into the text field collects it (3 rows, the pasted one last), the text stays in the field', (await pk()) === 'pic.png,doc.pdf,pasted.png' && await ev(`document.querySelector('#chat-text').value === ''`), await pk());
  421. await fileInput('files-upload input[type=file]', [join(UP, 'big.bin')]);
  422. await page.waitFor(`document.querySelectorAll('files-upload li.refused').length === 1`, { label: 'refused' }).catch(() => {});
  423. check(w + ' pick: a file over maxSize (2 MB) gets a refused row "Too big", the three others stay', /Too big/.test(await ev(`(document.querySelector('files-upload li.refused .state') || {}).textContent || ''`)) && (await ev(`document.querySelectorAll('files-upload li.picked').length`)) === 3, await pk());
  424. await page.click('files-upload li.refused button.remove');
  425. await page.waitFor(`document.querySelectorAll('files-upload li.refused').length === 0`, { label: 'refused gone' }).catch(() => {});
  426. await page.click('files-upload li.picked[data-i="1"] button.remove');
  427. await page.waitFor(`document.querySelectorAll('files-upload li.picked').length === 2`, { label: 'removed' }).catch(() => {});
  428. check(w + ' pick: ✕ on the refused row and on doc.pdf take them away → pic.png, pasted.png (the page\'s list follows)', (await pk()) === 'pic.png,pasted.png', await pk());
  429. await shot('pick-' + w + '-picked');
  430. const rm = await ev(`(() => { const r = document.querySelector('files-upload li.picked button.remove').getBoundingClientRect(); return [r.width, r.height]; })()`);
  431. check(w + ' pick: the ✕ is at least 44 × 44', rm[0] >= 44 && rm[1] >= 44, rm.join('x'));
  432. await page.click('#chat-text');
  433. await typeText('Two files');
  434. await page.click('#chat-send');
  435. await page.waitFor(`document.querySelectorAll('#sent li').length === 1`, { label: 'sent' }).catch(() => {});
  436. check(w + ' pick: Send shows "Two files" with "2 files: pic.png, pasted.png", empties the list and the field', (await ev(`document.querySelector('#sent .sent-text').textContent`)) === 'Two files' && (await ev(`document.querySelector('#sent .sent-files').textContent`)) === '2 files: pic.png, pasted.png' && (await pk()) === '' && (await ev(`document.querySelector('#chat-text').value`)) === '', await ev(`document.querySelector('#sent').textContent`));
  437. await shot('pick-' + w + '-sent');
  438. await noSideways(w + ' /components/files-upload-pick (used)');
  439. // comments with attachments
  440. await open('/components/comments');
  441. check(w + ' comments attach: the form sits inside a pick area with a "Choose files" input; the editor has no File button', await ev(`!!document.querySelector('comments-block files-upload pick-area drop-zone label.choose input[type=file]') && !!document.querySelector('comments-block files-upload pick-area form.comment-form') && getComputedStyle(document.querySelector('comments-block form.comment-form md-editor button.file')).display === 'none'`));
  442. check(w + ' comments attach: the existing comment c3 shows its file as a plain row (no link)', (await ev(`(document.querySelector('comments-block li.comment[data-id="c3"] .comment-file') || {}).textContent || ''`)).includes('notes-from-the-meeting.pdf') && await ev(`document.querySelector('comments-block li.comment[data-id="c3"] .comment-file').tagName === 'SPAN'`));
  443. await shot('comments-' + w + '-before');
  444. await fileInput('comments-block files-upload label.choose input[type=file]', [join(UP, 'pic.png'), join(UP, 'doc.pdf')]);
  445. await page.waitFor(`document.querySelectorAll('comments-block li.picked').length === 2`, { label: 'comment files' }).catch(() => {});
  446. await pasteFile('comments-block form.comment-form md-editor article', 'shot.png', 'image/png');
  447. await page.waitFor(`document.querySelectorAll('comments-block li.picked').length === 3`, { label: 'comment paste' }).catch(() => {});
  448. check(w + ' comments attach: two chosen + one pasted into the editor (files="off": the FilesUpload takes it) → 3 waiting', (await ev(`document.querySelectorAll('comments-block li.picked').length`)) === 3 && (await ev(`document.querySelector('comments-block form.comment-form article').textContent`)) === '');
  449. await page.click('comments-block form.comment-form md-editor article');
  450. await typeText('with files');
  451. await shot('comments-' + w + '-attached');
  452. await key('Enter', 'Enter', 13, '\r', 2);
  453. await page.waitFor(`document.querySelectorAll('comments-block li.comment').length === 4 && document.querySelector('#comments-told').textContent === 'post with 3 files'`, { label: 'posted with files' }).catch(() => {});
  454. check(w + ' comments attach: Ctrl+Enter posts → 4 comments, told "post with 3 files", the new one lists pic.png, doc.pdf, shot.png as rows, the waiting files are cleared', (await told()) === 'post with 3 files' && (await ev(`[...document.querySelectorAll('comments-block li.comment[data-id="n1"] .comment-file')].map(e => e.textContent.replace(/\\s+/g, ' ').trim()).join('|')`)).split('|').length === 3 && (await ev(`document.querySelectorAll('comments-block li.picked').length`)) === 0, await told());
  455. await shot('comments-' + w + '-posted');
  456. await noSideways(w + ' /components/comments (with files)');
  457. // md-editor: rows, files="off", md-empty
  458. await open('/components/md-editor');
  459. const me = await ev(`(() => { const ed = [...document.querySelectorAll('md-editor')].find(e => e.querySelector('[name=line]') || e.getAttribute('name') === 'line' || /One line/.test(e.innerHTML)); if (!ed) return null; const s = ed.querySelector('article'); return { h: s.getBoundingClientRect().height, file: getComputedStyle(ed.querySelector('button.file')).display !== 'none', empty: ed.classList.contains('md-empty'), old: ed.classList.contains('empty'), min: getComputedStyle(s).minHeight, fs: parseFloat(getComputedStyle(s).fontSize) }; })()`);
  460. check(w + ' md-editor rows=1: the surface is one line high (min-height 24px, < 3 lines), no File button, empty state is the class md-empty (not "empty")', !!me && me.h < me.fs * 3 && me.min === '24px' && !me.file && me.empty && !me.old, JSON.stringify(me));
  461. const first = await ev(`(() => { const ed = document.querySelector('md-editor'); return { file: getComputedStyle(ed.querySelector('button.file')).display !== 'none', h: ed.querySelector('article').getBoundingClientRect().height }; })()`);
  462. check(w + ' md-editor default: the File button is there and the surface keeps its six-row height (≥ 6 lines)', first.file && first.h >= 6 * 16 * 1.4, JSON.stringify(first));
  463. await page.click('md-editor[name="line"] article, form:last-of-type md-editor article').catch(() => {});
  464. await shot('mdeditor-' + w);
  465. const tb = await ev(`(() => { const t = [...document.querySelectorAll('md-editor')].find(e => /One line/.test(e.innerHTML)).querySelector('nav'); if (!t) return null; const r = t.getBoundingClientRect(); const kids = [...t.children].filter(c => getComputedStyle(c).display !== 'none').map(c => c.getBoundingClientRect()); return { h: r.height, rows: new Set(kids.map(k => Math.round(k.top))).size, w: r.width }; })()`);
  466. check(w + ' md-editor: toolbar of the one-row editor' + (w === 390 ? ' is a single row on the phone' : ' is drawn'), !!tb && (w !== 390 || tb.rows === 1), JSON.stringify(tb));
  467. await noSideways(w + ' /components/md-editor (new demos)');
  468. }
  469. await size(1280);
  470. // two corner radii only (docs/design-rules.md): every element of every page has corners of 0, 5px, 10px or 50%
  471. const cornersOf = `(() => { const out = {}; for (const el of document.querySelectorAll('*')) { const c = getComputedStyle(el);
  472. for (const v of [c.borderTopLeftRadius, c.borderTopRightRadius, c.borderBottomRightRadius, c.borderBottomLeftRadius])
  473. if (!['0px', '5px', '10px', '50%'].includes(v)) out[v] = (out[v] || el.localName + (el.className && typeof el.className === 'string' ? '.' + el.className.split(' ')[0] : '')); }
  474. return out; })()`;
  475. const odd = {};
  476. for (const r of routes) { await open(r); const o = await ev(cornersOf); if (Object.keys(o).length) odd[r] = o; }
  477. check(`1280 all ${routes.length} pages: every corner radius is 0, 5px (small), 10px (large) or 50%`, !Object.keys(odd).length, JSON.stringify(odd));
  478. await open('/elements');
  479. const rad = await ev(`(() => { const s = (q) => getComputedStyle(document.querySelector(q)).borderTopLeftRadius; return {
  480. button: s('elements-page button.primary'), input: s('#el-title'), pill: s('elements-page .pill'), details: s('elements-page details'), drop: s('drop-zone'), menuLink: s('#sidebar > nav a') }; })()`);
  481. check('1280 radii: buttons, fields, pills, menu links 5px; foldables and drop zones 10px', rad.button === '5px' && rad.input === '5px' && rad.pill === '5px' && rad.menuLink === '5px' && rad.details === '10px' && rad.drop === '10px', JSON.stringify(rad));
  482. // list-first desktop: both; welcome on /; an item opens beside the list
  483. await open('/shells/list-first');
  484. const lf = [await rect('list-first > aside'), await rect('list-first > main')];
  485. check('1280 list-first /: list and welcome side by side, full width', await shown('list-first > aside') && await shown('list-first > main') && lf[0].x === 0 && lf[1].x === lf[0].r && lf[1].r === 1280 && /Pick a note/.test(await ev(`document.querySelector('list-first > main').textContent`)), JSON.stringify(lf));
  486. const hb = await rect('application-header > a.brand');
  487. check('1280 list-first: the header spans the page like the shell (brand at the gutter)', hb.x === 16 || hb.x === 24, JSON.stringify(hb));
  488. await page.click('list-first > aside a[href="/shells/list-first/groceries"]');
  489. await waitPath('/shells/list-first/groceries');
  490. await page.waitFor(`document.querySelector('list-first > main h1') && document.querySelector('list-first > main h1').textContent === 'Groceries'`, { label: 'groceries' });
  491. await sleep(300);
  492. check('1280 list-first item: the note beside the list, the item marked, no back link', await shown('list-first > aside') && (await ev(`document.querySelector('list-first > aside a.selected').getAttribute('href')`)) === '/shells/list-first/groceries' && !(await shown('list-first a.back')));
  493. await shot('1280-list-first-detail');
  494. // three-pane desktop: all three at the same time
  495. await open('/shells/three-pane/m2');
  496. const tp = [await rect('#sidebar'), await rect('three-pane > aside'), await rect('three-pane > main')];
  497. check('1280 three-pane: folders, list and message side by side', tp.every(Boolean) && tp[0].x === 0 && tp[1].x === tp[0].r && tp[2].x === tp[1].r && tp[2].r === 1280 && !(await shown('application-header .menu-toggle')), JSON.stringify(tp));
  498. check('1280 three-pane: the actions panel and the opened message', await shown('three-pane > main > menu') && /borderless/.test(await ev(`document.querySelector('three-pane > main h1').textContent`)));
  499. await page.click('three-pane > aside a[href="/shells/three-pane/m4"]');
  500. await waitPath('/shells/three-pane/m4');
  501. await page.waitFor(`/invoice/.test(document.querySelector('three-pane > main h1').textContent)`, { label: 'm4' });
  502. check('1280 three-pane: another message opens in place, all three still shown', await shown('#sidebar') && await shown('three-pane > aside'));
  503. await shot('1280-three-pane');
  504. // content-first demo desktop: the header menu, the column, the login
  505. await open('/shells/content-first/series');
  506. const tb = [await rect('application-header > a.brand'), await rect('content-first > main'), await rect('application-header a.button.primary')];
  507. check('1280 tracker demo: header flush with the centred column (brand left = column left, login right = column right)', Math.abs(tb[0].x - tb[1].x) <= 1 && Math.abs(tb[2].r - tb[1].r) <= 1 && tb[1].x > 16, JSON.stringify(tb));
  508. check('1280 tracker demo: the phone-only sidebar is gone, the main menu is in the header with Series marked', !(await shown('#sidebar')) && (await ev(`document.querySelector('application-header main-menu a.current').textContent`)) === 'Series');
  509. await shot('1280-tracker-demo');
  510. // the user menu on desktop
  511. await open('/');
  512. await page.click('user-menu .user-toggle');
  513. await page.waitFor(`document.querySelector('#user-menu').matches(':popover-open')`, { label: 'user menu desktop' });
  514. await sleep(200);
  515. const ud = [await rect('#user-menu'), await rect('content-first > main')];
  516. check('1280 user menu: the dropdown ends flush with the column, under the header', Math.abs(ud[0].r - ud[1].r) <= 1 && ud[0].y >= 52, JSON.stringify(ud));
  517. await shot('1280-user-menu');
  518. // ---- tap targets at 390 (mission 006): every button, icon button, brand, menu item, tab and list link >= 44 x 44, fields >= 16 px ----
  519. await size(390);
  520. for (const path of ['/', '/elements', '/components/pagination', '/components/md-editor', '/components/file-upload', '/components/date-picker', '/shells/content-first/movie', '/shells/list-first/trip', '/shells/three-pane/m2']) {
  521. await open(path);
  522. for (const [label, toggle, pop] of [['', null, null], ['sidebar open', 'application-header .menu-toggle', '#sidebar'], ['user menu open', 'user-menu .user-toggle', '#user-menu'], ['search open', 'application-header .search-toggle', '#app-search']]) {
  523. if (toggle) {
  524. if (!(await shown(toggle)) || !(await ev(`!!document.querySelector(${JSON.stringify(pop)})`))) continue;
  525. await page.click(toggle);
  526. await page.waitFor(`document.querySelector(${JSON.stringify(pop)}).matches(':popover-open')`, { label });
  527. await sleep(150);
  528. }
  529. const a = await ev(AUDIT);
  530. const hard = a.taps.filter(t => !t.inline);
  531. check(`390 ${path} ${label}: ${a.n} tap targets, none under 44 px, no field under 16 px, nothing wider than the screen`, hard.length === 0 && a.inputs.length === 0 && a.nwide === 0 && a.sw <= a.w, JSON.stringify({ taps: hard.slice(0, 6), inputs: a.inputs.slice(0, 3), wide: a.wide.slice(0, 3), sw: a.sw }));
  532. if (toggle) await ev(`document.querySelector(${JSON.stringify(pop)}).hidePopover()`);
  533. }
  534. }
  535. // mission 007: the display audit (found in a real Chrome): per page and width — no sideways scroll, nothing outside the screen,
  536. // no text cut off or spilling, no overlapping siblings, no control hidden behind another, no closed popover left on the page,
  537. // no text under 4.5:1, no content under the sticky header
  538. // ---- mission 009: the main menu marks the current page (aria-current, a visible non-colour marker, contrast), a count badge, the host's say ----
  539. 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]; };
  540. const ratio = (a, b) => { const x = lum(a), y = lum(b); return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05); };
  541. const rgbOf = (s) => (String(s).match(/rgba?\(([^)]+)\)/) || [0, '0,0,0'])[1].split(',').slice(0, 3).map(Number);
  542. const marks = (root) => ev(`[...document.querySelectorAll(${JSON.stringify(root + ' a')})].filter(a => a.getAttribute('aria-current') === 'page').map(a => a.firstChild.textContent.trim())`);
  543. const markStyle = (sel) => ev(`(() => { const a = document.querySelector(${JSON.stringify(sel)}); if (!a) return null; const c = getComputedStyle(a); return { color: c.color, bg: c.backgroundColor, shadow: c.boxShadow, accent: getComputedStyle(document.documentElement).getPropertyValue('--color-accent').trim(), n: a.parentElement.querySelectorAll('a.current').length }; })()`);
  544. const markOk = (m) => { if (!m || m.shadow === 'none') return false; const sh = rgbOf(m.shadow); const bg = rgbOf(m.bg); return ratio(rgbOf(m.color), bg) >= 4.5 && ratio(sh, bg) >= 3; };
  545. await size(1280);
  546. await open('/components');
  547. check('1280 main menu: exactly Components is marked (aria-current="page")', JSON.stringify(await marks('application-header main-menu')) === '["Components"]', JSON.stringify(await marks('application-header main-menu')));
  548. let ms = await markStyle('application-header main-menu a.current');
  549. check('1280 main menu: the marked link has a visible marker beyond colour (a bar in the accent), text >= 4.5:1 and marker >= 3:1 on its background', markOk(ms), JSON.stringify(ms));
  550. await page.click('application-header main-menu a[href="/shells"]');
  551. await waitPath('/shells');
  552. await sleep(400);
  553. check('1280 click Shells in the header: the marker moved to Shells, only one', JSON.stringify(await marks('application-header main-menu')) === '["Shells"]', JSON.stringify(await marks('application-header main-menu')));
  554. await shot('1280-menu-shells');
  555. await page.click('application-header main-menu a[href="/docs"]');
  556. await waitPath('/docs');
  557. await sleep(400);
  558. check('1280 click Docs: the marker moved to Docs', JSON.stringify(await marks('application-header main-menu')) === '["Docs"]');
  559. await open('/components/pagination');
  560. check('1280 a page below a section (/components/pagination) marks Components in the menu, Pagination in the sidebar', JSON.stringify(await marks('application-header main-menu')) === '["Components"]' && JSON.stringify(await marks('#sidebar nav:not(main-menu nav)')).includes('Pagination'), JSON.stringify([await marks('application-header main-menu'), await marks('#sidebar')]));
  561. ms = await markStyle('#sidebar nav a[aria-current="page"]:not(main-menu a)');
  562. check('1280 sidebar nav: the current page has the bar marker and the contrast', markOk(ms), JSON.stringify(ms));
  563. await shot('1280-menu-sidebar-current');
  564. await open('/read/using-the-theme');
  565. check('1280 the host says which one (current = "/docs" on a /read page): Docs is marked', JSON.stringify(await marks('application-header main-menu')) === '["Docs"]', JSON.stringify(await marks('application-header main-menu')));
  566. await open('/shells/content-first');
  567. check('1280 item.current = true (host override, no path match): Series is marked on the all-titles page', JSON.stringify(await marks('application-header main-menu')) === '["Series"]', JSON.stringify(await marks('application-header main-menu')));
  568. const badge = await ev(`(() => { const a = document.querySelector('application-header main-menu 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 }; })()`);
  569. check('1280 a menu item carries a count badge as a prop (label stays "Shows", badge 12, text >= 4.5:1)', badge && badge.label === 'Shows' && badge.count === '12' && ratio(rgbOf(badge.color), rgbOf(badge.bg)) >= 4.5, JSON.stringify(badge));
  570. check('1280 items without a count have no badge', (await ev(`document.querySelectorAll('application-header main-menu span.count').length`)) === 1);
  571. await shot('1280-menu-badge');
  572. await page.click('application-header main-menu a[href="/shells/content-first/movie"]');
  573. await waitPath('/shells/content-first/movie');
  574. await sleep(400);
  575. check('1280 click Movies in the tracker demo: the marker moved from Series to Movies', JSON.stringify(await marks('application-header main-menu')) === '["Movies"]', JSON.stringify(await marks('application-header main-menu')));
  576. // mission 011 (hybriel#197): the tracker demo gives MainMenu NO `current`; the marker comes from the route and is in the server's HTML (no flicker)
  577. const ssrMarks = async (path) => { const html = await (await fetch(BASE + path)).text(); return [...html.matchAll(/<main-menu>.*?<\/main-menu>/gs)].map(m => [...m[0].matchAll(/<a href="[^"]*" class="current" aria-current="page">([^<]*)/g)].map(x => x[1]).join(',')); };
  578. for (const [path, want] of [['/shells/content-first/movie', 'Movies'], ['/shells/content-first/genre', 'Genres'], ['/shells/content-first/person', 'People']]) {
  579. const got = await ssrMarks(path);
  580. check('SSR ' + path + ': both main menus (header, sidebar) carry the marker from the route, before any script', got.length === 2 && got.every(g => g === want), JSON.stringify(got));
  581. }
  582. check('SSR /shells/content-first: Series is marked (item.current flag stays the fallback)', (await ssrMarks('/shells/content-first')).every(g => g === 'Series'));
  583. await size(390);
  584. await open('/components');
  585. await page.click('application-header .menu-toggle');
  586. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'sidebar opens (menu mark)' });
  587. await sleep(250);
  588. check('390 sidebar main menu: Components marked', JSON.stringify(await marks('#sidebar main-menu')) === '["Components"]');
  589. ms = await markStyle('#sidebar main-menu a.current');
  590. check('390 sidebar main menu: bar marker + contrast', markOk(ms), JSON.stringify(ms));
  591. await shot('390-menu-components');
  592. await page.click('#sidebar main-menu a[href="/shells"]');
  593. await waitPath('/shells');
  594. await sleep(400);
  595. await page.click('application-header .menu-toggle');
  596. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'sidebar opens again' });
  597. await sleep(250);
  598. check('390 click Shells in the sidebar menu, reopen: the marker moved to Shells', JSON.stringify(await marks('#sidebar main-menu')) === '["Shells"]', JSON.stringify(await marks('#sidebar main-menu')));
  599. await shot('390-menu-shells');
  600. await ev(`document.querySelector('#sidebar').hidePopover()`);
  601. await open('/shells/content-first/show');
  602. await page.click('application-header .menu-toggle');
  603. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'tracker sidebar opens' });
  604. await sleep(250);
  605. check('390 the badge shows in the phone menu next to "Shows" and the tap target stays >= 44 px', await ev(`(() => { const a = document.querySelector('#sidebar main-menu a[href="/shells/content-first/show"]'); const b = a.querySelector('span.count'); return !!b && b.textContent === '12' && a.getBoundingClientRect().height >= 44; })()`));
  606. await shot('390-menu-badge');
  607. await ev(`document.querySelector('#sidebar').hidePopover()`);
  608. const shownPages = ['/', '/elements', '/components', '/components/month-view', '/components/date-picker', '/components/pagination', '/components/md-editor', '/components/comments', '/components/files-upload-pick', '/components/modal', '/shells', '/shells/content-first/movie', '/shells/list-first', '/shells/list-first/trip', '/shells/three-pane', '/shells/three-pane/m2', '/docs', '/read/using-the-theme', '/settings', '/search/modal'];
  609. const findings = (d) => {
  610. const bits = [];
  611. if (d.hscroll) bits.push('sideways scroll ' + d.sw);
  612. for (const k of ['wide', 'spill', 'overlaps', 'covered', 'stray', 'contrast']) if (d[k].length) bits.push(`${k}: ${JSON.stringify(d[k][0])}${d[k].length > 1 ? ' +' + (d[k].length - 1) : ''}`);
  613. const clip = d.clipped.filter(c => !c.ellipsis); if (clip.length) bits.push('clipped: ' + JSON.stringify(clip[0]));
  614. if (d.underHeader) bits.push('under the header: ' + JSON.stringify(d.underHeader));
  615. return bits.join(' ; ');
  616. };
  617. for (const w of [390, 1280]) {
  618. await size(w);
  619. for (const path of shownPages) {
  620. await open(path);
  621. const states = [['', null, null]];
  622. if (await shown('application-header .menu-toggle')) states.push(['sidebar open', 'application-header .menu-toggle', '#sidebar']);
  623. if (await shown('application-header .search-toggle')) states.push(['search open', 'application-header .search-toggle', '#app-search']);
  624. if (await shown('user-menu .user-toggle')) states.push(['user menu open', 'user-menu .user-toggle', '#user-menu']);
  625. for (const [label, toggle, pop] of states) {
  626. if (toggle) { await page.click(toggle); await page.waitFor(`document.querySelector(${JSON.stringify(pop)}).matches(':popover-open')`, { label }); await sleep(150); }
  627. const d = await ev(DISPLAY);
  628. check(`${w} display ${path} ${label}: nothing overlaps, spills, hides behind another or leaves the screen`, findings(d) === '', findings(d));
  629. if (toggle) await ev(`document.querySelector(${JSON.stringify(pop)}).hidePopover()`);
  630. }
  631. }
  632. }
  633. const problems = page.problems().filter(m => !/favicon|Failed to load resource/.test(m.text));
  634. check('no console errors or warnings on any page', problems.length === 0, problems.map(p => p.text).join('\n'));
  635. }
  636. try {
  637. await main();
  638. } catch (e) {
  639. failures++;
  640. console.log('FAIL (aborted) ' + (e && e.stack || e));
  641. } finally {
  642. await stop();
  643. }
  644. console.log(`\n${passes} passed, ${failures} failed — screenshots in .scratch/gate-shots/`);
  645. process.exit(failures ? 1 : 0);

Branches

Latest commits

  • f4ad7eecsync components 9a: shared Icon (icons/icons.hl), md-editor toolbar icons + single focus ring (components f4-icons ba96735)mre
  • db258c11sync-components: copy icons/icons.hl + README (F4); testsmre
  • badc1879md-editor.hl: verbatim copy of components f3-mdvalue (an older text handed back is kept)mre
  • 867a8375md-editor.hl: verbatim copy of components f3-mdvalue (an outside value change is shown by the editor)mre
  • 5d8d2c67tests: wait for hydration before real clicks after a navigation (H2)mre
  • 99db79f0re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • 30353f60tests: e2e-md-showcase Chrome range from LAYOUTS_GATE_CHROME_MD, default unchangedmre
  • 16a7878cre-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • 6af559e8docker-compose: nofile 65536 (Hybriel int 6+ boot opened >1024 files in the tracker)mre
  • 5599cf56deploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • 0bcc6294Mission 011: e2e-197, brief, report, LOGmre
  • 137303c5MainMenu marks the current page from the route (hybriel#197, server-rendered); current prop/item.current stay as fallback; tracker demo drops current; gate: SSR marker; docsmre
  • 9325b403Re-vendor Hybriel to master 7f13a82f (hl:web batch 2: #190 #193 #197 #194 named regions); plugins whole, bin/hybriel static build (git-ignored)mre
  • b31dc74dusage: calendar (theme 76f99f6-era ContentFirst, user menu, ☰ menu) and tracker (theme 76f99f6, modal + pagination current, own current marker until hybriel#197) rowsmre
  • 8a3d5d40Mission 010: brief, report, LOG, STATUSmre
  • a56abf1fSync components to components.hybriel 3794c59 (MdEditor real-key fixes); showcase real-key check on the md-editor pagemre
  • 76f99f64E2E in lisbeth's Chrome for the menu's current page (mission 009): tests/e2e-menu-current.mjs, reportmre
  • 159b1d53MainMenu/Sidebar: current page marked beyond colour, count badge, item current flag; gate 300/0 (mission 009)mre
  • 0573eed3usage: notes + tickets on MdEditor (md-editor.js retired), gitoria on theme dbe3de7, tracker theme oldermre
  • 78478f6eSync showcase to components.hybriel 1442e58: pick-mode page, comments attach, md-editor rows/files off; gates 285/0mre