gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit4b94a5944b94a594ident#34: tests: fix selector of the identity choicemre4b94a594/tests/docs.mjs

8.9 KB

  1. // tests/docs.mjs — GATE ident#45: /docs shows docs/IDENT.md, the only source of the text, in ident's shell.
  2. // 1. signed out: GET /docs is 200 and carries every heading of docs/IDENT.md; in headless Chrome at 390 px the page renders in
  3. // the shell, every heading is there, nothing makes the page wider than the screen (code blocks scroll inside themselves), the
  4. // console is clean.
  5. // 2. signed in (real sign-in with the mail sink): the main menu has ONE "Docs" entry; a real click on it opens /docs; same checks
  6. // at 390 and at 1280 px.
  7. // On code without the page the first check fails (/docs is the 404 page). Own server, own storage, real headless Chrome on loreana.
  8. // Shots go to DOCS_GATE_SHOTS when set. Run: node tests/docs.mjs
  9. import { spawn } from 'node:child_process';
  10. import { rmSync, mkdirSync, writeFileSync, existsSync, readFileSync } from 'node:fs';
  11. import { dirname, join, resolve } from 'node:path';
  12. import { fileURLToPath } from 'node:url';
  13. import { launchBrowser } from './cdp.mjs';
  14. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  15. const APP = resolve(dirname(fileURLToPath(import.meta.url)), '..');
  16. const G = join(APP, '.scratch/docs-gate');
  17. rmSync(G, { recursive: true, force: true });
  18. mkdirSync(join(G, 'sess'), { recursive: true });
  19. const PORT = Number(process.env.DOCS_GATE_PORT || 8782), BASE = `http://127.0.0.1:${PORT}`, SINK = join(G, 'mail.txt');
  20. const SHOTS = process.env.DOCS_GATE_SHOTS || '';
  21. if (SHOTS) mkdirSync(SHOTS, { recursive: true });
  22. const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
  23. let passed = 0, failed = 0;
  24. const check = (n, ok, d = '') => { if (ok) { passed++; console.log('ok ' + n); } else { failed++; console.log('FAIL ' + n + (d ? ' — ' + d : '')); } };
  25. // the headings of the source, as a reader sees them (Markdown marks removed)
  26. const plain = (s) => s.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1').replace(/[*`_]/g, '').replace(/\s+/g, ' ').trim();
  27. const headings = readFileSync(join(APP, 'docs/IDENT.md'), 'utf8').split('\n').filter((l) => /^#{1,6} /.test(l)).map((l) => plain(l.replace(/^#+ /, '')));
  28. let log = '';
  29. const srv = spawn(join(APP, 'bin/hybriel'), ['project.hl'], { cwd: APP, env: { ...process.env, SMTP_HOST: '', IDENT_PORT: String(PORT), IDENT_STORAGE: join(G, 'store'), IDENT_SESSIONS: join(G, 'sess'), IDENT_MAIL_SINK: SINK, IDENT_IP_LIMIT: '1000', IDENT_IP_DAY_LIMIT: '1000', IDENT_WATCH: '0' }, stdio: ['ignore', 'pipe', 'pipe'] });
  30. srv.stdout.on('data', (d) => log += d); srv.stderr.on('data', (d) => log += d);
  31. let browser;
  32. async function finish() {
  33. try { await browser.close(); } catch {}
  34. try { process.kill(srv.pid); } catch {}
  35. writeFileSync(join(G, 'server.log'), log);
  36. console.log(`\n${passed} passed, ${failed} failed`);
  37. process.exit(failed ? 1 : 0);
  38. }
  39. const viewport = async (p, w, h) => { await p.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: w < 600 }); await sleep(300); };
  40. const shot = async (p, name, full = false) => {
  41. if (!SHOTS) return;
  42. const opts = { format: 'png' };
  43. if (full) { const m = await p.send('Page.getLayoutMetrics'); opts.captureBeyondViewport = true; opts.clip = { x: 0, y: 0, width: m.cssContentSize.width, height: Math.min(m.cssContentSize.height, 6000), scale: 1 }; }
  44. const { data } = await p.send('Page.captureScreenshot', opts); writeFileSync(join(SHOTS, name + '.png'), Buffer.from(data, 'base64'));
  45. };
  46. // what a reader of the page sees: the headings, the width, the code blocks
  47. const pageState = (p) => p.evaluate(`(() => {
  48. const hs = [...document.querySelectorAll('main docs-page h1, main docs-page h2, main docs-page h3, main docs-page h4')].map((h) => h.textContent.replace(/\\s+/g, ' ').trim());
  49. const pres = [...document.querySelectorAll('docs-page pre')];
  50. const preBad = pres.filter((x) => { const r = x.getBoundingClientRect(); return r.right > window.innerWidth + 1 || r.left < -1 || getComputedStyle(x).overflowX !== 'auto'; }).length;
  51. return { hs, pres: pres.length, preBad, sw: document.documentElement.scrollWidth, iw: window.innerWidth, shell: !!document.querySelector('application-header') };
  52. })()`);
  53. const pageChecks = async (p, label) => {
  54. const s = await pageState(p);
  55. const missing = headings.filter((h) => !s.hs.includes(h));
  56. check(label + ': renders in the shell (header)', s.shell);
  57. check(label + ': every heading of docs/IDENT.md is on the page (' + headings.length + ')', headings.length > 5 && missing.length === 0, 'missing ' + JSON.stringify(missing) + ' page ' + JSON.stringify(s.hs.slice(0, 4)));
  58. check(label + ': the code blocks are there and scroll inside themselves', s.pres > 0 && s.preBad === 0, JSON.stringify({ pres: s.pres, bad: s.preBad }));
  59. check(label + ': nothing makes the page wider than the screen', s.sw <= s.iw, s.sw + '/' + s.iw);
  60. };
  61. try {
  62. for (let i = 0; i < 480; i++) { try { await fetch(BASE + '/'); break; } catch {} await sleep(250); }
  63. // ---- 1. signed out, plain HTTP
  64. const r = await fetch(BASE + '/docs');
  65. const html = await r.text();
  66. check('GET /docs answers 200 signed out', r.status === 200, String(r.status));
  67. const htmlText = html.replace(/<[^>]*>/g, '').replace(/&amp;/g, '&').replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/\s+/g, ' ');
  68. const notInHtml = headings.filter((h) => !htmlText.includes(h));
  69. check('the server HTML carries every heading of docs/IDENT.md', notInHtml.length === 0, JSON.stringify(notInHtml));
  70. browser = await launchBrowser({ debugPortRange: (process.env.DOCS_GATE_CHROME || '8783-8786').split('-').map(Number) });
  71. const p = await browser.newPage();
  72. const connected = () => p.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1');
  73. await viewport(p, 390, 844);
  74. await p.goto(BASE + '/docs'); await connected(); await sleep(800);
  75. await pageChecks(p, 'signed out 390');
  76. await shot(p, 'docs-out-390-top');
  77. await p.evaluate('document.querySelector("docs-page pre").scrollIntoView()'); await sleep(300);
  78. await shot(p, 'docs-out-390-code');
  79. check('signed out 390: console clean', p.problems().length === 0, p.dumpConsole());
  80. // ---- 2. signed in: the menu's Docs entry
  81. const email = '[email protected]';
  82. const code = async () => { for (let i = 0; i < 30; i++) { if (existsSync(SINK)) { const l = readFileSync(SINK, 'utf8').split('\n').filter((x) => x.startsWith(email + ' ')); if (l.length) return l.at(-1).split(' ')[1]; } await sleep(100); } };
  83. await viewport(p, 1280, 900);
  84. await p.goto(BASE + '/');
  85. await p.waitForSelector('#email'); await connected();
  86. await p.type('#email', email, { clear: true });
  87. await p.click('#sendcode');
  88. await p.waitForSelector('#code'); await connected(); await sleep(300);
  89. await p.type('#code', await code(), { clear: true });
  90. await p.click('#verify');
  91. await p.waitForSelector('#menusignoutall'); await connected(); await sleep(500);
  92. await shot(p, 'header-in-1280');
  93. const entries = await p.evaluate('[...document.querySelectorAll("application-header main-menu a")].map((a) => a.textContent.trim() + " " + a.getAttribute("href"))');
  94. check('signed in 1280: the header menu has one Docs entry after Apps (and the Access entry, ident#27)', JSON.stringify(entries) === JSON.stringify(['Identities /', 'Inbox /inbox', 'Apps /apps', 'Access /access', 'Docs /docs']), JSON.stringify(entries));
  95. await p.click('application-header main-menu a[href="/docs"]');
  96. await p.waitFor('location.pathname === "/docs" && !!document.querySelector("docs-page h1")'); await sleep(800);
  97. await pageChecks(p, 'signed in 1280');
  98. await shot(p, 'docs-in-1280-top');
  99. await p.evaluate('document.querySelector("docs-page pre").scrollIntoView()'); await sleep(300);
  100. await shot(p, 'docs-in-1280-code');
  101. check('signed in 1280: the Docs entry is marked as the current page', await p.evaluate('(() => { const a = document.querySelector("application-header main-menu a[href=\\"/docs\\"]"); return !!a && (a.getAttribute("aria-current") === "page" || a.matches(".current, .active")); })()'));
  102. await viewport(p, 390, 844);
  103. await p.goto(BASE + '/docs'); await connected(); await sleep(800);
  104. await pageChecks(p, 'signed in 390');
  105. await shot(p, 'docs-in-390-top');
  106. await shot(p, 'docs-in-390-full', true);
  107. // the phone's menu (☰ → the sidebar): the same Docs entry
  108. await p.click('application-header > button.menu-toggle');
  109. await p.waitFor('document.querySelector("#sidebar").matches(":popover-open")'); await sleep(400);
  110. await shot(p, 'menu-in-390');
  111. const side = await p.evaluate('[...document.querySelectorAll("#sidebar main-menu a")].map((a) => a.textContent.trim() + " " + a.getAttribute("href"))');
  112. check('signed in 390: the phone menu has one Docs entry after Apps (and the Access entry, ident#27)', JSON.stringify(side) === JSON.stringify(['Identities /', 'Inbox /inbox', 'Apps /apps', 'Access /access', 'Docs /docs']), JSON.stringify(side));
  113. check('signed in: console clean', p.problems().length === 0, p.dumpConsole());
  114. } catch (e) {
  115. check('no exception', false, e.stack || String(e));
  116. }
  117. await finish();

