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
- 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
- f9d6fb38ident#34: apps and identity rows: the Edit/New secret/Delete buttons carry name=..., the API key is found by its element; unused row classes (app, identity, shortid) droppedmre
- b323265aMerge branch 'f5-styles' into mainIdent
- 9ced53c3|||PR ident#33 ident#35 every component's styles live in its own Style block; styles.hl keeps the page-wide rest; the account bar is phone first (min-width: 60rem block); the avatar preview is hidden with the hidden attribute (ident#34 in part)mre
- f28333e4ident#33 ident#35: styles.hl keeps only the accent, the page column and the shared patterns; the account bar is written phone first (base rule + one min-width: 60rem block) instead of a max-width overridemre
- 5b4541fcident#33: the selector sign-in frame's rules move into embed.hl's Stylemre