usage: Hide accounts and Used/Left stand apart in the Allowances head

The owner's screenshot: 「账号打码」 sat flush against the Used/Left
segments (这两个之间竟然没有空隙,贴在一起了). Only the trend's range had a
margin; the mask button, added beside it later, had none. The head is now
spaced by a gap of 8px between each control, in place of that one margin.

Run (mote, at 2b3f76d88; the new test again 20/20 rebased on 30b7a1732): the new usage-quota-head-gap.test.cjs, both
engines, en/zh/zh-TW/ja/de at 1100 and 420px, 20/20; with usage-fold and
account-mask, 30/34. The 4 reds are usage-fold's (#3415, #4790), red
the same at the base, which also had account-mask and usage-fold's
chromium zh red in that run.
Broken by hand: app.css at origin/main, the new test is red 18 of 20
(de 420px wraps the segments onto their own line, so nothing touches).
Not tried: the real macOS app.
This commit is contained in:
yetone
2026-11-08 02:41:08 +08:00
parent 30b7a17326
commit 60cb1bd9e1
2 changed files with 67 additions and 1 deletions
+1 -1
View File
@@ -1057,7 +1057,7 @@ body.window .field.solo { grid-column: auto; }
.credit-days .cd-note { margin-top: 4px; font-size: 10px; color: var(--muted); }
/* what was left over time (#651): a line a window, an even burn dashed, now
upright; the range (or Off) is picked once, in the allowances' head */
.quota-head .quota-trend { margin-right: 8px; }
#view-usage .row-head.quota-head { gap: 8px; }
.quota-curve { margin-top: 10px; }
.quota-curve .qc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 10.5px; color: var(--muted); }
.quota-curve .qc-range { font-size: 10px; color: var(--muted); }
@@ -0,0 +1,66 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// The Usage page's Allowances head: Hide accounts, the trend's range and
// Used/Left stand apart, never touching (the owner: 这两个之间竟然没有空隙,
// 贴在一起了 — Hide accounts against Used/Left). Both engines, every
// language, wide and narrow; 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 later = new Date(Date.now() + 5 * 3600e3).toISOString();
const quotas = [{ provider: "codex", name: "Codex", kind: "subscription", icon: "openai", plan: "Plus", user: "one@example.com", windows: [{ name: "5 hours", used: 20, resetsAt: later }] }];
function serve(lang) {
const settings = { theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd" };
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: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(quotas);
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: "" }); }
};
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const width of [1100, 420]) {
test(`${engine} ${lang} ${width}px: the Allowances head's controls stand apart`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const page = await (await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
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.waitForSelector("#quotaMode:not([hidden]) .opt");
// with the trend's range shown too, as when a curve is on
await page.evaluate(() => { document.querySelector("#quotaTrend").hidden = false; });
const boxes = await page.evaluate(() => ["#quotaTrend", "#usageMask", "#quotaMode"].map((s) => {
const r = document.querySelector(s).getBoundingClientRect();
return { s, left: r.left, right: r.right, top: r.top, bottom: r.bottom, w: r.width };
}));
for (const b of boxes) assert.ok(b.w > 0, `${b.s} is shown`);
for (let i = 1; i < boxes.length; i++) {
const [a, b] = [boxes[i - 1], boxes[i]];
if (b.top >= a.bottom) continue; // wrapped onto its own line
assert.ok(b.left - a.right >= 6, `${a.s} and ${b.s} are ${(b.left - a.right).toFixed(1)}px apart`);
}
assert.deepEqual(errors, []);
});
}
}
}