Files
magpie/internal/gui/tests/plugin-page-arrange.test.cjs
T
yetone 16ed1a9524 gui: a setting's hint card starts at the pointer, not at the row's name (mmmg_btc on X)
Resting the pointer on Settings › About's 更新内容 row put the hint at the
far left of the row. 5710283da lined its text up with the row's name; the
pointer is what asked, so settingshints.js now keeps the pointer's x and a
card the pointer asked starts there (12px left of it, kept 16px inside the
window), with its grow-from origin at the pointer. A card a key asked
(focus) still lines up with the name. Every row hint comes through this one
module (Settings, a provider editor's fields, Routing groups), so they all
behave the same; native titles already show at the pointer.

Run on mote: provider-prefs-layout (card at the pointer; red on the old
code, 5 of 10), editor-hints, settings-hints (its pointer and key checks
changed), searcher-pick, settings-lines-wrap, sign-in-moves, and the gui-*
and i18n-* files, chromium and webkit; TestCoreScriptBudget; gofmt.
Reds: settings-hints "Settings' explanations show on hover and focus"
(chromium and webkit) fails the same way on base before reaching the
changed lines ("the card doesn't say the row's line"), and editor-hints in
webkit ("Tab didn't come back") fails on base too; both are filed.
Not tried: a live Mac window.
2026-11-11 04:45:46 -08:00

77 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);
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"]);
});
}