providers: a key's chips keep their whole text; what ends its row goes under it when it doesn't fit (young02036)
young02036 (Discord #feedback, zh, Windows) had a Remote magpie key row whose models chip「全部模型」was squeezed to「全」. The row also showed the protocol pick and the actions (停用 移除 设为首选). Now only the name and the masked key shrink. Every chip and button keeps its whole text. Switch off/on, Remove and First/Make first are held together in one .key-acts group at the row's right. When they don't fit, the group goes onto its own line, still at the right. A press there now keeps its row open (`held`) through the redraw the press brings, until the pointer moves off the row. Without that, a wrapped row drawn again after a click goes back to one line, slips out from under the pointer, and hides the button that was pressed. key-switch.test caught this at en/ja/de 900px. WebKit gets plain `:hover`/`.held` selectors, not `:is()`/`:not()` lists. Trade-off: in a narrow card, a hovered key row grows by one line. Not changed: account rows, which use the .acc-line/⋯ layout, and the gateway's caller-key rows, which ellipsize on purpose. New test: tests/key-row-chips-fit.test.cjs, 60 cases (2 engines x zh, en, ja, de, zh-TW x 6 widths down to 390px). It checks that no chip or button of a key row is cut, and that the actions stay on one line at the right. Run: - key-row-chips-fit + key-switch, Chromium and WebKit on Linux (WSL magpie-desktop): 40/40 each. key-row-chips-fit on mote: 60/60; on Windows (xiaomi-gpu): 30/30. - Whole GUI suite, WebKit, on mote at this commit (another session's suite ran there too, load 55 to 160): 8663 tests, 8489 pass, 174 fail, in 50 files. Each red file was then run alone at origin/main20482d71fand at this commit, back to back, one at a time: base 570/419 pass/151 fail, head 570/414/156. 41 files are red on both sides, and 2 more (menu-input-scroll, routing-upstream) only at head. The 4 files whose tests differed (context-map, menu-input-scroll, routing-rule-remove, routing-upstream) were run twice more on each side: base 15/15 fail, head 13/15 fail. None of the reds is in a key row. - Whole GUI suite, Chromium, on mote at this commit: 5092 top-level results before mote went down mid-run (load ~200, "Connection to mote closed by remote host"; from sessions-convert on, every test read "browser has been closed"). After mote came back, the 30 files red before the drop, plus every file from sessions-* on (273 files), were run again: 2320 tests, 2194 pass, 126 fail, in 30 files. Those 30 were run alone at20482d71fand at this commit: base 251/123/128, head 251/126/125, the same files with the same counts, give or take one flake. The one red only at head, searcher-pick, went red 2 of 3 times alone at base and 0 of 3 at head (#4274). - Rebased on origin/mainfa4704f06(126 commits later). At this commit: TestCoreScriptBudget ok, under 1,539,856 (two comments in renderKeyAccounts trimmed, no budget raised). key-row-chips-fit, key-switch, key-weight-fit and i18n-keys: 52/52 in Chromium and 52/52 in WebKit. Reds at both base and head (WebKit, Chromium), with their issues: model-chip-steady #4388, agent-panel-name-width #4203, usage-agents-hide #3414, segs-press-redraw #4566, provider-fetch-again #3292, routing-rule-remove/rules-line/ story-shrinks/steps-cap/steady/row-swap/order-unknown/upstream #4585 #3954 #4628 #3412 #3799 #4627, page-width-steady #4541, rest-try-now #4127, recovered-file #4320, mobile-web #3952, key-replace #4126, models-works-only #4391, warm-now #4322, usage-ledger #1948, remote-magpie #4398, omarchy #4624, tencent-cloud #1579, s3-sync #3413, provider-typed #4461, provider-picks-stay #4397, provider-models-rest #4396, plugin-move-unserved #4392, plugin-card-update #3079, phone-connect-menu #3524, models-fold #4071, model-copy-id #4621, context-map #3488, provider-levels-scroll #4395, nav-timeout #4622, header-centre #3479, gui-ja #4580, gateway-key-models #4616, gateway-caller-keys #3797, i18n-keys #4524 (green atfa4704f06), menu-input-scroll #3402, models-select-all-api #4389, routing-rule-drag #3789, routing-many-keys #4082, searcher-pick #4274, account-weight #4644 (filed with this change). The whole-suite umbrellas are #4471 (WSL) and #4431 (WebKit on Windows). Broken by hand: - With the old app.css/app.js, key-row-chips-fit is 50/60 red: "amodels 「全部模型」is cut (14 of 58px)". The 10 passes are the 420px phone tab cases, where the old row already wrapped. - With `if (keyHeld === k.id) row.classList.add("held"), ` replaced by `if (0) `, key-switch en/ja/de 900px go red ("Switch off" hidden). Not tried: the real Windows app with a real Remote magpie, Linux WebKitGTK in the real app, and the account and gateway-key sibling rows, which are not changed.
This commit is contained in:
+34
-20
@@ -2681,7 +2681,7 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
.acc.in-use .dot { background: var(--fg); box-shadow: none; color: var(--card); }
|
||||
.acc .using { font-size: 11px; color: var(--fg-2); padding: 2px 8px; border-radius: 999px; box-shadow: inset 0 0 0 1px var(--line); }
|
||||
.acc .text.quiet { opacity: 0; transition: opacity .15s; }
|
||||
.acc:hover .text.quiet { opacity: 1; }
|
||||
.acc:hover .text.quiet, .acc.held .text.quiet { opacity: 1; }
|
||||
.acc .text.quiet:focus-visible { opacity: 1; }
|
||||
/* an account signed out (#1363) shows its Remove without a hover: it is
|
||||
one of the two ways out of that state, beside Sign in again */
|
||||
@@ -2746,7 +2746,7 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
.acc .proto svg { opacity: .7; transition: transform .15s var(--ease); }
|
||||
.acc .proto.open svg { transform: rotate(180deg); }
|
||||
.acc .proto:not(.set) { opacity: 0; background: none; box-shadow: inset 0 0 0 1px var(--line); }
|
||||
.acc:hover .proto, .acc .proto.open, .acc.adding .proto { opacity: 1; }
|
||||
.acc:hover .proto, .acc.held .proto, .acc .proto.open, .acc.adding .proto { opacity: 1; }
|
||||
.acc .proto:focus-visible { opacity: 1; }
|
||||
.acc .proto.set { color: var(--fg-2); }
|
||||
.acc .proto:hover, .acc .proto.open { color: var(--fg); background: var(--pill-hover); }
|
||||
@@ -2754,7 +2754,7 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
shown always once it keeps some only, and its picker under the row */
|
||||
.acc .amodels { flex: none; display: inline-flex; align-items: center; height: 20px; padding: 0 7px; font: inherit; font-size: 11px; color: var(--muted); border: 0; border-radius: 5px; background: var(--pill); white-space: nowrap; cursor: default; transition: opacity .15s, background .12s, color .12s; }
|
||||
.acc .amodels:not(.set) { opacity: 0; background: none; box-shadow: inset 0 0 0 1px var(--line); }
|
||||
.acc:hover .amodels, .acc .amodels.open { opacity: 1; }
|
||||
.acc:hover .amodels, .acc.held .amodels, .acc .amodels.open { opacity: 1; }
|
||||
.acc .amodels:focus-visible { opacity: 1; }
|
||||
.acc .amodels.set { color: var(--accent); background: var(--accent-soft); font-weight: 500; }
|
||||
.acc .amodels:hover, .acc .amodels.open { color: var(--fg); background: var(--pill-hover); }
|
||||
@@ -2769,7 +2769,7 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
/* an account's or key's limit on requests at once (#892), and how many
|
||||
run and wait under it: shown on hover unless a limit applies */
|
||||
.acc .alane { flex: none; display: inline-flex; align-items: center; height: 20px; padding: 0 7px; font: inherit; font-size: 11px; color: var(--muted); border: 0; border-radius: 5px; background: none; box-shadow: inset 0 0 0 1px var(--line); white-space: nowrap; cursor: default; opacity: 0; transition: opacity .15s, background .12s, color .12s; font-variant-numeric: tabular-nums; }
|
||||
.acc:hover .alane, .acc .alane.open, .acc .alane.set { opacity: 1; }
|
||||
.acc:hover .alane, .acc.held .alane, .acc .alane.open, .acc .alane.set { opacity: 1; }
|
||||
/* apart: Safari before 15.4 drops a whole selector list with :focus-visible in it */
|
||||
.acc .alane:focus-visible { opacity: 1; }
|
||||
.acc .alane.set { color: var(--fg); background: var(--pill-hover); box-shadow: none; }
|
||||
@@ -2826,33 +2826,46 @@ body.window .ag-sk-icon { width: 22px; height: 22px; border-radius: 6px; }
|
||||
/* Remove ends the line, and where the line wraps it ends the next */
|
||||
.acc .acc-tools > .text.quiet { margin-left: auto; }
|
||||
/* a key's row (#841): what shows only on hover takes no room till then,
|
||||
so a key's weight never squeezes its name away; the room it takes on
|
||||
hover is the row's free room, else the masked key's, and the models
|
||||
badge gives its own up first. First and Make first stay one line */
|
||||
.accts.keys .acc .plan { flex: 0 1 auto; min-width: 3em; overflow: hidden; text-overflow: ellipsis; }
|
||||
.accts.keys .acc > :is(.amodels:not(.set), .proto:not(.set), .alane:not(.set), .text.quiet) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.accts.keys .acc:not(:hover) > :is(.amodels:not(.set), .proto:not(.set), .alane:not(.set), .text.quiet):not(.open):not(:focus-visible) { max-width: 0; padding-left: 0; padding-right: 0; box-shadow: none; }
|
||||
.accts.keys .acc > :is(.amodels, .alane):not(.set):not(.open):not(:focus-visible) { flex-shrink: 10000; }
|
||||
so a key's weight never squeezes its name away. Shown, a chip keeps
|
||||
its whole text (young02036: 全部模型 was cut to 全): the name and the
|
||||
masked key give way, down to a few letters each, and what doesn't fit
|
||||
beside them then goes under the row's first line. What ends the row
|
||||
(key-acts) goes as one, still at the right end, each on one line. A
|
||||
press there keeps its row open (held) through the redraw it brings,
|
||||
till the pointer moves off: else the row, one line again, slips out
|
||||
from under the pointer and what was pressed hides */
|
||||
.accts.keys .acc[data-account-id] { flex-wrap: wrap; row-gap: 3px; }
|
||||
.accts.keys .acc > .n { flex: 1000 1 4.5em; max-width: max-content; min-width: 0; }
|
||||
.accts.keys .acc .plan { flex: 1000 1 3em; max-width: max-content; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
||||
.accts.keys .acc > :is(.amodels, .proto, .alane), .accts.keys .key-acts > .text.quiet { flex-shrink: 0; white-space: nowrap; }
|
||||
.accts.keys .acc > :is(.amodels:not(.set), .proto:not(.set), .alane:not(.set)), .accts.keys .key-acts > .text.quiet { overflow: hidden; }
|
||||
.accts.keys .acc:not(:hover):not(.held) > :is(.amodels:not(.set), .proto:not(.set), .alane:not(.set)):not(.open):not(:focus-visible),
|
||||
.accts.keys .acc:not(:hover):not(.held) .key-acts > .text.quiet:not(:focus-visible) { min-width: 0; max-width: 0; padding-left: 0; padding-right: 0; box-shadow: none; }
|
||||
/* and hidden, the gap beside it too */
|
||||
.accts.keys .acc:not(:hover):not(.held) > :is(.amodels:not(.set), .proto:not(.set)):not(.open):not(:focus-visible) { margin-left: -9px; }
|
||||
.accts.keys .acc:not(:hover):not(.held) .key-acts > .text.quiet:not(:focus-visible) { margin-right: -9px; }
|
||||
/* the limit pill unset on a key's row is quiet text, as the row's other
|
||||
hover-only controls: no padding to keep, and hidden it takes back the
|
||||
gap before it too (#892) */
|
||||
.accts.keys .acc > .alane:not(.set):not(.open):not(:focus-visible) { padding: 0; box-shadow: none; background: none; }
|
||||
.accts.keys .acc:not(:hover) > .alane:not(.set):not(.open):not(:focus-visible) { margin-left: -9px; }
|
||||
.accts.keys .acc > :is(.proto, .text.quiet) { flex-shrink: 0; }
|
||||
.accts.keys .acc:not(:hover):not(.held) > .alane:not(.set):not(.open):not(:focus-visible) { margin-left: -9px; }
|
||||
/* Safari before 15.4 has no :focus-visible and drops the rules above
|
||||
whole: there a focused control stays out on :focus instead */
|
||||
@supports not selector(:focus-visible) {
|
||||
.accts.keys .acc:not(:hover) > :is(.amodels:not(.set), .proto:not(.set), .alane:not(.set), .text.quiet):not(.open):not(:focus) { max-width: 0; padding-left: 0; padding-right: 0; box-shadow: none; }
|
||||
.accts.keys .acc > :is(.amodels, .alane):not(.set):not(.open):not(:focus) { flex-shrink: 10000; }
|
||||
.accts.keys .acc:not(:hover):not(.held) > :is(.amodels:not(.set), .proto:not(.set), .alane:not(.set)):not(.open):not(:focus),
|
||||
.accts.keys .acc:not(:hover):not(.held) .key-acts > .text.quiet:not(:focus) { min-width: 0; max-width: 0; padding-left: 0; padding-right: 0; box-shadow: none; }
|
||||
.accts.keys .acc:not(:hover):not(.held) > :is(.amodels:not(.set), .proto:not(.set)):not(.open):not(:focus) { margin-left: -9px; }
|
||||
.accts.keys .acc:not(:hover):not(.held) .key-acts > .text.quiet:not(:focus) { margin-right: -9px; }
|
||||
.accts.keys .acc > .alane:not(.set):not(.open):not(:focus) { padding: 0; box-shadow: none; background: none; }
|
||||
.accts.keys .acc:not(:hover) > .alane:not(.set):not(.open):not(:focus) { margin-left: -9px; }
|
||||
.accts.keys .acc:not(:hover):not(.held) > .alane:not(.set):not(.open):not(:focus) { margin-left: -9px; }
|
||||
}
|
||||
.accts.keys .acc .using, .accts.keys .acc > .text:not(.quiet) { flex: none; white-space: nowrap; }
|
||||
.accts.keys .acc > .key-acts { flex: none; display: flex; align-items: center; gap: 9px; margin-left: auto; }
|
||||
.accts.keys .acc .using, .accts.keys .key-acts > .text:not(.quiet) { flex: none; white-space: nowrap; }
|
||||
/* Switch off on hover, beside Remove (wei_VC on X): in a narrow weighted
|
||||
list the weight pill and Make first leave no room for it, and the name
|
||||
went to nothing; there the tick dot alone switches an on key off */
|
||||
.accts.keys { container-type: inline-size; }
|
||||
@container (max-width: 520px) { .accts.keys.weighted .acc > .key-switch.quiet { display: none; } }
|
||||
@container (max-width: 520px) { .accts.keys.weighted .key-acts > .key-switch.quiet { display: none; } }
|
||||
#gatewayKeys .acc { min-width: 0; }
|
||||
#gatewayKeys .acc .plan { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
||||
/* a gateway key's own limit (#585): the badge, what it used under the
|
||||
@@ -4059,8 +4072,9 @@ body.panel .modal { padding: 16px 12px; }
|
||||
key's row gives it back the room it folds away till a hover (#841) */
|
||||
body.web .acc :is(.text.quiet, .proto, .amodels, .alane) { opacity: 1; }
|
||||
body.web .acc .acc-more { opacity: 1; }
|
||||
body.web .accts.keys .acc > :is(.amodels, .proto, .alane, .text.quiet) { max-width: none !important; padding: 0 7px !important; flex-shrink: 0 !important; }
|
||||
body.web .accts.keys .acc > .alane:not(.set) { margin-left: 0 !important; }
|
||||
body.web .accts.keys .acc > :is(.amodels, .proto, .alane), body.web .accts.keys .key-acts > .text.quiet { max-width: none !important; padding: 0 7px !important; flex-shrink: 0 !important; }
|
||||
body.web .accts.keys .acc > :is(.amodels, .proto, .alane):not(.set) { margin-left: 0 !important; }
|
||||
body.web .accts.keys .key-acts > .text.quiet { margin-right: 0 !important; }
|
||||
body.web #gatewayKeys .acc > .key-quotas { max-width: none !important; padding: 0 7px !important; margin-left: 0 !important; flex-shrink: 0; }
|
||||
body.web #gatewayKeys .acc > .key-quotas:not(.set) { box-shadow: inset 0 0 0 1px var(--line) !important; }
|
||||
}
|
||||
|
||||
+14
-14
@@ -14444,7 +14444,7 @@ function keyWeight(p, k, w, total, path = "keys/weight", body = { id: p.id, ref:
|
||||
|
||||
// renderKeyAccounts: a key provider's accounts, one per key, the same list
|
||||
// a subscription has. addingKey holds the half-typed new one.
|
||||
let addingKey = null;
|
||||
let addingKey = null, keyHeld;
|
||||
function renderKeyAccounts(p) {
|
||||
const list = el("div", "accts keys");
|
||||
list.dataset.provider = p.id;
|
||||
@@ -14471,8 +14471,7 @@ function renderKeyAccounts(p) {
|
||||
name.onclick = () => renameIn(name, k.name || "", t("Name, e.g. Personal or Team"), (n) => accountAction("keys/rename", { id: p.id, ref: k.id, name: n }));
|
||||
row.append(dot, name);
|
||||
if (k.name) row.append(el("span", "plan mono", k.masked));
|
||||
// a key rotated at the vendor (#1869): its new value pasted in place,
|
||||
// keeping its name, place and settings; a rest it had is lifted
|
||||
// a key rotated at the vendor (#1869): its new value pasted in place
|
||||
const edit = el("button", "key-edit");
|
||||
edit.title = t("Paste a new value for this key; its name, place and settings stay");
|
||||
edit.setAttribute("aria-label", t("Change key"));
|
||||
@@ -14498,8 +14497,7 @@ function renderKeyAccounts(p) {
|
||||
};
|
||||
// a double-click on the row is the shortcut, away from its controls
|
||||
row.ondblclick = (e) => { if (!e.target.closest("button, input, textarea, .acct-models")) edit.onclick(e); };
|
||||
// each key copies its own (#1480): with several, the editor has no
|
||||
// API key field to show one in
|
||||
// each key copies its own (#1480)
|
||||
const cp = el("button", "copy");
|
||||
cp.title = t("Copy");
|
||||
cp.append(svg(COPY_ICON, 12, 1.5));
|
||||
@@ -14552,28 +14550,30 @@ function renderKeyAccounts(p) {
|
||||
// how many requests it has out at once, and waiting (#892)
|
||||
row.append(laneLimitPill(p, k.id, p.id + "#" + k.id, k.name || k.masked));
|
||||
row.append(el("span", "grow"));
|
||||
// off and on again by name, beside Remove (wei_VC on X: the dot alone
|
||||
// wasn't seen as a switch, so keeping a key meant adding it again).
|
||||
// The last key on stays on: the provider's own switch is for that.
|
||||
// Switch off shows on hover, as Remove does; an off key's Switch on
|
||||
// always shows, the one thing to do with it.
|
||||
// one, under the chips if it doesn't fit (young02036); held: app.css
|
||||
const acts = el("span", "key-acts");
|
||||
acts.onclick = () => keyHeld = k.id;
|
||||
if (keyHeld === k.id) row.classList.add("held"), addEventListener("pointermove", function go(e) { if (!row.contains(e.target)) keyHeld = null, row.classList.remove("held"), removeEventListener("pointermove", go); });
|
||||
// off and on by name (wei_VC on X); not the last key on, which the
|
||||
// provider's own switch is for. An off key's Switch on always shows
|
||||
if (!k.on || several) {
|
||||
const sw = el("button", "text key-switch" + (k.on ? " quiet" : ""), k.on ? t("Switch off") : t("Switch on"));
|
||||
sw.title = k.on ? t("Stop using this key") : t("Use this key too");
|
||||
sw.onclick = () => { sw.classList.add("busy"); accountAction("keys/" + (k.on ? "off" : "on"), { id: p.id, ref: k.id }); };
|
||||
row.append(sw);
|
||||
acts.append(sw);
|
||||
}
|
||||
if (!k.active || several) {
|
||||
const rm = el("button", "text quiet", t("Remove"));
|
||||
rm.onclick = () => accountAction("keys/remove", { id: p.id, ref: k.id }, t("Key removed"));
|
||||
row.append(rm);
|
||||
acts.append(rm);
|
||||
}
|
||||
if (k.active) row.append(el("span", "using", several ? t("First") : t("In use")));
|
||||
if (k.active) acts.append(el("span", "using", several ? t("First") : t("In use")));
|
||||
else if (k.on) {
|
||||
const first = el("button", "text", t("Make first"));
|
||||
first.onclick = () => { first.classList.add("busy"); accountAction("keys/use", { id: p.id, ref: k.id }, t("{name} tries {key} first", { name: p.name, key: k.name || k.masked })); };
|
||||
row.append(first);
|
||||
acts.append(first);
|
||||
}
|
||||
row.append(acts);
|
||||
if (restLine) row.append(restLine);
|
||||
if (amBox) row.append(amBox), row.classList.add("with-am");
|
||||
list.append(row);
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// A key's row keeps every chip and button whole (young02036 on Discord, a
|
||||
// Remote magpie's keys on Windows): hovered, a key with a protocol pick, its
|
||||
// models chip, its limit and Switch off, Remove and Make first showed its
|
||||
// models chip as one character, "全", the rest of 全部模型 cut off. Only the
|
||||
// key's name and its masked key give way; what doesn't fit beside them then
|
||||
// goes under the row's first line, Make first still at the right end. Every
|
||||
// chip's text fits its box, no two controls overlap and nothing leaves the
|
||||
// card, hovered or not. In every language, in the app's window from its
|
||||
// narrowest and in a browser tab, Chromium and WebKit.
|
||||
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(process.env.ASSET_DIR || path.resolve(__dirname, "../assets"));
|
||||
const remote = () => ({
|
||||
id: "remote", name: "Remote magpie", preset: "remote-magpie", icon: "generic",
|
||||
chat: "https://magpie.example.com/v1", responses: "https://magpie.example.com/v1", anthropic: "https://magpie.example.com", catalog: "",
|
||||
models: [{ id: "glm-5", name: "", on: true }, { id: "claude-opus-5", name: "", on: true }, { id: "gpt-6", name: "", on: true }],
|
||||
agents: [], fallback: [], headers: {}, routing: "",
|
||||
key: { set: true, masked: "sk-m…a1b2" }, balanceToken: { takes: false, set: false }, proxy: "",
|
||||
keyList: [
|
||||
{ id: "aaaaaaaaaa", name: "GLM", masked: "sk-m…a1b2", on: true, active: true },
|
||||
{ id: "bbbbbbbbbb", name: "除GLM之外的全部模型", masked: "sk-m…c3d4", on: true },
|
||||
{ id: "cccccccccc", name: "", masked: "sk-m…e5f6", on: true },
|
||||
],
|
||||
accountModels: { aaaaaaaaaa: ["glm-5"] },
|
||||
});
|
||||
|
||||
function serve(lang, web) {
|
||||
const providers = { providers: [remote()], presets: [], excluded: [], gateway: { running: true, window: true } };
|
||||
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:${web}};` });
|
||||
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" } });
|
||||
if (url.pathname === "/api/providers") return json(providers);
|
||||
if (url.pathname === "/api/groups") return json({ groups: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
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).catch(() => ""), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
// measure: each shown control of a key's row, in order, and the card's edges
|
||||
function measure(id) {
|
||||
const row = document.querySelector(`.editor .accts.keys .acc[data-account-id="${id}"]`);
|
||||
const card = row.closest(".accts").getBoundingClientRect();
|
||||
const shown = [...row.querySelectorAll("button, .plan, .using, .key-nourl")].filter((e) => {
|
||||
const s = getComputedStyle(e), b = e.getBoundingClientRect();
|
||||
return s.display !== "none" && s.visibility !== "hidden" && +s.opacity > 0.5 && b.width > 0;
|
||||
});
|
||||
return {
|
||||
card: { left: card.left, right: card.right },
|
||||
els: shown.map((e) => {
|
||||
const b = e.getBoundingClientRect();
|
||||
return { cls: String(e.className), text: e.textContent.trim(), left: b.left, right: b.right, top: b.top, bottom: b.bottom, sw: e.scrollWidth, cw: e.clientWidth };
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
const langs = ["zh", "en", "zh-TW", "ja", "de"];
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of langs) {
|
||||
// the app's window (its least is 560px) and a browser tab, which at
|
||||
// 760px and under lays a row out as on a phone
|
||||
for (const [web, width] of [[false, 560], [false, 760], [false, 1000], [false, 1280], [true, 420], [true, 1000]]) {
|
||||
const mode = web ? "tab" : "app";
|
||||
test(`${engine} ${lang} ${mode} ${width}px: a key's chips and buttons keep their whole text`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" })).newPage();
|
||||
t.after(async () => {
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
await page.locator(".editor .accts.keys").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${mode}-${width}-key-row-chips.png`) }).catch(() => {});
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, web));
|
||||
await page.goto("http://magpie.test/?view=providers");
|
||||
await page.locator(".row.provider", { hasText: "Remote magpie" }).first().click();
|
||||
await page.locator('.editor .accts.keys .acc[data-account-id="bbbbbbbbbb"] .proto').waitFor({ state: "attached" });
|
||||
|
||||
const check = async (id, hovered) => {
|
||||
const row = page.locator(`.editor .accts.keys .acc[data-account-id="${id}"]`);
|
||||
if (hovered) {
|
||||
await row.scrollIntoViewIfNeeded();
|
||||
await row.locator(".dot").hover();
|
||||
} else await page.mouse.move(0, 0);
|
||||
// the hover's fade is over: waited for, not timed (a busy WebKit
|
||||
// was still fading in after 250ms)
|
||||
await page.waitForFunction(() => document.getAnimations().every((a) => a.playState !== "running"));
|
||||
const m = await page.evaluate(measure, id);
|
||||
const at = `${id}${hovered ? " hovered" : ""}`;
|
||||
const all = m.els.map((e) => `${e.cls}「${e.text}」${Math.round(e.left)}–${Math.round(e.right)}@${Math.round(e.top)}`).join(" | ");
|
||||
// the chips the report is about are shown, when hovered
|
||||
if (hovered) {
|
||||
for (const c of ["proto", "amodels", "key-switch"]) assert.ok(m.els.some((e) => e.cls.split(" ").includes(c)), `${at}: no ${c} shown: ${all}`);
|
||||
}
|
||||
for (const e of m.els) {
|
||||
const words = e.cls.split(" ");
|
||||
// only the name and the masked key may end in "…"
|
||||
if (!words.includes("n") && !words.includes("plan")) assert.ok(e.sw <= e.cw + 1, `${at}: ${e.cls}「${e.text}」is cut (${e.cw} of ${e.sw}px): ${all}`);
|
||||
assert.ok(e.left >= m.card.left - 0.5 && e.right <= m.card.right + 0.5, `${at}: ${e.cls}「${e.text}」leaves the card (${e.left}–${e.right} in ${m.card.left}–${m.card.right})`);
|
||||
}
|
||||
// the name is never squeezed to nothing: a short one is whole,
|
||||
// a long one keeps a few letters
|
||||
const name = m.els.find((e) => e.cls.split(" ").includes("n"));
|
||||
assert.ok(name && name.cw >= Math.min(name.sw - 1, 30), `${at}: the name is squeezed to ${name?.cw}px: ${all}`);
|
||||
// not hovered, a key's row is one line, Make first beside its
|
||||
// name; a phone's tab lays its buttons out under it
|
||||
if (!hovered && !(web && width <= 760)) {
|
||||
const tops = m.els.map((e) => (e.top + e.bottom) / 2);
|
||||
assert.ok(Math.max(...tops) - Math.min(...tops) < 8, `${at}: the row isn't one line: ${all}`);
|
||||
}
|
||||
// no two controls overlap
|
||||
for (let i = 0; i < m.els.length; i++) for (let j = i + 1; j < m.els.length; j++) {
|
||||
const a = m.els[i], b = m.els[j];
|
||||
const apart = a.right <= b.left + 0.5 || b.right <= a.left + 0.5 || a.bottom <= b.top + 0.5 || b.bottom <= a.top + 0.5;
|
||||
assert.ok(apart, `${at}: ${a.cls}「${a.text}」and ${b.cls}「${b.text}」overlap: ${all}`);
|
||||
}
|
||||
};
|
||||
for (const id of ["aaaaaaaaaa", "bbbbbbbbbb", "cccccccccc"]) {
|
||||
await check(id, false);
|
||||
await check(id, true);
|
||||
}
|
||||
// Make first ends its row on the right, wrapped or not
|
||||
const ends = await page.evaluate(() => {
|
||||
const row = document.querySelector('.editor .accts.keys .acc[data-account-id="bbbbbbbbbb"]');
|
||||
const first = [...row.querySelectorAll("button.text")].find((b) => !b.classList.contains("quiet"));
|
||||
const pad = parseFloat(getComputedStyle(row).paddingRight);
|
||||
return { first: first.getBoundingClientRect().right, row: row.getBoundingClientRect().right - pad };
|
||||
});
|
||||
assert.ok(Math.abs(ends.first - ends.row) <= 1, `Make first doesn't end its row (${ends.first} vs ${ends.row})`);
|
||||
const over = await page.evaluate(() => [...document.querySelectorAll(".editor .accts .acc")].filter((e) => e.scrollWidth > e.clientWidth + 1).map((e) => `${e.dataset.accountId}:${e.scrollWidth}/${e.clientWidth}`));
|
||||
assert.deepEqual(over, [], "a row overflows its card");
|
||||
assert.equal(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth), true, "the page scrolls sideways");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user