From 1024 points wide (SIDE_AT) the window lays its pages down the left as a Mac app's sidebar: Work (Agents, Sessions, Library), Models (Providers, Routing, Gateway), Insights (Usage), Extend (Plugins), with Settings and the gateway's address at the foot. The open page's own tabs (Usage, Library, Plugins, Settings) are listed under it, opening and folding on an iOS-like spring, and the page's strip is hidden. The header becomes a breadcrumb, and pages whose head held only tools have them in the title bar. Graphite: the open page is in the text's ink, not purple. A pressed row darkens and never shrinks. The selection under the tabs sets off as the row is pressed, on a 0.3s curve (it felt behind the finger), and is the list's only shape: a sub-row hovered or pressed has no ground of its own, which showed a block under the finger before the selection slid there. The page's tab is clicked at once, so what is typed next goes to it. The title bar's button (or ⌃⌘S, Ctrl+Shift+S), there at every width, picks the sidebar or the header's tabs. The choice is kept in localStorage magpie.navLayout (side or top) at every width, so it is laid out from the first frame; picked in a narrow window the sidebar is 184 points under 860. The two trade places in a view transition: the sidebar slides, each tab flies to its place, and the page slides as one. Without view transitions or under reduced motion, the change is at once. With nothing picked, narrower than 1024 the page beside a sidebar would be narrower than Usage's requests table needs, so the header's tabs come back. A resize drops what a click held (heldWidth). Usage's KPI strip goes two to a line by the room the page gives it (a container query), and Japanese counts wrap there. Tests whose window is 1024+ were updated for the sidebar, and docs/subsystems/gui-shell.md says how it works. Run: sidebar.test.cjs and side-toggle.test.cjs 16/16 in chromium and webkit, in en, zh, zh-TW, ja and de. Each was broken by hand (press shrink, address cut, press glide, sub-row ground, view transition, kept choice) and went red. Every page at 560 points with the sidebar picked, zh and de, both engines: nothing scrolls sideways. session-identity's ledger row sits under the footer beside the sidebar; WebKit's click doesn't scroll to it, so the test wheels it up first. Animation frames were checked from a recorded video. The 105 affected GUI files in both engines; their reds were rerun alone and fixed (filter-ime: the sub-row's click now at once; session-identity, above) or fail the same on main (tray-logos). The full GUI suite in chromium, on the rebase ontod5cae267a, was cut short at 352 tests on the owner's "ship": 6 reds (account-alias, account-models, codex-auto-review, codex-credits, context-text) each pass alone, here and on maind5cae267a, so they are timing under the full run's load and are to be filed. After rebasing ontoe4e22b23e: sidebar, side-toggle, session-identity, filter-ime, library-instr-busy, usage-speed-count and view-scrollbar, 50/50 in chromium and webkit. go build ./... passes.
189 lines
12 KiB
JavaScript
189 lines
12 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// The window's sidebar (app.js layoutNav): from 1024 points the pages are
|
|
// listed down the left in their groups, the open one's own tabs under it in
|
|
// place of the page's strip, Settings and the gateway's address at the foot
|
|
// and the header a breadcrumb; narrower, they go back into the header's row.
|
|
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");
|
|
|
|
function serve(lang, reads) {
|
|
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
|
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(state);
|
|
if (url.pathname === "/api/providers") { reads.push(performance.now()); return json({ providers: [], presets: [], excluded: [], gateway: { url: "http://127.0.0.1:3425", running: true, window: true } }); }
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
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)];
|
|
await route.fulfill({ body: await fs.readFile(file), contentType });
|
|
};
|
|
}
|
|
|
|
// each language's group names, and Settings' Models tab
|
|
const words = {
|
|
en: { groups: ["Work", "Models", "Insights", "Extend"], settings: "Settings", models: "Models" },
|
|
zh: { groups: ["使用", "模型", "观测", "扩展"], settings: "设置", models: "模型" },
|
|
"zh-TW": { groups: ["使用", "模型", "觀測", "擴充"], settings: "設定", models: "模型" },
|
|
ja: { groups: ["利用", "モデル", "観測", "拡張"], settings: "設定", models: "モデル" },
|
|
de: { groups: ["Arbeit", "Modelle", "Einblick", "Zusätze"], settings: "Einstellungen", models: "Modelle" },
|
|
};
|
|
const frame = (page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(`${engine}: the window's sidebar`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
|
|
for (const [lang, w] of Object.entries(words)) await t.test(lang, async () => {
|
|
const reads = [];
|
|
const context = await browser.newContext({ viewport: { width: 1024, height: 760 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, reads));
|
|
await page.goto("http://magpie.test/");
|
|
await page.waitForSelector("#nav button.on");
|
|
|
|
// at 1024 points the pages are down the left, in their groups
|
|
assert.ok(await page.evaluate(() => document.body.classList.contains("side-nav")), "a sidebar from 1024 points");
|
|
assert.ok(await page.locator("#side .side-scroll #nav").isVisible(), "the pages are in the sidebar");
|
|
assert.equal(await page.locator(".top #nav").count(), 0, "and not in the header");
|
|
assert.deepEqual(await page.locator("#nav .nav-gl:visible").allTextContents(), w.groups);
|
|
assert.deepEqual(await page.locator("#nav button[data-view]").evaluateAll((bs) => bs.map((b) => b.dataset.view)),
|
|
["agents", "sessions", "library", "providers", "routing", "gateway", "usage", "plugins"]);
|
|
assert.ok(await page.locator("#side .side-foot #prefs").isVisible(), "Settings at the sidebar's foot");
|
|
assert.equal((await page.locator("#prefs .side-l").textContent()).trim(), w.settings);
|
|
// no page's name or group cut, and nothing scrolls sideways
|
|
const cut = await page.locator("#side :is(.nav-gl, button[data-view] > span, #prefs .side-l)").evaluateAll((es) => es.filter((e) => e.scrollWidth > e.clientWidth + 1).map((e) => e.textContent));
|
|
assert.deepEqual(cut, [], "names read whole");
|
|
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth), "the window does not scroll sideways");
|
|
|
|
// the open page in the graphite of the text, not an accent colour
|
|
const [ic, fg] = await page.evaluate(() => [getComputedStyle(document.querySelector("#nav button.on .nav-ic")).color, getComputedStyle(document.body).color]);
|
|
assert.equal(ic, fg, "the open page's icon is the text's colour");
|
|
|
|
// a row pressed darkens and keeps its size: no button's squeeze
|
|
for (const sel of ['#nav button[data-view="usage"]', "#prefs"]) {
|
|
const r = page.locator(sel);
|
|
const bg = await r.evaluate((b) => getComputedStyle(b).backgroundColor);
|
|
const box = await r.boundingBox();
|
|
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
|
await page.mouse.down();
|
|
await page.waitForTimeout(250);
|
|
const [tf, pressed] = await r.evaluate((b) => [getComputedStyle(b).transform, getComputedStyle(b).backgroundColor]);
|
|
await page.mouse.move(box.x + box.width + 400, box.y);
|
|
await page.mouse.up();
|
|
assert.equal(tf, "none", `${sel} pressed is not squeezed`);
|
|
assert.notEqual(pressed, bg, `${sel} pressed darkens`);
|
|
}
|
|
|
|
// the gateway's address at the foot, read once the window has settled
|
|
await page.locator("#sideGw").waitFor();
|
|
assert.match(await page.locator("#sideGw").textContent(), /127\.0\.0\.1:3425/);
|
|
assert.ok(await page.locator("#sideGw span").evaluate((s) => s.scrollWidth <= s.clientWidth), "the address is read whole");
|
|
assert.equal(reads.length, 1, "read once for the sidebar");
|
|
|
|
// Settings: its tabs listed under it, its own strip hidden, and picked there
|
|
await page.locator("#prefs").click();
|
|
const subs = page.locator("#side .nav-sub:not(.leaving) .nav-s");
|
|
await subs.first().waitFor();
|
|
assert.equal(await subs.count(), 8);
|
|
assert.equal(await page.locator("#setTabs").isVisible(), false, "the page's own strip is hidden");
|
|
assert.deepEqual(await subs.evaluateAll((ss) => ss.map((s) => s.dataset.of)),
|
|
["setTab-general", "setTab-usage", "setTab-network", "setTab-models", "setTab-privacy", "setTab-otel", "setTab-sync", "setTab-about"]);
|
|
assert.deepEqual(await subs.evaluateAll((ss) => ss.filter((s) => s.scrollWidth > s.clientWidth + 1).map((s) => s.textContent)), [], "tab names read whole");
|
|
// the selection sets off as the row is pressed, ahead of the page,
|
|
// and goes back when the press leaves the row
|
|
const hlTo = () => page.evaluate(() => { const h = document.querySelector(".nav-sub:not(.leaving) .nav-hl"); return h.style.transform; });
|
|
const rowAt = (of) => page.evaluate((of) => `translateY(${document.querySelector(`.nav-s[data-of=${of}]`).offsetTop}px)`, of);
|
|
const startAt = await hlTo();
|
|
const net = await page.locator(".nav-s[data-of=setTab-network]").boundingBox();
|
|
await page.mouse.move(net.x + net.width / 2, net.y + net.height / 2);
|
|
await page.mouse.down();
|
|
assert.equal(await hlTo(), await rowAt("setTab-network"), "pressed, the selection is going to it");
|
|
assert.equal(await page.locator("#setTab-network").evaluate((b) => b.classList.contains("on")), false, "before the page has the tab");
|
|
// the selection is the one shape: the row pressed has no ground of its own
|
|
assert.equal(await page.locator(".nav-s[data-of=setTab-network]").evaluate((b) => getComputedStyle(b).backgroundColor), "rgba(0, 0, 0, 0)", "no block under the finger ahead of the selection");
|
|
await page.mouse.move(net.x + net.width / 2, net.y + 200);
|
|
assert.equal(await hlTo(), startAt, "the press left the row: back");
|
|
await page.mouse.up();
|
|
assert.equal(await page.locator("#setTab-network").evaluate((b) => b.classList.contains("on")), false, "nothing picked");
|
|
await page.locator(".nav-s[data-of=setTab-models]").click();
|
|
await page.waitForFunction(() => document.querySelector("#setTab-models").classList.contains("on"));
|
|
await frame(page);
|
|
assert.equal(await page.locator(".nav-s.cur").getAttribute("data-of"), "setTab-models");
|
|
assert.equal(await page.locator(".nav-s.cur").getAttribute("aria-selected"), "true");
|
|
const crumb = await page.locator("#crumb").evaluate((c) => [...c.querySelectorAll("span, b")].map((e) => e.textContent));
|
|
assert.deepEqual(crumb, [w.settings, w.models], "the header says where the reader is");
|
|
// the selection sits on the tab picked
|
|
const [hl, cur] = await page.evaluate(() => [document.querySelector(".nav-sub:not(.leaving) .nav-hl").getBoundingClientRect().top, document.querySelector(".nav-s.cur").getBoundingClientRect().top]);
|
|
assert.ok(Math.abs(hl - cur) < 1, `the selection is on the tab: ${hl} ${cur}`);
|
|
|
|
// another page without tabs of its own: the list folds away
|
|
await page.locator('#nav button[data-view="agents"]').click();
|
|
await page.waitForFunction(() => !document.querySelector(".nav-sub"));
|
|
|
|
// a point narrower, the header's row has them again, and no sidebar
|
|
await page.setViewportSize({ width: 1023, height: 760 });
|
|
await page.waitForFunction(() => !document.body.classList.contains("side-nav"));
|
|
await frame(page);
|
|
assert.ok(await page.locator(".top #nav").isVisible(), "the pages are in the header");
|
|
assert.equal(await page.locator("#side").isVisible(), false);
|
|
assert.equal(await page.locator("#crumb").isVisible(), false);
|
|
assert.equal(await page.locator("#nav .nav-gl:visible").count(), 0, "no group names in the header's row");
|
|
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth), "the window does not scroll sideways");
|
|
// Settings' tabs are its own strip again
|
|
await page.locator("#prefs").click();
|
|
await page.locator("#setTabs").waitFor();
|
|
assert.equal(await page.locator(".nav-sub").count(), 0);
|
|
|
|
assert.deepEqual(errors, []);
|
|
await context.close();
|
|
});
|
|
|
|
await t.test("narrow from the start: the gateway is not read for a sidebar", async () => {
|
|
const reads = [];
|
|
const context = await browser.newContext({ viewport: { width: 900, height: 700 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
await page.route("**/*", serve("en", reads));
|
|
await page.goto("http://magpie.test/");
|
|
await page.waitForSelector("#nav button.on");
|
|
await page.waitForTimeout(2000);
|
|
assert.equal(reads.length, 0, "no read with no sidebar to show it");
|
|
// and read when the window is made wide
|
|
await page.setViewportSize({ width: 1200, height: 700 });
|
|
await page.locator("#sideGw").waitFor();
|
|
assert.equal(reads.length, 1);
|
|
await context.close();
|
|
});
|
|
|
|
await t.test("the list opens and folds as it plays", async () => {
|
|
const context = await browser.newContext({ viewport: { width: 1200, height: 760 } });
|
|
const page = await context.newPage();
|
|
await page.route("**/*", serve("en", []));
|
|
await page.goto("http://magpie.test/");
|
|
await page.waitForSelector("#nav button.on");
|
|
await page.locator("#prefs").click();
|
|
const box = page.locator("#side .nav-sub").first();
|
|
await box.waitFor();
|
|
assert.ok(await box.evaluate((b) => b.getAnimations().length > 0), "the list unrolls");
|
|
await page.locator('#nav button[data-view="agents"]').click();
|
|
// folding: out of reach at once, gone once it has played
|
|
assert.equal(await page.locator(".nav-sub:not(.leaving)").count(), 0);
|
|
assert.equal(await page.locator(".nav-s").count(), 0, "its rows are no tabs while they fold");
|
|
await page.waitForFunction(() => !document.querySelector(".nav-sub"));
|
|
await context.close();
|
|
});
|
|
});
|
|
}
|