The owner on the Gateway page: "一点都不精致、优雅", the key row's copy button "很奇怪的位置,太突兀了", the gateway icon ugly, Connect should start folded, and "Share on local network" should be picked on this page with the LAN addresses shown. Agreed on a canvas first. - The status row has the sidebar's server glyph in a 28px tile with two lights (green running, amber not), the state beside it and the fix button at the right. The address pill left the row. - Under it, in the same card: Share on local network as This computer / Local network segments (settings/lan, as Settings does), and every address the gateway answers on, each with its own copy: this computer (or the public address on the web), then the LAN addresses, or a line saying there are none. Settings' container note comes from the same lanShown(). The "open LAN settings" button is gone. - A key's row: its copy right after the masked key; Rotate key and Remove moved into a "…" (Key actions) row menu at the end. - Connect starts folded; opening it is remembered (magpie.gwConnectFolded). - At narrow widths the status row wraps and the address list is a label/value grid, so no language overflows at 420px. Tests: new gateway-card (5 languages x 1100/420 x chromium/webkit): the lights, Connect folded, sharing from the card with every address and a copy of a LAN one, no scroll, the copy within 6px of the key, the … last with its menu, nothing overflowing, no left borders. Tests that used Connect open now open it; Rotate/Remove go through the menu (fixtures' keyAction). Run on mote, at the tree before the last rebase (51e3169fb+ this): gateway-card 52 of 52 over both engines; every GUI file this touches in both engines green except gateway-caller-keys' webkit en 560px overflow, red 3 of 3 at the base too (#3797). go test ./internal/gui: budgets ok; TestMainWindowCorners/macOS_26_SDK red on mote's macOS 27 alone (#3949). At this head (0dc4cec85+ this; main touched no GUI file since): gateway-card, gateway-fold, gateway-caller-keys 26 of 26, go test -run Budget ./internal/gui ok. Broken by hand: the copy moved after the spacer -> "the copy follows the masked key" red; the fold default put back -> gateway-card and gateway-fold red; the LAN addresses not rendered -> gateway-card times out. Screenshots looked at: zh 1100 and de 420, shared. Not tried yet: the whole GUI suite (mote was busy with another session's; it runs after this push), and the real Linux/Windows apps; the change is CSS and DOM in a page the GUI suite loads as the app does.
141 lines
7.8 KiB
JavaScript
141 lines
7.8 KiB
JavaScript
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 { fixture, keyAction } = require("./fixtures/caller-keys.cjs");
|
|
const { openPart } = require("./reader.cjs");
|
|
|
|
async function palette(page, selectors) {
|
|
return page.evaluate((selectors) => {
|
|
const root = getComputedStyle(document.documentElement);
|
|
const rgb = (name) => {
|
|
const hex = root.getPropertyValue(name).trim();
|
|
return `rgb(${[1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16)).join(", ")})`;
|
|
};
|
|
const colors = Object.fromEntries(["bg", "card", "card-2", "fg", "fg-2", "muted", "ctl-fg", "pill", "line", "accent", "accent-fg"]
|
|
.map((name) => [name, rgb("--" + name)]));
|
|
const elements = Object.fromEntries(Object.entries(selectors).map(([name, selector]) => {
|
|
const s = getComputedStyle(document.querySelector(selector));
|
|
return [name, { color: s.color, bg: s.backgroundColor, border: s.borderTopColor }];
|
|
}));
|
|
return { colors, elements };
|
|
}, selectors);
|
|
}
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const theme of (process.env.THEME ? [process.env.THEME] : ["light", "dark", "system"])) {
|
|
test(`${engine} ${theme}: API key controls follow the global palette`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const context = await browser.newContext({ viewport: { width: 1000, height: 760 }, reducedMotion: "reduce", colorScheme: "light" });
|
|
const page = await context.newPage();
|
|
await page.addInitScript(() => { try { localStorage.setItem("magpie.gwConnectFolded", "0"); } catch {} }); // Connect opened, as a user who reads it
|
|
page.setDefaultTimeout(6000);
|
|
const events = [], errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", fixture("en", theme, events, { lan: true }));
|
|
await page.goto("http://magpie.test/?view=gateway");
|
|
await page.locator('#gatewayKeys .acc[data-key="server"] .dot').click();
|
|
await page.locator('#gatewayKeys .acc.off[data-key="server"]').waitFor();
|
|
await page.locator("#addGatewayKey").click();
|
|
await page.locator('#gatewayKeys .acc[data-key="laptop"] .rename').click();
|
|
await page.locator("#gatewayKeys .rename-in").waitFor();
|
|
await page.mouse.move(500, 20);
|
|
const gatewaySelectors = { card: "#gatewayKeys .accts", enabled: '#gatewayKeys .acc[data-key="work"] .dot',
|
|
disabled: "#gatewayKeys .acc.off .dot", masked: "#gatewayKeys .acc .plan", form: "#gatewayKeys .adding",
|
|
input: "#gatewayKeys .adding input", rename: "#gatewayKeys .rename-in", create: "#gatewayKeys .primary", more: '#gatewayKeys .acc[data-key="work"] .gw-key-more', keyPick: "#connectKey" };
|
|
const gatewayPaints = [];
|
|
for (const scheme of ["light", "dark"]) {
|
|
await page.emulateMedia({ colorScheme: scheme });
|
|
await page.waitForTimeout(200);
|
|
const { colors: c, elements: e } = await palette(page, gatewaySelectors);
|
|
assert.equal(e.card.bg, c.card);
|
|
assert.equal(e.card.border, c.line);
|
|
assert.equal(e.enabled.bg, c.fg);
|
|
assert.equal(e.enabled.color, c.card);
|
|
assert.equal(e.disabled.color, c.muted);
|
|
assert.equal(e.masked.bg, c.pill);
|
|
assert.equal(e.masked.color, c.muted);
|
|
assert.equal(e.form.bg, c["card-2"]);
|
|
for (const input of [e.input, e.rename]) {
|
|
assert.equal(input.bg, c.card, "key inputs must not use the browser's default background");
|
|
assert.equal(input.color, c.fg);
|
|
}
|
|
assert.equal(e.more.color, c.muted); // the key's …, in the row's quiet text
|
|
assert.equal(e.keyPick.bg, "rgba(0, 0, 0, 0)");
|
|
assert.equal(e.create.bg, c.accent);
|
|
assert.equal(e.create.color, c["accent-fg"]);
|
|
gatewayPaints.push(c.bg);
|
|
if (process.env.ARTIFACT_DIR) {
|
|
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
|
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${theme}-${scheme}-keys.png`) });
|
|
}
|
|
}
|
|
assert.equal(gatewayPaints[0] === gatewayPaints[1], theme !== "system", "only System follows an OS palette change");
|
|
|
|
await keyAction(page, page.locator('#gatewayKeys .acc[data-key="work"]'), "Rotate key");
|
|
await page.locator("#modal .lib-confirm").waitFor();
|
|
for (const scheme of ["light", "dark"]) {
|
|
await page.emulateMedia({ colorScheme: scheme });
|
|
await page.waitForTimeout(200);
|
|
const { colors: c, elements: e } = await palette(page, {
|
|
dialog: "#modal .dialog", message: "#modal .lib-confirm", confirm: "#modal .primary",
|
|
});
|
|
assert.equal(e.dialog.bg, c.card);
|
|
assert.equal(e.message.color, c["fg-2"]);
|
|
assert.equal(e.confirm.bg, c.accent);
|
|
assert.equal(e.confirm.color, c["accent-fg"]);
|
|
if (process.env.ARTIFACT_DIR) {
|
|
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${theme}-${scheme}-confirm.png`) });
|
|
}
|
|
}
|
|
await page.locator("#modal").getByRole("button", { name: "Cancel", exact: true }).click();
|
|
await page.locator("#modal").waitFor({ state: "hidden" });
|
|
assert.equal(events.filter((e) => e.action === "rotate-key").length, 0);
|
|
|
|
await page.goto("http://magpie.test/?view=settings&tab=network");
|
|
const on = page.locator("#lanList").getByRole("button", { name: "On", exact: true });
|
|
await on.waitFor();
|
|
// the settings are read twice as the page opens (its own read and the
|
|
// state's), each drawing #lanList again: where On is comes from one read
|
|
// in the page, since a box asked of a button already replaced is null
|
|
const y = await (await page.waitForFunction(() => [...document.querySelectorAll("#lanList button")]
|
|
.find((b) => b.textContent.trim() === "On")?.getBoundingClientRect().y)).jsonValue();
|
|
await page.mouse.move(500, 400);
|
|
await page.mouse.wheel(0, y - 250);
|
|
await on.click();
|
|
await page.locator("#lanList .lan-url").waitFor();
|
|
await page.mouse.move(500, 20);
|
|
for (const scheme of ["light", "dark"]) {
|
|
await page.emulateMedia({ colorScheme: scheme });
|
|
await page.waitForTimeout(200);
|
|
const { colors: c, elements: e } = await palette(page, { card: "#lanList", text: "#lanList .row.pref:last-child .name",
|
|
key: "#lanList .lan-url", copy: "#lanList .row.pref:last-child .copy" });
|
|
assert.equal(e.card.bg, c.card);
|
|
assert.equal(e.text.color, c.fg);
|
|
assert.equal(e.key.color, c["fg-2"]);
|
|
assert.equal(e.copy.color, c.muted);
|
|
}
|
|
if (theme === "system") {
|
|
await page.mouse.move(500, 400);
|
|
await page.mouse.wheel(0, -5000);
|
|
for (const choice of ["Dark", "Light", "System"]) {
|
|
await openPart(page, "general");
|
|
await page.locator("#themeSegs").getByRole("button", { name: choice, exact: true }).click();
|
|
await page.waitForFunction((want) => (document.documentElement.dataset.theme || "system") === want, choice.toLowerCase());
|
|
await page.waitForFunction(() => !document.documentElement.classList.contains("theming"));
|
|
await openPart(page, "network");
|
|
const { colors: c, elements: e } = await palette(page, { card: "#lanList", key: "#lanList .lan-url" });
|
|
assert.equal(e.card.bg, c.card);
|
|
assert.equal(e.key.color, c["fg-2"]);
|
|
}
|
|
await page.reload();
|
|
await page.locator("#themeSegs button.on").waitFor({ state: "attached" });
|
|
assert.equal(await page.locator("#themeSegs button.on").textContent(), "System");
|
|
}
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|