Branches

Latest commits

  • 4b94a594ident#34: tests: fix selector of the identity choicemre
  • bebc88e4ident#34: main.hl drops the unstyled classes inboxlink and whomre
  • b4e7ad04ident#34: the identity choice link/button has no class (rule on #chooselist a)mre
  • 3c33d6eaident#34: the connection link in inbox has no class (rule on #conns a)mre
  • dc97ec0dident#34: the Notif. chip and the Used in link share chipLook (Style.pChip) instead of the classes chip/used/notifmre
  • 378bd432ident#34: the identity picture look is a static in styles.hl (Style.pAvatar); sizes stay with each listmre
  • 1cf79e7eident#34: the wide page column is a static in styles.hl (Style.pWide), not the class "wide"mre
  • ddc7d135Merge branch 'f7-hooks' into mainIdent
  • eee0b513|||PR ident#34 part: test-hook classes replaced by name/element/attribute selectors (tests adjusted), the shared lead/message/notice looks are statics in styles.hlmre
  • ccd6d0c4ident#34: browser gate: rowButton finds the row's button by namemre
  • 24dd414eident#34: the shared lead, message and notice looks are statics in components/styles.hl, imported by the components (lib/looks.hl gone)mre
  • 03ed26c7ident#34: access.hl: the remaining lead classes droppedmre
  • 1d066c42ident#34: access.hl drops its unstyled lead class (the shared lead rule would otherwise mute it)mre
  • 1e1dd7b4ident#34: the access page keeps its lead class string (the page has no ident-card, so its lead line was never muted; a shared rule would change the look)mre
  • 89ac6553ident#34: the lead, message and notice lines are named with Style.pLead / pMessage / pNotice (shared bodies in lib/looks.hl) instead of class stringsmre
  • e84be3deident#34: browser gate lists the Edit/Delete buttons by namemre
  • fb7111faident#34: access page: unstyled test-hook classes (idrow, never, who, whoname, appname, neverrevoke) dropped; the tests use element/name selectorsmre
  • 9f2ad803ident#34: notification switches: push/email by name=..., locked by aria-disabled, the switch look is the role=switch button (no switch/push/email/locked classes)mre
  • e0f0ddaaident#34: inbox: the Mark read/unread button is styled as the button of its note-foot, the icon is found as the row's img (no toggle/icon classes)mre
  • 16b49756ident#34: unused row classes (choice, usedrow, kind, shortid) droppedmre