| 1 | // The smart door in a real browser (internal/calls/signin_browser_test.go, |
| 2 | // TestSmartDoorInABrowser): every state Go names, at 320px and 1280px, |
| 3 | // forced to light. For each it checks what a person on a phone would hit |
| 4 | // first: nothing scrolls sideways, every link, button and field on the card |
| 5 | // is at least 24px each way (WCAG 2.2 target size, minimum), and Continue |
| 6 | // with Oficina ID draws its glyph. It prints one JSON line per check; Go |
| 7 | // decides. |
| 8 | // |
| 9 | // node test/browser/door.mjs '{"base":"http://127.0.0.1:1234","states":[{"name":"first visit","path":"/__door/0/signin","glyph":true}],"shots":""}' |
| 10 | // |
| 11 | // shots, when set, is a directory each state's screenshot is written to. |
| 12 | import { chromium } from 'playwright'; |
| 13 | import { mkdirSync } from 'node:fs'; |
| 14 | import { join } from 'node:path'; |
| 15 | |
| 16 | const config = JSON.parse(process.argv[2]); |
| 17 | const browser = await chromium.launch({ headless: true }); |
| 18 | try { |
| 19 | for (const width of [320, 1280]) { |
| 20 | const context = await browser.newContext({ viewport: { width, height: 900 }, colorScheme: 'light' }); |
| 21 | const page = await context.newPage(); |
| 22 | await page.emulateMedia({ colorScheme: 'light' }); |
| 23 | for (const state of config.states) { |
| 24 | const response = await page.goto(config.base + state.path, { waitUntil: 'load' }); |
| 25 | const found = await page.evaluate(() => { |
| 26 | const card = document.querySelector('[estilo-signin]') || document.querySelector('main') || document.body; |
| 27 | const small = []; |
| 28 | for (const el of card.querySelectorAll('a[href], button, input:not([type=hidden])')) { |
| 29 | const box = el.getBoundingClientRect(); |
| 30 | const style = getComputedStyle(el); |
| 31 | if (style.display === 'none' || style.visibility === 'hidden' || box.width === 0) continue; |
| 32 | if (box.width < 24 || box.height < 24) { |
| 33 | small.push(`${el.tagName.toLowerCase()} "${(el.textContent || el.getAttribute('name') || '').trim().slice(0, 40)}" ${Math.round(box.width)}x${Math.round(box.height)}`); |
| 34 | } |
| 35 | } |
| 36 | const oficina = [...card.querySelectorAll('a[href^="/signin/oficina"]')]; |
| 37 | const glyph = oficina.some((a) => { |
| 38 | const svg = a.querySelector('svg'); |
| 39 | if (!svg) return false; |
| 40 | const box = svg.getBoundingClientRect(); |
| 41 | return box.width >= 12 && box.height >= 12; |
| 42 | }); |
| 43 | return { |
| 44 | scroll: document.documentElement.scrollWidth - window.innerWidth, |
| 45 | small, |
| 46 | oficina: oficina.length, |
| 47 | glyph, |
| 48 | text: card.innerText.slice(0, 2000), |
| 49 | }; |
| 50 | }); |
| 51 | if (config.shots) { |
| 52 | mkdirSync(config.shots, { recursive: true }); |
| 53 | const file = `${state.name.replace(/[^a-z0-9]+/gi, '-').toLowerCase()}-${width}.png`; |
| 54 | await page.screenshot({ path: join(config.shots, file), fullPage: true }); |
| 55 | } |
| 56 | process.stdout.write(JSON.stringify({ name: state.name, width, status: response.status(), ...found }) + '\n'); |
| 57 | } |
| 58 | await context.close(); |
| 59 | } |
| 60 | } finally { |
| 61 | await browser.close(); |
| 62 | } |
| 63 | |