gitoria

ident

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmain0f6d1592Merge branch 'f18b-shell-session' into mainIdentmain/tests/mobile.mjs

7.6 KB

  1. // tests/mobile.mjs — ident mobile gate (Arachne W90 sweep, mission I4): at 390 px
  2. // 1. the 404 page renders like every ident page (shell, viewport meta, a clear "not found", a 44 px way home);
  3. // 2. the open user menu hides nothing: it covers none of the page's buttons/links/inputs, and its own items are 44 px taps.
  4. // Own server, real headless Chrome, real clicks. Shots (before/after, 390 + 1280) go to MOBILE_GATE_SHOTS when set.
  5. // node tests/mobile.mjs
  6. import { spawn } from 'node:child_process';
  7. import { rmSync, mkdirSync, writeFileSync, existsSync, readFileSync } from 'node:fs';
  8. import { dirname, join, resolve } from 'node:path';
  9. import { fileURLToPath } from 'node:url';
  10. import { launchBrowser } from './cdp.mjs';
  11. if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';
  12. const APP = resolve(dirname(fileURLToPath(import.meta.url)), '..');
  13. const G = join(APP, '.scratch/mobile-gate');
  14. rmSync(G, { recursive: true, force: true });
  15. mkdirSync(join(G, 'sess'), { recursive: true });
  16. const PORT = Number(process.env.MOBILE_GATE_PORT || 8711), BASE = `http://127.0.0.1:${PORT}`, SINK = join(G, 'mail.txt');
  17. const SHOTS = process.env.MOBILE_GATE_SHOTS || '';
  18. if (SHOTS) mkdirSync(SHOTS, { recursive: true });
  19. const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
  20. let passed = 0, failed = 0;
  21. const check = (n, ok, d = '') => { if (ok) { passed++; console.log('ok ' + n); } else { failed++; console.log('FAIL ' + n + (d ? ' — ' + d : '')); } };
  22. let log = '';
  23. 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' }, stdio: ['ignore', 'pipe', 'pipe'] });
  24. srv.stdout.on('data', (d) => log += d); srv.stderr.on('data', (d) => log += d);
  25. let browser;
  26. async function finish() {
  27. try { await browser.close(); } catch {}
  28. try { process.kill(srv.pid); } catch {}
  29. writeFileSync(join(G, 'server.log'), log);
  30. console.log(`\n${passed} passed, ${failed} failed`);
  31. process.exit(failed ? 1 : 0);
  32. }
  33. const viewport = async (p, w, h) => { await p.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: w < 600 }); await sleep(300); };
  34. const shot = async (p, name) => { if (!SHOTS) return; const { data } = await p.send('Page.captureScreenshot', { format: 'png' }); writeFileSync(join(SHOTS, name + '.png'), Buffer.from(data, 'base64')); };
  35. try {
  36. for (let i = 0; i < 480; i++) { try { await fetch(BASE + '/'); break; } catch {} await sleep(250); }
  37. browser = await launchBrowser({ debugPortRange: (process.env.MOBILE_GATE_CHROME || '8712-8716').split('-').map(Number) });
  38. const p = await browser.newPage();
  39. const connected = () => p.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1');
  40. // ---- 1. the 404 page
  41. const r404 = await fetch(BASE + '/nope');
  42. check('404: /nope answers status 404', r404.status === 404, String(r404.status));
  43. await viewport(p, 390, 844);
  44. await p.goto(BASE + '/nope');
  45. await sleep(800);
  46. check('404: has the viewport meta (width=device-width)', await p.evaluate('!!document.querySelector(\'meta[name=viewport][content*="width=device-width"]\')'));
  47. check('404: lays out at the phone width (no 980 px layout)', await p.evaluate('document.documentElement.scrollWidth <= window.innerWidth && window.innerWidth <= 400'), await p.evaluate('document.documentElement.scrollWidth + "/" + window.innerWidth'));
  48. check('404: renders in the app shell (header with the brand)', await p.evaluate('!!document.querySelector("application-header") && /ident/.test(document.querySelector("application-header").textContent) && !!document.querySelector("main identity-card, main ident-card")'));
  49. check('404: says "not found" clearly', await p.evaluate('/not found/i.test((document.querySelector("main h1") || {}).textContent || "") && /nope/.test((document.querySelector("#notfound") || {}).textContent || "")'));
  50. await shot(p, '404-390');
  51. const home = await p.evaluate('(() => { const a = document.querySelector("#gohome"); if (!a) return null; const r = a.getBoundingClientRect(); return { h: r.height, w: r.width, href: a.getAttribute("href") }; })()');
  52. check('404: a way home (#gohome) is a 44 px tap', !!home && home.h >= 44 && home.href === '/', JSON.stringify(home));
  53. if (home) { await p.click('#gohome'); await p.waitFor('location.pathname === "/"'); check('404: the way home goes to /', true); }
  54. await viewport(p, 1280, 900);
  55. await p.goto(BASE + '/nope'); await sleep(800); await shot(p, '404-1280');
  56. check('404: 1280 no horizontal overflow', await p.evaluate('document.documentElement.scrollWidth <= window.innerWidth'));
  57. // ---- 2. the user menu at 390
  58. const email = '[email protected]';
  59. 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); } };
  60. await viewport(p, 390, 844);
  61. await p.goto(BASE + '/');
  62. await p.waitForSelector('#email'); await connected();
  63. await p.type('#email', email, { clear: true });
  64. await p.click('#sendcode');
  65. await p.waitForSelector('#code'); await connected(); await sleep(300);
  66. await p.type('#code', await code(), { clear: true });
  67. await p.click('#verify');
  68. await p.waitForSelector('#menusignoutall'); await connected(); await sleep(500);
  69. await shot(p, 'menu-closed-390');
  70. await p.click('user-menu > button');
  71. await p.waitFor('document.querySelector("#user-menu").matches(":popover-open")');
  72. await sleep(300);
  73. await shot(p, 'menu-open-390');
  74. // every visible interactive page element outside the menu must not sit under the popover
  75. const hidden = await p.evaluate(`(() => {
  76. const m = document.querySelector('#user-menu').getBoundingClientRect();
  77. const out = [];
  78. for (const e of document.querySelectorAll('main button, main a, main input, main select, main textarea')) {
  79. if (e.closest('#user-menu')) continue;
  80. const r = e.getBoundingClientRect();
  81. if (r.width === 0 || r.height === 0) continue;
  82. if (r.left < m.right && r.right > m.left && r.top < m.bottom && r.bottom > m.top) out.push((e.id || e.textContent.trim()).slice(0, 30));
  83. }
  84. return out;
  85. })()`);
  86. check('menu: the open user menu covers no button, link or input of the page', hidden.length === 0, JSON.stringify(hidden));
  87. const items = await p.evaluate(`[...document.querySelectorAll('#user-menu a, #user-menu button')].map(e => { const r = e.getBoundingClientRect(); const t = document.elementFromPoint(r.left + r.width / 2, r.top + r.height / 2); return { id: e.id, h: Math.round(r.height), reach: !!t && (t === e || e.contains(t)), inView: r.left >= 0 && r.right <= innerWidth && r.bottom <= innerHeight }; })`);
  88. check('menu: it has items, each a reachable 44 px tap inside the screen', items.length >= 1 && items.every((i) => i.h >= 44 && i.reach && i.inView), JSON.stringify(items));
  89. check('menu: Sign out and Sign out everywhere are both in the menu', items.some((i) => i.id === 'menusignout') && items.some((i) => i.id === 'menusignoutall'), JSON.stringify(items));
  90. await p.evaluate('document.querySelector("#user-menu").hidePopover()');
  91. await viewport(p, 1280, 900);
  92. await p.click('user-menu > button'); await sleep(300); await shot(p, 'menu-open-1280');
  93. check('menu: 1280 no horizontal overflow', await p.evaluate('document.documentElement.scrollWidth <= window.innerWidth'));
  94. await finish();
  95. } catch (e) { check('gate ran to the end', false, String(e && e.stack || e)); await finish(); }

