diff --git a/internal/gui/tests/reader.cjs b/internal/gui/tests/reader.cjs index ee8aecb23..1b0bec0ca 100644 --- a/internal/gui/tests/reader.cjs +++ b/internal/gui/tests/reader.cjs @@ -87,9 +87,25 @@ async function viewOf(page, locator) { } // wheeled sends one wheel over the view and waits for its scroll to land; -// false when the view didn't move in a second (it is at its end). +// false when the view didn't move in a second (it is at its end). The +// wheel is sent over a point of the view with no box of its own that +// scrolls under it: one under the pointer takes the wheel first, as +// Routing's steps did once they scrolled in 200px (ca9b5048e), and the +// view never moved. async function wheeled(page, id, dy) { - const was = await page.locator("#" + id).evaluate((v) => v.scrollTop); + const { was, x, y } = await page.locator("#" + id).evaluate((v) => { + const r = v.getBoundingClientRect(); + const scrolls = (e) => e.scrollHeight > e.clientHeight && /auto|scroll/.test(getComputedStyle(e).overflowY); + for (let fy = 0.5; fy < 1; fy += 0.1) for (const fx of [0.5, 0.15, 0.85, 0.02]) for (const s of [1, -1]) { + const x = r.left + r.width * fx, y = r.top + r.height * (s > 0 ? fy : 1 - fy); + let e = document.elementFromPoint(x, y); + if (!e || !v.contains(e)) continue; + while (e !== v && !scrolls(e)) e = e.parentElement; + if (e === v) return { was: v.scrollTop, x, y }; + } + return { was: v.scrollTop, x: r.left + r.width / 2, y: r.top + r.height / 2 }; + }); + await page.mouse.move(x, y); await page.mouse.wheel(0, dy); return page.waitForFunction(([id, was]) => document.getElementById(id).scrollTop !== was, [id, was], { timeout: 1000 }).then(() => true, () => false); } @@ -176,4 +192,14 @@ async function openAgentSettings(page, id = "codex") { await page.waitForFunction(() => __settingsReads.asked > 0 && __settingsReads.asked === __settingsReads.drawn); } -module.exports = { inView, reach, wheelTo, click, openPart, watchSettingsReads, settingsDrawn, agentRow, openAgentSettings }; +// settled waits for the page's motion to end: a routing group opening +// into its editor moves its height and parts for ~700ms (91b0be836), and +// where a control will be is read once that has stopped. Two frames pass +// first: WebKit lists an animation a click started only a frame later, so +// a look right after the click found none and went on. +async function settled(page) { + await page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r)))); + await page.waitForFunction(() => !document.getAnimations().some((a) => a.playState === "running" && Number.isFinite(a.effect?.getComputedTiming().endTime))); +} + +module.exports = { settled, inView, reach, wheelTo, click, openPart, watchSettingsReads, settingsDrawn, agentRow, openAgentSettings }; diff --git a/internal/gui/tests/routing-intent-entry.test.cjs b/internal/gui/tests/routing-intent-entry.test.cjs index bb6622a25..d33b52bf5 100644 --- a/internal/gui/tests/routing-intent-entry.test.cjs +++ b/internal/gui/tests/routing-intent-entry.test.cjs @@ -13,6 +13,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { settled } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const models = [ @@ -64,6 +65,8 @@ function serve(lang, posts) { // wheel down to a control, as the reader would (the page keeps still for // any other scroll), then click it with the mouse async function press(page, loc, height) { + // where loc will be is read once the editor has stopped moving + await settled(page); await page.mouse.move(Math.min(550, (page.viewportSize().width / 2) | 0), 300); for (let i = 0; i < 12 && (await loc.boundingBox()).y > height - 160; i++) { await page.mouse.wheel(0, 300); @@ -102,6 +105,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(await ed.locator(".rt-classifier").isVisible(), false); // a rule, its intent box focused, Jev picked; nothing scrolled + await settled(page); await page.mouse.move(Math.min(550, width / 2), 300); for (let i = 0; i < 12 && (await byIntent.boundingBox()).y > height - 160; i++) { await page.mouse.wheel(0, 300); diff --git a/internal/gui/tests/routing-manual.test.cjs b/internal/gui/tests/routing-manual.test.cjs index b52a96dbc..7a836dafc 100644 --- a/internal/gui/tests/routing-manual.test.cjs +++ b/internal/gui/tests/routing-manual.test.cjs @@ -11,6 +11,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { settled } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const models = [ @@ -129,6 +130,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // the reader wheels the editor's routing into the middle (code that // scrolls is put back: only the reader moves the view) const wheelTo = async (x) => { + // the distance is read once the editor has stopped moving + await settled(page); const d = await x.evaluate((e) => { const v = document.querySelector("#view-routing"); return Math.round(e.getBoundingClientRect().top - v.getBoundingClientRect().top - v.clientHeight / 2); }); await page.mouse.move(550, 400);