// The smart door in a real browser (internal/calls/signin_browser_test.go, // TestSmartDoorInABrowser): every state Go names, at 320px and 1280px, // forced to light. For each it checks what a person on a phone would hit // first: nothing scrolls sideways, every link, button and field on the card // is at least 24px each way (WCAG 2.2 target size, minimum), and Continue // with Oficina ID draws its glyph. It prints one JSON line per check; Go // decides. // // node test/browser/door.mjs '{"base":"http://127.0.0.1:1234","states":[{"name":"first visit","path":"/__door/0/signin","glyph":true}],"shots":""}' // // shots, when set, is a directory each state's screenshot is written to. import { chromium } from 'playwright'; import { mkdirSync } from 'node:fs'; import { join } from 'node:path'; const config = JSON.parse(process.argv[2]); const browser = await chromium.launch({ headless: true }); try { for (const width of [320, 1280]) { const context = await browser.newContext({ viewport: { width, height: 900 }, colorScheme: 'light' }); const page = await context.newPage(); await page.emulateMedia({ colorScheme: 'light' }); for (const state of config.states) { const response = await page.goto(config.base + state.path, { waitUntil: 'load' }); const found = await page.evaluate(() => { const card = document.querySelector('[estilo-signin]') || document.querySelector('main') || document.body; const small = []; for (const el of card.querySelectorAll('a[href], button, input:not([type=hidden])')) { const box = el.getBoundingClientRect(); const style = getComputedStyle(el); if (style.display === 'none' || style.visibility === 'hidden' || box.width === 0) continue; if (box.width < 24 || box.height < 24) { small.push(`${el.tagName.toLowerCase()} "${(el.textContent || el.getAttribute('name') || '').trim().slice(0, 40)}" ${Math.round(box.width)}x${Math.round(box.height)}`); } } const oficina = [...card.querySelectorAll('a[href^="/signin/oficina"]')]; const glyph = oficina.some((a) => { const svg = a.querySelector('svg'); if (!svg) return false; const box = svg.getBoundingClientRect(); return box.width >= 12 && box.height >= 12; }); return { scroll: document.documentElement.scrollWidth - window.innerWidth, small, oficina: oficina.length, glyph, text: card.innerText.slice(0, 2000), }; }); if (config.shots) { mkdirSync(config.shots, { recursive: true }); const file = `${state.name.replace(/[^a-z0-9]+/gi, '-').toLowerCase()}-${width}.png`; await page.screenshot({ path: join(config.shots, file), fullPage: true }); } process.stdout.write(JSON.stringify({ name: state.name, width, status: response.status(), ...found }) + '\n'); } await context.close(); } } finally { await browser.close(); }