usage: a single-account card folds to its figures, and folded cards are one size (PILIHU2023 on X)

PILIHU2023 asked for a fold on each Usage → Overview card that leaves
only the usage, with the cards all one height and width.

- A card with one account (or one key) and figures to show (windows or a
  balance) now has a disclosure chevron at the end of its head, before
  its ⋯. It reuses the per-account fold (usageAcctFold, usageAccts in
  localStorage), so its state is kept across restarts and its titles
  are the existing ones. Folded, the card keeps its windows' names,
  bars and figures. It drops resets, curves, history, the reading line
  and the auto-reset and credits rows. A plan-only card (OpenCode Zen
  Free) has nothing to fold and gets no chevron.
- Cards with several accounts keep their own folds: each account's
  chevron, and the All N accounts strip's.
- Folded cards are packed to one height: the tallest folded single
  card. A card of several accounts, each in brief, takes whole rows of
  that height. A fully folded page is a grid of one width and one
  height. Open cards keep their natural height, so nothing is stretched
  or clipped (jen_celeus, #860).
- app.js was at its budget with no room. The Usage packing block
  (packUsage and its helpers, about 3.8KB of code) moved from app.js to
  plugins/usage/page.js, which already holds the Usage page's card
  menus. app.js code is now about 3.2KB under its budget. No budget was
  raised.
- The chevron's turn uses --ease-out (cubic-bezier(.23, 1, .32, 1)),
  .15s.

What was run:
- New usage-card-fold.test.cjs: Chromium and WebKit × en, zh, zh-TW,
  ja, de, at 1400, 900 and 400px and after a reload. It folds every
  card and checks they are one width and one height, sit on whole rows
  and don't overlap. It then unfolds two cards and checks they are
  their own height again. Red on origin/main 96d1b93b2 (0 of 1 in
  chromium-en), 10 of 10 on this change.
- usage-fold (one-account case updated), usage-pack, usage-card-fold,
  i18n-keys and go test -run Budget ./internal/gui, on mica after the
  rebase on 45185710e. Everything passed except four usage-fold
  subtests. Those four ('17 subscriptions and 29 accounts' in
  chromium and webkit, 'several accounts…' in webkit en and zh) fail
  the same way alone at origin/main 96d1b93b2. Noted on #6003.
- The first version gave a plan-only card a chevron. That wrapped Zen's
  head at 897px and turned usage-pack's "head's height" check red,
  which is why the windows-or-balance condition was added.
- A 175-file GUI run (the usage-related files and i18n-keys) on mica,
  before the plan-only fix. Only account-eye was red: "a Usage card's
  eye" in Chromium. Eight parallel runs on mote give 1–3 reds each at
  origin/main too, all at the same line. Noted on #5052.
- go test ./internal/gui: ok, before the rebase.

Not tried: the real app (WebKitGTK on Linux, WebView2 on Windows) and
real accounts. Only test fixtures were used.
This commit is contained in:
yetone
2026-11-15 14:04:13 +08:00
parent 45185710e4
commit 2e1c0a377b
5 changed files with 339 additions and 105 deletions
+4 -1
View File
@@ -1097,8 +1097,11 @@ body.panel .row.pref.flash { border-radius: 10px; }
.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 :is(.user, .acct-eye) + .quota-acct-fold { margin-left: auto; }
/* one account's card folds from its head's end, before its ⋯ (PILIHU2023 on X) */
.subscription-head > .quota-acct-fold { margin-left: auto; }
.subscription-head > :is(.plan, .quota-every, .quota-sum) ~ .quota-acct-fold { margin-left: 2px; }
.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 svg { transform: rotate(180deg); transition: transform .15s var(--ease-out); }
.quota-acct-fold[aria-expanded="false"] svg { transform: none; }
@media (prefers-reduced-motion: reduce) { .quota-acct-fold svg { transition: none; } }
.quota-windows.brief { row-gap: 5px; }
+12 -103
View File
@@ -16222,11 +16222,18 @@ function renderQuotas(lazy) {
// many accounts (Linx on X: twenty-odd): the same, each a row
const accts = !shut && !keys && several && subs.length > ACCTS_FOLD;
const folded = shut ? new Set(subs) : keys ? keysFolded(subs) : accts ? acctsFolded(subs) : new Set();
// one account or key folds from its head, in brief its windows alone;
// folded cards are packed to one height (PILIHU2023 on X): one account,
// or several under All N accounts, a row; several in brief, whole rows.
// One with no figures (a plan alone) has nothing to fold
const figures = !several && (first.windows?.length || first.balance);
const lone = figures && !usageAcctOpen(first, subs);
if (lone || shut || several && !keys && subs.every((q) => !usageAcctOpen(q, subs))) card.dataset.folded = several && !shut ? "n" : 1;
for (const sub of subs) {
if (folded.has(sub)) continue;
// "Every model" by the account, or the card's name: where the click
// was, whichever way the meters under it grow or shrink
const brief = several && !usageAcctOpen(sub, subs);
const brief = !usageAcctOpen(sub, subs);
const history = !brief && quotaHistoryView(sub);
const shownSub = history ? quotaHistoryCard(sub, history) : sub;
const [meters, every] = history ? [quotaWindows(shownSub), null] : familyQuota(sub);
@@ -16241,8 +16248,9 @@ function renderQuotas(lazy) {
who.append(...quotaWho(sub));
const warm = quotaWarm(sub);
if (warm) who.append(warm);
// in brief, its resets and whether it uses them by itself (#719)
const auto = brief && autoResetBrief(sub);
// in brief, its resets and whether it uses them by itself (#719);
// one card folded shows its figures alone
const auto = brief && several && autoResetBrief(sub);
if (auto) who.append(auto);
if (sub.plan || sub.until) who.append(planSpan(sub));
if (every) who.append(every);
@@ -16308,6 +16316,7 @@ function renderQuotas(lazy) {
// kept in its room: the strip stays put
if (shut) { m.inert = true; m.style.visibility = "hidden"; }
}
if (figures) head.append(usageAcctFold(first, !lone));
head.append(quotaCardMore(card, subs)); // its menu, where it is seen (page.js)
if (keys && (folded.size || usageKeysAll.has(first.provider))) card.append(keysMore(first.provider, folded.size));
if (accts && (folded.size || usageAcctsAll.has(first.provider))) card.append(acctsMore(first.provider, folded.size));
@@ -16488,106 +16497,6 @@ function keyCards(list) {
return gone.size ? list.filter((q) => !gone.has(q)).map((q) => merged.get(q) || q) : list;
}
// packUsage lays the Usage cards in 260px columns, each card to the column
// that ends highest (#860), as tall as what it holds (jen_celeus on X).
const USAGE_MIN = 260, USAGE_GAP = 7;
let usagePacked = null, usagePackFrame = 0;
function packUsage() {
const list = $("#subscriptionUsage");
if (usagePackFrame) { cancelAnimationFrame(usagePackFrame); usagePackFrame = 0; }
if (!list || list.classList.contains("sorting")) return;
const cards = [...list.children], width = list.clientWidth;
if (!width || !cards.length) {
// out of sight: the grid as it is without packing, packed once it shows
list.classList.remove("packed");
list.style.gridTemplateColumns = "";
for (const c of cards) { c.style.gridArea = ""; c.style.minHeight = ""; }
usagePacked = null;
return;
}
// sorted: a drag keeps the columns it was shown in
const keys = cards.map((c) => c.dataset.key || "").sort().join();
const most = Math.max(1, Math.min(cards.length, Math.floor((width + USAGE_GAP) / (USAGE_MIN + USAGE_GAP))));
const place = (n, hs) => {
const { at, ends } = usagePlace(n, hs);
const tall = Math.max(...ends) - USAGE_GAP;
// what stands empty under the columns' ends, by the columns' width
const empty = ends.reduce((s, e) => s + tall - (e - USAGE_GAP), 0) * (width - (n - 1) * USAGE_GAP) / n;
return { n, at, tall, empty };
};
const heights = () => {
for (const c of cards) c.style.minHeight = "";
fitQuota([...list.querySelectorAll(".quota-windows")]);
return cards.map((c) => c.getBoundingClientRect().height);
};
const columns = (n) => { list.style.gridTemplateColumns = `repeat(${n}, minmax(0, 1fr))`; };
let best;
if (usagePacked && usagePacked.most === most && usagePacked.keys === keys && list.classList.contains("packed")) {
// the same cards, as many columns fitting: the columns as they are
best = place(usagePacked.n, heights());
} else {
list.classList.remove("packed");
for (const c of cards) c.style.gridArea = "";
for (let n = most; n >= Math.max(1, most - 1); n--) {
columns(n);
const p = place(n, heights());
if (!best) best = p;
else if (p.tall <= best.tall * 1.3 && p.empty < best.empty * 0.6) best = p;
}
// measured again: a count beside its name or under it is the width's
columns(best.n);
best = place(best.n, heights());
}
usagePacked = { most, keys, n: best.n };
list.classList.add("packed");
best.at.forEach(([c, top, h], i) => {
const area = `${top + 1} / ${c + 1} / span ${Math.max(1, h)} / span 1`;
if (cards[i].style.gridArea !== area) cards[i].style.gridArea = area;
if (cards[i].style.minHeight) cards[i].style.minHeight = "";
});
}
// usagePlace packs heights hs into n columns: [column, top, height] each
function usagePlace(n, hs) {
const ends = Array(n).fill(0), at = [];
for (const h of hs.map(Math.ceil)) {
// the leftmost of those ending within a pixel of the highest
const low = Math.min(...ends), c = ends.findIndex((e) => e <= low + 1);
at.push([c, ends[c], h]);
ends[c] += h + USAGE_GAP;
}
return { at, ends };
}
// usageLayout: dragCards' layout for the packed Usage cards
function usageLayout(rects) {
const list = $("#subscriptionUsage");
const n = usagePacked?.n;
if (!n || !list?.classList.contains("packed")) return null;
const hs = rects.map((r) => r.height), now = usagePlace(n, hs).at;
const left = [];
now.forEach(([c], i) => { left[c] ??= rects[i].left; });
if (left.length < n || left.includes(undefined)) return null;
const top0 = rects[0].top - now[0][1];
return (order) => {
const at = [];
usagePlace(n, order.map((i) => hs[i])).at.forEach(([c, top], k) => { at[order[k]] = { left: left[c], top: top0 + top }; });
return at;
};
}
// a card's height or the page's width moved: packed on the next frame (in
// the observer's call WebKit reports a ResizeObserver loop). What is in a
// card is watched too, so one that only shrinks is packed again (#2059).
const usagePack = new ResizeObserver(() => { if (!usagePackFrame) usagePackFrame = requestAnimationFrame(packUsage); });
function packUsageNow(list) {
packUsage();
usagePack.disconnect();
usagePack.observe(list);
for (const card of list.children) {
usagePack.observe(card);
for (const part of card.children) usagePack.observe(part);
}
}
// usageHandle: a card's logo is its handle (drag, or Alt+arrows); a grip
// shows by it on hover.
let usageArranging = false, usageRenderPending = false;
+110
View File
@@ -5379,3 +5379,113 @@ function panelPageCut(list, peek = () => false, hidden = new Set()) {
function cardsShownFor(p) {
return (state.settings.usageCardsHidden || []).filter((k) => k.split("|")[0] !== p);
}
// The Usage cards' packing, moved from app.js (its renderQuotas calls
// packUsageNow once this file has run)
// packUsage lays the Usage cards in 260px columns, each card to the column
// that ends highest (#860), as tall as what it holds (jen_celeus on X).
const USAGE_MIN = 260, USAGE_GAP = 7;
let usagePacked = null, usagePackFrame = 0;
function packUsage() {
const list = $("#subscriptionUsage");
if (usagePackFrame) { cancelAnimationFrame(usagePackFrame); usagePackFrame = 0; }
if (!list || list.classList.contains("sorting")) return;
const cards = [...list.children], width = list.clientWidth;
if (!width || !cards.length) {
// out of sight: the grid as it is without packing, packed once it shows
list.classList.remove("packed");
list.style.gridTemplateColumns = "";
for (const c of cards) { c.style.gridArea = ""; c.style.minHeight = ""; }
usagePacked = null;
return;
}
// sorted: a drag keeps the columns it was shown in
const keys = cards.map((c) => c.dataset.key || "").sort().join();
const most = Math.max(1, Math.min(cards.length, Math.floor((width + USAGE_GAP) / (USAGE_MIN + USAGE_GAP))));
const place = (n, hs) => {
const { at, ends } = usagePlace(n, hs);
const tall = Math.max(...ends) - USAGE_GAP;
// what stands empty under the columns' ends, by the columns' width
const empty = ends.reduce((s, e) => s + tall - (e - USAGE_GAP), 0) * (width - (n - 1) * USAGE_GAP) / n;
return { n, at, tall, empty };
};
const heights = () => {
for (const c of cards) c.style.minHeight = "";
fitQuota([...list.querySelectorAll(".quota-windows")]);
return foldedHeights(cards, cards.map((c) => c.getBoundingClientRect().height));
};
const columns = (n) => { list.style.gridTemplateColumns = `repeat(${n}, minmax(0, 1fr))`; };
let best;
if (usagePacked && usagePacked.most === most && usagePacked.keys === keys && list.classList.contains("packed")) {
// the same cards, as many columns fitting: the columns as they are
best = place(usagePacked.n, heights());
} else {
list.classList.remove("packed");
for (const c of cards) c.style.gridArea = "";
for (let n = most; n >= Math.max(1, most - 1); n--) {
columns(n);
const p = place(n, heights());
if (!best) best = p;
else if (p.tall <= best.tall * 1.3 && p.empty < best.empty * 0.6) best = p;
}
// measured again: a count beside its name or under it is the width's
columns(best.n);
best = place(best.n, heights());
}
usagePacked = { most, keys, n: best.n };
list.classList.add("packed");
best.at.forEach(([c, top, h], i) => {
const area = `${top + 1} / ${c + 1} / span ${Math.max(1, h)} / span 1`;
if (cards[i].style.gridArea !== area) cards[i].style.gridArea = area;
const min = cards[i].dataset.folded ? h + "px" : "";
if (cards[i].style.minHeight !== min) cards[i].style.minHeight = min;
});
}
// foldedHeights: a folded card as tall as the tallest folded one of one
// account, or whole rows of it, so folded cards line up in a grid; an
// open one stays as tall as itself (jen_celeus on X)
function foldedHeights(cards, hs) {
const row = Math.max(0, ...hs.filter((h, i) => cards[i].dataset.folded == 1)) + USAGE_GAP;
return hs.map((h, i) => row > USAGE_GAP && cards[i].dataset.folded ? Math.ceil((h + USAGE_GAP) / row - .01) * row - USAGE_GAP : h);
}
// usagePlace packs heights hs into n columns: [column, top, height] each
function usagePlace(n, hs) {
const ends = Array(n).fill(0), at = [];
for (const h of hs.map(Math.ceil)) {
// the leftmost of those ending within a pixel of the highest
const low = Math.min(...ends), c = ends.findIndex((e) => e <= low + 1);
at.push([c, ends[c], h]);
ends[c] += h + USAGE_GAP;
}
return { at, ends };
}
// usageLayout: dragCards' layout for the packed Usage cards
function usageLayout(rects) {
const list = $("#subscriptionUsage");
const n = usagePacked?.n;
if (!n || !list?.classList.contains("packed")) return null;
const hs = rects.map((r) => r.height), now = usagePlace(n, hs).at;
const left = [];
now.forEach(([c], i) => { left[c] ??= rects[i].left; });
if (left.length < n || left.includes(undefined)) return null;
const top0 = rects[0].top - now[0][1];
return (order) => {
const at = [];
usagePlace(n, order.map((i) => hs[i])).at.forEach(([c, top], k) => { at[order[k]] = { left: left[c], top: top0 + top }; });
return at;
};
}
// a card's height or the page's width moved: packed on the next frame (in
// the observer's call WebKit reports a ResizeObserver loop). What is in a
// card is watched too, so one that only shrinks is packed again (#2059).
const usagePack = new ResizeObserver(() => { if (!usagePackFrame) usagePackFrame = requestAnimationFrame(packUsage); });
function packUsageNow(list) {
packUsage();
usagePack.disconnect();
usagePack.observe(list);
for (const card of list.children) {
usagePack.observe(card);
for (const part of card.children) usagePack.observe(part);
}
}
+211
View File
@@ -0,0 +1,211 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// PILIHU2023 on X (Usage > Overview): 「用量的概览页卡片,添加折叠按钮,随后
// 点击后仅显示用量,同时控制每个卡片高度宽度一致」. A card of one account or
// key has a fold in its head; folded, it shows its windows' figures and bars
// alone (no curve, resets line or "Updated"), and stays so across a reload.
// Folded cards are one width and one height, in rows that line up: a
// provider's accounts folded under "All N accounts" are a row too, and
// accounts each in brief (no All N accounts: their plans differ) take
// whole rows. A card left open is as tall as what it holds, never cut and
// never stretched (jen_celeus on X). Unfolding gives the card back as it was.
// Chromium and WebKit, at 1400, 900 and 400px, in every language; no
// backend, the API is faked here.
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 H = 3600e3;
const iso = (ms) => new Date(ms).toISOString();
function fixtures(now) {
const w = (name, used, h) => ({ name, used, resetsAt: iso(now + h * H) });
const ag = (name, family, used, h) => ({ name, family, used, resetsAt: iso(now + h * H) });
const rw = now + 4 * 24 * H;
const week = [];
for (let h = 72; h >= 0; h -= 4) week.push({ at: iso(now - h * H), left: 19 + h, start: iso(rw - 168 * H), resetsAt: iso(rw) });
const points = [[48, 30], [36, 25], [24, 22], [12, 20], [0, 17.41]].map(([h, v]) => ({ at: iso(now - h * H), amount: v }));
const quotas = [
{ provider: "claude", name: "Claude Code", icon: "claude-color", user: "me@example.com", plan: "Max 5x", lastServedAt: iso(now), readAt: iso(now),
windows: [w("5 hours", 23, 3), w("7 days", 41, 90)] },
{ provider: "codex", name: "Codex", icon: "codex-color", user: "me@example.com", plan: "Pro", lastServedAt: iso(now), readAt: iso(now),
windows: [{ name: "7 days", used: 81, resetsAt: iso(rw) }], resets: { count: 3, until: iso(now + 13 * 24 * H) } },
{ provider: "antigravity", name: "Antigravity", icon: "antigravity-color", user: "ag@example.com", plan: "Google AI Pro", readAt: iso(now), windows: [
ag("Gemini 3.1 Pro (High)", "Gemini", 100, 13), ag("Gemini 3 Flash", "Gemini", 20, 13),
ag("Claude Sonnet 4.6", "Claude", 0, 5), ag("GPT-OSS 120B (Medium)", "GPT-OSS", 0, 5),
] },
{ provider: "kimi", name: "Kimi", icon: "kimi", windows: [w("Weekly", 10, 90)] },
{ provider: "deepseek", name: "DeepSeek", icon: "deepseek", windows: [], balance: "¥17.41", readAt: iso(now),
balanceTrend: { points, fitFrom: iso(now - 48 * H), fitStart: 30, fitNow: 17.41, perDay: 6, runsOut: iso(now + 70 * H) } },
{ provider: "zai", name: "Z.ai", icon: "zai", user: "a@example.com", plan: "Pro", lastServedAt: iso(now), windows: [w("5 hours", 20, 2), w("7 days", 40, 90)] },
{ provider: "zai", name: "Z.ai", icon: "zai", user: "b@example.com", plan: "Pro", windows: [w("5 hours", 50, 2), w("7 days", 60, 90)] },
{ provider: "minimax", name: "MiniMax", icon: "minimax", user: "c@example.com", plan: "Plus", lastServedAt: iso(now), windows: [w("5 hours", 30, 2)] },
{ provider: "minimax", name: "MiniMax", icon: "minimax", user: "d@example.com", plan: "Max", windows: [w("5 hours", 70, 2)] },
];
const history = [{ provider: "codex", user: "me@example.com", lines: [{ name: "7 days", points: week }] }];
return { quotas, history };
}
function serve(lang, data) {
const settings = { theme: "light", lang, tray: "panel", quotaLeft: true, currency: "cny" };
return async (route) => {
const url = new URL(route.request().url());
const json = (body) => route.fulfill({ json: body });
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings });
if (url.pathname === "/api/settings") return json(settings);
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true } });
if (url.pathname === "/api/usage/quotas") return json(data.quotas);
if (url.pathname === "/api/usage/quotas/history") return json(data.history || []);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
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)];
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
};
}
const boxes = (page) => page.$$eval("#subscriptionUsage > .subscription-card", (cs) => cs.map((c) => {
const r = c.getBoundingClientRect();
const inner = Math.max(...[...c.children].filter((e) => e.offsetParent).map((e) => e.getBoundingClientRect().bottom));
return { key: c.dataset.key, folded: c.dataset.folded || "", x: Math.round(r.left), y: Math.round(r.top), w: Math.round(r.width), h: Math.round(r.height), bottom: r.bottom, inner };
}));
const settle = (page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => requestAnimationFrame(r)))));
const fold = (page, key) => page.locator(`#subscriptionUsage > [data-key="${key}"] > .subscription-head > .quota-acct-fold`);
function apart(cards, what) {
for (const a of cards) {
assert.ok(a.inner <= a.bottom + 0.5, `${what}: ${a.key} holds what is in it: ${JSON.stringify(a)}`);
for (const b of cards) {
if (a === b) continue;
const ok = a.x + a.w <= b.x + 1 || b.x + b.w <= a.x + 1 || a.y + a.h <= b.y + 1 || b.y + b.h <= a.y + 1;
assert.ok(ok, `${what}: ${a.key} and ${b.key} overlap: ${JSON.stringify([a, b])}`);
}
}
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of (process.env.LANGS ? process.env.LANGS.split(",") : ["en", "zh", "zh-TW", "ja", "de"])) {
test(`${engine} ${lang}: a Usage card folds to its figures, folded cards one size`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
let page;
t.after(async () => {
if (process.env.ARTIFACT_DIR && page) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-usage-card-fold.png`), fullPage: true }).catch(() => {});
}
await browser.close();
});
const errors = [];
const context = await browser.newContext({ viewport: { width: 1400, height: 900 }, reducedMotion: "reduce" });
page = await context.newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, fixtures(Date.now())));
await page.goto("http://magpie.test/?view=usage");
await page.locator("#subscriptionUsage > .subscription-card[data-key]").first().waitFor();
await settle(page);
// every card of one account or key has its fold, open; a provider of
// several keeps its accounts' folds and "All N accounts"
for (const key of ["claude", "codex", "antigravity", "kimi", "deepseek"]) {
assert.equal(await fold(page, key).getAttribute("aria-expanded"), "true", `${key}: a fold in its head, open`);
}
for (const key of ["zai", "minimax"]) assert.equal(await fold(page, key).count(), 0, `${key}: several accounts, their own folds, none in the head`);
assert.equal(await page.locator('#subscriptionUsage > [data-key="minimax"] .quota-all').count(), 0, "MiniMax's plans differ: no All 2 accounts");
const codex = page.locator('#subscriptionUsage > [data-key="codex"]');
assert.ok(await codex.locator(".quota-resets").count() > 0, "open: Codex's resets line");
const open = await boxes(page);
assert.ok(open.every((c) => !c.folded), "nothing folded at first");
// folding Codex: its figures and bars alone, the fold turned
await fold(page, "codex").click();
await page.waitForSelector('#subscriptionUsage > [data-key="codex"][data-folded]');
assert.equal(await fold(page, "codex").getAttribute("aria-expanded"), "false");
assert.equal(await codex.locator(".quota-resets, .quota-curve, .quota-read, .quota-history").count(), 0, "folded: no resets, curve or read line");
assert.equal(await codex.locator(".quota-windows.brief").count(), 1, "folded: the windows in brief");
assert.ok(await codex.locator(".quota-windows .quota-track").count() > 0, "folded: the bars are there");
// every card folded: the provider of several folds its accounts under
// All N accounts, the rest from their heads
for (const key of ["claude", "antigravity", "kimi", "deepseek"]) await fold(page, key).click();
await page.locator('#subscriptionUsage > [data-key="zai"] .quota-all-fold').click();
await page.locator('#subscriptionUsage > [data-key="minimax"] .subscription-account:not(.brief) .quota-acct-fold').click();
await page.waitForSelector('#subscriptionUsage > [data-key="minimax"][data-folded="n"]');
await settle(page);
const sameSize = async (what) => {
const cards = await boxes(page);
apart(cards, what);
assert.ok(cards.every((c) => c.folded), `${what}: every card folded: ${JSON.stringify(cards)}`);
const ones = cards.filter((c) => c.folded === "1");
// Z.ai's accounts under All 2 accounts are a card of one row too
assert.equal(ones.length, 6, what);
assert.equal(cards.find((c) => c.key === "minimax").folded, "n", what);
for (const c of cards) assert.ok(Math.abs(c.w - cards[0].w) <= 1, `${what}: one width: ${JSON.stringify(cards)}`);
for (const c of ones) assert.ok(Math.abs(c.h - ones[0].h) <= 1, `${what}: one height: ${JSON.stringify(ones)}`);
// whole rows: a card of several is n rows of a lone one's height
const row = ones[0].h + 7;
for (const c of cards) {
const n = (c.h + 7) / row;
assert.ok(Math.abs(n - Math.round(n)) * row <= 2, `${what}: ${c.key} is whole rows of ${row}px: ${JSON.stringify(c)}`);
}
// the rows line up: every top is the first's plus whole rows
const top = Math.min(...cards.map((c) => c.y));
for (const c of cards) {
const n = (c.y - top) / row;
assert.ok(Math.abs(n - Math.round(n)) * row <= 2, `${what}: ${c.key} starts on a row: ${JSON.stringify(cards)}`);
}
return cards;
};
const wide = await sameSize("1400px");
if (process.env.ARTIFACT_DIR) await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-usage-card-folded.png`) });
assert.ok(new Set(wide.map((c) => c.x)).size > 1, "1400px: side by side");
// kept across a reload (a restart)
await page.reload();
await page.locator("#subscriptionUsage > .subscription-card[data-key]").first().waitFor();
await settle(page);
await sameSize("1400px after a reload");
assert.equal(await fold(page, "codex").getAttribute("aria-expanded"), "false", "folded after a reload");
for (const width of [900, 400]) {
await page.setViewportSize({ width, height: 900 });
await settle(page);
const cards = await sameSize(`${width}px`);
if (width === 400) assert.ok(cards.every((c) => c.x === cards[0].x), `400px: one column: ${JSON.stringify(cards)}`);
const sideways = await page.evaluate(() => document.scrollingElement.scrollWidth - innerWidth);
assert.ok(sideways <= 0, `${width}px: no sideways scroll (${sideways})`);
}
await page.setViewportSize({ width: 1400, height: 900 });
await settle(page);
// Antigravity unfolded: as tall as what it holds, cut nowhere, the
// folded ones still one height
await fold(page, "antigravity").click();
await page.waitForSelector('#subscriptionUsage > [data-key="antigravity"]:not([data-folded])');
await settle(page);
const mixed = await boxes(page);
apart(mixed, "Antigravity open");
const ag = mixed.find((c) => c.key === "antigravity");
assert.ok(ag.bottom - ag.inner < 16, `the open card is as tall as itself: ${JSON.stringify(ag)}`);
const ones = mixed.filter((c) => c.folded === "1");
for (const c of ones) assert.ok(Math.abs(c.h - ones[0].h) <= 1, `the folded ones one height: ${JSON.stringify(ones)}`);
// Codex unfolded again: its resets line back, as tall as itself
await fold(page, "codex").click();
await page.waitForSelector('#subscriptionUsage > [data-key="codex"]:not([data-folded])');
await settle(page);
assert.ok(await codex.locator(".quota-resets").count() > 0, "unfolded: Codex's resets line again");
const back = (await boxes(page)).find((c) => c.key === "codex");
assert.ok(back.bottom - back.inner < 16, `unfolded Codex is as tall as itself: ${JSON.stringify(back)}`);
assert.deepEqual(errors, []);
});
}
}
+2 -1
View File
@@ -100,7 +100,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(by("Codex"), { name: "Codex", full: ["one@example.com"], brief: ["two@example.com"], meters: 2, resets: 0, more: w.full1 });
assert.equal(by("ZCode").more, null, "one account: no button");
assert.deepEqual([by("ZCode").full, by("ZCode").brief], [["solo@example.com"], []]);
assert.equal(await page.locator("#subscriptionUsage > [data-key=zcode] .quota-acct-fold").count(), 0, "one account: no fold");
assert.equal(await page.locator("#subscriptionUsage > [data-key=zcode] .subscription-account .quota-acct-fold").count(), 0, "one account: no fold on its row");
assert.equal(await page.locator("#subscriptionUsage > [data-key=zcode] .subscription-head > .quota-acct-fold").count(), 1, "one account: the card's fold in its head");
// opening it doesn't move the page
const view = page.locator("#view-usage");