Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

gui: with Hide accounts on, an account's eye shows that one account in this window (yogurt36)

yetoned3191a51c89d
diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md
index 4efb23a89..37b7ee14a 100644
--- a/docs/subsystems/gui-shell.md
+++ b/docs/subsystems/gui-shell.md
@@ -391,6 +391,7 @@ covers it in both engines, every language and a narrow window.
- In Usage → Allowances, Trends → Cycle offers each account's own recorded cycle menu beside its curve (`quotaCurve`, `quotaRecordedCycles` in [`app.js`](../../internal/gui/assets/app.js)). The longest window (usually weekly) owns the menu; shorter windows are drawn over the selected dates with their own reset breaks. `/api/usage/quotas/history?days=45` supplies all retained readings, including remote cards. Completed cycles come from observed boundaries, not seven-day arithmetic; an early reset ends the previous cycle at the vendor's new start if it fits between readings, otherwise at the first new reading. Each menu option gives its observed duration, so an early reset is not labelled as a full seven days. The selected meters, plot, legend, tooltip and dashed pace use that cycle's last readings, never today's percentages. A window without a reading in the selected interval says so instead of showing a current value. A local account's past cycle asks `/api/usage/quotas/history/holds?provider=&user=&from=&to=` once per selection (`quotaCycleHoldsOf`), which asks no vendor (#2009, NorethSea): `HistoricalWindowHolds` in [`window_holds_history.go`](../../internal/usage/window_holds_history.go) reckons each window's whole at its own last reading in that cycle, from the request log up to that reading, so the 5-hour figure is the cycle's last 5-hour window, never its short windows added up. Its tooltip names that window's start and the reading's time. It shows "Loading…" until the answer comes. A window it can't reckon says "not enough data" with the reason, as a current card does; a reply that comes after another cycle was picked is dropped, and a card's Refresh or an asked read reckons again. Historical meters show the cycle end and sampling time; current account actions, balances and policies are left out until returning to the current view. Accounts are independent, and a selection survives card refreshes in the same page. Trends → 2 days temporarily shows recent readings; Off removes the curves; the tray always shows its current cycle. See `quota-curve.test.cjs` and the [history limits and reset inference](providers-accounts.md#constraints-and-failure-behavior).
- The Usage page's cards are packed into columns, never all stretched to a row's height (`packUsage`, #860): each card in that order goes to the leftmost column that ends highest, on 1px grid rows, so short cards stack beside a tall one. The last card in each column then reaches down to where the tallest column ends (a `min-height`, cleared before the cards are measured again), so cards side by side in one row are as tall as each other and a stack ends with the tall card beside it (ikunbots on X); content stays at each card's top. The page's order (DOM, dragging, Alt+arrows) stays `UsageOrder`. The column count is the most 260px columns that fit, or one fewer when that leaves much less empty room; it is chosen again only when the cards change or the width fits another number of columns, so a card opened or folded stays where it is, even as the scrollbar comes in. See `usage-pack.test.cjs`.
- The Providers page has a search box over its list (#1614, `findProviders` in [`app.js`](../../internal/gui/assets/app.js)): the words typed keep the rows, on and off, whose text or data say them all: name, id, preset, addresses, every model's id and name, the account's user and plan and each login's, account names and key names. The Turned off fold stays open while searching; Escape or clearing the box shows every row and the fold as it was. A row that is on reorders by dragging its logo, Alt+↑/↓, Alt+Shift+↑/↓ (top, bottom) or its right-click menu (`openProviderMenu`: Move to top, Move up, Move down, Move to bottom). While searching, a step or a drop moves it among the rows shown (it takes the place of the row it passes, `stepProvider`, `shownToOn`) and the hidden ones keep their order; Move to top and Move to bottom go to the ends of the whole list. Every move saves the whole order through `POST /api/providers/arrange`. See `provider-find.test.cjs` and `provider-order.test.cjs`.
+- Hide accounts (`window.hideAccounts` at the end of [`app.js`](../../internal/gui/assets/app.js), stored in `magpie.maskEmails`, which the panel follows) masks every account name and address in the page's text and tooltips. While it is on, an account's name on the provider editor's row (`accountNameButton`, and the one-account line) and on its Usage card (`quotaWho`) has an eye (`hideAccounts.eye`), in sight on hover or keyboard focus. A click shows that one account, its address and the name the user gave it together (`kin`), everywhere the window draws it, tooltips included, while the others stay hidden (yogurt36 on Discord, for a screen share). The accounts shown are a set held in memory that `hits()` skips; nothing stores them. The panel keeps hiding them, and closing the window hides them again: the page stays loaded while the window is hidden, so `hideMain` runs `mainClosedJS` (`hideAccounts.closed`) first (`account-eye.test.cjs`, `TestClosingHidesShownAccounts`).
- A new user's Agents page (the window's first page and the panel's Agents tab) has a *Get started* card above the agents in the welcome's place (wangye1644294 on X, `guideCard` in [`app.js`](../../internal/gui/assets/app.js)). Its three steps are: add a model source; connect an agent, where the agents magpie found that can be connected are named and each is connected in one click (`agents/connect`); and, optional, a routing group, with the most harmless starter template that can be made from the user's models (`provider.Templates`, Never stuck first) added in one click through `POST /api/groups/template`. Every tick comes from the state: the models magpie serves (`served` in `/api/state`, groups left out), an agent wired, or a group that isn't automatic. None comes from the card having been seen. The card goes once the first two steps are done. Its close button saves `settings.GuideHidden` through `POST /api/settings/guide`, so the panel, the window and a reload agree, and the Settings save keeps it. See `getting-started.test.cjs`.
- Every page of the window keeps to one width, at most 1200px of content centred, with a 16px gutter in a narrow window (`padding: max(16px, calc(50% - 600px))` on each `#view-…`, #860). Routing, Usage and Sessions are in that rule too (面条 on Discord), so a large screen doesn't stretch them edge to edge while the others sit in the middle; their columns follow the room they get (`byWidth`). See `page-width.test.cjs`.
- The page must work in Chromium (Windows' WebView2) and WebKit (macOS, and WebKitGTK on Linux). GUI tests run in both engines.
diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css
index e4949b00a..05f232f4c 100644
--- a/internal/gui/assets/app.css
+++ b/internal/gui/assets/app.css
@@ -869,7 +869,7 @@ body.window .field.solo { grid-column: auto; }
.subscription-card.several .subscription-account.brief:not(:nth-child(2)) { padding-top: 7px; }
.subscription-account.brief { margin-bottom: 4px; }
.quota-acct-fold { align-self: center; display: inline-grid; place-items: center; flex: none; width: 18px; height: 18px; margin: -2px -5px -2px -3px; padding: 0; border-radius: 4px; color: var(--faint); transition: background .12s, color .12s; }
-.subscription-account .user + .quota-acct-fold { margin-left: auto; }
+.subscription-account :is(.user, .acct-eye) + .quota-acct-fold { margin-left: auto; }
.quota-acct-fold:hover { background: var(--pill); color: var(--fg-2); }
.quota-acct-fold svg { transform: rotate(180deg); transition: transform .15s ease-out; }
.quota-acct-fold[aria-expanded="false"] svg { transform: none; }
@@ -1020,7 +1020,14 @@ body.window .field.solo { grid-column: auto; }
/* "Every model" at the end of the account's line, above its families */
.text.quota-every { flex: none; margin: -2px -7px -2px 0; padding: 1px 7px; font-size: 10.5px; }
.subscription-account .plan + .quota-every, .subscription-head .plan + .quota-every { margin-left: 4px; }
-.subscription-account .user + .quota-every, .subscription-head .quota-every { margin-left: auto; }
+.subscription-account :is(.user, .acct-eye) + .quota-every, .subscription-head .quota-every { margin-left: auto; }
+/* Hide accounts' eye by an account's name: that one shown while the rest
+ stay hidden, for this window (yogurt36); in sight on hover or focus, and
+ while it shows its account */
+.acct-eye { display: none; flex: none; align-self: center; padding: 2px; border-radius: 4px; color: var(--muted); line-height: 0; opacity: 0; }
+body.masked .acct-eye { display: inline-flex; }
+body.masked :hover > .acct-eye, body.masked :focus-within > .acct-eye, .acct-eye[aria-pressed="true"] { opacity: 1; }
+.acct-eye:hover { color: var(--fg); background: var(--pill-hover); }
.quota-balance b { margin-left: auto; font-size: 15px; color: var(--fg); font-weight: 600; font-variant-numeric: tabular-nums; }
/* a balance field's several amounts (#420): a line each, the label quiet
at the left and the figure at the right, the first the larger; a
diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js
index 49c757d5e..b07a43663 100644
--- a/internal/gui/assets/app.js
+++ b/internal/gui/assets/app.js
@@ -9057,7 +9057,7 @@ function drawEditor(p, presetID) {
if (p.move) ed.append(...renderMove(p));
} else {
const acct = el("div", "acct");
- acct.append(icon(a.agentIcon), el("span", "n", a.user), el("span", "plan", accountPlan(a)));
+ acct.append(icon(a.agentIcon), el("span", "n", a.user), hideAccounts.eye(a.user), el("span", "plan", accountPlan(a)));
ed.append(...field(t("Account"), acct, t("{agent}'s sign-in, read from its own files. Sign out there and this provider goes away.", { agent: a.agentName })));
}
ed.append(...field(t("Models"), renderModels(p), ""));
@@ -13416,6 +13416,7 @@ function accountNameButton(p, user) {
s.title = t("The same seat as the key plan {name}, shown once, on this account's card", { name: seat });
wrap.append(s);
}
+ wrap.append(hideAccounts.eye(user));
return wrap;
}
function accountCapOf(p, user) { return p?.accountCaps?.[String(user).toLowerCase()] || 0; }
@@ -24341,9 +24342,12 @@ window.noteAccounts = noteAccounts;
// an address always is
const WORD = /[A-Za-z0-9_]/, JOIN = /[-.]/;
const joined = (s, i, step) => WORD.test(s[i] || "") || (JOIN.test(s[i] || "") && WORD.test(s[i + step] || ""));
+ // accounts shown while the rest stay hidden, this window's only (yogurt36)
+ const shown = new Set(), low = (x) => String(x).trim().toLowerCase();
function* hits(s, re) {
re.lastIndex = 0; // matchAll starts where the pattern's last test ended
for (const m of s.matchAll(re)) {
+ if (shown.has(low(m[0]))) continue;
const name = !m[0].includes("@"), end = m.index + m[0].length;
if (name && ((WORD.test(m[0][0]) && joined(s, m.index - 1, -1)) || (WORD.test(m[0].at(-1)) && joined(s, end, 1)))) continue;
yield m;
@@ -24466,8 +24470,41 @@ window.noteAccounts = noteAccounts;
if (!keep) { chosen = on ? "1" : "0"; try { localStorage.setItem("magpie.maskEmails", chosen); } catch {} }
for (const set of pages) set(on);
}
+ const kin = (u) => {
+ const k = [u];
+ for (const p of providers?.providers || []) for (const [a, n] of Object.entries(p.accountNames || {})) if (a === low(u) || n === u) k.push(a, n);
+ for (const q of quotas || []) if (q.user === u || q.alias === u) k.push(q.user, q.alias);
+ return k.filter(Boolean).map(low);
+ };
+ const paint = (b) => {
+ const on = shown.has(low(b._u));
+ b.setAttribute("aria-pressed", on);
+ b.title = t(on ? "Hide this account" : "Show this account");
+ b.querySelector("path").setAttribute("d", on ? EYE : EYE_OFF);
+ };
+ const redraw = () => {
+ document.querySelectorAll(".acct-eye").forEach(paint);
+ if (masked) for (const set of pages) set(true);
+ };
// Settings' Privacy has the same switch, and the settings follow
window.hideAccounts = {
+ eye: (u) => {
+ const b = el("button", "acct-eye");
+ b._u = u;
+ b.setAttribute("aria-label", t("Show this account"));
+ b.append(svg("", 13, 2));
+ b.firstChild.setAttribute("viewBox", "0 0 24 24");
+ paint(b);
+ b.onclick = (e) => {
+ e.stopPropagation();
+ const on = !shown.has(low(u));
+ for (const k of kin(u)) on ? shown.add(k) : shown.delete(k);
+ redraw();
+ };
+ return b;
+ },
+ // the window closed (hideMain): every account hidden again
+ closed: () => { shown.clear(); redraw(); },
on: () => masked,
set: (on) => setMasked(on),
follow: (personal) => { if (chosen === null && personal !== masked) setMasked(personal, true); },
diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js
index 6fe1cb86a..51b337735 100644
--- a/internal/gui/assets/i18n.js
+++ b/internal/gui/assets/i18n.js
@@ -3138,6 +3138,8 @@ const I18N = {
"{date}: not counted — magpie began counting on {since}": "{date}:未统计,magpie 从 {since} 开始统计",
"Counted since {date}": "从 {date} 开始统计",
"Accounts hidden": "账号已打码",
+ "Show this account": "显示这个账号",
+ "Hide this account": "重新给这个账号打码",
"Accounts are masked for a screenshot — click to show them": "账号已打码,点击显示",
"Add a model": "添加模型",
"Patterns": "模式",
@@ -7085,6 +7087,8 @@ const I18N = {
"{date}: not counted — magpie began counting on {since}": "{date}:未統計,magpie 從 {since} 開始統計",
"Counted since {date}": "從 {date} 開始統計",
"Accounts hidden": "帳號已打碼",
+ "Show this account": "顯示這個帳號",
+ "Hide this account": "重新給這個帳號打碼",
"Accounts are masked for a screenshot — click to show them": "帳號已打碼,點選顯示",
"Add a model": "新增模型",
"Patterns": "模式",
@@ -11045,6 +11049,8 @@ const I18N = {
"{date}: not counted — magpie began counting on {since}": "{date}:集計なし — magpie の集計開始は {since} です",
"Counted since {date}": "{date} から集計",
"Accounts hidden": "アカウントを非表示中",
+ "Show this account": "このアカウントを表示",
+ "Hide this account": "このアカウントを再び隠す",
"Accounts are masked for a screenshot — click to show them": "スクリーンショット用にアカウントを伏せています。クリックすると表示します",
"Add a model": "モデルを追加",
"Patterns": "パターン",
@@ -15015,6 +15021,8 @@ const I18N = {
"{date}: not counted — magpie began counting on {since}": "{date}: nicht gezählt – magpie zählt erst seit {since}",
"Counted since {date}": "Gezählt seit {date}",
"Accounts hidden": "Konten verborgen",
+ "Show this account": "Dieses Konto zeigen",
+ "Hide this account": "Dieses Konto wieder verbergen",
"Accounts are masked for a screenshot — click to show them": "Konten sind für einen Screenshot maskiert – zum Anzeigen klicken",
"Add a model": "Modell hinzufügen",
"Patterns": "Muster",
diff --git a/internal/gui/assets/plugins/usage/page.js b/internal/gui/assets/plugins/usage/page.js
index 680048fdc..a2c47c518 100644
--- a/internal/gui/assets/plugins/usage/page.js
+++ b/internal/gui/assets/plugins/usage/page.js
@@ -375,6 +375,7 @@ function quotaWho(q) {
s.title = t("The same seat as the key plan {name}, shown once, on this account's card", { name: q.seat });
out.push(s);
} else if (q.seat) out[0].title += "\n" + t("The same seat as the key plan {name}, shown once, on this account's card", { name: q.seat });
+ if (q.user || q.alias) out.push(hideAccounts.eye(q.user || q.alias));
return out;
}
diff --git a/internal/gui/mainwindow.go b/internal/gui/mainwindow.go
index de1a8e0da..75c4560c3 100644
--- a/internal/gui/mainwindow.go
+++ b/internal/gui/mainwindow.go
@@ -47,11 +47,18 @@ func closeStep(goos string, fullscreen bool) closeAction {
return closeHide
}
+// mainClosedJS tells the page its window was closed: an account shown
+// while Hide accounts is on (its eye) is hidden again, as each is shown for
+// the window's session only (yogurt36 on Discord). The page stays loaded
+// while the window is hidden, so it can't tell by itself.
+const mainClosedJS = "window.hideAccounts?.closed?.()"
+
// hideMain hides the main window, and takes magpie out of the Dock if it is
// there only while the window is shown.
func (h *host) hideMain() {
application.InvokeSync(func() {
if h.main != nil {
+ h.main.ExecJS(mainClosedJS)
h.main.Hide()
}
})
diff --git a/internal/gui/mainwindow_test.go b/internal/gui/mainwindow_test.go
index 3cdd9a316..d3f8ce7ec 100644
--- a/internal/gui/mainwindow_test.go
+++ b/internal/gui/mainwindow_test.go
@@ -3,6 +3,8 @@
package gui
import (
+ "os"
+ "strings"
"testing"
"github.com/wailsapp/wails/v3/pkg/application"
@@ -76,3 +78,38 @@ func TestFullscreenKeepsDock(t *testing.T) {
}
}
}
+
+// yogurt36 on Discord: an account shown by its eye while Hide accounts is on
+// is shown for the window's session only. Closing the window only hides it,
+// so hideMain tells the page; the call it makes is one app.js answers, and
+// what answers it forgets every account shown.
+func TestClosingHidesShownAccounts(t *testing.T) {
+ if mainClosedJS != "window.hideAccounts?.closed?.()" {
+ t.Fatalf("hideMain runs %q", mainClosedJS)
+ }
+ src, err := os.ReadFile("mainwindow.go")
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, hide, _ := strings.Cut(string(src), "func (h *host) hideMain() {")
+ hide, _, _ = strings.Cut(hide, "\n}\n")
+ if i, j := strings.Index(hide, "h.main.ExecJS(mainClosedJS)"), strings.Index(hide, "h.main.Hide()"); i < 0 || j < i {
+ t.Fatalf("hideMain doesn't tell the page before it hides the window:%s", hide)
+ }
+ js, err := os.ReadFile("assets/app.js")
+ if err != nil {
+ t.Fatal(err)
+ }
+ _, fn, ok := strings.Cut(string(js), "window.hideAccounts = {")
+ if !ok {
+ t.Fatal("app.js has no window.hideAccounts")
+ }
+ _, fn, ok = strings.Cut(fn, "\n closed: () => {")
+ if !ok {
+ t.Fatal("window.hideAccounts has no closed")
+ }
+ fn, _, _ = strings.Cut(fn, "\n")
+ if !strings.Contains(fn, "shown.clear()") {
+ t.Fatalf("closed forgets no shown account: %q", fn)
+ }
+}
diff --git a/internal/gui/tests/account-eye.test.cjs b/internal/gui/tests/account-eye.test.cjs
new file mode 100644
index 000000000..bb386ab1c
--- /dev/null
+++ b/internal/gui/tests/account-eye.test.cjs
@@ -0,0 +1,233 @@
+// Run with Node's test runner and Playwright on the module path; see README.md.
+// One account shown while Hide accounts hides the rest (yogurt36 on
+// Discord, for a screen share): with Hide accounts on, an account's name
+// on the provider editor's row and on its Usage card has a quiet eye, in
+// sight on hover or keyboard focus. A click shows that account, by its
+// address and the name the user gave it, wherever the window draws it,
+// tooltips too; the others stay hidden. It is the window's alone: the tray
+// panel keeps hiding it, and closing the window (hideMain's closed) hides
+// it again. With Hide accounts off there is no eye. A click moves nothing;
+// no native select, no border stripe; it fits at 360px. 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");
+const SEAT = "某某·GLM高级版", TEAM = "[email protected]", ME = "[email protected]";
+const inHours = (h) => new Date(Date.now() + h * 3600e3 + 60e3).toISOString();
+const provider = () => ({
+ id: "zcode", name: "ZCode", icon: "zcode", chat: "", responses: "", anthropic: "", catalog: "",
+ models: [{ id: "glm-5", name: "", on: true }],
+ agents: [], fallback: [], headers: {}, keyList: [], proxy: "",
+ account: {
+ agent: "zcode", agentName: "ZCode", user: TEAM, plan: "Pro",
+ logins: [
+ { user: TEAM, plan: "Pro", active: true, on: true },
+ { user: ME, plan: "Lite", on: true },
+ ],
+ },
+ accountNames: { [ME]: "Personal" },
+ accountSeats: { [TEAM]: SEAT },
+});
+const quotas = () => [
+ { provider: "zcode", name: "ZCode", icon: "zcode", plan: "Pro", user: TEAM, alias: SEAT, seat: SEAT,
+ windows: [{ name: "5 hours", used: 20, resetsAt: inHours(3) }] },
+ { provider: "zcode", name: "ZCode", icon: "zcode", plan: "Lite", user: ME, alias: "Personal",
+ windows: [{ name: "5 hours", used: 60, resetsAt: inHours(2) }] },
+];
+
+function serve(lang, panel = false) {
+ const settings = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd" };
+ const providers = { providers: [provider()], 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:${!panel}};` });
+ 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 });
+ if (url.pathname === "/api/settings") return json(settings);
+ if (url.pathname === "/api/providers") return json(providers);
+ if (url.pathname === "/api/usage/quotas") return json(quotas());
+ if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
+ if (url.pathname === "/api/plugins") return json({ plugins: [] });
+ if (url.pathname === "/api/login/usage") return json({});
+ 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)];
+ try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
+ };
+}
+
+const KEYS = ["Show this account", "Hide this account"];
+const LANGS = ["en", "zh", "zh-TW", "ja", "de"];
+
+for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
+ for (const lang of LANGS) {
+ const launch = async (t) => {
+ const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
+ t.after(() => browser.close());
+ return browser;
+ };
+ const tr = (page, k) => page.evaluate((k) => t(k), k);
+ const scrolled = (page) => page.evaluate(() => [window.scrollY, ...[...document.querySelectorAll("*")].filter((e) => e.scrollTop > 0).map((e) => `${e.className}:${e.scrollTop}`)].join(" "));
+ const wide = (page) => page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
+ const stripes = (page, sel) => page.evaluate((sel) => [...document.querySelectorAll(sel)].map((e) => getComputedStyle(e).borderLeftWidth).filter((b) => parseFloat(b) > 1), sel);
+ const opacity = (loc) => loc.evaluate((e) => getComputedStyle(e).display === "none" ? "none" : getComputedStyle(e).opacity);
+ // what of an element is in sight: its text and every tooltip in it
+ const seen = (loc) => loc.evaluate((e) => [e.textContent, ...[e, ...e.querySelectorAll("[title]")].map((x) => x.title || "")].join(" | "));
+ // a sentence and a tooltip elsewhere in the window naming both accounts
+ const sample = (page) => page.evaluate(([me, team]) => {
+ const d = document.createElement("div");
+ d.id = "sample";
+ d.textContent = `Personal · ${me} · ${team}`;
+ d.title = `${me} · ${team}`;
+ document.querySelector("main, body").append(d);
+ }, [ME, TEAM]);
+
+ test(`${engine} ${lang}: the provider editor's eye shows one account while the others stay hidden`, async (t) => {
+ const browser = await launch(t);
+ for (const width of [900, 360]) {
+ const context = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" });
+ const errors = [];
+ const open = async (url) => {
+ const page = await context.newPage();
+ page.setDefaultTimeout(5000);
+ page.on("pageerror", (e) => errors.push(e.message));
+ await page.route("**/*", serve(lang, url.includes("mode=panel")));
+ await page.goto(url);
+ return page;
+ };
+ const page = await open("http://magpie.test/?view=providers");
+ await page.locator(".row.provider", { hasText: "ZCode" }).first().click();
+ const row = (id) => page.locator(`.editor .accts .acc[data-account-id="${id}"]`);
+ await row(TEAM).locator(".acct-who").waitFor();
+ const eye = (id) => row(id).locator(".acct-eye");
+
+ // Hide accounts off: no eye at all
+ assert.equal(await eye(ME).count(), 1);
+ assert.equal(await opacity(eye(ME)), "none", "no eye while Hide accounts is off");
+
+ await page.evaluate(() => hideAccounts.set(true));
+ await sample(page);
+ await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 3);
+ await page.waitForFunction((me) => document.querySelector(`.editor .acc[data-account-id="${me}"] .acct-user .pii`), ME);
+ for (const id of [ME, TEAM]) assert.ok(!(await seen(row(id))).includes(id), `${id} is hidden first`);
+
+ // quiet until the name is pointed at; named for what it does
+ assert.equal(await opacity(eye(ME)), "0");
+ await row(ME).locator(".acct-who").hover();
+ assert.equal(await opacity(eye(ME)), "1", "the eye shows on hover");
+ assert.equal(await eye(ME).getAttribute("aria-label"), await tr(page, KEYS[0]));
+ assert.equal(await eye(ME).getAttribute("aria-pressed"), "false");
+ assert.equal(await eye(ME).getAttribute("title"), await tr(page, KEYS[0]));
+
+ // a click shows that one, by its address and its name, everywhere
+ // the window has it, its tooltips too; nothing moves
+ await eye(ME).scrollIntoViewIfNeeded();
+ await page.waitForTimeout(150);
+ const top = await row(ME).evaluate((e) => Math.round(e.getBoundingClientRect().top)), sc = await scrolled(page);
+ await eye(ME).click();
+ await page.waitForFunction((me) => !document.querySelector(`.editor .acc[data-account-id="${me}"] .pii`), ME);
+ assert.equal(await row(ME).evaluate((e) => Math.round(e.getBoundingClientRect().top)), top, "the row moved");
+ assert.equal(await scrolled(page), sc, "a click scrolled");
+ assert.equal(await row(ME).locator(".n.rename").textContent(), "Personal");
+ assert.equal(await row(ME).locator(".acct-user").textContent(), ME);
+ assert.ok((await row(ME).locator(".n.rename").getAttribute("title")).includes(ME), "its tooltip names it");
+ assert.equal(await eye(ME).getAttribute("aria-pressed"), "true");
+ assert.equal(await eye(ME).getAttribute("title"), await tr(page, KEYS[1]));
+ assert.equal(await opacity(eye(ME)), "1", "a shown account's eye stays in sight");
+ await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 1);
+ assert.equal(await page.locator("#sample .pii").getAttribute("data-raw"), TEAM);
+ assert.ok((await page.locator("#sample").textContent()).startsWith(`Personal · ${ME} · `));
+ assert.ok(!(await page.locator("#sample").textContent()).includes(TEAM));
+ assert.equal(await page.locator("#sample").getAttribute("title"), `${ME} · ${"•".repeat(10)}@••.•••`);
+ // the other stays hidden, in its row and its tooltips
+ assert.ok(await row(TEAM).locator(".pii").count() > 0);
+ assert.ok(!(await seen(row(TEAM))).includes(TEAM), "the other account stays hidden");
+ assert.equal(await eye(TEAM).getAttribute("aria-pressed"), "false");
+
+ // from the keyboard: Tab from the name reaches its eye, which shows
+ await page.mouse.move(0, 0);
+ await row(TEAM).locator(".n.rename").focus();
+ // WebKit on macOS tabs to a button only with Option, as Safari does
+ await page.keyboard.press(engine === "webkit" && process.platform === "darwin" ? "Alt+Tab" : "Tab");
+ assert.ok(await eye(TEAM).evaluate((e) => e === document.activeElement), "Tab reaches the eye");
+ assert.equal(await opacity(eye(TEAM)), "1", "the eye shows on focus");
+ await page.keyboard.press("Enter");
+ await page.waitForFunction((id) => !document.querySelector(`.editor .acc[data-account-id="${id}"] .pii`), TEAM);
+ assert.ok((await seen(row(TEAM))).includes(TEAM));
+ await page.keyboard.press(" ");
+ await page.waitForFunction((id) => document.querySelector(`.editor .acc[data-account-id="${id}"] .pii`), TEAM);
+ assert.ok(!(await seen(row(TEAM))).includes(TEAM), "pressed again, hidden again");
+
+ // the tray panel follows the window's setting, not its eye
+ const panel = await open("http://magpie.test/?mode=panel");
+ await panel.evaluate(() => setPanelTab("usage"));
+ await panel.locator("#panelQuota .pq-user").first().waitFor();
+ await panel.waitForFunction(() => document.querySelector("#panelQuota .pq-user .pii"));
+ const pq = await panel.evaluate(() => [...document.querySelectorAll("#panelQuota .pq-card")].map((c) => c.textContent + c.title).join(" "));
+ assert.ok(!pq.includes(ME) && !pq.includes("Personal"), "the panel still hides it: " + pq);
+ await panel.close();
+
+ // the window closed: every account hidden again
+ await page.evaluate(() => hideAccounts.closed());
+ await page.waitForFunction(() => document.querySelectorAll("#sample .pii").length === 3);
+ for (const id of [ME, TEAM]) assert.ok(!(await seen(row(id))).includes(id), `${id} is hidden after the window closed`);
+ assert.equal(await eye(ME).getAttribute("aria-pressed"), "false");
+
+ // and Hide accounts off: the eyes go
+ await page.evaluate(() => hideAccounts.set(false));
+ assert.equal(await opacity(eye(ME)), "none");
+
+ assert.equal(await page.locator("select").count(), 0, "no native select");
+ assert.deepEqual(await stripes(page, ".accts .acct-who, .accts .acct-who *"), [], "no border stripes");
+ assert.equal(await wide(page), 0, `no sideways scroll at ${width}px`);
+ const missing = await page.evaluate(([keys, lang]) => lang === "en" ? [] : keys.filter((k) => !I18N[lang]?.[k]), [KEYS, lang]);
+ assert.deepEqual(missing, [], `every string has its ${lang}`);
+ assert.deepEqual(errors, []);
+ await context.close();
+ }
+ });
+
+ test(`${engine} ${lang}: a Usage card's eye shows its account, on the card and its tooltips`, async (t) => {
+ const browser = await launch(t);
+ for (const width of [900, 360]) {
+ const context = await browser.newContext({ viewport: { width, height: 760 }, reducedMotion: "reduce" });
+ const page = await context.newPage();
+ page.setDefaultTimeout(5000);
+ const errors = [];
+ page.on("pageerror", (e) => errors.push(e.message));
+ await page.route("**/*", serve(lang));
+ await page.goto("http://magpie.test/?view=usage");
+ await page.locator(".subscription-account .quota-alias").first().waitFor();
+ const card = (id) => page.locator(".subscription-account", { has: page.locator(".quota-of", { hasText: id }) });
+ assert.equal(await opacity(card(ME).locator(".acct-eye")), "none");
+
+ await page.locator("#usageMask").click();
+ await page.waitForFunction(() => document.querySelectorAll(".subscription-account .quota-of .pii").length === 2);
+ const eye = (id) => page.locator(".subscription-account .acct-eye").nth(id === TEAM ? 0 : 1);
+ assert.equal(await opacity(eye(ME)), "0");
+ await page.locator(".subscription-account").nth(1).hover();
+ assert.equal(await opacity(eye(ME)), "1");
+ const sc = await scrolled(page);
+ await eye(ME).click();
+ await page.waitForFunction(() => document.querySelectorAll(".subscription-account .quota-of .pii").length === 1);
+ assert.equal(await scrolled(page), sc, "a click scrolled");
+ const mine = page.locator(".subscription-account").nth(1), team = page.locator(".subscription-account").nth(0);
+ assert.equal(await mine.locator(".quota-alias").textContent(), "Personal");
+ assert.equal(await mine.locator(".quota-alias").getAttribute("title"), "Personal · " + ME);
+ assert.equal(await mine.locator(".quota-of").textContent(), ME);
+ assert.ok(!(await seen(team)).includes(TEAM) && !(await seen(team)).includes(SEAT), "the other card stays hidden");
+ assert.equal(await eye(ME).getAttribute("aria-pressed"), "true");
+
+ assert.equal(await page.locator("select").count(), 0, "no native select");
+ assert.deepEqual(await stripes(page, ".subscription-account, .subscription-account *"), [], "no border stripes");
+ assert.equal(await wide(page), 0, `no sideways scroll at ${width}px`);
+ assert.deepEqual(errors, []);
+ await context.close();
+ }
+ });
+ }
+}