From 41dde238dd258d070ef1d4d7bf37ebf3c6d1fdb0 Mon Sep 17 00:00:00 2001 From: yetone Date: Thu, 1 Oct 2026 22:54:49 +0800 Subject: [PATCH] =?UTF-8?q?usage:=20a=20sessions=20bar's=20name=20takes=20?= =?UTF-8?q?the=20width=20it=20needs,=20its=20bar=20what=20is=20left=20(Joh?= =?UTF-8?q?n=20on=20Discord:=20widened,=20the=20names=20stayed=20cut=20sho?= =?UTF-8?q?rt=20with=20=E2=80=A6=20while=20the=20bars=20grew)=20=E2=80=94?= =?UTF-8?q?=20the=20Sessions=20overview's=20projects,=20models,=20tools=20?= =?UTF-8?q?and=20skills=20rows=20held=20their=20names=20to=209em,=2010em?= =?UTF-8?q?=20and=2011em=20whatever=20the=20window's=20width,=20every=20ex?= =?UTF-8?q?tra=20pixel=20going=20to=20the=20bar.=20Each=20card=20is=20now?= =?UTF-8?q?=20one=20grid=20whose=20rows=20are=20subgrids:=20the=20names'?= =?UTF-8?q?=20column=20is=20as=20wide=20as=20the=20longest=20(minmax(0,=20?= =?UTF-8?q?max-content)),=20the=20bars=20take=20the=20rest=20and=20are=20n?= =?UTF-8?q?ever=20under=205em,=20and=20every=20row's=20bar=20starts=20at?= =?UTF-8?q?=20the=20same=20place;=20narrow,=20the=20names=20are=20shortene?= =?UTF-8?q?d=20rather=20than=20a=20bar.=20Without=20subgrid=20(before=20Sa?= =?UTF-8?q?fari=2016)=20each=20row=20sizes=20its=20own=20name=20the=20same?= =?UTF-8?q?=20way.=20sessions-bar-names.test.cjs=20fails=20without=20the?= =?UTF-8?q?=20change=20(196px=20name=20shown=20in=20108px=20at=201600=20wi?= =?UTF-8?q?de);=20it,=20sessions-overview,=20sessions-calendar-fill,=20ses?= =?UTF-8?q?sions-today,=20click-scroll=20and=20old-webkit=20pass=20in=20Ch?= =?UTF-8?q?romium=20and=20WebKit,=20en=20and=20zh.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/gui/assets/app.css | 28 +++- internal/gui/assets/app.js | 2 +- internal/gui/tests/README.md | 9 +- .../gui/tests/sessions-bar-names.test.cjs | 137 ++++++++++++++++++ 4 files changed, 167 insertions(+), 9 deletions(-) create mode 100644 internal/gui/tests/sessions-bar-names.test.cjs diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index 42eca4769..8cad3107d 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -808,8 +808,13 @@ details.cx-part[open] > summary .cx-h { margin-bottom: 2px; } .sess-card-foot .grow { flex: 1; } .sess-none { color: var(--faint); font-size: 12px; padding: 18px 0; text-align: center; margin: auto 0; } .sess-more { font-size: 11px; color: var(--faint); padding: 4px 2px 0; } -.sess-bars { display: flex; flex-direction: column; gap: 1px; } -.sess-bar { display: grid; grid-template-columns: minmax(0, 9em) minmax(0, 1fr) auto 4.2em; align-items: center; gap: 10px; height: 26px; padding: 0 6px; margin: 0 -6px; border: 0; border-radius: 6px; background: none; color: var(--fg-2); font: inherit; font-size: 12px; text-align: left; cursor: default; } +/* a card of bars is one grid: its names take the width the longest needs + and the bars what is left, every row's bar starting at the same place; + a window too narrow for that shortens the names, never a bar past 5em */ +.sess-bars { display: grid; grid-template-columns: minmax(0, max-content) minmax(5em, 1fr) auto 4.2em; column-gap: 10px; row-gap: 1px; } +.sess-bars.tools { grid-template-columns: minmax(0, max-content) minmax(5em, 1fr) auto auto 2.8em; } +.sess-bars > * { grid-column: 1 / -1; } +.sess-bar { display: grid; grid-template-columns: subgrid; align-items: center; gap: 10px; height: 26px; padding: 0 6px; margin: 0 -6px; border: 0; border-radius: 6px; background: none; color: var(--fg-2); font: inherit; font-size: 12px; text-align: left; cursor: default; } .sess-bar:hover { background: var(--pill); } .sess-bar.on { background: var(--pill); color: var(--fg); font-weight: 550; } .sess-bar .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } @@ -836,9 +841,8 @@ details.cx-part[open] > summary .cx-h { margin-bottom: 2px; } .sess-shape .col span { font-size: 10.5px; color: var(--muted); text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; } .sess-tools-cols { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 22px; } @container (max-width: 700px) { .sess-tools-cols { grid-template-columns: minmax(0, 1fr); } } -.sess-bar.tool { grid-template-columns: minmax(0, 10em) minmax(0, 1fr) auto auto 2.8em; } .sess-bar.tool .n { display: flex; align-items: center; gap: 7px; } -.sess-bar.tool .n span { overflow: hidden; text-overflow: ellipsis; } +.sess-bar.tool .n span { min-width: 0; overflow: hidden; text-overflow: ellipsis; } .sess-bar.tool .track i { opacity: .85; } .sess-bar.tool .s { font-size: 11px; color: var(--muted); white-space: nowrap; } .sess-bar.tool .p { font-size: 11px; color: var(--faint); text-align: right; font-variant-numeric: tabular-nums; } @@ -856,10 +860,20 @@ details.cx-part[open] > summary .cx-h { margin-bottom: 2px; } .sess-weeks .stack { width: 100%; display: flex; flex-direction: column-reverse; border-radius: 3px; overflow: hidden; } .sess-weeks .stack i { min-height: 1px; } .sess-weeks-labels { display: flex; justify-content: space-between; font-size: 10px; color: var(--faint); } -.sess-skills { display: flex; flex-direction: column; gap: 2px; } -.sess-skill { padding: 4px 6px; margin: 0 -6px; border-radius: 6px; min-width: 0; } +.sess-skills { display: grid; grid-template-columns: minmax(0, max-content) minmax(5em, 1fr) auto; column-gap: 10px; row-gap: 2px; } +.sess-skills > * { grid-column: 1 / -1; } +.sess-skill { display: grid; grid-template-columns: subgrid; padding: 4px 6px; margin: 0 -6px; border-radius: 6px; min-width: 0; } .sess-skill:hover { background: var(--pill); } -.sess-skill .line { display: grid; grid-template-columns: minmax(0, 11em) minmax(0, 1fr) auto; align-items: center; gap: 10px; font-size: 12px; } +.sess-skill .line, .sess-skill .sub { grid-column: 1 / -1; } +.sess-skill .line { display: grid; grid-template-columns: subgrid; align-items: center; gap: 10px; font-size: 12px; } +/* before subgrid (Safari 16) each row is a grid of its own, its name as + wide as it needs and its bar at least 5em */ +@supports not (grid-template-columns: subgrid) { + .sess-bar { grid-template-columns: minmax(0, max-content) minmax(5em, 1fr) auto 4.2em; } + .sess-bar.tool { grid-template-columns: minmax(0, max-content) minmax(5em, 1fr) auto auto 2.8em; } + .sess-skill { display: block; } + .sess-skill .line { grid-template-columns: minmax(0, max-content) minmax(5em, 1fr) auto; } +} .sess-skill .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--fg); font-weight: 550; } .sess-skill .track { height: 6px; border-radius: 3px; background: var(--pill); overflow: hidden; } .sess-skill:hover .track { background: var(--card); } diff --git a/internal/gui/assets/app.js b/internal/gui/assets/app.js index e4df5dc26..cd004a7e3 100644 --- a/internal/gui/assets/app.js +++ b/internal/gui/assets/app.js @@ -9764,7 +9764,7 @@ function renderSessTools() { const cols = el("div", "sess-tools-cols"); // the most called, each with its kind's dot, calls, sessions and share - const top = el("div", "sess-bars"); + const top = el("div", "sess-bars tools"); const peak = Math.max(1, ...tu.top.map((x) => x.calls)); for (const x of tu.top) { const r = el("div", "sess-bar tool"); diff --git a/internal/gui/tests/README.md b/internal/gui/tests/README.md index 5ba323d1c..61074f148 100644 --- a/internal/gui/tests/README.md +++ b/internal/gui/tests/README.md @@ -477,6 +477,13 @@ autonomy (remembered, the page left where it was), tool use (the top tools, their kinds and weeks) and the top skills with their last use, agents and projects. +`sessions-bar-names.test.cjs` checks the Sessions overview's bar rows +(projects, models, tools and skills: a name, a bar, figures): at 1600 wide +every long name is shown whole, each card's bars start at one place and are +at least 5em, at 420 wide the long names are shortened while no bar is under +5em and nothing runs past its card, and wide again the names are whole; in +Chromium and WebKit, English and Chinese. + `sessions-calendar-fill.test.cjs` checks that the Sessions overview's activity calendar fills its card: 118 days (17 weeks) at 1400 wide take over 90% of it, the weeks before the range coming in as empty cells without tooltips, the @@ -976,7 +983,7 @@ reads shows none of it. English and Chinese, Chromium and WebKit, with With Node.js and Playwright available: ```sh -node --test internal/gui/tests/menu-scroll.test.cjs internal/gui/tests/click-scroll.test.cjs internal/gui/tests/panel-fold.test.cjs internal/gui/tests/rollup-short.test.cjs internal/gui/tests/panel-routing.test.cjs internal/gui/tests/gateway-fold.test.cjs internal/gui/tests/routing-kind.test.cjs internal/gui/tests/balance-fix.test.cjs internal/gui/tests/cli-update.test.cjs internal/gui/tests/login-import.test.cjs internal/gui/tests/agy-launch.test.cjs internal/gui/tests/currency.test.cjs internal/gui/tests/usage-ledger.test.cjs internal/gui/tests/update-check.test.cjs internal/gui/tests/omarchy.test.cjs internal/gui/tests/brand.test.cjs internal/gui/tests/library-loading.test.cjs internal/gui/tests/provider-typed.test.cjs node --test internal/gui/tests/signin-callback.test.cjs internal/gui/tests/routing-steady.test.cjs internal/gui/tests/old-webkit.test.cjs internal/gui/tests/session-terminal.test.cjs internal/gui/tests/text-size.test.cjs internal/gui/tests/zcode-site.test.cjs internal/gui/tests/rail-tip.test.cjs internal/gui/tests/sync-update.test.cjs internal/gui/tests/plugin-signin.test.cjs internal/gui/tests/plugin-market.test.cjs internal/gui/tests/s3-sync.test.cjs internal/gui/tests/routing-wb-refused.test.cjs internal/gui/tests/routing-blocked.test.cjs internal/gui/tests/routing-zcode-blocked.test.cjs internal/gui/tests/routing-shape.test.cjs internal/gui/tests/market-have.test.cjs internal/gui/tests/sessions-today.test.cjs internal/gui/tests/routing-side-calls.test.cjs internal/gui/tests/import-all-skills.test.cjs internal/gui/tests/routing-flood.test.cjs internal/gui/tests/routing-busy.test.cjs internal/gui/tests/own-skill.test.cjs internal/gui/tests/routing-manual.test.cjs internal/gui/tests/tray-usages.test.cjs internal/gui/tests/provider-remove.test.cjs internal/gui/tests/signin-link.test.cjs internal/gui/tests/tray-inuse.test.cjs internal/gui/tests/codex-auto-reset.test.cjs internal/gui/tests/routing-auto-reset.test.cjs internal/gui/tests/claude-usage-asked.test.cjs internal/gui/tests/claude-risk.test.cjs internal/gui/tests/library-toggle-status.test.cjs internal/gui/tests/library-all.test.cjs internal/gui/tests/routing-reroute-title.test.cjs internal/gui/tests/plain-names.test.cjs internal/gui/tests/panel-effort.test.cjs internal/gui/tests/agent-models-all-hidden.test.cjs internal/gui/tests/omp-roles.test.cjs internal/gui/tests/claude-effort.test.cjs internal/gui/tests/remote-magpie.test.cjs internal/gui/tests/qoder-cn-tile.test.cjs internal/gui/tests/provider-levels-scroll.test.cjs internal/gui/tests/signin-paste-codex.test.cjs internal/gui/tests/signin-paste-key.test.cjs internal/gui/tests/usage-alert.test.cjs internal/gui/tests/quota-families.test.cjs internal/gui/tests/provider-search.test.cjs internal/gui/tests/webdav-settings-refresh.test.cjs internal/gui/tests/lan-docker.test.cjs internal/gui/tests/plugin-key-hint.test.cjs internal/gui/tests/update-hide.test.cjs internal/gui/tests/tray-logos.test.cjs internal/gui/tests/routing-proxy.test.cjs internal/gui/tests/sse-body.test.cjs internal/gui/tests/remote-group-served.test.cjs internal/gui/tests/plugin-move-overflow.test.cjs internal/gui/tests/routing-time.test.cjs internal/gui/tests/unlisted-models.test.cjs internal/gui/tests/plugin-updates.test.cjs internal/gui/tests/request-archive.test.cjs internal/gui/tests/group-member-fast.test.cjs internal/gui/tests/providers-off-fold.test.cjs internal/gui/tests/account-return.test.cjs internal/gui/tests/usage-ledger-detail.test.cjs internal/gui/tests/usage-ledger-chart.test.cjs internal/gui/tests/usage-chart-axis.test.cjs internal/gui/tests/panel-usage.test.cjs internal/gui/tests/usage-refresh.test.cjs internal/gui/tests/usage-ledger-content.test.cjs internal/gui/tests/claude-direct.test.cjs internal/gui/tests/signin-again.test.cjs internal/gui/tests/sessions-calendar-fill.test.cjs internal/gui/tests/editor-short-window.test.cjs internal/gui/tests/group-from-model-add.test.cjs internal/gui/tests/sync-other-kind.test.cjs internal/gui/tests/web-page.test.cjs internal/gui/tests/balance-parts.test.cjs internal/gui/tests/search-api.test.cjs internal/gui/tests/provider-file-error.test.cjs internal/gui/tests/sessions-manage.test.cjs internal/gui/tests/number-units.test.cjs +node --test internal/gui/tests/menu-scroll.test.cjs internal/gui/tests/click-scroll.test.cjs internal/gui/tests/panel-fold.test.cjs internal/gui/tests/rollup-short.test.cjs internal/gui/tests/panel-routing.test.cjs internal/gui/tests/gateway-fold.test.cjs internal/gui/tests/routing-kind.test.cjs internal/gui/tests/balance-fix.test.cjs internal/gui/tests/cli-update.test.cjs internal/gui/tests/login-import.test.cjs internal/gui/tests/agy-launch.test.cjs internal/gui/tests/currency.test.cjs internal/gui/tests/usage-ledger.test.cjs internal/gui/tests/update-check.test.cjs internal/gui/tests/omarchy.test.cjs internal/gui/tests/brand.test.cjs internal/gui/tests/library-loading.test.cjs internal/gui/tests/provider-typed.test.cjs node --test internal/gui/tests/signin-callback.test.cjs internal/gui/tests/routing-steady.test.cjs internal/gui/tests/old-webkit.test.cjs internal/gui/tests/session-terminal.test.cjs internal/gui/tests/text-size.test.cjs internal/gui/tests/zcode-site.test.cjs internal/gui/tests/rail-tip.test.cjs internal/gui/tests/sync-update.test.cjs internal/gui/tests/plugin-signin.test.cjs internal/gui/tests/plugin-market.test.cjs internal/gui/tests/s3-sync.test.cjs internal/gui/tests/routing-wb-refused.test.cjs internal/gui/tests/routing-blocked.test.cjs internal/gui/tests/routing-zcode-blocked.test.cjs internal/gui/tests/routing-shape.test.cjs internal/gui/tests/market-have.test.cjs internal/gui/tests/sessions-today.test.cjs internal/gui/tests/routing-side-calls.test.cjs internal/gui/tests/import-all-skills.test.cjs internal/gui/tests/routing-flood.test.cjs internal/gui/tests/routing-busy.test.cjs internal/gui/tests/own-skill.test.cjs internal/gui/tests/routing-manual.test.cjs internal/gui/tests/tray-usages.test.cjs internal/gui/tests/provider-remove.test.cjs internal/gui/tests/signin-link.test.cjs internal/gui/tests/tray-inuse.test.cjs internal/gui/tests/codex-auto-reset.test.cjs internal/gui/tests/routing-auto-reset.test.cjs internal/gui/tests/claude-usage-asked.test.cjs internal/gui/tests/claude-risk.test.cjs internal/gui/tests/library-toggle-status.test.cjs internal/gui/tests/library-all.test.cjs internal/gui/tests/routing-reroute-title.test.cjs internal/gui/tests/plain-names.test.cjs internal/gui/tests/panel-effort.test.cjs internal/gui/tests/agent-models-all-hidden.test.cjs internal/gui/tests/omp-roles.test.cjs internal/gui/tests/claude-effort.test.cjs internal/gui/tests/remote-magpie.test.cjs internal/gui/tests/qoder-cn-tile.test.cjs internal/gui/tests/provider-levels-scroll.test.cjs internal/gui/tests/signin-paste-codex.test.cjs internal/gui/tests/signin-paste-key.test.cjs internal/gui/tests/usage-alert.test.cjs internal/gui/tests/quota-families.test.cjs internal/gui/tests/provider-search.test.cjs internal/gui/tests/webdav-settings-refresh.test.cjs internal/gui/tests/lan-docker.test.cjs internal/gui/tests/plugin-key-hint.test.cjs internal/gui/tests/update-hide.test.cjs internal/gui/tests/tray-logos.test.cjs internal/gui/tests/routing-proxy.test.cjs internal/gui/tests/sse-body.test.cjs internal/gui/tests/remote-group-served.test.cjs internal/gui/tests/plugin-move-overflow.test.cjs internal/gui/tests/routing-time.test.cjs internal/gui/tests/unlisted-models.test.cjs internal/gui/tests/plugin-updates.test.cjs internal/gui/tests/request-archive.test.cjs internal/gui/tests/group-member-fast.test.cjs internal/gui/tests/providers-off-fold.test.cjs internal/gui/tests/account-return.test.cjs internal/gui/tests/usage-ledger-detail.test.cjs internal/gui/tests/usage-ledger-chart.test.cjs internal/gui/tests/usage-chart-axis.test.cjs internal/gui/tests/panel-usage.test.cjs internal/gui/tests/usage-refresh.test.cjs internal/gui/tests/usage-ledger-content.test.cjs internal/gui/tests/claude-direct.test.cjs internal/gui/tests/signin-again.test.cjs internal/gui/tests/sessions-calendar-fill.test.cjs internal/gui/tests/editor-short-window.test.cjs internal/gui/tests/group-from-model-add.test.cjs internal/gui/tests/sync-other-kind.test.cjs internal/gui/tests/web-page.test.cjs internal/gui/tests/balance-parts.test.cjs internal/gui/tests/search-api.test.cjs internal/gui/tests/provider-file-error.test.cjs internal/gui/tests/sessions-manage.test.cjs internal/gui/tests/number-units.test.cjs internal/gui/tests/sessions-bar-names.test.cjs ``` If Playwright is installed outside the repository, set `NODE_PATH` to the diff --git a/internal/gui/tests/sessions-bar-names.test.cjs b/internal/gui/tests/sessions-bar-names.test.cjs new file mode 100644 index 000000000..91f3fde7d --- /dev/null +++ b/internal/gui/tests/sessions-bar-names.test.cjs @@ -0,0 +1,137 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// The Sessions overview's bars, a name, a bar and figures a row (John on +// Discord: widening the window grew the bars and left the names cut short +// with "…"): the names were held to 9em, 10em and 11em whatever the width. +// Now a card's names take the width the longest needs and the bars what is +// left, every row's bar starting at the same place; narrow, the names are +// shortened and a bar is never under 5em. +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 iso = (d) => [d.getFullYear(), d.getMonth() + 1, d.getDate()].map((n) => String(n).padStart(2, "0")).join("-"); +const to = new Date(2026, 8, 28); +const back = (i) => { const d = new Date(to); d.setDate(d.getDate() - i); return d; }; +const LONG_DIR = "/work/a-rather-long-project-folder-name"; +const LONG_MODEL = "claude-sonnet-4-5-20250929-extended"; +const LONG_TOOL = "mcp__slack__send_message_draft"; +const LONG_SKILL = "document-skills:frontend-design"; +const allDays = Array.from({ length: 20 }, (_, i) => back(19 - i)).map((d, i) => ({ + date: iso(d), + usage: [ + { agent: "claude", cwd: LONG_DIR, model: LONG_MODEL, input: 30000 * (i + 1), output: 4000, cache_read: 0, cache_write: 0, cost: 1.5, priced: true }, + { agent: "codex", cwd: "/work/b", model: "gpt-5", input: 10000, output: 2000, cache_read: 0, cache_write: 0, cost: 0.4, priced: true }, + ], + active: [], +})); + +function serve(lang) { + const state = { agents: [{ id: "claude", name: "Claude Code", path: "/test/settings.json", fields: [] }], profiles: [], settings: { lang, theme: "light" } }; + 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(state); + if (url.pathname === "/api/plugins") return json({ plugins: [] }); + if (url.pathname === "/api/sessions/progress") return json({ indexing: false }); + if (url.pathname === "/api/sessions") return json({ sessions: [], dirs: ["/test/sessions"] }); + if (url.pathname === "/api/sessions/stats") return json({ from: allDays[0].date, to: iso(to), days: allDays, agents: { claude: "Claude Code", codex: "Codex" } }); + if (url.pathname === "/api/sessions/overview") { + return json({ count: 4, median: 1000, p90: 2000, days: allDays.map(() => 1), top: { tokens: [], cost: [], active: [] }, + messages: allDays.map(() => 3), output: allDays.map(() => 0), + shape: { messages: { edges: [1], counts: [4], total: 4 }, minutes: { edges: [1], counts: [4], total: 4 }, autonomy: { edges: [0], counts: [4], total: 4 } }, + tools: { + calls: 100, sessions: 4, + top: [{ name: LONG_TOOL, category: "Tool", calls: 60, sessions: 3 }, { name: "Bash", category: "Bash", calls: 40, sessions: 4 }], + categories: [{ name: "Tool", calls: 60, sessions: 3 }, { name: "Bash", calls: 40, sessions: 4 }], + weeks: [], + }, + skills: { + calls: 30, count: 2, + top: [{ name: LONG_SKILL, calls: 20, sessions: 3, agents: { claude: 20 }, projects: [] }, { name: "pdf", calls: 10, sessions: 1, agents: { claude: 10 }, projects: [] }], + } }); + } + if (url.pathname === "/api/groups") return json({ groups: [] }); + if (url.pathname === "/api/usage/quotas") 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)]; + const body = await fs.readFile(file).catch(() => null); + await (body ? route.fulfill({ body, contentType }) : route.fulfill({ status: 404, body: "" })); + }; +} + +// each bar row of the four cards: its name's full and shown widths, its bar's +const rows = (page) => page.evaluate(() => { + const out = []; + const pick = (sel, name, track) => document.querySelectorAll(sel).forEach((r) => { + const n = r.querySelector(name), b = r.querySelector(track).getBoundingClientRect(); + out.push({ sel, text: n.textContent, full: n.scrollWidth, shown: n.clientWidth, bar: b.width, left: b.left, card: r.closest(".sess-card").id }); + }); + pick("#sessProjects .sess-bar", ".n", ".track"); + pick("#sessModels .sess-bar", ".n", ".track"); + pick("#sessTools .sess-bar.tool", ".n span", ".track"); + pick("#sessSkills .sess-skill .line", ".n", ".track"); + return out; +}); + +for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) { + for (const lang of ["en", "zh"]) { + test(`${engine} ${lang}: the sessions bars' names take the width they need`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + const context = await browser.newContext({ viewport: { width: 1600, height: 900 }, reducedMotion: "reduce", timezoneId: "Asia/Shanghai" }); + 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.addInitScript(() => { localStorage.setItem("magpie.usageTab", "sessions"); localStorage.setItem("magpie.sessRange", "all"); }); + t.after(async () => { + if (process.env.ARTIFACT_DIR) { + await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true }); + await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-sess-bars.png`), fullPage: true }); + } + await browser.close(); + }); + await page.goto("http://magpie.test/?view=usage"); + await page.locator("#sessGrid:not([hidden])").waitFor(); + await page.waitForFunction(() => document.querySelector("#sessSkills .sess-skill") && document.querySelector("#sessTools .sess-bar.tool") && document.querySelectorAll("#sessModels .sess-bar").length === 2); + + await t.test("wide: every name whole, the bars still there and lined up", async () => { + const rs = await rows(page); + assert.equal(rs.length, 8, JSON.stringify(rs)); + for (const r of rs) { + assert.ok(r.full <= r.shown + 0.5, `${r.sel} "${r.text}" cut short: ${r.full} > ${r.shown}`); + assert.ok(r.bar >= 60, `${r.sel} "${r.text}" bar ${r.bar}`); + } + for (const card of new Set(rs.map((r) => r.card))) { + const lefts = rs.filter((r) => r.card === card).map((r) => Math.round(r.left)); + assert.equal(new Set(lefts).size, 1, `${card} bars start at ${lefts}`); + } + assert.ok(rs.some((r) => r.text === LONG_DIR.split("/").pop()) && rs.some((r) => r.text === LONG_MODEL)); + }); + + await t.test("narrow: the long names shortened, no bar under 5em", async () => { + await page.setViewportSize({ width: 420, height: 900 }); + await page.waitForTimeout(100); + const rs = await rows(page); + for (const r of rs) assert.ok(r.bar >= 59, `${r.sel} "${r.text}" bar ${r.bar}`); + assert.ok(rs.some((r) => r.full > r.shown), "a long name should be shortened at 420 wide"); + // nothing past its card + const over = await page.evaluate(() => [...document.querySelectorAll("#sessGrid .sess-card")].filter((c) => c.scrollWidth > c.clientWidth + 1).map((c) => c.id)); + assert.deepEqual(over, []); + }); + + await t.test("wide again", async () => { + await page.setViewportSize({ width: 1600, height: 900 }); + await page.waitForTimeout(100); + for (const r of await rows(page)) assert.ok(r.full <= r.shown + 0.5, `${r.sel} "${r.text}" cut short`); + }); + assert.deepEqual(errors, []); + }); + } +}