gitoria

layouts

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3d4f8e193d4f8e19Sync showcase to components.hybriel 9db927d: comments and files-upload pages, pagination onPage, md-editor readonly, gate 99 checksmre3d4f8e19/tests/browser.mjs

41.5 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. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  14. const APP = resolve(dirname(fileURLToPath(import.meta.url)), '..');
  15. const PORT = Number(process.env.LAYOUTS_GATE_PORT || 8760);
  16. const [CH_FROM, CH_TO] = (process.env.LAYOUTS_GATE_CHROME || '8761-8764').split('-').map(Number);
  17. const BASE = `http://127.0.0.1:${PORT}`;
  18. const SCRATCH = join(APP, '.scratch');
  19. mkdirSync(SCRATCH, { recursive: true });
  20. for (const f of ['gate-shots']) rmSync(join(SCRATCH, f), { recursive: true, force: true });
  21. const SHOTS = join(SCRATCH, 'gate-shots');
  22. mkdirSync(SHOTS, { recursive: true });
  23. let failures = 0, passes = 0;
  24. function check(label, ok, detail = '') {
  25. console.log(`${ok ? 'ok ' : 'FAIL'} ${label}${ok ? '' : ' — ' + detail}`);
  26. if (ok) passes++; else failures++;
  27. }
  28. const sleep = (ms) => new Promise(r => setTimeout(r, ms));
  29. let log = '', server = null, browser = null;
  30. async function startServer() {
  31. server = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, env: { ...process.env, LAYOUTS_PORT: String(PORT), LAYOUTS_WATCH: '0' }, stdio: ['ignore', 'pipe', 'pipe'] });
  32. server.stdout.on('data', d => log += d); server.stderr.on('data', d => log += d);
  33. for (let i = 0; ; i++) {
  34. try { if ((await fetch(BASE + '/')).ok) break; } catch {}
  35. if (i > 480) throw new Error('server did not come up\n' + log);
  36. await sleep(250);
  37. }
  38. }
  39. async function stop() {
  40. if (browser) { try { await browser.close(); } catch {} browser = null; }
  41. if (server) {
  42. try { server.kill('SIGTERM'); } catch {}
  43. await new Promise(r => { if (server.exitCode !== null || server.signalCode !== null) return r(); server.once('exit', r); setTimeout(r, 3000); });
  44. server = null;
  45. }
  46. }
  47. async function main() {
  48. // ---- the theme gate helper (no server needed) -----------------------------------------------------------------
  49. 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) }; } };
  50. const own = helper([APP]);
  51. check('check-theme on this app: 0 problems (exit 0)', own.code === 0 && /0 problems/.test(own.out), own.out.slice(-600));
  52. const fx = join(SCRATCH, 'gate-check-fixture');
  53. rmSync(fx, { recursive: true, force: true });
  54. mkdirSync(fx, { recursive: true });
  55. writeFileSync(join(fx, 'styles.hl'), [
  56. "a { color = '#ff0000' }",
  57. "'.card' { border = '1px solid ' + colorBorder }",
  58. "'.box' { background = 'white' }",
  59. "details { border = '1px solid ' + colorBorder }",
  60. "'.zone' { border = '2px dashed ' + colorBorder } // functional: a drop zone",
  61. "'.x' { color = 'var(--color-text, #c3c8cd)' border = '0' }",
  62. "'.r1' { padding = '0' borderRadius = '.4rem' }",
  63. "'.r2' { borderRadius = 'var(--layout-radius)' }",
  64. "'.r3' { borderRadius = radiusSmall borderTopLeftRadius = 'var(--radius-large, 10px)' }",
  65. "'.r4' { borderRadius = radiusLarge + ' ' + radiusLarge + ' 0 0' }",
  66. "'.r5' { borderRadius = '50%' } // an avatar",
  67. "'.r6' { borderRadius = radiusLarge + ' 3px' }",
  68. ].join('\n'));
  69. writeFileSync(join(fx, 'extra.css'), '.a { border-radius: var(--radius-small); }\n.b { border-top-left-radius: 4px; border-radius: 0 }\n');
  70. const bad = helper([fx]);
  71. 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);
  72. const radiusLines = bad.out.split('\n').filter(l => /corner radius/.test(l)).map(l => l.split(':').slice(0, 2).join(':')).sort().join(' ');
  73. 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);
  74. // ---- the server ---------------------------------------------------------------------------------------------------
  75. await startServer();
  76. 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', '/shells/content-first', '/shells/content-first/movie', '/shells/list-first', '/shells/list-first/trip', '/shells/three-pane', '/shells/three-pane/m2', '/search/modal'];
  77. const codes = await Promise.all(routes.map(async r => [r, (await fetch(BASE + r)).status]));
  78. check(`all ${routes.length} pages answer 200`, codes.every(([, c]) => c === 200), JSON.stringify(codes.filter(([, c]) => c !== 200)));
  79. const readme = await fetch(BASE + '/components/modal/README.md');
  80. check('a component README is served as Markdown', readme.ok && /markdown/.test(readme.headers.get('content-type')));
  81. const doc = await fetch(BASE + '/docs/layouts/list-first.md');
  82. check('a layout doc is served as Markdown', doc.ok && /markdown/.test(doc.headers.get('content-type')) && (await doc.text()).includes('# ListFirst'));
  83. const sr = await fetch(BASE + '/search?q=Date+Pick', { redirect: 'manual' });
  84. 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'));
  85. const css = await (await fetch(BASE + '/__hl/app.css')).text();
  86. 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);}') && /--radius-small:5px;--radius-large:10px;/.test(css) && css.includes('html md-editor{border:0'), css.slice(0, 300));
  87. 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');
  88. check('no style rule dropped at boot', !/style DROPPED/.test(log), log.split('\n').filter(l => /DROPPED/.test(l)).join('\n'));
  89. browser = await launchBrowser({ debugPortRange: [CH_FROM, CH_TO] });
  90. const page = await browser.newPage();
  91. const ev = (e) => page.evaluate(e);
  92. const shot = async (name) => { const { data } = await page.send('Page.captureScreenshot', { format: 'png' }); writeFileSync(join(SHOTS, `gate-${name}.png`), Buffer.from(data, 'base64')); };
  93. const size = (w) => page.send('Emulation.setDeviceMetricsOverride', { width: w, height: w < 600 ? 844 : 900, deviceScaleFactor: 1, mobile: w < 600 });
  94. const open = async (path) => {
  95. await page.goto(BASE + path, { timeout: 45000 });
  96. await page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1', { timeout: 30000, label: 'hydrated ' + path });
  97. await sleep(300);
  98. };
  99. 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; })()`);
  100. 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) }; })()`);
  101. 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)); };
  102. const waitPath = (p) => page.waitFor(`location.pathname === ${JSON.stringify(p)}`, { timeout: 15000, label: 'path ' + p });
  103. const press = async (key) => {
  104. const vk = key === 'Escape' ? 27 : 13;
  105. await page.send('Input.dispatchKeyEvent', { type: 'keyDown', key, code: key, windowsVirtualKeyCode: vk });
  106. if (key === 'Enter') await page.send('Input.dispatchKeyEvent', { type: 'char', text: '\r' });
  107. await page.send('Input.dispatchKeyEvent', { type: 'keyUp', key, code: key, windowsVirtualKeyCode: vk });
  108. };
  109. const popOpen = (sel) => ev(`document.querySelector(${JSON.stringify(sel)}).matches(':popover-open')`);
  110. // ================================== PHONE (390) ==================================
  111. await size(390);
  112. // content-first (the showcase site itself): content shown, sidebar hidden until the toggle
  113. await open('/elements');
  114. check('390 content-first: main shown, sidebar hidden, toggle shown', await shown('content-first > main') && !(await shown('#sidebar')) && await shown('application-header .menu-toggle'));
  115. 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'));
  116. await noSideways('390 /elements');
  117. await shot('390-content-first');
  118. await page.click('application-header .menu-toggle');
  119. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'sidebar opens' });
  120. await sleep(250);
  121. const sb = await rect('#sidebar');
  122. 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));
  123. 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');
  124. await shot('390-sidebar-open');
  125. await press('Escape');
  126. await page.waitFor(`!document.querySelector('#sidebar').matches(':popover-open')`, { label: 'Esc closes the sidebar' });
  127. check('390 Esc closes the sidebar', !(await shown('#sidebar')));
  128. await page.click('application-header .menu-toggle');
  129. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'sidebar opens again' });
  130. await page.click('#sidebar nav a[href="/components/pagination"]');
  131. await waitPath('/components/pagination');
  132. await page.waitFor(`!!document.querySelector('pagination')`, { label: 'pagination page' });
  133. await sleep(300);
  134. check('390 a link in the sidebar navigates and the overlay is closed after it', !(await popOpen('#sidebar')) && !(await shown('#sidebar')));
  135. // search: the loupe opens the field under the bar, focused; Enter searches
  136. await open('/');
  137. await page.click('application-header .search-toggle');
  138. await page.waitFor(`document.querySelector('#app-search').matches(':popover-open')`, { label: 'search opens' });
  139. await sleep(200);
  140. const sf = await rect('#app-search');
  141. 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));
  142. await shot('390-search-open');
  143. await page.type('#app-search input', 'modal');
  144. await press('Enter');
  145. await waitPath('/search/modal');
  146. await page.waitForSelector('ul.pages a[href="/components/modal"]', { timeout: 15000 });
  147. check('390 the search lands on /search/modal and finds the Modal page', true);
  148. // user menu: the icon opens the dropdown; Esc closes it
  149. await open('/');
  150. await page.click('user-menu .user-toggle');
  151. await page.waitFor(`document.querySelector('#user-menu').matches(':popover-open')`, { label: 'user menu opens' });
  152. await sleep(200);
  153. const um = await rect('#user-menu');
  154. const items = await ev(`[...document.querySelectorAll('#user-menu a')].map(a => a.textContent)`);
  155. 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 }));
  156. await shot('390-user-menu');
  157. await press('Escape');
  158. await page.waitFor(`!document.querySelector('#user-menu').matches(':popover-open')`, { label: 'Esc closes the user menu' });
  159. check('390 Esc closes the user menu', true);
  160. // list-first: the list first; an item replaces it; back returns
  161. await open('/shells/list-first');
  162. check('390 list-first /: the list shown, the welcome text never', await shown('list-first > aside') && !(await shown('list-first > main')));
  163. check('390 list-first: no sidebar toggle (no overlay in this shell)', !(await shown('application-header .menu-toggle')));
  164. await noSideways('390 list-first');
  165. await shot('390-list-first-list');
  166. await page.click('list-first > aside a[href="/shells/list-first/trip"]');
  167. await waitPath('/shells/list-first/trip');
  168. await page.waitFor(`document.querySelector('list-first').classList.contains('detail')`, { label: 'detail state' });
  169. await sleep(300);
  170. 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`)));
  171. check('390 list-first detail: a back link to the list', await shown('list-first a.back'));
  172. await noSideways('390 list-first detail (long title)');
  173. await shot('390-list-first-detail');
  174. await page.click('list-first a.back');
  175. await waitPath('/shells/list-first');
  176. await page.waitFor(`document.querySelector('list-first').classList.contains('list')`, { label: 'back to the list' });
  177. check('390 back → the list again', await shown('list-first > aside'));
  178. // three-pane: list first; folders are the overlay; an item shows with its actions
  179. await open('/shells/three-pane');
  180. 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')));
  181. await page.click('application-header .menu-toggle');
  182. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'folders open' });
  183. await sleep(250);
  184. check('390 three-pane: the toggle slides the folders in', /Inbox/.test(await ev(`document.querySelector('#sidebar').textContent`)) && await shown('#sidebar'));
  185. await shot('390-three-pane-folders');
  186. await page.click('#sidebar .sidebar-close');
  187. await page.waitFor(`!document.querySelector('#sidebar').matches(':popover-open')`, { label: '× closes the folders' });
  188. check('390 three-pane: the × closes the folders', true);
  189. await page.click('three-pane > aside a[href="/shells/three-pane/m3"]');
  190. await waitPath('/shells/three-pane/m3');
  191. await page.waitFor(`document.querySelector('three-pane').classList.contains('detail')`, { label: 'mail detail' });
  192. await sleep(300);
  193. 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`)));
  194. await noSideways('390 three-pane detail');
  195. await page.click('three-pane > main > menu button[value="Archived"]');
  196. await page.waitFor(`/Archived/.test(document.querySelector('three-pane > main output').textContent)`, { label: 'action answered' });
  197. check('390 three-pane: an action button answers (mock)', true);
  198. await shot('390-three-pane-detail');
  199. // content-first demo (signed out): the phone-only sidebar holds the main menu
  200. await open('/shells/content-first');
  201. 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')`)));
  202. await page.click('application-header .menu-toggle');
  203. await page.waitFor(`document.querySelector('#sidebar').matches(':popover-open')`, { label: 'tracker sidebar' });
  204. await page.click('#sidebar main-menu a[href="/shells/content-first/movie"]');
  205. await waitPath('/shells/content-first/movie');
  206. await page.waitFor(`document.querySelector('main h1').textContent === 'Movie'`, { label: 'movies' });
  207. 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')));
  208. await noSideways('390 tracker demo');
  209. await shot('390-tracker-demo');
  210. // every other page at 390: no sideways scroll
  211. 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/pagination', '/docs']) {
  212. await open(r);
  213. await noSideways('390 ' + r);
  214. if (/comments|files-upload|pagination/.test(r)) await shot('390' + r.replace(/\//g, '-'));
  215. }
  216. // ================================== DESKTOP (1280) ==================================
  217. await size(1280);
  218. await open('/elements');
  219. 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')));
  220. 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')];
  221. 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 }));
  222. 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'));
  223. check('1280 the sidebar does not repeat the main menu', !(await shown('#sidebar main-menu')));
  224. await shot('1280-content-first');
  225. // themed plain elements: borderless except the foldable and the drop zone
  226. const b = await ev(`(() => { const s = (q, p) => getComputedStyle(document.querySelector(q))[p]; return {
  227. button: s('elements-page button.primary', 'borderTopStyle'), input: s('#el-title', 'borderTopStyle'),
  228. details: s('elements-page details', 'borderTopStyle'), drop: s('drop-zone', 'borderTopStyle'),
  229. td: s('elements-page td', 'borderTopStyle'), h1: s('elements-page h1', 'color'), strong: s('elements-page strong', 'color') }; })()`);
  230. 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));
  231. check('1280 elements: titles white (text-strong)', b.h1 === 'rgb(245, 250, 255)' && b.strong === 'rgb(245, 250, 255)', JSON.stringify(b));
  232. await page.click('elements-page details:nth-of-type(2) summary');
  233. check('1280 elements: a foldable opens on its summary', await ev(`document.querySelectorAll('elements-page details')[1].open`));
  234. // the accent switcher: a palette colour becomes --color-accent, survives a reload, Reset returns the default
  235. const accentOf = () => ev(`getComputedStyle(document.querySelector('application-header main-menu a.current')).color`);
  236. const before = await accentOf();
  237. await page.click('accent-switcher button[value="purple"]');
  238. await sleep(200);
  239. check('1280 accent switcher: purple → the marked menu link is purple', (await accentOf()) === 'rgb(197, 134, 192)', await accentOf());
  240. await open('/shells');
  241. check('1280 accent switcher: the accent stays on the next page (localStorage)', (await accentOf()) === 'rgb(197, 134, 192)', await accentOf());
  242. await shot('1280-accent-purple');
  243. await page.click('accent-switcher button.reset');
  244. await sleep(200);
  245. check('1280 accent switcher: Reset → the theme default again', (await accentOf()) === before, `${await accentOf()} vs ${before}`);
  246. // themed components: no decorative frames left, functional ones kept
  247. await open('/components/pagination');
  248. 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');
  249. await page.click('pagination li:nth-child(3) button');
  250. await page.waitFor(`document.querySelector('pagination li.current button').textContent === '3'`, { label: 'page 3' });
  251. check('1280 pagination still works themed (page 3)', true);
  252. await open('/components/md-editor');
  253. 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');
  254. await shot('1280-md-editor');
  255. await open('/components/code-editor');
  256. 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');
  257. await open('/components/month-view');
  258. 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);
  259. await shot('1280-month-view');
  260. await open('/components/date-picker');
  261. await page.click('date-picker input');
  262. await page.waitFor(`getComputedStyle(document.querySelector('date-picker picker-popup')).display !== 'none'`, { label: 'date popup' });
  263. await sleep(300);
  264. 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');
  265. await shot('1280-date-picker-open');
  266. await open('/components/file-upload');
  267. 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');
  268. await open('/components/modal');
  269. await page.click('#open-confirm');
  270. await page.waitFor(`document.querySelector('#confirm').open`, { label: 'modal open' });
  271. await sleep(300);
  272. 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');
  273. await shot('1280-modal-open');
  274. await page.click('#confirm footer button[value="delete"]');
  275. await page.waitFor(`document.querySelector('#modal-last').textContent === 'confirm: delete'`, { label: 'modal closed' });
  276. check('1280 modal still reports how it closed (confirm: delete)', true);
  277. // ---- mission 005: pagination tells the page (onPage), md-editor readonly, the two new components: comments, files-upload ----------
  278. 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); };
  279. const typeText = async (t) => { for (const ch of t) await key(ch, '', undefined, ch); };
  280. await open('/components/pagination');
  281. check('1280 pagination: before any click the page says "none yet"', (await ev(`document.querySelector('#pagination-heard').textContent`)) === 'none yet');
  282. await page.click('pagination li:nth-child(4) button');
  283. await page.waitFor(`document.querySelector('#pagination-heard').textContent === 'page 4'`, { label: 'told page 4' }).catch(() => {});
  284. 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`));
  285. await page.click('pagination li:last-child button');
  286. await sleep(400);
  287. 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`));
  288. await shot('1280-pagination');
  289. await open('/components/md-editor');
  290. 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') }; })()`);
  291. 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));
  292. await ev(`[...document.querySelectorAll('md-editor')].find(m => m.querySelector('input[name=shown]')).scrollIntoView()`);
  293. await shot('1280-md-editor-readonly');
  294. // ---- comments ----
  295. await open('/components/comments');
  296. const R = (id) => `document.querySelector('comments-block li.comment[data-id="${id}"]')`;
  297. const art = (id) => ev(`(${R(id)}.querySelector('md-editor article') || {}).innerHTML`);
  298. const ids = () => ev(`[...document.querySelectorAll('comments-block li.comment')].map(li => li.dataset.id).join(',')`);
  299. const count = () => ev(`document.querySelector('comments-block .comments-count').textContent`);
  300. const told = () => ev(`document.querySelector('#comments-told').textContent`);
  301. const btns = (id) => ev(`[...${R(id)}.querySelectorAll('comment-actions button')].map(b => b.textContent).join('|')`);
  302. await page.waitFor(`!!${R('c1')}.querySelector('md-editor article ul')`, { label: 'comment Markdown drawn' }).catch(() => {});
  303. 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')));
  304. 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'`));
  305. 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(' / '));
  306. 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'); })()`));
  307. await shot('1280-comments');
  308. await page.click('comments-block li.comment[data-id="c1"] .comment-like');
  309. await page.waitFor(`${R('c1')}.querySelector('.comment-like').textContent === '♥ 3' && document.querySelector('#comments-told').textContent === 'like c1'`, { label: 'liked' }).catch(() => {});
  310. 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());
  311. await page.click('comments-block form.comment-form md-editor article');
  312. await typeText('Hello **world** by keys');
  313. await sleep(200);
  314. 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`)));
  315. await key('Enter', 'Enter', 13, '\r', 2);
  316. await page.waitFor(`document.querySelectorAll('comments-block li.comment').length === 4 && !!${R('n1')}.querySelector('md-editor article p')`, { label: 'posted by Ctrl+Enter' }).catch(() => {});
  317. 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()));
  318. await page.click('comments-block li.comment[data-id="n1"] .comment-edit-start');
  319. await page.waitFor(`!!${R('n1')}.querySelector('form.comment-edit article p')`, { label: 'edit form' }).catch(() => {});
  320. await page.click('comments-block li.comment[data-id="n1"] form.comment-edit article');
  321. await key('End', 'End', 35, undefined, 2);
  322. await typeText(' and more');
  323. await page.click('comments-block li.comment[data-id="n1"] .comment-save');
  324. await page.waitFor(`!!${R('n1')}.querySelector('details.comment-history') && /by keys and more/.test((${R('n1')}.querySelector('md-editor article') || {}).innerHTML || '')`, { label: 'edited' }).catch(() => {});
  325. 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()));
  326. await page.click('comments-block li.comment[data-id="n1"] .comment-delete');
  327. await page.waitFor(`!!${R('n1')}.querySelector('.comment-delete-yes')`, { label: 'asks' }).catch(() => {});
  328. 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`)));
  329. await page.click('comments-block li.comment[data-id="n1"] .comment-delete-yes');
  330. await page.waitFor(`!${R('n1')}`, { label: 'deleted' }).catch(() => {});
  331. 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()));
  332. await page.click('#as-bob');
  333. await page.waitFor(`document.querySelector('#comments-me').textContent === 'bob' && ${R('c2')}.querySelector('.comment-edit-start')`, { label: 'bob' }).catch(() => {});
  334. 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(' / '));
  335. await page.click('#as-nobody');
  336. await page.waitFor(`document.querySelector('#comments-me').textContent === ''`, { label: 'nobody' }).catch(() => {});
  337. await sleep(300);
  338. 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`)));
  339. await page.click('#as-alice');
  340. await page.waitFor(`!!document.querySelector('comments-block form.comment-form')`, { label: 'alice again' }).catch(() => {});
  341. await ev('scrollTo(0, 0)');
  342. // the look: the bubble is a surface without a frame, the avatar round, the post button not framed
  343. 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') }; })()`);
  344. 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));
  345. // ---- files-upload ----
  346. const UP = join(SCRATCH, 'up');
  347. mkdirSync(UP, { recursive: true });
  348. writeFileSync(join(UP, 'a.txt'), 'hello a');
  349. writeFileSync(join(UP, 'b.txt'), 'hello b, a bit longer');
  350. writeFileSync(join(UP, 'c.bin'), Buffer.alloc(1536 * 1024, 7));
  351. await open('/components/files-upload');
  352. const rows = () => ev(`[...document.querySelectorAll('files-upload ul.files li')].map(li => [li.querySelector('.name').textContent, li.querySelector('.state').textContent].join('|'))`);
  353. const summary = () => ev(`(document.querySelector('files-upload output.summary') || {}).textContent`);
  354. 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`)));
  355. await shot('1280-files-upload');
  356. const zone = await page.box('files-upload drop-zone');
  357. const dropData = { items: [], files: [join(UP, 'a.txt'), join(UP, 'b.txt'), join(UP, 'c.bin')], dragOperationsMask: 1 };
  358. 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 });
  359. await page.waitFor(`document.querySelectorAll('files-upload li.done').length === 3`, { timeout: 60000, label: 'three uploaded' }).catch(() => {});
  360. const r1 = await rows();
  361. 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());
  362. const { root } = await page.send('DOM.getDocument');
  363. const { nodeId } = await page.send('DOM.querySelector', { nodeId: root.nodeId, selector: 'files-upload input[type=file]' });
  364. await page.send('DOM.setFileInputFiles', { files: [join(UP, 'a.txt'), join(UP, 'b.txt')], nodeId });
  365. await page.waitFor(`document.querySelectorAll('files-upload li.done').length === 5`, { timeout: 30000, label: 'five uploaded' }).catch(() => {});
  366. 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());
  367. await ev('scrollTo(0, 0)');
  368. await shot('1280-files-upload-done');
  369. // two corner radii only (docs/design-rules.md): every element of every page has corners of 0, 5px, 10px or 50%
  370. const cornersOf = `(() => { const out = {}; for (const el of document.querySelectorAll('*')) { const c = getComputedStyle(el);
  371. for (const v of [c.borderTopLeftRadius, c.borderTopRightRadius, c.borderBottomRightRadius, c.borderBottomLeftRadius])
  372. if (!['0px', '5px', '10px', '50%'].includes(v)) out[v] = (out[v] || el.localName + (el.className && typeof el.className === 'string' ? '.' + el.className.split(' ')[0] : '')); }
  373. return out; })()`;
  374. const odd = {};
  375. for (const r of routes) { await open(r); const o = await ev(cornersOf); if (Object.keys(o).length) odd[r] = o; }
  376. check(`1280 all ${routes.length} pages: every corner radius is 0, 5px (small), 10px (large) or 50%`, !Object.keys(odd).length, JSON.stringify(odd));
  377. await open('/elements');
  378. const rad = await ev(`(() => { const s = (q) => getComputedStyle(document.querySelector(q)).borderTopLeftRadius; return {
  379. 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') }; })()`);
  380. 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));
  381. // list-first desktop: both; welcome on /; an item opens beside the list
  382. await open('/shells/list-first');
  383. const lf = [await rect('list-first > aside'), await rect('list-first > main')];
  384. 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));
  385. const hb = await rect('application-header > a.brand');
  386. 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));
  387. await page.click('list-first > aside a[href="/shells/list-first/groceries"]');
  388. await waitPath('/shells/list-first/groceries');
  389. await page.waitFor(`document.querySelector('list-first > main h1') && document.querySelector('list-first > main h1').textContent === 'Groceries'`, { label: 'groceries' });
  390. await sleep(300);
  391. 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')));
  392. await shot('1280-list-first-detail');
  393. // three-pane desktop: all three at the same time
  394. await open('/shells/three-pane/m2');
  395. const tp = [await rect('#sidebar'), await rect('three-pane > aside'), await rect('three-pane > main')];
  396. 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));
  397. 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`)));
  398. await page.click('three-pane > aside a[href="/shells/three-pane/m4"]');
  399. await waitPath('/shells/three-pane/m4');
  400. await page.waitFor(`/invoice/.test(document.querySelector('three-pane > main h1').textContent)`, { label: 'm4' });
  401. check('1280 three-pane: another message opens in place, all three still shown', await shown('#sidebar') && await shown('three-pane > aside'));
  402. await shot('1280-three-pane');
  403. // content-first demo desktop: the header menu, the column, the login
  404. await open('/shells/content-first/series');
  405. const tb = [await rect('application-header > a.brand'), await rect('content-first > main'), await rect('application-header a.button.primary')];
  406. 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));
  407. 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');
  408. await shot('1280-tracker-demo');
  409. // the user menu on desktop
  410. await open('/');
  411. await page.click('user-menu .user-toggle');
  412. await page.waitFor(`document.querySelector('#user-menu').matches(':popover-open')`, { label: 'user menu desktop' });
  413. await sleep(200);
  414. const ud = [await rect('#user-menu'), await rect('content-first > main')];
  415. 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));
  416. await shot('1280-user-menu');
  417. const problems = page.problems().filter(m => !/favicon|Failed to load resource/.test(m.text));
  418. check('no console errors or warnings on any page', problems.length === 0, problems.map(p => p.text).join('\n'));
  419. }
  420. try {
  421. await main();
  422. } catch (e) {
  423. failures++;
  424. console.log('FAIL (aborted) ' + (e && e.stack || e));
  425. } finally {
  426. await stop();
  427. }
  428. console.log(`\n${passes} passed, ${failures} failed — screenshots in .scratch/gate-shots/`);
  429. process.exit(failures ? 1 : 0);

Branches

Latest commits

  • 3d4f8e19Sync showcase to components.hybriel 9db927d: comments and files-upload pages, pagination onPage, md-editor readonly, gate 99 checksmre
  • 64d635acmission brief 005mre
  • 0d0fef25paths: projects moved into /media/STORAGE/projects/WorldAPI/mre
  • 2dbe0df5Re-vendor Hybriel to the shared static build 0f396652 (plugins; bin/ is git-ignored), compose cache volume + tmpfs /tmp, gate wait 120 s, report 004mre
  • 0adc551emission brief 004mre
  • 1376e905deploy.sh: wait up to DEPLOY_URL_WAIT (120 s) for 200 after the restart, as the other apps (cold compile, hybriel#148)mre
  • c0fdbf6cdocker-compose: init: true (hybriel#156, PID 1 ignored SIGTERM, every restart waited 10 s)mre
  • ecf70665usage: layouts on components a567b57mre
  • 315731efcomponents re-synced to components.hybriel a567b57 (md-editor tables)mre
  • b59e2ee9docs/usage.md + tools/usage.sh: which app carries which component/theme/tokens copy, and whether it matches the sourcemre
  • 0222f67ctheme: two corner radii only (radiusSmall 5px, radiusLarge 10px); check-theme flags any other radius; gate 76/0mre
  • 877b63acdesign rules: two radii only (5px small, 10px large)mre
  • 635234dfcomponents re-synced to components.hybriel 5a98d77 (#15 black/white base look); gate 73/0, check-theme 0, screenshots unchangedmre
  • 876b2064docs: workaround note for hybriel#130 (slot marker mid-line)mre
  • 85b56541layouts mission 002 3/3: same-output tests, letcount, shots ports, docs, reportmre
  • 0f325d3blayouts mission 002 2/3: code rules — styles.hl -> components/styles.hl, the one never-reassigned let dropped; gate 73/0, same outputmre
  • a3e74c8alayouts mission 002 1/3: components re-copied byte-verbatim from components.hybriel 3f93d71 by tools/sync-components.sh (+ --check, components/SOURCE); gate 73/0, check-theme 0mre
  • 80ce6ba9report 001 (mission 075)mre
  • 5c6e338flayouts.worldapi.org in Hybriel: WorldAPI theme (tokens, borderless elements, themed components.hybriel components), shells (header, main/user menu, sidebar overlay, content-first, list-first, three-pane), showcase, check-theme helper; gate 73/0 (mission 075)mre