| 1 | // The Roster stream in WebKit: as an iPhone (390x844 at 3x, touch) and at |
| 2 | // 1280, light and dark. Measures testdata/roster-geometry.js with the |
| 3 | // decision card beside its report and with it set aside, and saves a shot |
| 4 | // of each when cfg.art names a directory. Prints one JSON object. |
| 5 | import { createRequire } from "node:module"; |
| 6 | import { readFileSync } from "node:fs"; |
| 7 | const require = createRequire(import.meta.url); |
| 8 | const { webkit } = require(process.env.EQUIPO_PLAYWRIGHT_CORE); |
| 9 | const cfg = JSON.parse(process.env.EQUIPO_ROSTER); |
| 10 | const geometry = readFileSync("testdata/roster-geometry.js", "utf8"); |
| 11 | const out = {}; |
| 12 | const browser = await webkit.launch(); |
| 13 | try { |
| 14 | for (const width of [390, 1280]) for (const scheme of ["light", "dark"]) { |
| 15 | const phone = width === 390; |
| 16 | const ctx = await browser.newContext(phone ? { viewport: { width, height: 844 }, deviceScaleFactor: 3, hasTouch: true, isMobile: true, colorScheme: scheme } : { viewport: { width, height: 900 }, colorScheme: scheme }); |
| 17 | await ctx.addCookies([{ name: cfg.cookie.name, value: cfg.cookie.value, url: cfg.base }]); |
| 18 | const page = await ctx.newPage(); |
| 19 | await page.goto(cfg.base + "/conversation"); |
| 20 | await page.waitForFunction(() => document.querySelector("[equipo-offline]").hidden && !!document.querySelector("[data-roster-enhanced]")); |
| 21 | const measure = phase => page.evaluate(`(${geometry})(${JSON.stringify(phase)}, ${phone})`); |
| 22 | const shot = async (name, sel) => { |
| 23 | if (!cfg.art) return; |
| 24 | if (sel) await page.evaluate(s => document.querySelector(s).scrollIntoView({ block: "center" }), sel); |
| 25 | await page.waitForTimeout(150); |
| 26 | await page.screenshot({ path: `${cfg.art}/roster-${name}-${width}-${scheme}.png` }); |
| 27 | }; |
| 28 | const res = {}; |
| 29 | await shot("report", "[equipo-roster-report]"); |
| 30 | await shot("question", "[equipo-mini-pill]"); |
| 31 | res.compact = await measure("compact"); |
| 32 | await shot("end"); |
| 33 | await page.click('[equipo-card="merge"] [data-set-aside]'); |
| 34 | await page.waitForSelector('[equipo-card="merge"] [equipo-aside-stub]'); |
| 35 | await page.waitForSelector("[equipo-roster-report] [data-track]"); |
| 36 | await shot("full", "[equipo-roster-report]"); |
| 37 | res.full = await measure("full"); |
| 38 | await page.click('[equipo-card="merge"] [equipo-aside-stub] [data-aside-undo]'); |
| 39 | await page.waitForSelector('[equipo-card="merge"] [data-set-aside]'); |
| 40 | out[`${width}-${scheme}`] = res; |
| 41 | await ctx.close(); |
| 42 | } |
| 43 | } finally { |
| 44 | await browser.close(); |
| 45 | } |
| 46 | console.log(JSON.stringify(out)); |
| 47 | |