gui: the Gateway page is one compact card, shares on the network from itself, and a key's copy sits by the key

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.
This commit is contained in:
yetone
2026-10-28 20:46:38 +08:00
parent 0dc4cec85d
commit f835bd713d
23 changed files with 315 additions and 99 deletions
+35 -10
View File
@@ -2277,20 +2277,45 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
.gw-sk-call .result { width: 68px; }
/* the status card: a dot where the logo would be, the URL as a pill */
.gwcard { margin: 4px 0 2px; }
.gw .dot { width: 8px; height: 8px; margin: 0 7px; border-radius: 50%; background: var(--amber); flex: none; box-shadow: 0 0 0 3px var(--amber-soft); }
.gw .dot.on { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.gw .who { flex: 1 1 auto; }
/* the gateway's mark, the sidebar's glyph in a tile, its two lights the
state: green running, amber not or served by an older magpie */
.gw { min-height: 52px; padding: 8px 10px 8px 11px; gap: 8px 11px; flex-wrap: wrap; }
.gw .gw-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; flex: none; color: var(--fg-2); background: var(--pill); box-shadow: inset 0 0 0 1px var(--line-2); }
.gw .gw-mark svg { display: block; }
.gw .gw-mark .led { fill: var(--amber); }
.gw .gw-mark.on .led { fill: var(--green); }
/* narrow, the fix button goes under the state rather than squeeze it */
.gw .who { flex: 1 1 15em; min-width: 0; }
.gw .name .state { margin-left: 8px; font-size: 11px; font-weight: 500; color: var(--green); }
.gw .dot:not(.on) ~ .who .state { color: var(--amber); }
.gw .gw-mark:not(.on) ~ .who .state { color: var(--amber); }
.gw .sub.old { white-space: normal; overflow: visible; text-overflow: clip; }
.gw .sub.err { color: var(--red); overflow-wrap: anywhere; }
/* the take-over / restart button: bordered, so it reads as a button on the
card in either theme (leslie_luo on Discord: in dark mode it didn't) */
.gw .gw-fix { display: inline-flex; height: auto; min-height: 27px; margin: 6px 0 0; padding: 4px 10px; white-space: normal; text-align: left; }
.gw .url { display: inline-flex; align-items: center; height: 24px; padding: 0 8px; border-radius: 6px; background: var(--pill); box-shadow: inset 0 0 0 1px var(--line-2); flex: none; transition: background .12s, box-shadow .12s; }
.gw .url:hover { background: var(--pill-hover); box-shadow: inset 0 0 0 1px var(--line); }
.gw .url code { color: var(--fg-2); font-size: 11px; }
.gw .url:hover code { color: var(--fg); }
.gw .gw-fix { display: inline-flex; flex: none; height: auto; min-height: 27px; max-width: 100%; margin: 0 0 0 auto; padding: 4px 10px; white-space: normal; text-align: left; }
/* Share on local network, on the card under the state, and the addresses
the gateway answers on: one quiet line each, the copy beside it */
#gatewayLan { border-top: 1px solid var(--line-2); }
/* narrow, the choice goes under its name rather than wrap it word by word */
.gw-share { min-height: 40px; padding: 5px 10px 5px 11px; flex-wrap: wrap; row-gap: 4px; }
.gw-share .name { flex: 1 1 9em; font-size: 12.5px; white-space: normal; overflow-wrap: anywhere; }
.gw-share .segs { align-self: center; flex: none; max-width: 100%; margin-left: auto; }
/* the addresses: their labels one column as wide as the longest, the
address and its copy the next */
.gw-urls { display: grid; grid-template-columns: max-content minmax(0, 1fr); column-gap: 14px; padding: 0 10px 7px 11px; }
.gw-url { display: contents; }
.gw-url-label { align-self: center; max-width: 12em; font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gw-url-val { display: flex; align-items: center; gap: 6px; min-height: 28px; min-width: 0; }
.gw-url code { flex: 0 1 auto; min-width: 0; font-size: 12px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: text; }
.gw-url .copy { flex: none; }
.gw-url-none { grid-column: 2; padding: 4px 0 2px; font-size: 11.5px; color: var(--muted); }
/* a gateway key: the copy right beside the masked key, the rest under
its … (the owner: a copy out in the row's middle looked lost) */
.gw-keys .acc > .plan + .copy { margin-left: -5px; }
/* narrow, the masked key gives up its room before the key's name does */
.gw-keys .acc > .plan { flex-shrink: 6; }
.gw-keys .gw-key-more { flex: none; color: var(--muted); }
.gw-keys .gw-key-more:is(:hover, .open) { color: var(--fg); }
#view-gateway .row-head, #view-usage .row-head { margin: 14px 0 6px; padding: 0 2px; }
#view-usage .row-head.quota-head { margin: 6px 0 6px; }
#view-gateway .row-head .note { font-size: 11px; color: var(--faint); }
@@ -3805,7 +3830,7 @@ body.panel .modal { padding: 16px 12px; }
body.web .row.gw { flex-wrap: wrap; }
body.web .row.gw > .who { flex: 1 1 0; min-width: 0; }
body.web .row.gw .sub { white-space: normal; }
body.web .row.gw > .url { order: 2; margin-left: 17px; max-width: calc(100% - 17px); }
body.web .row.gw > .gw-fix { order: 2; margin-left: 39px; max-width: calc(100% - 39px); }
body.web .call { flex-wrap: wrap; height: auto; min-height: 24px; padding: 3px 6px; }
body.web .call > .m { order: 2; margin-left: 20px; min-width: 0; }
body.web .call > .p { order: 3; }
+4
View File
@@ -451,6 +451,7 @@ const I18N = {
"Gateway key created. Use Copy on its row to connect a client.": "网关密钥已创建,用该行的复制按钮配置客户端。",
"Copy gateway key": "复制网关密钥",
"Rotate key": "轮换密钥",
"Key actions": "密钥操作",
"No gateway keys yet": "尚无网关密钥",
"No gateway key": "无网关密钥",
"Rotate gateway key?": "轮换网关密钥?",
@@ -4506,6 +4507,7 @@ const I18N = {
"Gateway key created. Use Copy on its row to connect a client.": "閘道金鑰已建立,用該行的複製按鈕設定用戶端。",
"Copy gateway key": "複製閘道金鑰",
"Rotate key": "輪換金鑰",
"Key actions": "金鑰操作",
"No gateway keys yet": "尚無閘道金鑰",
"No gateway key": "無閘道金鑰",
"Rotate gateway key?": "輪換閘道金鑰?",
@@ -8523,6 +8525,7 @@ const I18N = {
"Gateway key created. Use Copy on its row to connect a client.": "ゲートウェイキーを作成しました。行のコピーを使ってクライアントを接続してください。",
"Copy gateway key": "ゲートウェイキーをコピー",
"Rotate key": "キーを再発行",
"Key actions": "キーの操作",
"No gateway keys yet": "ゲートウェイキーはまだありません",
"No gateway key": "ゲートウェイキーなし",
"Rotate gateway key?": "ゲートウェイキーを再発行しますか?",
@@ -12557,6 +12560,7 @@ const I18N = {
"Gateway key created. Use Copy on its row to connect a client.": "Zugangsschlüssel erstellt. Mit „Kopieren“ in seiner Zeile einen Client verbinden.",
"Copy gateway key": "Zugangsschlüssel kopieren",
"Rotate key": "Schlüssel erneuern",
"Key actions": "Schlüsselaktionen",
"No gateway keys yet": "Noch keine Zugangsschlüssel",
"No gateway key": "Ohne Zugangsschlüssel",
"Rotate gateway key?": "Zugangsschlüssel erneuern?",
+61 -13
View File
@@ -15,8 +15,10 @@ let lang = gwParams.get("lang") || localStorage.getItem("magpie.lang") || "shell
let snipOS = localStorage.getItem("magpie.snipOS") || ""; // the shell the Shell and curl snippets are for (#1514)
let exampleModel = localStorage.getItem("magpie.model") || ""; // the model in the snippets
let decideModel = localStorage.getItem("magpie.decideModel") || ""; // the System One snippets' decision model
let connectFolded = false; // Connect folded away under its heading
try { connectFolded = localStorage.getItem("magpie.gwConnectFolded") === "1"; } catch {}
// Connect folded away under its heading: folded until it is opened, as it
// is set up once and seldom read again (the owner)
let connectFolded = true;
try { connectFolded = localStorage.getItem("magpie.gwConnectFolded") !== "0"; } catch {}
const expandedCalls = new Set(); // recent-call ids whose wire bodies are open
const callBodies = new Map(); // callRow → its bodies, read when it is opened (#1521)
// recent calls drawn a page at a time, as many as the plugin's setting
@@ -71,6 +73,7 @@ function renderGatewayView() {
page.classList.remove("loading");
page.removeAttribute("aria-busy");
renderGateway();
renderGatewayLan();
$("#gatewayKeysBlock").hidden = !providers.gateway.lan;
// not shared, the keys are left out; this line says where they come from,
// as a tunnel to loopback is refused until sharing is on (DD on Discord)
@@ -132,7 +135,9 @@ function gatewayFixSays(o) {
return t("The gateway couldn't be served here: {error}", p);
}
// The status card: dot, state, the URL.
// The status card: the gateway's mark, its state and what it does, and the
// button that fixes what stands in its way.
const GW_GLYPH = '<svg viewBox="0 0 20 20" width="16" height="16" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="14" height="5" rx="1.5"/><rect x="3" y="11" width="14" height="5" rx="1.5"/></g><circle class="led" cx="6.2" cy="6.5" r="1.1"/><circle class="led" cx="6.2" cy="13.5" r="1.1"/></svg>';
function renderGateway() {
const g = providers.gateway;
const box = $("#gateway");
@@ -140,7 +145,9 @@ function renderGateway() {
// an older magpie keeping the port sends every agent's request its own
// way, without this version's fixes (#506): said in place of the counts
const older = g.running && !g.mine && g.older;
const dot = el("span", "dot " + (older ? "old" : g.running ? "on" : ""));
// the sidebar's mark, its lights the state: green running, amber not
const mark = el("span", "gw-mark " + (older ? "old" : g.running ? "on" : ""));
mark.innerHTML = GW_GLYPH;
const who = el("div", "who");
const name = el("div", "name", t("Gateway"));
name.append(el("span", "state", older
@@ -154,18 +161,59 @@ function renderGateway() {
} else who.append(name, el("div", "sub", g.running
? [t(g.models === 1 ? "{n} model" : "{n} models", { n: g.models }), n ? t(n === 1 ? "{n} agent routed through it" : "{n} agents routed through it", { n }) : t("no agent routed through it yet"), t("five APIs, one URL")].join(" · ")
: t("start it with magpie serve, or open magpie at login")));
const fix = gatewayFixButton(g, older);
if (fix) who.append(fix);
if (gatewayFix.err && gatewayFix.when === gatewayFixWhen(g)) who.append(el("div", "sub old err", gatewayFix.err));
box.append(mark, who);
const fix = gatewayFixButton(g, older);
if (fix) box.append(fix);
}
// Share on local network, set on the page that hands out its keys (the
// owner): the same setting as Settings › Network and sharing, and every
// address the gateway answers on, each to copy.
let gatewayLanBusy = false;
function renderGatewayLan() {
const g = providers.gateway;
const box = $("#gatewayLan");
box.replaceChildren();
const head = el("div", "row gw-share");
const choice = segs([["off", t("This computer")], ["on", t("Local network")]], g.lan ? "on" : "off", (v) => {
if (gatewayLanBusy || (v === "on") === !!g.lan) return;
gatewayLanBusy = true;
writingPrefs(api("settings/lan", { on: v === "on" }))
.then((ns) => { prefs = ns; if (ns.rekeyed) status(ns.rekeyed, "err"); })
.catch((e) => status(t(e.message), "err"))
.then(() => loadProviders().catch(() => {}))
.finally(() => {
gatewayLanBusy = false;
if (view !== "gateway" || !providers) return;
renderGatewayView();
if (providers.gateway.lan) loadGatewayKeys();
});
});
choice.setAttribute("role", "group");
choice.setAttribute("aria-label", t("Share on local network"));
head.append(el("div", "name grow", t("Share on local network")), choice);
box.append(head);
const list = el("div", "gw-urls");
const line = (label, url) => {
const r = el("div", "gw-url");
const val = el("span", "gw-url-val");
val.append(el("code", "", url), copyBtn(url, t("Gateway URL")));
r.append(el("span", "gw-url-label", label), val);
list.append(r);
};
// served to other machines' browsers (magpie web), the address shown is
// the one they reach, MAGPIE_PUBLIC_URL's, not this computer's loopback
// (#1551)
const shown = web && g.publicURL || g.url;
const url = el("button", "url");
url.append(el("code", "", shown));
url.title = t("Copy the gateway URL");
url.onclick = () => copy(shown, t("Gateway URL"));
box.append(dot, who, url);
line(t(shown === g.url ? "This computer" : "Public address"), shown);
if (g.lan) {
const { urls, sub } = lanShown(g.lanURLs || [], prefs?.lanContainer);
urls.filter((u) => u !== shown).forEach((u, i) => line(i ? "" : t("Local network"), u));
if (!urls.length) list.append(el("div", "gw-url-none", t("This computer has no local network address right now")));
if (sub) list.append(el("div", "gw-url-none", sub));
}
box.append(list);
}
// One entry per API the gateway serves: where each SDK's base URL points,
@@ -660,13 +708,14 @@ magpie.plugin("gateway", (ctx) => {
html: `
<div class="list gwcard">
<div class="row gw" id="gateway"></div>
<div id="gatewayLan"></div>
</div>
<section id="gatewayKeysBlock" hidden>
<div class="row-head"><span class="label" data-t>Gateway keys</span><span class="grow"></span><button class="text" id="addGatewayKey" data-t>Add gateway key</button></div>
<p class="usage-note" data-t>Create a gateway key for each client. Usage is counted separately for each key.</p>
<section id="gatewayKeys"></section>
</section>
<p class="usage-note gw-keys-off" id="gatewayKeysOff" hidden><span data-t>Gateway keys are for other computers, and for a tunnel to this one such as Cloudflare Tunnel: they are added here once Share on local network is on. Agents on this computer need none.</span> <button class="text" id="openLanSettings" data-t>Network and sharing</button></p>
<p class="usage-note gw-keys-off" id="gatewayKeysOff" hidden data-t>Gateway keys are for other computers, and for a tunnel to this one such as Cloudflare Tunnel: they are added here once Share on local network is on. Agents on this computer need none.</p>
<div class="row-head"><button class="fold" id="foldConnect" aria-expanded="true" aria-controls="connect"><span class="label" data-t>Connect</span></button><span class="grow"></span><span class="note" id="connectNote"></span></div>
<section class="list connect" id="connect"></section>
<div class="row-head"><button class="fold" id="foldModels" aria-expanded="true" aria-controls="gwModels"><span class="label" data-t>Models</span><span class="note" id="modelsCount"></span></button><span class="grow"></span><button class="text" id="copyModels" data-t>Copy all ids</button></div>
@@ -689,7 +738,6 @@ magpie.plugin("gateway", (ctx) => {
renderGatewayModels();
backToReader($("#view-gateway"));
};
$("#openLanSettings").onclick = () => { openSettings(); setSetTab("network", true); };
new MutationObserver(gatewayKeysTicks).observe($("#view-gateway"), { attributes: true, attributeFilter: ["hidden"] });
document.addEventListener("visibilitychange", gatewayKeysTicks);
gatewayKeysTicks();
+26 -6
View File
@@ -205,7 +205,9 @@ function renderGatewayKeys() {
$("#gatewayKeysBlock").hidden = !providers?.gateway.lan;
box.replaceChildren();
$("#addGatewayKey").onclick = () => { gatewayKeyDraft = ""; renderGatewayKeys(); };
const list = el("div", "accts");
// keys: a badge left unset folds away until the row is pointed at, as
// on a provider's keys, so nothing invisible holds a place in the row
const list = el("div", "accts keys gw-keys");
if (gatewayKeys === null) {
if (gatewayKeysErr) list.append(el("div", "none", t(gatewayKeysErr))), box.append(list);
return;
@@ -218,11 +220,9 @@ function renderGatewayKeys() {
tick.setAttribute("aria-label", tick.title);
if (!k.off) tick.append(svg(CHECK, 10, 2.2));
tick.onclick = () => gatewayKeyAction(k.off ? "on-key" : "off-key", { key: k.id });
const rm = el("button", "text quiet", t("Remove"));
rm.onclick = () => askGatewayKey(k, false);
const rotate = el("button", "text quiet", t("Rotate key"));
rotate.onclick = () => askGatewayKey(k, true);
row.append(tick, gatewayRename(k), el("span", "plan mono", k.masked), el("span", "grow"), gatewayModelsBadge(k), gatewayQuotasBadge(k), gatewayLimitBadge(k), copyCallerKeyBtn(k), rotate, rm);
// the copy sits by the key it copies (the owner: stranded among the
// badges it read as nobody's); Rotate and Remove wait in the row's menu
row.append(tick, gatewayRename(k), el("span", "plan mono", k.masked), copyCallerKeyBtn(k), el("span", "grow"), gatewayModelsBadge(k), gatewayQuotasBadge(k), gatewayLimitBadge(k), gatewayKeyMore(k));
const under = gatewayLimit?.id === k.id ? [gatewayLimitEditor(k)] : keyUsed(k).map((u) => gatewayLimitLine(k, u));
if (under.length) row.classList.add("with-limit"), row.append(...under);
list.append(row);
@@ -232,6 +232,26 @@ function renderGatewayKeys() {
box.append(list);
}
const ROTATE_GLYPH = "M13.5 8a5.5 5.5 0 1 1-1.6-3.9M13.5 2.5v3.25h-3.25";
const REMOVE_GLYPH = "M3 4.5h10M6.5 4.5V3h3v1.5M4.5 4.5l.6 8.5h5.8l.6-8.5M7 7v4M9 7v4";
function gatewayKeyMore(k) {
const more = el("button", "copy gw-key-more");
more.type = "button";
more.title = t("Key actions");
more.setAttribute("aria-label", t("Key actions"));
more.setAttribute("aria-haspopup", "menu");
more.append(svg(DOTS, 14, 2));
more.onclick = (e) => {
e.stopPropagation();
if (more.classList.contains("open")) return closeAgentMenu();
openRowMenu(more, [
{ name: "Rotate key", icon: ROTATE_GLYPH, run: () => askGatewayKey(k, true) },
{ name: "Remove", icon: REMOVE_GLYPH, sep: true, run: () => askGatewayKey(k, false) },
]);
};
return more;
}
function askGatewayKey(k, rotate) {
const ed = el("div", "editor");
const head = el("div", "ehead");
+14 -11
View File
@@ -227,6 +227,19 @@ let lanSelectedURL = "", lanProtocol = "openai";
// the address picked under Share on local network is kept like Connect's
let lanWant = "";
try { lanWant = localStorage.getItem("magpie.lanAddress") || ""; } catch {}
// lanShown: the local network addresses the gateway is offered at, and a
// line on them when magpie runs in a container, for Settings and Gateway
// alike. In a container magpie finds only the container's own addresses;
// the page opened over the network was reached at the host's, so the
// gateway is offered there, on its port.
function lanShown(urls, container) {
if (!container) return { urls, sub: "" };
const host = location.hostname, port = urls.length ? new URL(urls[0]).port : "";
if (web && host && port && !/^(localhost|127\.|\[::1\]$)/.test(host))
return { urls: ["http://" + host + ":" + port], // an IPv6 hostname comes bracketed
sub: t("Where this page was opened, on the gateway’s port; MAGPIE_PUBLIC_URL sets another") };
return { urls, sub: t("The container’s own addresses, which other devices can’t reach: set MAGPIE_PUBLIC_URL to the host’s") };
}
function renderLAN(s) {
const box = $("#lanList");
box.replaceChildren();
@@ -250,17 +263,7 @@ function renderLAN(s) {
row(t("Share on local network"), t("Agents on other computers on this network, or through a tunnel to this one such as Cloudflare Tunnel, can use magpie’s models with a gateway key from Gateway"), "",
segs([["off", t("Off")], ["on", t("On")]], s.lan ? "on" : "off", (v) => set({ on: v === "on" })));
if (!s.lan) return;
let urls = s.lanURLs || [], sub = "";
// in a container magpie finds only the container's own addresses; the
// page opened over the network was reached at the host's, so the
// gateway is offered there, on its port
if (s.lanContainer) {
const host = location.hostname, port = urls.length ? new URL(urls[0]).port : "";
if (web && host && port && !/^(localhost|127\.|\[::1\]$)/.test(host)) {
urls = ["http://" + host + ":" + port]; // an IPv6 hostname comes bracketed
sub = t("Where this page was opened, on the gateway’s port; MAGPIE_PUBLIC_URL sets another");
} else sub = t("The container’s own addresses, which other devices can’t reach: set MAGPIE_PUBLIC_URL to the host’s");
}
const { urls, sub } = lanShown(s.lanURLs || [], s.lanContainer);
if (!urls.length) row(t("Address"), t("This computer has no local network address right now"), "");
else {
lanSelectedURL = urls.includes(lanWant) ? lanWant : urls[0];
+5 -4
View File
@@ -3,7 +3,7 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { fixture } = require("./fixtures/caller-keys.cjs");
const { fixture, keyAction } = require("./fixtures/caller-keys.cjs");
const { openPart } = require("./reader.cjs");
async function palette(page, selectors) {
@@ -30,6 +30,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["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));
@@ -43,7 +44,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
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", rotate: '#gatewayKeys .acc[data-key="work"] .text', keyPick: "#connectKey" };
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 });
@@ -61,7 +62,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
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.rotate.color, c["ctl-fg"]); // a text button, in a control's quiet text (#477)
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"]);
@@ -73,7 +74,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
}
assert.equal(gatewayPaints[0] === gatewayPaints[1], theme !== "system", "only System follows an OS palette change");
await page.locator('#gatewayKeys .acc[data-key="work"]').getByRole("button", { name: "Rotate key", exact: true }).click();
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 });
@@ -17,6 +17,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
await page.addInitScript(() => { try { localStorage.setItem("magpie.gwConnectFolded", "0"); } catch {} }); // Connect opened, as a user who reads it
page.setDefaultTimeout(6000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
@@ -43,6 +43,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const context = await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" });
await context.addInitScript((p) => Object.defineProperty(Navigator.prototype, "platform", { get: () => p }), platform);
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 errors = [];
page.on("pageerror", (e) => errors.push(e.message));
+7 -2
View File
@@ -178,9 +178,14 @@ function fixture(lang, theme, events, options = {}) {
await route.fulfill({ body: await fs.readFile(file), contentType: { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)] });
};
}
// keyAction picks Rotate key or Remove from a key's … menu
async function keyAction(page, row, label) {
await row.locator(".gw-key-more").click();
await page.locator(".row-menu").getByRole("menuitem", { name: label, exact: true }).click();
}
async function confirmKeyAction(page, row, label) {
await row.getByRole("button", { name: label, exact: true }).click();
await keyAction(page, row, label);
await page.locator("#modal").getByRole("button", { name: label, exact: true }).click();
await page.locator("#modal").waitFor({ state: "hidden" });
}
module.exports = { fixture, confirmKeyAction };
module.exports = { fixture, keyAction, confirmKeyAction };
@@ -3,7 +3,7 @@ const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { fixture, confirmKeyAction } = require("./fixtures/caller-keys.cjs");
const { fixture, keyAction, confirmKeyAction } = require("./fixtures/caller-keys.cjs");
const { openPart } = require("./reader.cjs");
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
@@ -93,7 +93,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert(events.some((e) => e.action === "clipboard" && e.body.text === "fixture-lan-1"));
const rotateLabel = lang === "zh" ? "轮换密钥" : "Rotate key";
const cancelLabel = lang === "zh" ? "取消" : "Cancel";
await lanRow.getByRole("button", { name: rotateLabel, exact: true }).click();
await keyAction(page, lanRow, rotateLabel);
assert.equal(await page.evaluate(() => callerFocus.at(-1)?.preventScroll), true, "confirmation focuses without scrolling");
await page.locator("#modal").getByRole("button", { name: cancelLabel, exact: true }).click();
await page.locator("#modal").waitFor({ state: "hidden" });
@@ -104,7 +104,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await lanRow.getByRole("button", { name: w.copy, exact: true }).click();
await page.waitForFunction(() => document.querySelector("#gatewayKeys .copy.done"));
assert(events.some((e) => e.action === "clipboard" && e.body.text === "fixture-rotated-2"));
await lanRow.getByRole("button", { name: w.remove, exact: true }).click();
await keyAction(page, lanRow, w.remove);
await page.keyboard.press("Escape");
await page.locator("#modal").waitFor({ state: "hidden" });
assert.equal(events.filter((e) => e.action === "remove-key").length, 0);
+118
View File
@@ -0,0 +1,118 @@
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 } = require("./fixtures/caller-keys.cjs");
// The Gateway page's card (the owner: "一点都不精致、优雅", and the key
// row's copy "很奇怪的位置"): the gateway's mark and state, Share on local
// network switched on the card itself with the addresses it answers on,
// each to copy; a key's copy right beside its masked key, Rotate key and
// Remove under its …; and Connect folded until it is opened.
const WORDS = {
en: { share: "Share on local network", local: "This computer", lan: "Local network", more: "Key actions", rotate: "Rotate key", remove: "Remove" },
zh: { share: "局域网共享", local: "本机", lan: "局域网", more: "密钥操作", rotate: "轮换密钥", remove: "移除" },
"zh-TW": { share: "區域網共享", local: "本機", lan: "區域網", more: "金鑰操作" },
ja: { share: "ローカルネットワークで共有", local: "このコンピュータ", lan: "ローカルネットワーク", more: "キーの操作" },
de: { share: "Im lokalen Netzwerk freigeben", local: "Dieser Computer", lan: "Lokales Netzwerk", more: "Schlüsselaktionen" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const locale of Object.keys(WORDS)) {
for (const width of [1100, 420]) {
test(`${engine} ${locale} ${width}: the gateway card shares on the network, and a key's copy sits by the key`, async (t) => {
const w = WORDS[locale];
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
t.after(async () => {
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}-${locale}-${width}-gateway-card.png`), fullPage: true });
}
await browser.close();
});
page.setDefaultTimeout(6000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
const events = [];
await page.route("**/*", fixture(locale, "dark", events));
await page.goto("http://magpie.test/?view=gateway");
const lanBox = page.locator("#gatewayLan");
await lanBox.locator(".gw-share").waitFor();
// the mark in its tile, the state beside it
assert.equal(await page.locator("#gateway > .gw-mark.on svg .led").count(), 2, "the mark's two lights");
assert.equal(await page.locator("#gateway .url").count(), 0, "no address pill in the status row");
// Connect folded by default, its base URL in its head
assert.equal(await page.locator("#foldConnect").getAttribute("aria-expanded"), "false", "Connect starts folded");
assert(await page.locator("#connect").evaluate((c) => c.hidden));
// not shared: the choice says This computer, one address, the keys away
assert.equal((await lanBox.locator(".gw-share .name").textContent()).trim(), w.share);
const opts = lanBox.locator(".segs button");
assert.deepEqual((await opts.allTextContents()).map((s) => s.trim()), [w.local, w.lan]);
assert.equal(await lanBox.locator(".gw-url").count(), 1);
assert.equal((await lanBox.locator(".gw-url code").textContent()).trim(), "http://127.0.0.1:3999");
assert.equal((await lanBox.locator(".gw-url-label").textContent()).trim(), w.local);
assert.equal(await page.locator("#gatewayKeysBlock").isVisible(), false);
// shared from the card, without a scroll: every LAN address, each with a copy
const y = await page.locator("#view-gateway").evaluate((v) => v.scrollTop);
await opts.last().click();
await page.locator("#gatewayKeysBlock").waitFor({ state: "visible" });
await page.waitForFunction(() => document.querySelectorAll("#gatewayLan .gw-url").length === 3);
assert.deepEqual(events.filter((e) => e.action === "lan").map((e) => e.body), [{ on: true }]);
assert.deepEqual((await lanBox.locator(".gw-url code").allTextContents()).map((s) => s.trim()),
["http://127.0.0.1:3999", "http://192.168.1.10:3999", "http://10.0.0.10:3999"]);
assert.deepEqual((await lanBox.locator(".gw-url-label").allTextContents()).map((s) => s.trim()), [w.local, w.lan, ""]);
assert.equal(await lanBox.locator(".gw-url .copy").count(), 3);
assert.equal(y, await page.locator("#view-gateway").evaluate((v) => v.scrollTop), "sharing moved the page");
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}-${locale}-${width}-gateway-card-shared.png`), fullPage: true });
}
await lanBox.locator(".gw-url").nth(1).locator(".copy").click();
await page.waitForFunction(() => document.querySelector("#gatewayLan .copy.done"));
assert(events.some((e) => e.action === "clipboard" && e.body.text === "http://192.168.1.10:3999"));
// a key's row: the copy right after the masked key, the … at the end
await page.waitForFunction(() => document.querySelectorAll("#gatewayKeys .acc[data-key]").length >= 3);
const row = page.locator('#gatewayKeys .acc[data-key="work"]');
const near = await row.evaluate((r) => {
const plan = r.querySelector(".plan"), copy = plan.nextElementSibling, more = r.querySelector(".gw-key-more");
const p = plan.getBoundingClientRect(), c = copy.getBoundingClientRect(), m = more.getBoundingClientRect(), b = r.getBoundingClientRect();
return { isCopy: copy.classList.contains("copy"), gap: c.left - p.right, moreRight: b.right - m.right, last: r.lastElementChild === more, label: more.getAttribute("aria-label") };
});
assert(near.isCopy, "the copy follows the masked key");
assert(near.gap >= 0 && near.gap <= 6, `the copy sits ${near.gap}px from the key`);
assert(near.last && near.moreRight <= 14, "the … ends the row");
assert.equal(near.label, w.more);
assert.equal(await row.locator(".text.quiet").count(), 0, "no Rotate or Remove words in the row");
await row.locator(".gw-key-more").click();
const menu = page.locator(".row-menu");
await menu.waitFor();
const items = (await menu.getByRole("menuitem").allTextContents()).map((s) => s.trim());
assert.equal(items.length, 2);
if (w.rotate) assert.deepEqual(items, [w.rotate, w.remove]);
assert.deepEqual(items, await page.evaluate(() => [t("Rotate key"), t("Remove")]));
await page.keyboard.press("Escape");
await menu.waitFor({ state: "detached" });
// nothing runs out of the page or a card, no coloured left border
const over = await page.evaluate(() => [...document.querySelectorAll("#gateway, #gatewayLan *, #gatewayKeys .acc")]
.filter((e) => e.scrollWidth > e.clientWidth + 1 && !e.matches("code, .gw-url-label, .plan, .rename, .n")).map((e) => e.className || e.tagName));
assert.deepEqual(over, [], "a row overflows");
assert(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth + 1), "the page scrolls sideways");
const borders = await page.evaluate(() => [...document.querySelectorAll(".gwcard *")].filter((e) => { const s = getComputedStyle(e); return parseFloat(s.borderLeftWidth) > 1 && s.borderLeftStyle !== "none"; }).map((e) => e.className));
assert.deepEqual(borders, []);
// back to This computer: one address again, the keys away
await opts.first().click();
await page.locator("#gatewayKeysBlock").waitFor({ state: "hidden" });
await page.waitForFunction(() => document.querySelectorAll("#gatewayLan .gw-url").length === 1);
assert.deepEqual(errors, []);
});
}
}
}
@@ -12,6 +12,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width: 1000, height: 760 }, reducedMotion: "reduce" })).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));
+22 -19
View File
@@ -41,7 +41,7 @@ const view = "#view-gateway";
const top = (page, sel) => page.locator(sel).evaluate((e) => e.getBoundingClientRect().top);
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": Connect folds away and stays folded", async (t) => {
test(engine + ": Connect starts folded, and opened or folded it stays so", async (t) => {
assert(["chromium", "webkit"].includes(engine), "BROWSER must be chromium or webkit");
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const context = await browser.newContext({ viewport: { width: 900, height: 560 }, reducedMotion: "reduce" });
@@ -58,45 +58,48 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await browser.close();
});
// folded until it is opened: set up once, seldom read again (the owner)
await page.goto("http://magpie.test/?view=gateway");
await page.locator("#connect .val code").first().waitFor();
await page.locator("#connectNote code").waitFor();
const fold = page.locator("#foldConnect");
assert.equal(await fold.getAttribute("aria-expanded"), "true", "Connect starts open");
assert.equal(await page.locator("#connectNote code").count(), 0, "open, the head has no URL of its own");
assert.equal(await fold.getAttribute("aria-expanded"), "false", "Connect starts folded");
assert(await page.locator("#connect").evaluate((c) => c.hidden), "folded, Connect's fields are hidden");
assert.equal((await page.locator("#connectNote code").textContent()).trim(), "http://127.0.0.1:3999/v1", "folded, the head shows the base URL");
assert.equal(await page.locator("#connectNote .copy").count(), 1, "with a copy button");
// scrolled so the Connect head is well down the view, the fold leaves it there
// scrolled so the Connect head is well down the view, opening leaves it there
await page.locator(view).evaluate((v) => { v.scrollTop = 40; });
await page.waitForTimeout(300);
const was = await top(page, "#foldConnect");
await fold.click();
await page.waitForTimeout(600);
assert.equal(await fold.getAttribute("aria-expanded"), "false");
assert(await page.locator("#connect").evaluate((c) => c.hidden), "folded, Connect's fields are hidden");
assert.equal(await fold.getAttribute("aria-expanded"), "true");
assert(await page.locator("#connect").evaluate((c) => !c.hidden), "opened, Connect's fields show");
assert.equal(await page.locator("#connectNote code").count(), 0, "open, the head has no URL of its own");
const is = await top(page, "#foldConnect");
assert(Math.abs(is - was) <= 1, `folding moved the head ${Math.round(is - was)}px`);
assert.equal((await page.locator("#connectNote code").textContent()).trim(), "http://127.0.0.1:3999/v1", "folded, the head shows the base URL");
assert.equal(await page.locator("#connectNote .copy").count(), 1, "with a copy button");
assert(Math.abs(is - was) <= 1, `opening moved the head ${Math.round(is - was)}px`);
// remembered across a reload
// opened, it stays open across a reload
await page.reload();
await page.locator("#activity .call").first().waitFor();
await page.locator("#connect .val code").first().waitFor();
// Reduced-motion animations can still be on their first frame when
// fast fixtures return. Compare the settled heading position.
await page.locator(view).evaluate(async (v) => {
await Promise.all(v.getAnimations().map((a) => a.finished.catch(() => {})));
});
assert.equal(await page.locator("#foldConnect").getAttribute("aria-expanded"), "false", "the fold is remembered");
assert(await page.locator("#connect").evaluate((c) => c.hidden));
assert.equal(await page.locator("#foldConnect").getAttribute("aria-expanded"), "true", "the open fold is remembered");
// and opens again, the head where it was
// and folds again, the head where it was, and stays folded
const before = await top(page, "#foldConnect");
await page.locator("#foldConnect").click();
await page.waitForTimeout(600);
assert.equal(await page.locator("#foldConnect").getAttribute("aria-expanded"), "true");
assert(await page.locator("#connect").evaluate((c) => !c.hidden));
assert.equal(await page.locator("#connectNote code").count(), 0);
assert.equal(await page.locator("#foldConnect").getAttribute("aria-expanded"), "false");
assert(await page.locator("#connect").evaluate((c) => c.hidden));
const after = await top(page, "#foldConnect");
assert(Math.abs(after - before) <= 1, `unfolding moved the head ${Math.round(after - before)}px`);
assert(Math.abs(after - before) <= 1, `folding moved the head ${Math.round(after - before)}px`);
await page.reload();
await page.locator("#connectNote code").waitFor();
assert.equal(await page.locator("#foldConnect").getAttribute("aria-expanded"), "false", "the fold is remembered");
assert.deepEqual(errors, []);
});
}
+8 -22
View File
@@ -6,8 +6,8 @@ const { fixture } = require("./fixtures/caller-keys.cjs");
// Gateway keys are left out of Gateway while magpie isn't shared, and a
// tunnel to loopback (Cloudflare Tunnel) is refused until it is. DD on
// Discord looked for the keys to put a tunnel behind one and found none:
// the page says where they come from, and its button opens Settings ›
// Network and sharing. Shared, the line gives way to the keys.
// the page says where they come from, and sharing is switched on right
// there, on the gateway's card. Shared, the line gives way to the keys.
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const locale of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1100, 420]) {
@@ -15,6 +15,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
await page.addInitScript(() => { try { localStorage.setItem("magpie.gwConnectFolded", "0"); } catch {} }); // Connect opened, as a user who reads it
page.setDefaultTimeout(6000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
@@ -28,31 +29,16 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const text = await hint.textContent();
assert(text.includes("Cloudflare Tunnel"), text);
if (locale !== "en") assert(!text.includes("other computers"), "translated: " + text);
// the line fits the page, the button inside it
const fits = await hint.evaluate((n) => {
const b = n.querySelector("button").getBoundingClientRect(), p = n.getBoundingClientRect();
return b.right <= p.right + 1 && p.right <= document.documentElement.clientWidth + 1;
});
// the line fits the page
const fits = await hint.evaluate((p) => p.getBoundingClientRect().right <= document.documentElement.clientWidth + 1);
assert(fits, "the hint overflows at " + width);
// shared from the card: the keys show and the line is gone
const y = await page.evaluate(() => scrollY);
await page.locator("#openLanSettings").click();
await page.locator("#setPage-network").waitFor({ state: "visible" });
assert.equal(await page.locator("#setTab-network").getAttribute("aria-selected"), "true");
const share = await page.locator("#lanList .row").first().textContent();
assert(share.includes("Cloudflare Tunnel"), share);
// shared: the keys show and the line is gone
const on = page.locator("#lanList .segs button").last();
const bounds = await on.boundingBox();
await page.mouse.move(width / 2, 400);
await page.mouse.wheel(0, bounds.y - 250);
await on.click();
await page.locator("#lanList .lan-address-row").waitFor();
await page.goto("http://magpie.test/?view=gateway");
await page.locator("#gatewayLan .segs button").last().click();
await page.locator("#gatewayKeysBlock").waitFor({ state: "visible" });
assert.equal(await hint.isVisible(), false);
assert.equal(y, 0);
assert.equal(y, await page.evaluate(() => scrollY), "sharing moved the page");
assert.deepEqual(errors, []);
});
}
@@ -61,6 +61,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const context = await browser.newContext({ viewport: { width: 900, height: 1000 }, reducedMotion: "reduce", colorScheme: theme });
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(5000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
-1
View File
@@ -109,7 +109,6 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
});
await page.goto("http://magpie.test/?view=gateway");
await page.locator("#foldConnect").click(); // Connect away, the calls in view
const rows = page.locator("#activity .call-item");
await rows.first().waitFor();
// what is clicked is brought into view by the wheel, as the reader
@@ -22,6 +22,7 @@ async function setup(t, engine, lang, width, pub) {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
await page.addInitScript(() => { try { localStorage.setItem("magpie.gwConnectFolded", "0"); } catch {} }); // Connect opened, as a user who reads it
page.setDefaultTimeout(6000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
+2 -2
View File
@@ -105,9 +105,9 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// its markup came back translated, and its wiring with it
assert.equal((await page.locator("#foldConnect .label").textContent()).trim(), await page.evaluate(() => t("Connect")), `${where}: translated again`);
await page.locator("#foldConnect").click();
await page.waitForFunction(() => document.querySelector("#connect").hidden);
await page.locator("#foldConnect").click();
await page.waitForFunction(() => !document.querySelector("#connect").hidden);
await page.locator("#foldConnect").click();
await page.waitForFunction(() => document.querySelector("#connect").hidden);
assert.deepEqual(errors, [], where);
await context.close();
}
@@ -29,6 +29,7 @@ async function setup(t, engine, lang, width, options) {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
await page.addInitScript(() => { try { localStorage.setItem("magpie.gwConnectFolded", "0"); } catch {} }); // Connect opened, as a user who reads it
page.setDefaultTimeout(6000);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
@@ -66,7 +67,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await keyed(page, PUBLIC + "/v1");
assert.doesNotMatch(await shown("#connect pre.snip"), /127\.0\.0\.1/);
// in the app, the gateway's own address stays this computer's
assert.equal(await shown("#gateway .url code"), LOCAL);
assert.equal(await shown("#gatewayLan .gw-url:first-child code"), LOCAL);
if (width >= 1100) assert.match(await shown("#sideGw span"), /127\.0\.0\.1:3999/);
await page.locator("#connectAddress").click();
assert.match(await page.locator(".proto-menu .pm-item", { hasText: "magpie.example.com" }).textContent(), new RegExp(words[lang]));
@@ -98,7 +99,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await open();
assert.equal(await shown("#connectAddress"), PUBLIC + "/v1");
await keyed(page, PUBLIC + "/v1");
assert.equal(await shown("#gateway .url code"), PUBLIC);
assert.equal(await shown("#gatewayLan .gw-url:first-child code"), PUBLIC);
// the sidebar's line at its foot, there at this width, says it too
if (width >= 1100) {
assert.match(await shown("#sideGw span"), /magpie\.example\.com/);
@@ -119,7 +120,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const { page, errors, open, shown, settingsTab } = await setup(t, engine, "en", 1100, { lanURLs: ["http://192.168.1.10:3999"], web: true });
await open();
assert.equal(await shown("#connectAddress"), LOCAL + "/v1");
assert.equal(await shown("#gateway .url code"), LOCAL);
assert.equal(await shown("#gatewayLan .gw-url:first-child code"), LOCAL);
await settingsTab("about");
await page.locator("#about .row").first().waitFor();
assert.equal(await page.locator("#publicURLRow").count(), 0);
+1
View File
@@ -74,6 +74,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
const context = await browser.newContext({ viewport: { width: 1100, height: 1000 }, reducedMotion: "reduce" });
t.after(() => context.close());
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 errors = [];
page.on("pageerror", (e) => errors.push(e.message));
@@ -64,7 +64,6 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.locator('[data-view="gateway"]').first().click();
const rows = page.locator("#activity .call-item");
await rows.first().waitFor();
await page.locator("#foldConnect").click();
assert.equal(seen.length, 0, "the recent list is metadata only");
await rows.first().locator(".call").click();
await rows.first().getByText(words[lang].loading, { exact: true }).waitFor();
@@ -118,7 +118,6 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
// the Gateway page: no switch, and a call the archive kept shows its
// bodies with nothing of the archive under them
await page.goto("http://magpie.test/?view=gateway");
await page.locator("#foldConnect").click();
const calls = page.locator("#activity .call-item");
await calls.first().waitFor();
assert.equal(await page.locator("#archiveList, #view-gateway [role=switch]").count(), 0, "no archive switch on the Gateway page");
-1
View File
@@ -113,7 +113,6 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
});
await page.goto("http://magpie.test/?view=gateway");
await page.locator("#foldConnect").click(); // Connect away, the calls in view
const rows = page.locator("#activity .call-item");
await rows.first().waitFor();
const body = (i) => rows.nth(i).locator(".call-body").nth(1);