diff --git a/internal/gui/tests/bare-ids.test.cjs b/internal/gui/tests/bare-ids.test.cjs index 93ff26ca6..6a7483cb6 100644 --- a/internal/gui/tests/bare-ids.test.cjs +++ b/internal/gui/tests/bare-ids.test.cjs @@ -11,7 +11,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); -const { watchSettingsReads, settingsDrawn } = require("./reader.cjs"); +const { watchSettingsReads, settingsDrawn, wheelTo } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -114,11 +114,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // scrolled by a wheel till the row is mid-view, On moves nothing and // is posted on its own - const box = await page.locator("#view-settings").boundingBox(); - await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2); - const top = () => page.locator("#bareIdsSegs").evaluate((e) => e.getBoundingClientRect().top); - for (let i = 0; i < 40 && (await top()) > 200; i++) { await page.mouse.wheel(0, 100); await page.waitForTimeout(30); } - await page.waitForTimeout(300); + // (each wheel's scroll lands before the next: a fixed pause read + // the row's place from before it under load, wheeled past the row, + // under the header, and the click was on a control out of sight, + // which the page brought back into view as it took focus, #2370) + await wheelTo(page, segs.nth(1), 200); const before = await view(page); assert(before > 0, "the settings list must scroll to the row"); await segs.nth(1).click(); diff --git a/internal/gui/tests/codex-auto-review.test.cjs b/internal/gui/tests/codex-auto-review.test.cjs index 3add8dbec..4f5b46dde 100644 --- a/internal/gui/tests/codex-auto-review.test.cjs +++ b/internal/gui/tests/codex-auto-review.test.cjs @@ -11,7 +11,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); -const { watchSettingsReads, settingsDrawn } = require("./reader.cjs"); +const { watchSettingsReads, settingsDrawn, wheelTo } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -103,10 +103,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // scrolled by a wheel till the row is mid-view, so a click that // moved the page would show - const box = await page.locator("#view-settings").boundingBox(); - await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2); - const top = () => pick.evaluate((e) => e.getBoundingClientRect().top); - for (let i = 0; i < 40 && (await top()) > 200; i++) { await page.mouse.wheel(0, 100); await page.waitForTimeout(30); } + await wheelTo(page, pick, 200); // each wheel landed before the next (#2370) const before = await view(page); assert(before > 0, "the settings list must scroll to the row"); diff --git a/internal/gui/tests/codex-descriptions.test.cjs b/internal/gui/tests/codex-descriptions.test.cjs index 0e11fcbcd..192de58cf 100644 --- a/internal/gui/tests/codex-descriptions.test.cjs +++ b/internal/gui/tests/codex-descriptions.test.cjs @@ -12,7 +12,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); -const { watchSettingsReads, settingsDrawn } = require("./reader.cjs"); +const { watchSettingsReads, settingsDrawn, wheelTo } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -104,10 +104,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // scrolled by a wheel till the row is mid-view, so a click that // moved the page would show - const box = await page.locator("#view-settings").boundingBox(); - await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2); - const top = () => pick.evaluate((e) => e.getBoundingClientRect().top); - for (let i = 0; i < 40 && (await top()) > 200; i++) { await page.mouse.wheel(0, 100); await page.waitForTimeout(30); } + await wheelTo(page, pick, 200); // each wheel landed before the next (#2370) const before = await view(page); assert(before > 0, "the settings list must scroll to the row"); diff --git a/internal/gui/tests/codex-titles.test.cjs b/internal/gui/tests/codex-titles.test.cjs index d46715260..d6b991317 100644 --- a/internal/gui/tests/codex-titles.test.cjs +++ b/internal/gui/tests/codex-titles.test.cjs @@ -11,7 +11,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); -const { watchSettingsReads, settingsDrawn } = require("./reader.cjs"); +const { watchSettingsReads, settingsDrawn, wheelTo } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -103,10 +103,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // scrolled by a wheel till the row is mid-view, so a click that // moved the page would show - const box = await page.locator("#view-settings").boundingBox(); - await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2); - const top = () => pick.evaluate((e) => e.getBoundingClientRect().top); - for (let i = 0; i < 40 && (await top()) > 200; i++) { await page.mouse.wheel(0, 100); await page.waitForTimeout(30); } + await wheelTo(page, pick, 200); // each wheel landed before the next (#2370) const before = await view(page); assert(before > 0, "the settings list must scroll to the row"); diff --git a/internal/gui/tests/reader.cjs b/internal/gui/tests/reader.cjs index 3fd3b2885..c2b45ac74 100644 --- a/internal/gui/tests/reader.cjs +++ b/internal/gui/tests/reader.cjs @@ -33,12 +33,19 @@ async function inView(page, locator) { // isn't the reader's, and one partly in sight it doesn't scroll at all, so // its press can wait on a control out of sight or under a bar till it times // out (in WebKit; Chromium gets through some of these by a few pixels). +// Each wheel step waits for its scroll to land before the control is +// looked at again: a wheel's scroll reaches the page a frame or more after +// it is sent, and on a busy machine a fixed pause read where the control +// was before it. The next step was sent on that stale reading, the view +// went past the control, under the header, and the click that followed +// was on a control out of sight (#2370). async function reach(page, locator) { await locator.waitFor({ state: "visible" }); const id = await locator.evaluate((e) => e.closest(".view")?.id || ""); if (!id) return; const v = await page.locator("#" + id).boundingBox(); await page.mouse.move(v.x + v.width / 2, v.y + v.height / 2); + let stalls = 0; for (let i = 0; i < 120; i++) { const at = await locator.evaluate((e) => { const b = e.getBoundingClientRect(), v = e.closest(".view").getBoundingClientRect(); @@ -47,12 +54,38 @@ async function reach(page, locator) { return { clear: inside && !!hit && (e === hit || e.contains(hit)), down: y > v.top + v.height / 2 }; }); if (at.clear) { await page.waitForTimeout(300); return; } - await page.mouse.wheel(0, at.down ? 20 : -20); - await page.waitForTimeout(40); + // landed, or the view is at its end and the wheel moves nothing: three + // of those in turn and the control can't be brought clear + stalls = (await wheeled(page, id, at.down ? 20 : -20)) ? 0 : stalls + 1; + if (stalls >= 3) break; } throw new Error("control did not come clear into sight: " + JSON.stringify({ view: v, target: await locator.boundingBox() })); } +// 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). +async function wheeled(page, id, dy) { + const was = await page.locator("#" + id).evaluate((v) => v.scrollTop); + await page.mouse.wheel(0, dy); + return page.waitForFunction(([id, was]) => document.getElementById(id).scrollTop !== was, [id, was], { timeout: 1000 }).then(() => true, () => false); +} + +// wheelTo scrolls the page the way a reader does, down till the control's +// top is at y or above, so a click that moved the page would show; then +// reach makes sure it is clear in sight. Each wheel lands before the +// control is looked at again (#2370). +async function wheelTo(page, locator, y) { + await locator.waitFor({ state: "visible" }); + const id = await locator.evaluate((e) => e.closest(".view")?.id || ""); + const v = await page.locator("#" + id).boundingBox(); + await page.mouse.move(v.x + v.width / 2, v.y + v.height / 2); + for (let i = 0; i < 80; i++) { + if ((await locator.evaluate((e) => e.getBoundingClientRect().top)) <= y) break; + if (!(await wheeled(page, id, 50))) break; + } + await reach(page, locator); +} + async function click(page, locator) { await inView(page, locator); await locator.click(); @@ -104,4 +137,4 @@ async function openPart(page, id) { await page.locator(`:is(#setTab-${id}, .nav-s[data-of=setTab-${id}]):visible`).press("Enter"); } -module.exports = { inView, reach, click, openPart, watchSettingsReads, settingsDrawn }; +module.exports = { inView, reach, wheelTo, click, openPart, watchSettingsReads, settingsDrawn };