diff --git a/internal/gui/tests/pick-skills.test.cjs b/internal/gui/tests/pick-skills.test.cjs index 73e197db9..6cc166844 100644 --- a/internal/gui/tests/pick-skills.test.cjs +++ b/internal/gui/tests/pick-skills.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 { reach } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const HOME = "/Users/me"; @@ -100,6 +101,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await v.locator(".lib-select").click(); assert.equal((await v.locator(".lib-select").textContent()).trim(), w.done); await row("pdf").locator(".lib-pickbox").waitFor(); + // pdf sits partly under the bar Select brings up (the window's page + // beside the sidebar since 18e82adc6): the reader scrolls it out + await reach(page, row("pdf").locator(".name")); const top = await v.evaluate((x) => x.scrollTop); await row("pdf").locator(".name").click(); assert.equal(await row("pdf").locator(".lib-pickbox").isChecked(), true); diff --git a/internal/gui/tests/reader.cjs b/internal/gui/tests/reader.cjs index 93b40f9a4..081deb0de 100644 --- a/internal/gui/tests/reader.cjs +++ b/internal/gui/tests/reader.cjs @@ -26,6 +26,33 @@ async function inView(page, locator) { throw new Error("control did not come into sight: " + JSON.stringify({view:v,target:await locator.boundingBox(),scroll:await view.evaluate(e=>e.scrollTop)})); } +// reach is inView for any page: the reader wheels the view the control is +// in (its .view) until the control is wholly in that view and nothing drawn +// over it (a sticky bar, the window's foot) takes the point Playwright will +// press. Playwright's own scroll is put back by the app, as any scroll that +// 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). +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); + for (let i = 0; i < 120; i++) { + const at = await locator.evaluate((e) => { + const b = e.getBoundingClientRect(), v = e.closest(".view").getBoundingClientRect(); + const x = b.left + b.width / 2, y = b.top + b.height / 2; + const inside = b.top >= v.top && b.bottom <= v.bottom, hit = document.elementFromPoint(x, y); + 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); + } + throw new Error("control did not come clear into sight: " + JSON.stringify({ view: v, target: await locator.boundingBox() })); +} + async function click(page, locator) { await inView(page, locator); await locator.click(); @@ -67,4 +94,4 @@ async function watchSettingsReads(page) { // settings, with no wait between, so once it is set the read is counted. const settingsDrawn = (page) => page.waitForFunction(() => load.done && __settingsReads.asked === __settingsReads.drawn); -module.exports = { inView, click, watchSettingsReads, settingsDrawn }; +module.exports = { inView, reach, click, watchSettingsReads, settingsDrawn }; diff --git a/internal/gui/tests/routing-group-fold.test.cjs b/internal/gui/tests/routing-group-fold.test.cjs index 7b67c6bf8..2f7052520 100644 --- a/internal/gui/tests/routing-group-fold.test.cjs +++ b/internal/gui/tests/routing-group-fold.test.cjs @@ -16,6 +16,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { reach } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const now = new Date(); @@ -140,8 +141,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const depth = (li) => li.evaluate((x) => getComputedStyle(x).getPropertyValue("--depth").trim()); assert.equal(await depth(fold("ChatGPT")), "1"); assert.equal(await depth(page.locator(".rt-accts > li").nth(2)), "2"); - // Team folded by the reader, Big opened + // Team folded by the reader, Big opened: with the pool open they are + // under the window's foot (the page beside the sidebar since + // 18e82adc6), and the reader scrolls down to them + await reach(page, fold("Team")); await fold("Team").click(); + await reach(page, fold("Big")); await fold("Big").click(); await page.waitForFunction(() => document.querySelectorAll(".rt-accts > li").length === 1 + 1 + 8 + 1 + 1 + 7 + 1); diff --git a/internal/gui/tests/routing-sessions.test.cjs b/internal/gui/tests/routing-sessions.test.cjs index d658ba2c7..de5994102 100644 --- a/internal/gui/tests/routing-sessions.test.cjs +++ b/internal/gui/tests/routing-sessions.test.cjs @@ -3,6 +3,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { reach } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const now = new Date(); @@ -183,6 +184,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.setViewportSize({ width: 1100, height: 1000 }); await page.locator(".rt-reqs").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-background-memory.png`) }); } + // at 560 By request is under the groups, out of sight: a resize lets + // go of what the last click held in place (heldWidth), so the reader + // scrolls down to it + await reach(page, page.locator(".rt-group-by button").first()); await page.locator(".rt-group-by button").first().click(); assert.equal(await page.locator(".rt-req").count(), 11, "by-request view retains all requests"); assert.deepEqual(errors, []);