The sidebar's list of a page's tabs (.nav-sub) unrolls from height 0 as
the page opens (navSubEnter). Its rows were flex items that shrink, so
while the list unrolled they were squeezed, 18px tall at 19px down
instead of 26px at 27px. Plugins draws its tab strip again once
/api/plugins answers ("Installed" becomes "Installed · 2"), navSubs then
rebuilds the rows, and navSubMark measured the squeezed row for the
selection. Nothing marked it again after the unroll, so with Installed
saved as the tab the grey selection sat 8px up and 8px short, over
Discover's text: the reporter's screenshot.
The rows are now flex: none, so they keep their size and place while the
list unrolls or folds, and offsetTop is right whenever the strip is drawn
again. The other pages' lists (Library, Usage, Settings) share the rule.
Run:
- new internal/gui/tests/nav-sub-unroll.test.cjs: Plugins with Installed
saved, /api/plugins held until the list is animating, then answered.
Chromium and WebKit; en, zh, zh-TW, ja, de; 1024 and 1440 wide.
- 20/20 fail on the old app.css (the selection at 444.6-462.6 against
the row's 452.6-478.6).
- 20/20 pass with the fix.
- sidebar, side-toggle, side-width, plugin-check-updates, plugin-market,
plugin-progressive and click-scroll in both engines: 82 pass.
Not tried: the packaged app on the reporter's machine. The timing there
is whatever /api/plugins takes; the test covers any answer that lands
during the 460ms unroll.
89 lines
6.0 KiB
JavaScript
89 lines
6.0 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||
// The sidebar's list of a page's tabs (app.js navSubs) unrolls as the page
|
||
// opens. A list drawn again while it unrolls (Plugins' Installed tab gets
|
||
// its count once the plugins are read) put the selection where the rows
|
||
// were squeezed into the unrolling list, and it stayed there: on Installed
|
||
// it sat a third of a row up, over Discover's text, and shorter than the
|
||
// row (#1787). The rows keep their size while the list unrolls, so the
|
||
// selection is on its row however early the page draws its strip again.
|
||
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");
|
||
|
||
// the plugins' read is held until the list is unrolling, then answered
|
||
function serve(lang, held) {
|
||
const installed = [{ spec: "@x/opencode-a-auth", providers: ["A"], version: "1.0.0", moved: [] }, { spec: "@x/opencode-b-auth", providers: ["B"], version: "1.0.0", moved: [] }];
|
||
return 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:${JSON.stringify(lang)},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, theme: "light" } });
|
||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { url: "http://127.0.0.1:3425", running: true, window: true }, plugins: [] });
|
||
if (url.pathname === "/api/groups") return json({ groups: [], pools: [] });
|
||
if (url.pathname === "/api/plugins") { await held; return json({ bun: true, bunVersion: "1.3.0", plugins: installed, movable: [] }); }
|
||
if (url.pathname === "/api/plugins/listings") return json({ listings: [] });
|
||
if (url.pathname === "/api/plugins/npm") return json({ npm: {} });
|
||
if (url.pathname === "/api/plugins/github") return json({ repos: [] });
|
||
if (url.pathname.startsWith("/api/")) return json({});
|
||
if (!/^\/[\w./-]*$/.test(url.pathname) || 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: "" }); }
|
||
};
|
||
}
|
||
|
||
const installedWord = { en: "Installed", zh: "已安装", "zh-TW": "已安裝", ja: "インストール済み", de: "Installiert" };
|
||
|
||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||
test(`${engine}: the sidebar's selection sits on its row when the list is drawn again as it unrolls`, async (t) => {
|
||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||
t.after(() => browser.close());
|
||
for (const lang of Object.keys(installedWord)) for (const width of [1024, 1440]) await t.test(`${lang} ${width}`, async () => {
|
||
let open;
|
||
const held = new Promise((r) => { open = r; });
|
||
const context = await browser.newContext({ viewport: { width, height: 760 } });
|
||
// the reader left Plugins on Installed
|
||
await context.addInitScript(() => { try { localStorage.setItem("magpie.pluginTab", "installed"); } catch {} });
|
||
const page = await context.newPage();
|
||
page.setDefaultTimeout(5000);
|
||
const errors = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
await page.route("**/*", serve(lang, held));
|
||
await page.goto("http://magpie.test/");
|
||
await page.waitForSelector("#nav button.on");
|
||
assert.ok(await page.evaluate(() => document.body.classList.contains("side-nav")), "a sidebar at " + width);
|
||
|
||
await page.locator('#nav button[data-view="plugins"]').click();
|
||
const box = page.locator("#side .nav-sub:not(.leaving)");
|
||
await box.waitFor();
|
||
// the plugins come in while the list is still unrolling
|
||
await page.waitForFunction(() => document.querySelector(".nav-sub:not(.leaving)")?.getAnimations().some((a) => a.playState === "running"));
|
||
open();
|
||
await page.waitForFunction((w) => document.querySelector(".nav-s.cur")?.textContent.startsWith(w) && /\d/.test(document.querySelector(".nav-s.cur").textContent), installedWord[lang]);
|
||
// every row, the list and its selection, done moving
|
||
await page.waitForFunction(() => {
|
||
const b = document.querySelector(".nav-sub:not(.leaving)");
|
||
return b && [b, ...b.querySelectorAll("*")].every((e) => e.getAnimations().every((a) => a.playState !== "running"));
|
||
});
|
||
await page.waitForTimeout(350); // the selection's own transition (.3s)
|
||
|
||
const [rows, hl] = await page.evaluate(() => {
|
||
const r = (e) => { const b = e.getBoundingClientRect(); return { top: b.top, bottom: b.bottom, text: e.textContent }; };
|
||
return [[...document.querySelectorAll(".nav-sub:not(.leaving) .nav-s")].map(r), r(document.querySelector(".nav-sub:not(.leaving) .nav-hl"))];
|
||
});
|
||
assert.equal(rows.length, 2);
|
||
assert.ok(rows[1].top >= rows[0].bottom, `the rows don't overlap: ${JSON.stringify(rows)}`);
|
||
assert.ok(Math.abs(hl.top - rows[1].top) < 1 && Math.abs(hl.bottom - rows[1].bottom) < 1,
|
||
`the selection is on Installed (${rows[1].top}–${rows[1].bottom}), not ${hl.top}–${hl.bottom}`);
|
||
assert.ok(hl.top >= rows[0].bottom, "and nothing of it over Discover");
|
||
assert.deepEqual(errors, []);
|
||
await context.close();
|
||
});
|
||
});
|
||
}
|