diff --git a/internal/gui/tests/account-discovery.test.cjs b/internal/gui/tests/account-discovery.test.cjs index 1ccf66027..deb49c6b1 100644 --- a/internal/gui/tests/account-discovery.test.cjs +++ b/internal/gui/tests/account-discovery.test.cjs @@ -14,6 +14,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -78,7 +79,7 @@ async function open(browser, lang, width, posts, over) { await page.route("**/*", server(lang, posts, over)); await page.goto("http://magpie.test/?view=usage"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-privacy, .nav-s[data-of=setTab-privacy]):visible").click(); + await openPart(page, "privacy"); await page.locator("#discoveryList .opt").first().waitFor(); return { context, page, errors }; } diff --git a/internal/gui/tests/api-key-theme.test.cjs b/internal/gui/tests/api-key-theme.test.cjs index 04fa54324..443e76b5d 100644 --- a/internal/gui/tests/api-key-theme.test.cjs +++ b/internal/gui/tests/api-key-theme.test.cjs @@ -4,6 +4,7 @@ const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); const { fixture } = require("./fixtures/caller-keys.cjs"); +const { openPart } = require("./reader.cjs"); async function palette(page, selectors) { return page.evaluate((selectors) => { @@ -119,11 +120,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.mouse.move(500, 400); await page.mouse.wheel(0, -5000); for (const choice of ["Dark", "Light", "System"]) { - await page.locator(":is(#setTab-general, .nav-s[data-of=setTab-general]):visible").click(); + await openPart(page, "general"); await page.locator("#themeSegs").getByRole("button", { name: choice, exact: true }).click(); await page.waitForFunction((want) => (document.documentElement.dataset.theme || "system") === want, choice.toLowerCase()); await page.waitForFunction(() => !document.documentElement.classList.contains("theming")); - await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click(); + await openPart(page, "network"); const { colors: c, elements: e } = await palette(page, { card: "#lanList", key: "#lanList .lan-url" }); assert.equal(e.card.bg, c.card); assert.equal(e.key.color, c["fg-2"]); diff --git a/internal/gui/tests/cli-path.test.cjs b/internal/gui/tests/cli-path.test.cjs index 289732dfe..21a7fcc89 100644 --- a/internal/gui/tests/cli-path.test.cjs +++ b/internal/gui/tests/cli-path.test.cjs @@ -14,7 +14,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, openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -96,7 +96,7 @@ async function open(browser, lang, ctl, errors) { await watchSettingsReads(page); await page.goto("http://magpie.test/?view=settings"); await settingsDrawn(page); // rows found are the ones that stay (#1659) - await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click(); + await openPart(page, "about"); await page.locator("#setPage-about").waitFor({ state: "visible" }); const row = page.locator("#about .row.pref.cli-row"); await row.locator(".cli-shell").first().waitFor(); diff --git a/internal/gui/tests/connect-address-kept.test.cjs b/internal/gui/tests/connect-address-kept.test.cjs index f842c9bc5..aeca56f6a 100644 --- a/internal/gui/tests/connect-address-kept.test.cjs +++ b/internal/gui/tests/connect-address-kept.test.cjs @@ -2,6 +2,7 @@ const assert = require("node:assert/strict"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); const { fixture } = require("./fixtures/caller-keys.cjs"); +const { openPart } = require("./reader.cjs"); // coeo91 on Discord: the LAN address picked as Gateway's Base URL went back // to 127.0.0.1 after a restart or an update. The address and the gateway key @@ -59,12 +60,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // Share on local network's address is kept the same way await page.locator("#prefs").click(); - await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click(); + await openPart(page, "network"); await page.locator("#lanList .lan-address-row").waitFor(); await pick("#lanList .lan-interface", "10.0.0.10"); await page.reload(); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click(); + await openPart(page, "network"); await page.locator("#lanList .lan-address-row").waitFor(); assert.match(await shown("#lanList .lan-interface"), /10\.0\.0\.10:3999/); diff --git a/internal/gui/tests/currency.test.cjs b/internal/gui/tests/currency.test.cjs index e4a1f9c7c..84810ed1e 100644 --- a/internal/gui/tests/currency.test.cjs +++ b/internal/gui/tests/currency.test.cjs @@ -9,6 +9,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -94,7 +95,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // Settings: the currency row, its rate in the tooltip await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); await page.locator("#currencySegs .opt").first().waitFor(); const segs = page.locator("#currencySegs .opt"); assert.equal(await segs.count(), 2); @@ -141,7 +142,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // and back to Settings, ¥ CNY is still picked after a reload await page.reload(); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); await page.locator("#currencySegs .opt").first().waitFor(); assert.equal(await page.locator('#currencySegs .opt', { hasText: cny }).evaluate((b) => b.classList.contains("on")), true); @@ -190,7 +191,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // Settings agrees await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); await page.locator("#currencySegs .opt").first().waitFor(); assert.equal(await page.locator("#currencySegs .opt", { hasText: cny }).evaluate((b) => b.classList.contains("on")), true); diff --git a/internal/gui/tests/gateway-caller-keys.test.cjs b/internal/gui/tests/gateway-caller-keys.test.cjs index 6f0f09252..7b8b99662 100644 --- a/internal/gui/tests/gateway-caller-keys.test.cjs +++ b/internal/gui/tests/gateway-caller-keys.test.cjs @@ -4,6 +4,7 @@ const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); const { fixture, confirmKeyAction } = require("./fixtures/caller-keys.cjs"); +const { openPart } = require("./reader.cjs"); for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { for (const lang of ["en", "zh"]) { @@ -71,7 +72,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert(events.some((e) => e.action === "export" && e.query.includes("callerKey=laptop") && !e.query.includes("key=") && !e.query.includes("user="))); await page.reload(); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click(); + await openPart(page, "network"); const share = page.locator("#lanList").getByRole("button", { name: lang === "zh" ? "开启" : "On", exact: true }); await share.waitFor(); // Real wheel input lets the page remember the reader's scroll position. @@ -117,7 +118,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.mouse.move(500, 400); await page.mouse.wheel(0, -2000); await page.waitForFunction(() => document.querySelector("#view-settings").scrollTop === 0); - await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click(); + await openPart(page, "network"); await page.locator("#lanList .lan-address-row").waitFor(); await page.locator("#lanList").getByRole("button", { name: lang === "zh" ? "关闭" : "Off", exact: true }).click(); await page.locator("#lanList .lan-address-row").waitFor({ state: "detached" }); diff --git a/internal/gui/tests/gateway-connect-keys.test.cjs b/internal/gui/tests/gateway-connect-keys.test.cjs index 6713aae46..5ec19625f 100644 --- a/internal/gui/tests/gateway-connect-keys.test.cjs +++ b/internal/gui/tests/gateway-connect-keys.test.cjs @@ -4,6 +4,7 @@ const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); const { fixture, confirmKeyAction } = require("./fixtures/caller-keys.cjs"); +const { openPart } = require("./reader.cjs"); for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { for (const locale of ["en", "zh"]) { @@ -38,7 +39,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.locator("#prefs").click(); - await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click(); + await openPart(page, "network"); const on = page.locator("#lanList").getByRole("button", { name: w.on, exact: true }); await on.waitFor(); const bounds = await on.boundingBox(); @@ -69,7 +70,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", }; await page.route("**/api/caller-keys", lateList); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click(); + await openPart(page, "network"); await page.locator("#lanList").waitFor(); await page.locator("#nav").getByRole("button", { name: w.gateway, exact: true }).click(); await started; @@ -169,7 +170,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await expectSecret("fixture-created-2"); assert.equal(await page.locator("#connectKey code").textContent(), "Replacement"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click(); + await openPart(page, "network"); await page.locator("#lanList .lan-address-row").waitFor(); await page.locator("#lanList").getByRole("button", { name: w.off, exact: true }).click(); await page.locator("#lanList .lan-address-row").waitFor({ state: "detached" }); diff --git a/internal/gui/tests/number-units.test.cjs b/internal/gui/tests/number-units.test.cjs index 71344173c..938166ba7 100644 --- a/internal/gui/tests/number-units.test.cjs +++ b/internal/gui/tests/number-units.test.cjs @@ -14,6 +14,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const midnight = new Date(); @@ -164,7 +165,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await p.locator("#prefs").click(); - await p.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(p, "usage"); await p.locator("#currencySegs .opt").first().waitFor(); if (lang === "en") { assert.equal(await p.locator("#unitsRow").isHidden(), true, "no Number units row in English"); diff --git a/internal/gui/tests/otel.test.cjs b/internal/gui/tests/otel.test.cjs index ab73eb60d..08db1d538 100644 --- a/internal/gui/tests/otel.test.cjs +++ b/internal/gui/tests/otel.test.cjs @@ -5,7 +5,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, openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -128,13 +128,13 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(p.otel.bodiesWhole, true); assert.equal(p.otel.bodies, true); assert.equal(await mode.textContent(), modes[2]); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); p = await saved(() => page.locator("#currencySegs .opt").nth(1).click()); assert.equal(p.otel.enabled, true); assert.equal(p.otel.bodiesWhole, true); assert.equal(p.otel.endpoint, "https://collector.test/api/public/otel"); assert.equal(p.otel.headers.Authorization, "Basic YWJjZA=="); - await page.locator(":is(#setTab-otel, .nav-s[data-of=setTab-otel]):visible").click(); + await openPart(page, "otel"); p = await saved(() => page.locator("#otelExportRow .opt").first().click()); assert.equal(p.otel.enabled, false); await page.reload(); diff --git a/internal/gui/tests/proto-menu-overflow.test.cjs b/internal/gui/tests/proto-menu-overflow.test.cjs index a2cd2abbd..b3aea93c7 100644 --- a/internal/gui/tests/proto-menu-overflow.test.cjs +++ b/internal/gui/tests/proto-menu-overflow.test.cjs @@ -14,6 +14,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -79,7 +80,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.route("**/*", server(lang, posts)); await page.goto("http://magpie.test/?view=usage"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); const pill = page.locator("#trayUsagePick button"); await pill.waitFor(); await pill.scrollIntoViewIfNeeded(); diff --git a/internal/gui/tests/proxy-own-wording.test.cjs b/internal/gui/tests/proxy-own-wording.test.cjs index c7711b9f9..58f46ca0a 100644 --- a/internal/gui/tests/proxy-own-wording.test.cjs +++ b/internal/gui/tests/proxy-own-wording.test.cjs @@ -10,7 +10,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, openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -96,7 +96,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await watchSettingsReads(page); await page.goto("http://magpie.test/?view=settings"); await settingsDrawn(page); - await page.locator(":is(#setTab-network, .nav-s[data-of=setTab-network]):visible").click(); + await openPart(page, "network"); const sub = page.locator("#proxySub"); await sub.waitFor({ state: "visible" }); assert.equal((await sub.textContent()).trim(), words[lang][source], `${lang} ${source}`); diff --git a/internal/gui/tests/public-url-default.test.cjs b/internal/gui/tests/public-url-default.test.cjs index 8600382a3..c1d69e584 100644 --- a/internal/gui/tests/public-url-default.test.cjs +++ b/internal/gui/tests/public-url-default.test.cjs @@ -2,6 +2,7 @@ const assert = require("node:assert/strict"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); const { fixture } = require("./fixtures/caller-keys.cjs"); +const { openPart } = require("./reader.cjs"); // #1551 (everpcpc): magpie web in Docker behind a reverse proxy, with // MAGPIE_PUBLIC_URL=https://magpie.example.com. The page is opened from @@ -36,7 +37,7 @@ async function setup(t, engine, lang, width, options) { const shown = (sel) => page.locator(sel).textContent(); const settingsTab = async (tab) => { if (!(await page.locator("#view-settings").isVisible())) await page.locator("#prefs").click(); - await page.locator(`:is(#setTab-${tab}, .nav-s[data-of=setTab-${tab}]):visible`).click(); + await openPart(page, tab); }; const fits = async (where) => assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, where + " wider than the window"); return { page, errors, open, shown, settingsTab, fits }; diff --git a/internal/gui/tests/quota-pace.test.cjs b/internal/gui/tests/quota-pace.test.cjs index 6fb86917f..821a08155 100644 --- a/internal/gui/tests/quota-pace.test.cjs +++ b/internal/gui/tests/quota-pace.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 { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const at = (h) => new Date(Date.now() + h * 3600e3).toISOString(); @@ -141,7 +142,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", t.after(() => browser.close()); const prefs = async (page) => { await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); await page.locator("#trayUsagePick button").waitFor(); }; const scrolled = (page) => page.locator("#view-settings").evaluate((v) => v.scrollTop); diff --git a/internal/gui/tests/quota-reads.test.cjs b/internal/gui/tests/quota-reads.test.cjs index 21c516a59..966c1efb7 100644 --- a/internal/gui/tests/quota-reads.test.cjs +++ b/internal/gui/tests/quota-reads.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 { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -82,7 +83,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.route("**/*", server(lang, posts)); await page.goto("http://magpie.test/?view=usage"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); const row = page.locator("#quotaReadsRow"); const opts = row.locator("#quotaReadsSegs .opt"); await opts.first().waitFor(); diff --git a/internal/gui/tests/reader.cjs b/internal/gui/tests/reader.cjs index 081deb0de..3fd3b2885 100644 --- a/internal/gui/tests/reader.cjs +++ b/internal/gui/tests/reader.cjs @@ -94,4 +94,14 @@ 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, reach, click, watchSettingsReads, settingsDrawn }; +// openPart opens a part of Settings (a tab, or its entry in the sidebar's +// strip) the way the keyboard does. A click waits for the tab to hold still +// over two animation frames, and on a loaded machine WebKit draws no frames +// for seconds while the page itself runs on, so the click can sit out the +// test's whole timeout over a tab that isn't moving (#2150). Enter on the +// focused button clicks it with no frame to wait for. +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 }; diff --git a/internal/gui/tests/s3-sync.test.cjs b/internal/gui/tests/s3-sync.test.cjs index 666c9b959..8a8c4be5b 100644 --- a/internal/gui/tests/s3-sync.test.cjs +++ b/internal/gui/tests/s3-sync.test.cjs @@ -8,6 +8,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -64,7 +65,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.goto("http://magpie.test/"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click(); + await openPart(page, "sync"); const list = page.locator("#syncList"); const first = list.locator(".row.pref").first(); await first.waitFor({ state: "visible" }); diff --git a/internal/gui/tests/settings-groups.test.cjs b/internal/gui/tests/settings-groups.test.cjs index e169aafc9..92da5896e 100644 --- a/internal/gui/tests/settings-groups.test.cjs +++ b/internal/gui/tests/settings-groups.test.cjs @@ -17,6 +17,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const today = new Date(Date.now() + 8 * 3600e3).toISOString().slice(0, 10); @@ -108,7 +109,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.route("**/*", server(lang, posts, over)); const go = async () => { await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); await page.locator("#warmSegs .opt").first().waitFor({ state: "attached" }); }; await page.goto("http://magpie.test/"); diff --git a/internal/gui/tests/settings-search.test.cjs b/internal/gui/tests/settings-search.test.cjs index ef559955e..9db318f56 100644 --- a/internal/gui/tests/settings-search.test.cjs +++ b/internal/gui/tests/settings-search.test.cjs @@ -14,6 +14,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -109,7 +110,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // a row's own words, in the language shown: that row alone, under // its part's name, the tabs set aside - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); await type(page, await tr("Appearance")); let s = await state(page); assert.deepEqual([s.parts, s.tabs, s.none], [["general"], false, ""]); diff --git a/internal/gui/tests/settings-sections.test.cjs b/internal/gui/tests/settings-sections.test.cjs index ab930e6b8..18618927d 100644 --- a/internal/gui/tests/settings-sections.test.cjs +++ b/internal/gui/tests/settings-sections.test.cjs @@ -18,6 +18,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -158,21 +159,21 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", assert.equal(posts.length, posted, id + ": a tab posts nothing"); } // the warm-ups are in Allowances, still a tab each - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); assert(await page.locator("#warmTab-codex").isVisible(), "the warm-ups under Allowances"); // a part's control posts what it did - await page.locator(":is(#setTab-general, .nav-s[data-of=setTab-general]):visible").click(); + await openPart(page, "general"); await page.locator("#themeSegs .opt").nth(2).click(); for (let i = 0; i < 50 && !posts.length; i++) await page.waitForTimeout(40); assert.equal(posts.at(-1)?.theme, "dark", "the theme still saves"); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); await page.locator("#currencySegs .opt").nth(1).click(); for (let i = 0; i < 50 && posts.at(-1)?.currency !== "cny"; i++) await page.waitForTimeout(40); assert.equal(posts.at(-1).currency, "cny", "the currency still saves"); // the keyboard: one tab in the Tab order, the arrows, Home and End - await page.locator(":is(#setTab-privacy, .nav-s[data-of=setTab-privacy]):visible").click(); + await openPart(page, "privacy"); assert.deepEqual(await page.locator("#setTabs [role=tab]").evaluateAll((bs) => bs.filter((b) => b.tabIndex === 0).map((b) => b.dataset.set)), ["privacy"]); await page.locator(":is(#setTab-privacy, .nav-s[data-of=setTab-privacy]):visible").focus(); await page.keyboard.press("ArrowRight"); @@ -231,7 +232,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const under = await page.evaluate(() => document.querySelector("#setPage-general").getBoundingClientRect().top - document.querySelector("#setTabs").getBoundingClientRect().bottom); assert(under >= 0, what + ": the part under the tabs"); // the last tab, on the last line, reached with one click, moving nothing - await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click(); + await openPart(page, "about"); await page.waitForTimeout(150); assert.deepEqual((await shown(page)).parts, ["about"], what); assert.equal(await top(page), 0, what + ": the click must not scroll the page"); diff --git a/internal/gui/tests/sync-auto-restore.test.cjs b/internal/gui/tests/sync-auto-restore.test.cjs index 8343d9da3..755aba7bb 100644 --- a/internal/gui/tests/sync-auto-restore.test.cjs +++ b/internal/gui/tests/sync-auto-restore.test.cjs @@ -14,6 +14,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -90,7 +91,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.goto("http://magpie.test/"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click(); + await openPart(page, "sync"); const list = page.locator("#syncList"); const rowNamed = (name) => list.locator(".row.pref").filter({ has: page.locator(".name", { hasText: name }) }); const auto = rowNamed(w.auto); diff --git a/internal/gui/tests/sync-not-backup.test.cjs b/internal/gui/tests/sync-not-backup.test.cjs index 4aa86e908..4dd641deb 100644 --- a/internal/gui/tests/sync-not-backup.test.cjs +++ b/internal/gui/tests/sync-not-backup.test.cjs @@ -12,6 +12,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const EN = "the file magpie/magpie.magpie-backup on the WebDAV server is empty (0 bytes): a write to it didn't finish."; @@ -77,7 +78,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", page.setDefaultTimeout(5000); await page.goto("http://magpie.test/"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click(); + await openPart(page, "sync"); const first = page.locator("#syncList .row.pref").first(); await first.waitFor({ state: "visible" }); const said = await first.locator(".who > .sub").first().textContent(); diff --git a/internal/gui/tests/sync-other-kind.test.cjs b/internal/gui/tests/sync-other-kind.test.cjs index e88590ff7..c9c17ec3a 100644 --- a/internal/gui/tests/sync-other-kind.test.cjs +++ b/internal/gui/tests/sync-other-kind.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 { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const DAV = { kind: "webdav", url: "https://dav.example.com/dav/", user: "me", passwordSet: true }; @@ -89,7 +90,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.goto("http://magpie.test/"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click(); + await openPart(page, "sync"); const list = page.locator("#syncList"); const first = list.locator(".row.pref").first(); await first.waitFor({ state: "visible" }); diff --git a/internal/gui/tests/sync-sign-in.test.cjs b/internal/gui/tests/sync-sign-in.test.cjs index 76cd28093..f78b774ba 100644 --- a/internal/gui/tests/sync-sign-in.test.cjs +++ b/internal/gui/tests/sync-sign-in.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 { reach } = require("./reader.cjs"); +const { reach, openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -67,7 +67,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", page.setDefaultTimeout(5000); await page.goto("http://magpie.test/"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click(); + await openPart(page, "sync"); const first = page.locator("#syncList .row.pref").first(); await first.waitFor({ state: "visible" }); const line = first.locator(".sync-sign-in"); diff --git a/internal/gui/tests/sync-usage-error.test.cjs b/internal/gui/tests/sync-usage-error.test.cjs index 41d924dfc..5c7eed1e1 100644 --- a/internal/gui/tests/sync-usage-error.test.cjs +++ b/internal/gui/tests/sync-usage-error.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 { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const CUT = "the WebDAV server kept 0 of 6869 bytes of 5f0c-2026-08-29.magpie-usage: the write was cut short — sync again, and if it keeps happening the network to the server is dropping long uploads"; @@ -68,7 +69,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", page.setDefaultTimeout(5000); await page.goto("http://magpie.test/"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click(); + await openPart(page, "sync"); const first = page.locator("#syncList .row.pref").first(); await first.waitFor({ state: "visible" }); const status = first.locator(".who > .sub").first(); diff --git a/internal/gui/tests/tray-bird.test.cjs b/internal/gui/tests/tray-bird.test.cjs index b4247967b..9264b617b 100644 --- a/internal/gui/tests/tray-bird.test.cjs +++ b/internal/gui/tests/tray-bird.test.cjs @@ -10,6 +10,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -68,7 +69,7 @@ async function open(browser, lang, posts, platform, over) { await page.route("**/*", server(lang, posts, over)); await page.goto("http://magpie.test/?view=usage"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); await page.locator("#trayUsagePick button").waitFor(); return { context, page }; } diff --git a/internal/gui/tests/tray-inuse.test.cjs b/internal/gui/tests/tray-inuse.test.cjs index d6dd0d493..b12788265 100644 --- a/internal/gui/tests/tray-inuse.test.cjs +++ b/internal/gui/tests/tray-inuse.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 { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -76,7 +77,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.route("**/*", server(lang, posts)); await page.goto("http://magpie.test/?view=usage"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); const pill = page.locator("#trayUsagePick button"); await pill.waitFor(); await pill.scrollIntoViewIfNeeded(); diff --git a/internal/gui/tests/tray-logos.test.cjs b/internal/gui/tests/tray-logos.test.cjs index d2c63c119..09c6f5313 100644 --- a/internal/gui/tests/tray-logos.test.cjs +++ b/internal/gui/tests/tray-logos.test.cjs @@ -10,6 +10,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -68,7 +69,7 @@ async function open(browser, lang, posts, platform, over) { await page.route("**/*", server(lang, posts, over)); await page.goto("http://magpie.test/?view=usage"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); await page.locator("#trayUsagePick button").waitFor(); return { context, page }; } diff --git a/internal/gui/tests/tray-totals.test.cjs b/internal/gui/tests/tray-totals.test.cjs index 9792e24e6..c63c3f5fd 100644 --- a/internal/gui/tests/tray-totals.test.cjs +++ b/internal/gui/tests/tray-totals.test.cjs @@ -12,6 +12,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -106,7 +107,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.goto("http://magpie.test/?view=usage"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); const pill = page.locator("#trayUsagePick button"); await pill.waitFor(); await pillIs(page, w.off); diff --git a/internal/gui/tests/tray-usage-redraw.test.cjs b/internal/gui/tests/tray-usage-redraw.test.cjs index 3ef4fb770..b3e88b73f 100644 --- a/internal/gui/tests/tray-usage-redraw.test.cjs +++ b/internal/gui/tests/tray-usage-redraw.test.cjs @@ -8,6 +8,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); const quotas = [ @@ -63,7 +64,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", // from Agents: the Usage page would have read the allowances already await page.goto("http://magpie.test/?view=agents"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); const pill = page.locator("#trayUsagePick button"); await pill.waitFor(); assert.equal(await page.evaluate(() => quotas), null, "the allowances were read before the click"); diff --git a/internal/gui/tests/tray-usages.test.cjs b/internal/gui/tests/tray-usages.test.cjs index 50044300d..c3f35590d 100644 --- a/internal/gui/tests/tray-usages.test.cjs +++ b/internal/gui/tests/tray-usages.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 { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -93,7 +94,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.goto("http://magpie.test/?view=usage"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); const pill = page.locator("#trayUsagePick button"); await pill.waitFor(); await page.waitForFunction(() => document.querySelector("#trayUsagePick button").textContent.trim() === "Copilot"); @@ -204,7 +205,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.goto("http://magpie.test/?view=usage"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-usage, .nav-s[data-of=setTab-usage]):visible").click(); + await openPart(page, "usage"); const pill = page.locator("#trayUsagePick button"); await pill.waitFor(); await pill.evaluate((b) => b.click()); diff --git a/internal/gui/tests/update-auto.test.cjs b/internal/gui/tests/update-auto.test.cjs index f3c0eb3b8..a98c6de5f 100644 --- a/internal/gui/tests/update-auto.test.cjs +++ b/internal/gui/tests/update-auto.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, openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -103,7 +103,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await settingsDrawn(page); // rows found are the ones that stay (#1659) // the rows are in Settings' About part const aboutTab = async () => { - await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click(); + await openPart(page, "about"); await page.locator("#setPage-about").waitFor({ state: "visible" }); }; await aboutTab(); @@ -179,7 +179,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await watchSettingsReads(page); await page.goto("http://magpie.test/?view=settings"); await settingsDrawn(page); - await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click(); + await openPart(page, "about"); await page.locator("#setPage-about").waitFor({ state: "visible" }); const auto = page.locator("#about .row.pref", { has: page.locator(".name", { hasText: new RegExp("^" + w.auto + "$") }) }); await auto.waitFor(); diff --git a/internal/gui/tests/update-blocked.test.cjs b/internal/gui/tests/update-blocked.test.cjs index ab2cdb597..04d93702e 100644 --- a/internal/gui/tests/update-blocked.test.cjs +++ b/internal/gui/tests/update-blocked.test.cjs @@ -10,6 +10,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -54,7 +55,7 @@ async function open(browser, lang, ctl, errors) { page.on("pageerror", (e) => errors.push(e.message)); await page.route("**/*", server(lang, ctl)); await page.goto("http://magpie.test/?view=settings"); - await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click(); + await openPart(page, "about"); await page.locator("#setPage-about").waitFor({ state: "visible" }); return page; } diff --git a/internal/gui/tests/update-mirror.test.cjs b/internal/gui/tests/update-mirror.test.cjs index a362b302b..e6190821b 100644 --- a/internal/gui/tests/update-mirror.test.cjs +++ b/internal/gui/tests/update-mirror.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, openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -76,7 +76,7 @@ async function open(browser, lang, ctl, errors) { await watchSettingsReads(page); await page.goto("http://magpie.test/?view=settings"); await settingsDrawn(page); // rows found are the ones that stay (#1659) - await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click(); + await openPart(page, "about"); await page.locator("#setPage-about").waitFor({ state: "visible" }); const row = page.locator("#about .row.pref.update-mirror-row"); await row.waitFor(); diff --git a/internal/gui/tests/update-restart.test.cjs b/internal/gui/tests/update-restart.test.cjs index 6e26fb721..25419c511 100644 --- a/internal/gui/tests/update-restart.test.cjs +++ b/internal/gui/tests/update-restart.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, openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -105,7 +105,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.goto("http://magpie.test/?view=settings"); await settingsDrawn(page); const aboutTab = async () => { - await page.locator(":is(#setTab-about, .nav-s[data-of=setTab-about]):visible").click(); + await openPart(page, "about"); await page.locator("#setPage-about").waitFor({ state: "visible" }); }; await aboutTab(); diff --git a/internal/gui/tests/usage-computers.test.cjs b/internal/gui/tests/usage-computers.test.cjs index bc20e3c4f..3c65cf3e4 100644 --- a/internal/gui/tests/usage-computers.test.cjs +++ b/internal/gui/tests/usage-computers.test.cjs @@ -177,7 +177,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", const posts = []; const { p, errors } = await open("http://magpie.test/", { width: 900, height: 420 }, false, [], [], posts); await p.locator("#prefs").click(); - await p.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click(); + await reader.openPart(p, "sync"); const first = p.locator("#syncList .row.pref").first(); await first.waitFor({ state: "visible" }); const toEnd = async () => { diff --git a/internal/gui/tests/webdav-settings-refresh.test.cjs b/internal/gui/tests/webdav-settings-refresh.test.cjs index 26fc9aab6..97f21edf9 100644 --- a/internal/gui/tests/webdav-settings-refresh.test.cjs +++ b/internal/gui/tests/webdav-settings-refresh.test.cjs @@ -12,6 +12,7 @@ const fs = require("node:fs/promises"); const path = require("node:path"); const { test } = require("node:test"); const { chromium, webkit } = require("playwright"); +const { openPart } = require("./reader.cjs"); const assets = path.resolve(__dirname, "../assets"); @@ -63,7 +64,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", await page.goto("http://magpie.test/"); await page.locator("#prefs").click(); - await page.locator(":is(#setTab-sync, .nav-s[data-of=setTab-sync]):visible").click(); + await openPart(page, "sync"); const list = page.locator("#syncList"); const first = list.locator(".row.pref").first(); await first.waitFor({ state: "visible" });