nav-timeout.test.cjs was red on main since #5425 was filed (11-06),
first for four files and now for 24: each new GUI test copied
page.setDefaultTimeout(5000) without a navigation timeout, and nothing
caught it because CI runs no GUI file. Each short default now sits
beside page.setDefaultNavigationTimeout(60000); clicks and waits keep
their 5s/6s/8s/30s bar. skygunner's 10275d5a6 did the same for the nine
files listed on 11-08, and was never taken; this covers those and the 15
added since.
The class: nav-timeout, i18n-keys and i18n-en-no-cjk read the sources
and need no browser, and LESSONS.md records each of them red on main
after a push that ran chosen GUI files. test.yml's Linux cli job, which
already sets up Node 22, now runs them, so the push that adds the next
offender goes red on CI.
Run (mica; mote was at load 26):
- node --test nav-timeout, i18n-keys, i18n-en-no-cjk at this tree on
origin/main b2b3d488c: 9/9 ok.
- usage-drag, form-align, accounts-switch-alone (changed files, both
engines, every language): 34/34 ok.
- Broken by hand: origin/main's usage-drag copied in beside the fix,
nav-timeout red, naming it.
Not run: the other 21 changed files in a browser (one added line each)
and the whole GUI suite; both machines were running other sessions'
GUI runs.
Co-authored-by: vincent <webmaster@palmit.com.au>
78 lines
4.7 KiB
JavaScript
78 lines
4.7 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// The sidebar's plugin pages (0lVeer on X): a press held on a tab picks it
|
|
// up, it is dragged to its place and the order is kept (plugin-pages/arrange);
|
|
// a quick drag or click moves nothing. The API is faked.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { chromium, webkit } = require("playwright");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
const entry = (name) => ({ spec: "/x/" + name, name, key: "plugin-" + name, title: name, reads: [], url: `/_magpie/plugin/${"a".repeat(32)}/${name}.html` });
|
|
const names = ["alpha", "beta", "gamma"];
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(`${engine}: a held press on a plugin tab drags it and the order is kept`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const context = await browser.newContext({ viewport: { width: 1100, height: 700 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(8000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const posts = [];
|
|
let order = [];
|
|
await page.route("**/*", async (route) => {
|
|
const url = new URL(route.request().url());
|
|
const json = (data) => route.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"en",theme:"light",web:false};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings: { lang: "en", theme: "light" } });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true }, plugins: [] });
|
|
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
|
if (url.pathname === "/api/plugin-pages/arrange") { const b = route.request().postDataJSON(); posts.push(b.order); order = b.order; return json({}); }
|
|
if (url.pathname === "/api/plugin-pages") return json(names.map(entry).sort((a, b) => (order.indexOf(a.key) + 1 || 9) - (order.indexOf(b.key) + 1 || 9)));
|
|
if (url.pathname === "/api/plugin-panels") return json([]);
|
|
if (url.pathname.startsWith("/api/") || url.pathname.startsWith("/_magpie/")) return json({});
|
|
if (url.host !== "magpie.test") return route.fulfill({ status: 404, body: "" });
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
|
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
|
});
|
|
await page.goto("http://magpie.test/");
|
|
const tabs = page.locator("#nav button[data-plugin-page]");
|
|
await tabs.nth(2).waitFor({ state: "attached" });
|
|
const keys = () => tabs.evaluateAll((l) => l.map((b) => b.dataset.view.replace("plugin-", "")));
|
|
const center = async (i) => { const r = await tabs.nth(i).boundingBox(); return [r.x + r.width / 2, r.y + r.height / 2]; };
|
|
assert.deepEqual(await keys(), names);
|
|
|
|
// quickly dragged: nothing is picked up
|
|
let [x, y] = await center(0), [, y2] = await center(2);
|
|
await page.mouse.move(x, y);
|
|
await page.mouse.down();
|
|
await page.mouse.move(x, y2, { steps: 6 });
|
|
await page.mouse.up();
|
|
assert.deepEqual(await keys(), names);
|
|
assert.deepEqual(posts, []);
|
|
|
|
// held, then dragged below the last
|
|
[x, y] = await center(0);
|
|
await page.mouse.move(x, y);
|
|
await page.mouse.down();
|
|
await page.waitForTimeout(550);
|
|
[, y2] = await center(2);
|
|
await page.mouse.move(x, y + 8, { steps: 3 });
|
|
await page.mouse.move(x, y2 + 6, { steps: 10 });
|
|
await page.mouse.up();
|
|
await page.waitForFunction(() => !document.querySelector("#nav.sorting"));
|
|
assert.deepEqual(await keys(), ["beta", "gamma", "alpha"]);
|
|
assert.deepEqual(posts, [["plugin-beta", "plugin-gamma", "plugin-alpha"]]);
|
|
assert.equal(await page.evaluate(() => document.querySelector("#view-plugin-alpha")?.classList.contains("on") ?? false), false, "the drop is not a click");
|
|
|
|
// a reload lists them as kept
|
|
await page.reload();
|
|
await tabs.nth(2).waitFor({ state: "attached" });
|
|
assert.deepEqual(await keys(), ["beta", "gamma", "alpha"]);
|
|
});
|
|
}
|