gui: the Usage page's short cards stack beside a tall one, packed into columns in the user's order (#860, huoranxuanyuan)
huoranxuanyuan's screenshots (1569px window at 175%, about 897px CSS):
a tall Codex card shared a grid row with Antigravity and a DeepSeek
balance, and both short cards stretched to Codex's height, mostly empty.
They asked for Antigravity and DeepSeek to stack beside Codex.
What changed
- packUsage (app.js) packs #subscriptionUsage into columns on 1px grid
rows. Each card takes the leftmost column that ends highest and is as
tall as itself; the cards' 7px gap stays.
- The DOM order is unchanged and is still settings.usageOrder, so
dragging, Alt+arrows and screen readers work as before.
- Column count: the most 260px columns that fit, or one fewer when
that leaves much less empty room (<0.6x) for a page at most 1.3x
taller. It is chosen again only when the cards change or the width
fits another number of columns. A card that grows or shrinks (a fold,
"Every model") is only re-packed, so the card clicked stays where it
was, even when the view's scrollbar appears and takes 10px of width.
Keying the choice on the pixel width moved a card turned to every
model in WebKit, which quota-families caught.
- A ResizeObserver on the list and each card re-packs on the next
frame. A hidden view falls back to the plain grid.
- fitQuotas is split into fitQuota(g), so heights are measured with each
meter box laid out for the width being tried.
- The tray panel's Allowances list is a single column with no row
stretching, so it needs no change.
- docs/subsystems/gui-shell.md describes the packing.
Tests
- New usage-pack.test.cjs, with fixtures of the reporter's cards:
- Codex with a 7-day window, credit resets and a curve; Antigravity by
family; a DeepSeek balance with its trend.
- At 897, 1018 and 1400px: Antigravity beside Codex at its top,
DeepSeek under it with the 7px gap, order kept, no overlap, no card
taller than its content.
- Equal cards: one row in order at 1300px, one column at 480px.
- Opening a brief Codex account grows that card in place, with no
scroll.
- Runs in Chromium and WebKit, in en/zh/ja/de. It goes red when
packUsage returns early (checked by hand).
- usage-accounts-fold: "Show fewer" now holds the card's head where it
was, as usage-keys-fold already does for keys. Its old assertions
expected the page to shrink to its end, which packing no longer does.
- usage-fold: scrolls to each fold button before clicking it, since
Codex is now packed under ZCode, past the 300px-tall window.
Run
- usage-*.test.cjs, quota-families and click-scroll in both engines:
all pass except usage-heatmap, which fails the same way alone on
origin/main 497656174.
- Full GUI suite at concurrency 6, under machine load ~170: 5125 pass,
56 subtests fail.
- Run alone, these pass in this tree and on origin/main:
account-arrange, agent-models-redraw, agent-stale-copies,
agent-update-all, factory-key, group-from-model-add,
library-servers-bulk, proto-menu-overflow, routing-mode-goes,
routing-served, sessions-overview, tray-cell-click, update-wait,
usage-ledger, usage-refresh.
- These fail the same alone on origin/main: mobile-web, old-webkit,
plugin-moved-signin, routing-context-fold, routing-group-fold,
usage-heatmap.
- quota-families was red only in this tree. That was the width-keyed
choice above, now fixed and green in both engines.
- No Go change.
This commit is contained in:
@@ -133,6 +133,7 @@ axis controls.
|
||||
- A click never moves the page. Code scrolls a view only with the reader's event in hand (`scrollOnPurpose`); `click-scroll.test.cjs` guards this.
|
||||
- There are no native `<select>` elements and no colored left-border stripes. State is shown with a dot or a swatch.
|
||||
- The Usage page's cards and the tray panel's Allowances tab share one order, `settings.UsageOrder` (`byUsageOrder`). In the panel a balance-only card stands where that order puts it, and balances next to each other share one *Balances* grid (`panelBalances`, #1510); none is gathered after the plans. The panel's *Arrange* (`panelArrange`) moves rows in it and hides subscriptions from that tab alone (`settings.PanelUsageHidden`); both save through `POST /api/usage/arrange`, which changes only the field it is sent, and the Settings save keeps both. Hiding is display only: a menu bar cell's card shows though hidden (`panelPeek`). See `TestUsageArrangePanelHidden`, `panel-arrange.test.cjs` and `panel-balance-order.test.cjs`.
|
||||
- The Usage page's cards are packed into columns, never 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 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 page must work in Chromium (Windows' WebView2) and WebKit (macOS, and WebKitGTK on Linux). GUI tests run in both engines.
|
||||
- On Linux the panel is frameless and the main window has a hidden title bar (`plainTitlebar`). GTK 3 asks KDE's Wayland session (KWin's decoration protocol) for a frame drawn by KWin on any window without client-side decorations, an undecorated one too, so `ownFrame` tells KWin the panel draws its own on each realize (#1283). GTK 4 builds ask for none themselves. With no KWin title bar, and with a Wayland window placed by the compositor rather than by the icon, the panel's header is its drag handle on Linux, as the window's is (`--wails-draggable` in `app.js`; `panel-drag-linux.test.cjs`); on the Mac and Windows the panel isn't dragged (#1430).
|
||||
- Wails calls the tray's click handler both for the icon's click (`Activate`) and when the tray host opens the icon's menu (dbusmenu's "opened" event). KDE opens the menu on a right-click, and the panel that click opened took the focus and shut the menu on Wayland. On Linux the handler ignores the call when it comes from the menu opening (`menuOpening` in [`trayclick.go`](../../internal/gui/trayclick.go), which looks for Wails' `(*linuxSystemTray).Event` among its callers; `TestTrayMenuOpenFrameIsWails` fails if Wails renames it or stops calling the handler there) (#1430).
|
||||
|
||||
@@ -579,7 +579,10 @@ body.window .field.solo { grid-column: auto; }
|
||||
/* the tabs sit on the head's middle line with the refresh beside them, not
|
||||
at its top as .segs elsewhere do */
|
||||
.usage-head > .segs { align-self: center; }
|
||||
.subscription-usage { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 7px; margin-bottom: 8px; flex: none; }
|
||||
.subscription-usage { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); align-items: start; gap: 7px; margin-bottom: 8px; flex: none; }
|
||||
/* packed into columns (packUsage): each card as tall as itself, placed on
|
||||
rows a pixel high, the gap between cards in its place on them (#860) */
|
||||
.subscription-usage.packed { grid-auto-rows: 1px; row-gap: 0; }
|
||||
.subscription-card { padding: 10px 12px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); min-width: 0; }
|
||||
.subscription-head { display: flex; align-items: center; gap: 7px; margin-bottom: 9px; }
|
||||
.subscription-head .ic { width: 17px; height: 17px; }
|
||||
|
||||
@@ -13537,6 +13537,7 @@ function renderQuotas() {
|
||||
card.append(el("span", "skeleton sk-title"), el("span", "skeleton sk-line"), el("span", "skeleton sk-line short"));
|
||||
subscriptions.append(card);
|
||||
}
|
||||
packUsageNow(subscriptions);
|
||||
return;
|
||||
}
|
||||
if (usageArranging) { usageRenderPending = true; return; }
|
||||
@@ -13645,6 +13646,7 @@ function renderQuotas() {
|
||||
subscriptions.append(card);
|
||||
}
|
||||
markUpstream();
|
||||
packUsageNow(subscriptions);
|
||||
restoreFlash();
|
||||
requestAnimationFrame(focusQuotaCard);
|
||||
}
|
||||
@@ -13797,6 +13799,90 @@ function byUsageOrder(list) {
|
||||
return list.map((q, i) => [q, i]).sort(([a, i], [b, j]) => rank(a) - rank(b) || i - j).map(([q]) => q);
|
||||
}
|
||||
|
||||
// packUsage lays the Usage page's cards out in columns, each card as tall
|
||||
// as itself, the next in the order going to the column that ends highest
|
||||
// (huoranxuanyuan, #860: a tall Codex card beside Antigravity and a
|
||||
// DeepSeek balance left the short two mostly empty; 把 antigravity 和
|
||||
// deepseek 两个上下堆叠和 Codex 对齐). The order still reads left to right,
|
||||
// row by row as near as the heights allow, and the cards stay in it on the
|
||||
// page, for dragging, Alt+arrows and a screen reader alike. As many columns
|
||||
// as 260px each fit, unless one fewer leaves much less empty beside the
|
||||
// short cards for a page not much taller. Decided again when the cards
|
||||
// change or the width fits another number of columns; a card growing (a
|
||||
// fold opened) only packs them again, so what was clicked stays where it
|
||||
// was, even as the view's scrollbar comes in and takes some of the width
|
||||
// (in WebKit a card turned to every model went to one column under its
|
||||
// neighbour, the page following it).
|
||||
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 = "";
|
||||
usagePacked = null;
|
||||
return;
|
||||
}
|
||||
const keys = cards.map((c) => c.dataset.key || "").join();
|
||||
const most = Math.max(1, Math.min(cards.length, Math.floor((width + USAGE_GAP) / (USAGE_MIN + USAGE_GAP))));
|
||||
const place = (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;
|
||||
}
|
||||
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 g of list.querySelectorAll(".quota-windows")) fitQuota(g);
|
||||
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;
|
||||
});
|
||||
}
|
||||
// a card's height or the page's width moved: packed again on the next frame
|
||||
// (in the observer's own call the change is owed to it in the same frame,
|
||||
// which WebKit reports as a ResizeObserver loop)
|
||||
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);
|
||||
}
|
||||
|
||||
// usageHandle is a card's logo, which is also its handle: drag it to move
|
||||
// the card among the others, Alt+arrows move it from the keyboard. The grip
|
||||
// that says so shows by the logo on hover (app.css).
|
||||
@@ -15342,17 +15428,18 @@ const quotaFit = new ResizeObserver((es) => {
|
||||
for (const { target } of es) quotaFitting.add(target);
|
||||
});
|
||||
function fitQuotas() {
|
||||
for (const g of quotaFitting) fitQuota(g);
|
||||
quotaFitting.clear();
|
||||
}
|
||||
function fitQuota(g) {
|
||||
// a count's own width, its parts laid end to end: once stacked it spans
|
||||
// the row and may be two lines, so its box no longer says
|
||||
const wide = (e) => [...e.children].reduce((w, c) => w + c.getBoundingClientRect().width, 0) + 4 * (e.children.length - 1);
|
||||
for (const g of quotaFitting) {
|
||||
const wraps = [...g.querySelectorAll(".quota-labels")].some((l) => {
|
||||
const [name, n] = l.children;
|
||||
return name.getBoundingClientRect().width + 6 + wide(n) > l.clientWidth;
|
||||
});
|
||||
g.classList.toggle("stacked", wraps);
|
||||
}
|
||||
quotaFitting.clear();
|
||||
const wraps = [...g.querySelectorAll(".quota-labels")].some((l) => {
|
||||
const [name, n] = l.children;
|
||||
return name.getBoundingClientRect().width + 6 + wide(n) > l.clientWidth;
|
||||
});
|
||||
g.classList.toggle("stacked", wraps);
|
||||
}
|
||||
|
||||
// balanceRow: what is left on an account, as a figure; a balance field
|
||||
|
||||
@@ -157,13 +157,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
got = await cards(page);
|
||||
assert.deepEqual(got["workbuddy-ai"].users, range(1, 5));
|
||||
assert.equal(got["workbuddy-ai"].more, w.more17);
|
||||
// seventeen rows fewer leave less page than was scrolled: it rests at
|
||||
// its end (the head can't be held), with the button still in sight
|
||||
const [top, sh, ch] = await view.evaluate((v) => [v.scrollTop, v.scrollHeight, v.clientHeight]);
|
||||
assert.ok(Math.abs(top - (sh - ch)) <= 1, "the page rests at its end");
|
||||
const after = await page.locator(`${sel} .quota-accts-more`).boundingBox();
|
||||
assert.ok(after.y > 0 && after.y + after.height < 500, "the button is still in sight");
|
||||
assert.ok(await head.evaluate((e) => e.getBoundingClientRect().top) > at, "the head came down, not further up");
|
||||
// the card's head stays where it was, as a provider's keys' does: the
|
||||
// cards packed into columns (#860), the next goes on under this one, so
|
||||
// the page no longer has to end there and come down to the button
|
||||
assert.equal(await head.evaluate((e) => e.getBoundingClientRect().top), at, "the card's head stays where it was");
|
||||
|
||||
// 440px: nothing cut or spilling, folded and open
|
||||
await page.setViewportSize({ width: 440, height: 700 });
|
||||
|
||||
@@ -122,6 +122,19 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
// an account opens and folds on its own, where it is
|
||||
const acct = (key, user) => page.locator(`#subscriptionUsage > [data-key=${key}] .subscription-account`, { hasText: user });
|
||||
const two = acct("codex", "two@example.com");
|
||||
// wheeled to, as a reader would (the page holds still for a script's
|
||||
// scroll): packed into columns (#860), Codex's card is under ZCode's,
|
||||
// past this short window's foot
|
||||
const wheelTo = async (l) => {
|
||||
for (let i = 0; i < 20; i++) {
|
||||
const y = (await l.boundingBox()).y;
|
||||
if (y > 60 && y + 40 < 300) break;
|
||||
await page.mouse.wheel(0, y > 60 ? 60 : -60);
|
||||
await page.waitForTimeout(150);
|
||||
}
|
||||
await page.waitForTimeout(300);
|
||||
};
|
||||
await wheelTo(two.locator(".quota-acct-fold"));
|
||||
const twoAt = await two.evaluate((e) => e.getBoundingClientRect().top);
|
||||
const scrolled = await view.evaluate((v) => v.scrollTop);
|
||||
assert.equal(await two.locator(".quota-acct-fold").getAttribute("aria-expanded"), "false");
|
||||
@@ -131,6 +144,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal(await two.evaluate((e) => e.getBoundingClientRect().top), twoAt, "the account stays where it was");
|
||||
got = await cards(page);
|
||||
assert.deepEqual([by("Codex").full, by("Codex").brief, by("Codex").more], [["one@example.com", "two@example.com"], [], w.brief]);
|
||||
await wheelTo(acct("workbuddy", "alpha@example.com").locator(".quota-acct-fold"));
|
||||
await acct("workbuddy", "alpha@example.com").locator(".quota-acct-fold").click();
|
||||
got = await cards(page);
|
||||
assert.deepEqual(by("WorkBuddy").brief, ["alpha@example.com"]);
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// The Usage page's cards packed into columns (huoranxuanyuan, #860): a tall
|
||||
// Codex card beside Antigravity and a DeepSeek balance left the short two
|
||||
// mostly empty, each stretched to Codex's height. Now each card is as tall
|
||||
// as itself, and the next in the order goes to the column that ends
|
||||
// highest: Antigravity and DeepSeek stacked beside Codex, at the reporter's
|
||||
// 897px (1569px at 175%) and 1018px windows and a wide one. Cards of a
|
||||
// height keep one row in their order; a narrow window has one column. The
|
||||
// order on the page is still the user's (dragging and Alt+arrows are
|
||||
// usage-arrange's), no card overlaps another, and a card opened to its
|
||||
// accounts in full pushes the one under it down rather than over it.
|
||||
// Chromium and WebKit, English, Chinese, Japanese and German; 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();
|
||||
|
||||
// as the reporter's: Codex's one account with its week, credits and a
|
||||
// curve; Antigravity by family, 5 hours and 7 days; DeepSeek a balance
|
||||
function fixtures(now) {
|
||||
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 ag = (name, family, used, h) => ({ name, family, used, resetsAt: iso(now + h * H) });
|
||||
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: "codex", name: "Codex", icon: "codex-color", user: "me@example.com", plan: "Prolite", until: iso(now + 13 * 24 * H),
|
||||
lastServedAt: 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", windows: [
|
||||
ag("Gemini 3.1 Pro (High)", "Gemini", 100, 13), ag("Gemini 3.1 Pro (Low)", "Gemini", 100, 13),
|
||||
ag("Claude Sonnet 4.6", "Claude", 0, 5), ag("GPT-OSS 120B (Medium)", "GPT-OSS", 0, 5),
|
||||
] },
|
||||
{ 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) } },
|
||||
];
|
||||
const history = [{ provider: "codex", user: "me@example.com", lines: [{ name: "7 days", points: week }] }];
|
||||
return { quotas, history };
|
||||
}
|
||||
// cards of one height: one row, in their order
|
||||
const even = (now) => ["kimi", "zai", "minimax", "moonshot"].map((p) => ({ provider: p, name: p, icon: p, windows: [{ name: "5 hours", used: 30, resetsAt: iso(now + 2 * H) }] }));
|
||||
// several accounts, the second in brief until opened
|
||||
const several = (now) => [
|
||||
{ provider: "codex", name: "Codex", icon: "codex-color", user: "a@example.com", plan: "Plus", lastServedAt: iso(now), windows: [{ name: "5 hours", used: 20, resetsAt: iso(now + 2 * H) }, { name: "7 days", used: 40, resetsAt: iso(now + 90 * H) }] },
|
||||
{ provider: "codex", name: "Codex", icon: "codex-color", user: "b@example.com", plan: "Plus", windows: [{ name: "5 hours", used: 50, resetsAt: iso(now + 2 * H) }, { name: "7 days", used: 60, resetsAt: iso(now + 90 * H) }] },
|
||||
{ provider: "kimi", name: "Kimi", icon: "kimi", windows: [{ name: "Weekly", used: 10, resetsAt: iso(now + 90 * H) }] },
|
||||
{ provider: "zai", name: "Z.ai", icon: "zai", windows: [{ name: "5 hours", used: 5, resetsAt: iso(now + 2 * H) }] },
|
||||
{ provider: "deepseek", name: "DeepSeek", icon: "deepseek", windows: [], balance: "¥3.00", readAt: iso(now) },
|
||||
];
|
||||
|
||||
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: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
// each card's box, the bottom of what is in it, and its key, in page order
|
||||
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, 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)))));
|
||||
|
||||
function sound(cards, what) {
|
||||
for (const c of cards) {
|
||||
// as tall as what is in it, its padding and border: never stretched
|
||||
assert.ok(c.bottom - c.inner < 16, `${what}: ${c.key} is as tall as itself: ${JSON.stringify(c)}`);
|
||||
}
|
||||
for (const a of cards) for (const b of cards) {
|
||||
if (a === b) continue;
|
||||
const apart = 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(apart, `${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 ["en", "zh", "ja", "de"]) {
|
||||
test(`${engine} ${lang}: the Usage page's short cards stack beside a tall one`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
const pages = [];
|
||||
t.after(async () => {
|
||||
if (process.env.ARTIFACT_DIR) {
|
||||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||||
for (const [name, p] of pages) await p.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-usage-pack-${name}.png`), fullPage: true });
|
||||
}
|
||||
await browser.close();
|
||||
});
|
||||
const errors = [];
|
||||
const open = async (name, data, width) => {
|
||||
const page = await (await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" })).newPage();
|
||||
pages.push([name, page]);
|
||||
page.setDefaultTimeout(5000);
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.route("**/*", serve(lang, data));
|
||||
await page.goto("http://magpie.test/?view=usage");
|
||||
await page.locator("#subscriptionUsage > .subscription-card[data-key]").first().waitFor();
|
||||
await settle(page);
|
||||
return page;
|
||||
};
|
||||
const now = Date.now();
|
||||
|
||||
// the reporter's three, at their window and wider
|
||||
for (const width of [897, 1018, 1400]) {
|
||||
const page = await open(`reporter-${width}`, fixtures(now), width);
|
||||
const cards = await boxes(page);
|
||||
assert.deepEqual(cards.map((c) => c.key), ["codex", "antigravity", "deepseek"], "the order on the page is the user's");
|
||||
sound(cards, `${width}px`);
|
||||
const [codex, ag, ds] = cards;
|
||||
assert.equal(ag.x, ds.x, `${width}px: DeepSeek under Antigravity: ${JSON.stringify(cards)}`);
|
||||
assert.ok(ag.x > codex.x && ag.y === codex.y, `${width}px: Antigravity beside Codex, at its top`);
|
||||
assert.ok(Math.abs(ds.y - (ag.y + ag.h) - 7) <= 1, `${width}px: the cards' own gap between them: ${JSON.stringify([ag, ds])}`);
|
||||
}
|
||||
|
||||
// cards of a height: one row, in their order; a narrow window one column
|
||||
const row = await open("even", { quotas: even(now) }, 1300);
|
||||
let cards = await boxes(row);
|
||||
assert.deepEqual(cards.map((c) => c.key), ["kimi", "zai", "minimax", "moonshot"]);
|
||||
assert.ok(cards.every((c) => c.y === cards[0].y), `one row: ${JSON.stringify(cards)}`);
|
||||
assert.deepEqual(cards.map((c) => c.x), [...cards.map((c) => c.x)].sort((a, b) => a - b), "left to right in their order");
|
||||
sound(cards, "even");
|
||||
await row.setViewportSize({ width: 480, height: 900 });
|
||||
await settle(row);
|
||||
cards = await boxes(row);
|
||||
assert.ok(cards.every((c) => c.x === cards[0].x), `one column: ${JSON.stringify(cards)}`);
|
||||
assert.deepEqual(cards.map((c) => c.y), [...cards.map((c) => c.y)].sort((a, b) => a - b), "top to bottom in their order");
|
||||
sound(cards, "narrow");
|
||||
|
||||
// an account opened in full: the card grows, the one under it moves
|
||||
// down, nothing moves the page
|
||||
const fold = await open("fold", { quotas: several(now) }, 897);
|
||||
cards = await boxes(fold);
|
||||
sound(cards, "folded");
|
||||
const scrollY = () => fold.evaluate(() => [document.scrollingElement.scrollTop, ...[...document.querySelectorAll("*")].filter((e) => e.scrollTop).map((e) => e.scrollTop)].join());
|
||||
const before = await scrollY(), codex0 = cards.find((c) => c.key === "codex");
|
||||
await fold.locator('#subscriptionUsage > [data-key="codex"] .subscription-account.brief .quota-acct-fold').click();
|
||||
await settle(fold);
|
||||
cards = await boxes(fold);
|
||||
const codex1 = cards.find((c) => c.key === "codex");
|
||||
assert.ok(codex1.h > codex0.h, "the card grew");
|
||||
assert.equal(codex1.x, codex0.x, "the card clicked stays where it was");
|
||||
assert.equal(codex1.y, codex0.y, "the card clicked stays where it was");
|
||||
sound(cards, "opened");
|
||||
assert.equal(await scrollY(), before, "no click moves the page");
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user