yogurt36 on Discord: the menu bar panel had a button to open the window
at the top (the header's open-as-a-window icon, #open) and another at
the bottom (the foot's "Open magpie", #openMain). Both called
api("window/main"). The foot's button is gone; the foot keeps what is
its own: Profiles, the status line and Quit. The four "Open magpie"
strings it alone used are out of i18n.js (the tray menu's own
"Open magpie" lives in traymenu.go and is unchanged).
Test: internal/gui/tests/panel-open-once.test.cjs, both engines, all five
languages: the header's icon opens the window, the foot's buttons are
Profiles and Quit only, Quit worded in each language.
Run:
- panel-open-once, Chromium on mote: 5/5 ok; i18n-keys on mote: 4/4 ok.
- panel-open-once, WebKit on Linux (wsl-run, magpie-desktop): 5/5 ok.
WebKit does not launch on mote right now (several pw_run.sh from other
sessions hung for hours; a bare webkit.launch() times out at 80s).
- Broken by hand: the test against the old assets (origin/main
0a9d9702f) is red in every language, "the foot's buttons" lists
'openMain'.
- Every GUI file that loads the panel, its foot or i18n (146 files),
both engines, on Linux WSL: 2170 tests, 2107 ok, 63 red. The 12 red
files run alone at concurrency 1: 62 red with this change, 64 red at
0a9d9702f without it, the same tests (agent-panel-name-width,
redact-rule-edit, remote-magpie, text-size, tray-totals and others).
Filed: #4120 and #4400 (Linux WSL reds at main), #3407, #4398, #4203,
#4082, #3501, #1866.
At the pushed head (rebased on 30939aa84^): panel-open-once
Chromium + i18n-keys on mote 9/9 ok, WebKit on Linux 5/5 ok.
Not run: the whole GUI suite (mote and WSL both had other sessions'
full GUI suites running), the Go suite (no Go changed). Not tried in
the real tray panel on a Mac.
68 lines
4.0 KiB
JavaScript
68 lines
4.0 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// The tray panel opens the main window from one place: the header's
|
|
// open-as-a-window icon. Its foot had an "Open magpie" button too, which did
|
|
// the same (yogurt36 on Discord); the foot keeps Profiles, the status line
|
|
// and Quit, which are its own.
|
|
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 handler(lang, calls) {
|
|
const state = { agents: [{ id: "codex", name: "codex", path: "/test/codex", fields: [] }], 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:"${lang}",theme:"light",web:true};` });
|
|
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/window/main" || url.pathname === "/api/window/quit") { calls.push(url.pathname); return route.fulfill({ status: 204 }); }
|
|
if (url.pathname === "/api/window/fit") return route.fulfill({ status: 204 });
|
|
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
|
if (url.pathname === "/api/usage/quotas") return json([]);
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });
|
|
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 });
|
|
};
|
|
}
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
|
test(`${engine} ${lang}: the tray panel opens the window from one button`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const page = await (await browser.newContext({ viewport: { width: 380, height: 520 }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(8000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
const calls = [];
|
|
await page.route("**/*", handler(lang, calls));
|
|
await page.goto("http://magpie.test/?mode=panel");
|
|
await page.locator("#agents .row.agent").first().waitFor();
|
|
|
|
// the header's icon opens the window
|
|
await page.locator(".top #open").click();
|
|
for (let i = 0; i < 100 && !calls.length; i++) await page.waitForTimeout(50);
|
|
assert.deepEqual(calls, ["/api/window/main"], "the header's icon opens the window");
|
|
|
|
// and the foot has no second way to it: Profiles and Quit are its only buttons
|
|
const foot = await page.locator(".foot button").evaluateAll((bs) => bs.map((b) => b.id));
|
|
assert.deepEqual(foot, ["profBtn", "quit"], "the foot's buttons");
|
|
|
|
// the foot keeps Quit, worded in the panel's language
|
|
const quit = page.locator(".foot #quit");
|
|
assert(await quit.isVisible(), "Quit stays in the foot");
|
|
const want = { en: "Quit", zh: "退出", "zh-TW": "退出", ja: "終了", de: "Beenden" }[lang];
|
|
assert.equal((await quit.textContent()).trim(), want);
|
|
assert.equal(await page.locator("#openMain").count(), 0);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|