/** * Flagship views QA: /explore, /trajectories, /scatter, /finder, /extremes × 320/375/390/430/768/1440/1920. * Checks: HTTP 200, no horizontal overflow, no console errors, no failed requests, tap targets ≥ 44 px on phones; * exercises the year slider (arrow keys + play 2 s) and a country tap on /explore at 390 and 1440. * Screenshots → qa/screens/flagship/-.png; report → qa/screens/flagship/report.json. * node qa/flagship-qa.mjs [BASE_URL] */ import { chromium } from '/Users/simon-pierreboucher/Desktop/uqo-eval/node_modules/playwright/index.mjs'; import { mkdirSync, writeFileSync } from 'node:fs'; const BASE = process.argv[2] ?? process.env.BASE_URL ?? 'http://localhost:8290'; const OUT = new URL('./screens/flagship/', import.meta.url).pathname; mkdirSync(OUT, { recursive: true }); const ROUTES = ['/explore', '/explore?indicator=life-expectancy&year=1990&view=rank', '/trajectories', '/scatter', '/finder?f=gdp-per-capita:gt:40000&f=population:gt:10000000', '/extremes?window=10']; const WIDTHS = [320, 375, 390, 430, 768, 1440, 1920]; const slug = (p) => p.slice(1).replace(/[/?=&:,]+/g, '_'); const report = []; const browser = await chromium.launch(); for (const width of WIDTHS) { const mobile = width < 768; const ctx = await browser.newContext({ viewport: { width, height: mobile ? 844 : 1000 }, deviceScaleFactor: 1, isMobile: mobile, hasTouch: mobile }); const page = await ctx.newPage(); const errors = []; const failed = []; page.on('pageerror', (e) => errors.push(`pageerror: ${String(e).slice(0, 160)}`)); page.on('console', (m) => { if (m.type() === 'error') errors.push(m.text().slice(0, 160)); }); page.on('requestfailed', (r) => { if (!r.url().includes('_rsc')) failed.push(r.url().slice(BASE.length)); }); for (const path of ROUTES) { let status = 0; try { const resp = await page.goto(BASE + path, { waitUntil: 'networkidle', timeout: 90_000 }); status = resp?.status() ?? 0; } catch (e) { report.push({ path, width, status: 'ERR', error: String(e).slice(0, 160) }); continue; } await page.evaluate(() => document.fonts.ready); await page.waitForTimeout(600); if (path.startsWith('/explore') && (width === 390 || width === 1440)) { const range = page.locator('input[type=range]').first(); if (await range.count()) { await range.focus(); for (let i = 0; i < 8; i++) await page.keyboard.press('ArrowLeft'); await page.waitForTimeout(300); const play = page.locator('button[aria-label="Play"]').first(); if (await play.count()) { await play.click(); await page.waitForTimeout(2000); await page.locator('button[aria-label="Pause"]').first().click().catch(() => {}); } const br = page.locator('path[aria-label^="Brazil"]').first(); if (await br.count()) { await br.click({ force: true }).catch(() => {}); await page.waitForTimeout(600); } } } const m = await page.evaluate(({ mobile }) => { const de = document.documentElement; const overflow = de.scrollWidth - de.clientWidth; const vis = (el) => { const r = el.getBoundingClientRect(); if (!r.width || !r.height) return false; const cs = getComputedStyle(el); return cs.visibility !== 'hidden' && cs.display !== 'none'; }; const targets = [...document.querySelectorAll('a,button,[role=button],input,select,[role=radio],[role=tab]')].filter(vis).filter((el) => !el.closest('svg')); const small = mobile ? targets.filter((el) => { const r = el.getBoundingClientRect(); return r.height < 44 && r.width < 44; }).map((el) => `${el.tagName.toLowerCase()} "${(el.getAttribute('aria-label') || el.textContent || '').trim().slice(0, 30)}" ${Math.round(el.getBoundingClientRect().width)}x${Math.round(el.getBoundingClientRect().height)}`) : []; const text = document.body.innerText || ''; const bad = []; for (const re of [/\bundefined\b/g, /\bNaN\b/g]) { let mm; while ((mm = re.exec(text)) && bad.length < 3) bad.push(text.slice(Math.max(0, mm.index - 30), mm.index + 20)); } return { overflow, small: small.slice(0, 8), nSmall: small.length, bad, title: document.title, url: location.href }; }, { mobile }); const file = `${slug(path)}-${width}.png`; await page.screenshot({ path: OUT + file, fullPage: !path.startsWith('/explore') && !path.startsWith('/trajectories') }).catch(() => {}); report.push({ path, width, status, ...m, errors: errors.splice(0), failed: failed.splice(0), file }); } await ctx.close(); } await browser.close(); writeFileSync(OUT + 'report.json', JSON.stringify(report, null, 2)); let fails = 0; for (const r of report) { const flags = []; if (r.status !== 200) flags.push(`HTTP ${r.status}`); if (r.overflow > 0) flags.push(`OVERFLOW +${r.overflow}px`); if (r.nSmall) flags.push(`${r.nSmall} small targets`); if (r.bad?.length) flags.push(`BAD TEXT ${r.bad.length}`); if (r.errors?.length) flags.push(`${r.errors.length} console errors`); if (r.failed?.length) flags.push(`${r.failed.length} failed requests`); if (flags.length) fails++; console.log(`${String(r.width).padStart(4)} ${r.path.padEnd(60)} ${flags.join(' · ') || 'ok'}`); if (r.small?.length) console.log(' small:', r.small.slice(0, 4).join(' | ')); if (r.errors?.length) console.log(' errors:', r.errors.slice(0, 2).join(' | ')); if (r.failed?.length) console.log(' failed:', r.failed.slice(0, 3).join(' | ')); if (r.bad?.length) console.log(' bad:', r.bad.join(' | ')); } console.log(`\n${report.length} renders, ${fails} with flags`);