ident
All repositories: gitoria
7.6 KB
// tests/mobile.mjs — ident mobile gate (Arachne W90 sweep, mission I4): at 390 px// 1. the 404 page renders like every ident page (shell, viewport meta, a clear "not found", a 44 px way home);// 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.// Own server, real headless Chrome, real clicks. Shots (before/after, 390 + 1280) go to MOBILE_GATE_SHOTS when set.// node tests/mobile.mjsimport { spawn } from 'node:child_process';import { rmSync, mkdirSync, writeFileSync, existsSync, readFileSync } from 'node:fs';import { dirname, join, resolve } from 'node:path';import { fileURLToPath } from 'node:url';import { launchBrowser } from './cdp.mjs';if (!process.env.HL_CHROME && existsSync('/opt/google/chrome/chrome')) process.env.HL_CHROME = '/opt/google/chrome/chrome';const APP = resolve(dirname(fileURLToPath(import.meta.url)), '..');const G = join(APP, '.scratch/mobile-gate');rmSync(G, { recursive: true, force: true });mkdirSync(join(G, 'sess'), { recursive: true });const PORT = Number(process.env.MOBILE_GATE_PORT || 8711), BASE = `http://127.0.0.1:${PORT}`, SINK = join(G, 'mail.txt');const SHOTS = process.env.MOBILE_GATE_SHOTS || '';if (SHOTS) mkdirSync(SHOTS, { recursive: true });const sleep = (ms) => new Promise((r) => setTimeout(r, ms));let passed = 0, failed = 0;const check = (n, ok, d = '') => { if (ok) { passed++; console.log('ok ' + n); } else { failed++; console.log('FAIL ' + n + (d ? ' — ' + d : '')); } };let log = '';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'] });srv.stdout.on('data', (d) => log += d); srv.stderr.on('data', (d) => log += d);let browser;async function finish() {try { await browser.close(); } catch {}try { process.kill(srv.pid); } catch {}writeFileSync(join(G, 'server.log'), log);console.log(`\n${passed} passed, ${failed} failed`);process.exit(failed ? 1 : 0);}const viewport = async (p, w, h) => { await p.send('Emulation.setDeviceMetricsOverride', { width: w, height: h, deviceScaleFactor: 1, mobile: w < 600 }); await sleep(300); };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')); };try {for (let i = 0; i < 480; i++) { try { await fetch(BASE + '/'); break; } catch {} await sleep(250); }browser = await launchBrowser({ debugPortRange: (process.env.MOBILE_GATE_CHROME || '8712-8716').split('-').map(Number) });const p = await browser.newPage();const connected = () => p.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1');// ---- 1. the 404 pageconst r404 = await fetch(BASE + '/nope');check('404: /nope answers status 404', r404.status === 404, String(r404.status));await viewport(p, 390, 844);await p.goto(BASE + '/nope');await sleep(800);check('404: has the viewport meta (width=device-width)', await p.evaluate('!!document.querySelector(\'meta[name=viewport][content*="width=device-width"]\')'));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'));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")'));check('404: says "not found" clearly', await p.evaluate('/not found/i.test((document.querySelector("main h1") || {}).textContent || "") && /nope/.test((document.querySelector("#notfound") || {}).textContent || "")'));await shot(p, '404-390');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") }; })()');check('404: a way home (#gohome) is a 44 px tap', !!home && home.h >= 44 && home.href === '/', JSON.stringify(home));if (home) { await p.click('#gohome'); await p.waitFor('location.pathname === "/"'); check('404: the way home goes to /', true); }await viewport(p, 1280, 900);await p.goto(BASE + '/nope'); await sleep(800); await shot(p, '404-1280');check('404: 1280 no horizontal overflow', await p.evaluate('document.documentElement.scrollWidth <= window.innerWidth'));// ---- 2. the user menu at 390const email = '[email protected]';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); } };await viewport(p, 390, 844);await p.goto(BASE + '/');await p.waitForSelector('#email'); await connected();await p.type('#email', email, { clear: true });await p.click('#sendcode');await p.waitForSelector('#code'); await connected(); await sleep(300);await p.type('#code', await code(), { clear: true });await p.click('#verify');await p.waitForSelector('#menusignoutall'); await connected(); await sleep(500);await shot(p, 'menu-closed-390');await p.click('user-menu > button');await p.waitFor('document.querySelector("#user-menu").matches(":popover-open")');await sleep(300);await shot(p, 'menu-open-390');// every visible interactive page element outside the menu must not sit under the popoverconst hidden = await p.evaluate(`(() => {const m = document.querySelector('#user-menu').getBoundingClientRect();const out = [];for (const e of document.querySelectorAll('main button, main a, main input, main select, main textarea')) {if (e.closest('#user-menu')) continue;const r = e.getBoundingClientRect();if (r.width === 0 || r.height === 0) continue;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));}return out;})()`);check('menu: the open user menu covers no button, link or input of the page', hidden.length === 0, JSON.stringify(hidden));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 }; })`);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));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));await p.evaluate('document.querySelector("#user-menu").hidePopover()');await viewport(p, 1280, 900);await p.click('user-menu > button'); await sleep(300); await shot(p, 'menu-open-1280');check('menu: 1280 no horizontal overflow', await p.evaluate('document.documentElement.scrollWidth <= window.innerWidth'));await finish();} 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