Files
magpie/internal/gui/tests/settings-update-source.test.cjs
T
yetone 7bdda04509 settings: Update source's menu button shows its whole name (jiangshangmuyun on X)
Settings › About › Update source showed only a clipped glyph and the
chevron (reported on Windows, reproduced in Chromium and WebKit alike).
Cause: .pref-pick's max-width is min(230px, 45%), meant for a picker
that is the row's own child (Language). Update source's button sits in
the row's .val box, whose width is its content's, so 45% resolved
against the button's own width and shrank it each time. A .pref-pick
inside .val now takes min(230px, 100%); .val is held to 60% of the row
already. Only #updateSourcePick sits there (langPick and the sidebar
pages picker are the row's own children), so nothing else moves.

settings-update-source.test.cjs now checks the label is not clipped
for each of its three choices.

Run (mote):
- settings-update-source.test.cjs on the old CSS: 10 of 20 red (every
  language at 1100px in chromium and webkit, e.g. "自动: the label is
  clipped (24px in 0px, button 25.6px)"); with the fix 20 of 20 ok.
- node --test settings-update-source, segs-glide, uninstall-settings,
  update-mirror, update-download-steps, update-hide, update-quiet,
  update-row-steady, update-check, i18n-keys: 300 of 300 ok (both
  engines, every language).
- go test -run 'Budget|CSS|Asset|I18n' ./internal/gui: ok. gofmt clean.
Not tried: the real Windows app (WebView2); the whole GUI suite, as the
rule matches one element.
2026-11-16 09:43:49 +08:00

131 lines
7.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Run with Node's test runner and Playwright on the module path; see README.md.
// Update source (RootSir and Sakugar_ on X): Settings › About has a menu
// button right under Download source, with the other update settings, and
// Network no longer has it (WeltAn_X on X). Automatic, usemagpie.ai only and GitHub
// only each save updateSource alone (""/"site"/"github"), in the app's menu
// and in every language.
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 server(lang, posts) {
let cur = {
theme: "light", lang, tray: "panel", currency: "usd", textSize: 100,
proxy: "direct", proxyNow: "", proxySource: "off", pluginProxy: "", updateProxy: "",
trayUsageEvery: 3, version: "test", dir: "/test", lanURLs: [],
visionModels: [], imageGenModels: [], workbuddyCheckins: [],
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
};
return async (route) => {
const req = route.request(), url = new URL(req.url());
const json = (data) => route.fulfill({ json: data });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = ${JSON.stringify({ 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({ agents: [], profiles: [], settings: { lang, theme: "light" }, fx: cur.fx });
if (url.pathname === "/api/settings") {
if (req.method() === "POST") {
const body = req.postDataJSON();
posts.push(body);
// as settings.Save: the custom copy is the server's, set from the value
cur = { ...cur, ...body };
}
return json(cur);
}
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
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)];
return route.fulfill({ body: await fs.readFile(file), contentType });
};
}
const labels = {
en: { row: "Update source", auto: "Automatic", site: "usemagpie.ai only", github: "GitHub only", saved: "Saved" },
zh: { row: "更新源", auto: "自动", site: "仅 usemagpie.ai", github: "仅 GitHub", saved: "已保存" },
"zh-TW": { row: "更新來源", auto: "自動", site: "僅 usemagpie.ai", github: "僅 GitHub", saved: "已儲存" },
ja: { row: "アップデート元", auto: "自動", site: "usemagpie.ai のみ", github: "GitHub のみ", saved: "保存しました" },
de: { row: "Update-Quelle", auto: "Automatisch", site: "Nur usemagpie.ai", github: "Nur GitHub", saved: "Gespeichert" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of Object.keys(labels)) {
const l = labels[lang];
for (const width of [1100, 420]) {
test(`${engine} ${lang} ${width}px: the update source is picked from the app's menu`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const context = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" });
const page = await context.newPage();
page.setDefaultTimeout(4000);
page.setDefaultNavigationTimeout(60000);
const posts = [], errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, posts));
await page.goto("http://magpie.test/?view=settings&tab=about");
const row = page.locator("#about > #updateSourceRow");
await row.getByText(l.row, { exact: true }).waitFor();
assert.equal(await page.locator("#updateSourceRow").count(), 1, "one Update source row");
assert.equal(await page.locator("#setPage-network #updateSourceRow, #setPage-network #updateSourcePick").count(), 0, "not on Network");
assert(await row.evaluate((r) => r.previousElementSibling?.classList.contains("update-mirror-row")), "right under Download source");
assert.equal(await row.locator("select").count(), 0, "no native select");
const pick = page.locator("#updateSourcePick");
assert.equal(await pick.textContent(), l.auto);
// About is long: scrolled to by the wheel, as a reader does (a
// scroll Playwright makes isn't the reader's, and a save's redraw
// puts the view back where the reader left it)
await page.locator("#view-settings").hover();
for (let i = 0; i < 40; i++) {
const box = await row.boundingBox(), v = await page.locator("#view-settings").boundingBox();
if (box.y >= v.y + 4 && box.y + box.height <= v.y + v.height - 4) break;
await page.mouse.wheel(0, 180);
await page.waitForTimeout(16);
}
const choose = async (name, want) => {
const count = posts.length;
const response = page.waitForResponse((r) => r.url().endsWith("/api/settings") && r.request().method() === "POST");
await pick.click();
await page.locator(".proto-menu").waitFor();
assert.equal(await page.locator(".proto-menu .pm-item").count(), 3);
await page.locator(".proto-menu").getByRole("menuitemradio", { name, exact: true }).click();
await response;
await page.waitForFunction((word) => document.querySelector("#status")?.textContent.includes(word), l.saved);
assert.equal(posts.length, count + 1, "save once");
assert.equal(posts.at(-1).updateSource, want);
assert.equal(posts.at(-1).updateProxy, "", "the update proxy stays as it was");
assert.equal(posts.at(-1).proxy, "direct", "the global proxy stays as it was");
await page.waitForFunction((word) => document.querySelector("#updateSourcePick")?.textContent === word, name);
};
// the button is as wide as its name (jiangshangmuyun on X, Windows):
// a percentage width inside the row's value box shrank it to a
// clipped glyph and the chevron
const fits = async (name) => {
const m = await pick.evaluate((b) => {
const s = b.querySelector("span");
return { span: s.getBoundingClientRect().width, text: s.scrollWidth, pick: b.getBoundingClientRect().width };
});
assert(m.text <= Math.ceil(m.span) + 1, `${name}: the label is clipped (${m.text}px in ${m.span}px, button ${m.pick}px)`);
assert(m.span > 0, `${name}: the label shows`);
};
await fits(l.auto);
await choose(l.github, "github");
await fits(l.github);
await choose(l.site, "site");
await fits(l.site);
await choose(l.auto, "");
// the menu ticks the one chosen
await pick.click();
assert.equal(await page.locator(".proto-menu .pm-item.on").textContent(), l.auto);
await page.keyboard.press("Escape");
const over = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
assert(over <= 0, `the page scrolls sideways by ${over}px`);
assert.deepEqual(errors, []);
});
}
}
}