Branches

Latest commits

  • 0f6d1592Merge branch 'f18b-shell-session' into mainIdent
  • 19868218|||PR ident#39 shell reads its session member instead of a cross-file emitmre
  • 5d1b3fedMerge branch 'v61-day61' into mainIdent
  • 83faeb15|||PR ident: vendor Hybriel day61mre
  • b2572b34Merge branch 'v59-day59' into mainIdent
  • 67cf016d|||PR ident: vendor Hybriel day59mre
  • 600c043dMerge branch 'v58-day58' into mainIdent
  • 365f8c80|||PR ident: vendor Hybriel day58mre
  • 585126e5Merge branch 'f16-setf' into mainIdent
  • 953bf03a|||PR ident setF mirror dropped (hybriel#370)mre
  • a1419d9cMerge branch 'f15-navigate' into mainIdent
  • 3b3e451f|||PR ident#36 navigate to the app instead of location.assignmre
  • e36f4516Merge branch 'f14-online' into mainIdent
  • 2c5eac91|||PR ident#38 online state without probe timermre
  • bf1980f2Merge branch 'v56-day56' into mainIdent
  • 62ae0adf|||PR ident: vendor Hybriel day56mre
  • 0d18abc4Merge branch 'f13-avatar' into mainIdent
  • 2a99730a|||PR ident#37 avatar in hlmre
  • fa4ed25bMerge branch 'f11-upsert' into mainIdent
  • 8f3d9bc9|||PR ident#42 keyed upsert and removemre