Public: anyone can read this; the crew can change it.
Design: the home KPIs use §5's stat, and the kpi* classes leave §5d #3903
scout/forge:scout/3877-design-the-home-kpis-use-5-s-stat-and-th → main 1 commit fork 1 thread · 1 unresolved
10 files
changed +80
−76
docs/DESIGN.md +2 −1
| @@ -150,6 +150,7 @@ specification. | ||
| 150 | 150 | | **name mark** `nameMark()` | `.name-mark[data-mark]` | `owner` / `crew`, from the account | never typed: escaped names cannot make it | beside the name, after the link | |
| 151 | 151 | | **avatar** `avatar()` | `.avatar` | `size=md\|lg`, `data-h=0..11` | initials, deterministic hue | two initial letters in the same hue | |
| 152 | 152 | | **count** | `.count` | — | glyph plus a tabular number | `⌸ 3` | |
| 153 | | **stat** `stat()` | `.row` in a `listCard()` (no class of its own) | — | label as the title, note as the meta, value (tabular, whole form in its `title`) and an optional sparkline `<svg class="muted">` as the trail; a flag is a `badge()` | `Label note value` | | |
| 153 | 154 | | **stat pill** `pill()` | `.pill` | `data-tone=accent\|danger` | tabular | a parenthesised count | |
| 154 | 155 | | **status dot** `dot()` | `.dot` | `data-tone=success\|danger\|attn\|merged`; `data-series=0…7` (`seriesDot()`) is a chart series' swatch, in its `--series-N` colour | — | `●` in the tone | |
| 155 | 156 | | **sha** `sha()` | `.sha` | — | first 7 chars | the same 7 chars, dim | |
| @@ -394,7 +395,7 @@ gone, so this list only shrinks. | ||
| 394 | 395 | - **`style/content.ts`, search results** — search results, the inbox's ask cards, the client list and the claim link: `.ask-acts` `.ask-card` `.ask-group` `.ask-kind` `.ask-meta` `.ask-more-acts` `.ask-pick` `.ask-pick-hit` `.ask-short` `.ask-waiting` `.claim-link-box` `.forges-sent` `.live-toggle` `.needs-you` `.no-hits` |
| 395 | 396 | - **`pages/board.ts`** — the spend tables `spend.ts` draws, first on the board (the board itself is §5's **board**): `.spend-table` `.spend-totals` |
| 396 | 397 | - **`pages/map.ts`** — the map of what waits for what: `.map-ask` `.map-breath` `.map-canvas` `.map-card` `.map-counts` `.map-dot` `.map-edge` `.map-edge-crit` `.map-edge-done` `.map-empty` `.map-list` `.map-main` `.map-meta` `.map-node` `.map-pillars` `.map-rule` `.map-svg` `.map-title` `.map-tool` `.map-tools` `.map-who` `.map-who-i` `.map-who-n` `.map-word` `.map-wrap` |
| 397 | - **`studio/feed_style.ts`** — the home feed's cards, its composer and the apps rail: `.composer` `.composer-bar` `.fcard-form` `.fcard-reason` `.fcard-reply` `.fcard-text` `.fcard-unblock` `.fcard-who` `.fcard-why` `.feed` `.feed-head` `.kpi` `.kpi-note` `.kpi-spark` `.kpi-value` `.kpis` `.home-app` `.home-apps` `.home-apps-verbs` `.home-pick` `.home-rail` `.home-tabs` | |
| 398 | - **`studio/feed_style.ts`** — the home feed's cards, its composer and the apps rail: `.composer` `.composer-bar` `.fcard-form` `.fcard-reason` `.fcard-reply` `.fcard-text` `.fcard-unblock` `.fcard-who` `.fcard-why` `.feed` `.feed-head` `.home-app` `.home-apps` `.home-apps-verbs` `.home-pick` `.home-rail` `.home-tabs` | |
| 398 | 399 | |
| 399 | 400 | --- |
| 400 | 401 |
src/web/studio/feed_style.ts −7
| @@ -19,13 +19,6 @@ export const feedCss = /* css */ ` | ||
| 19 | 19 | .composer textarea { width: 100%; min-height: 64px; resize: vertical; } |
| 20 | 20 | .composer-bar { display: flex; align-items: center; gap: 8px; min-width: 0; } |
| 21 | 21 | .composer-bar select { min-width: 0; max-width: 60%; } |
| 22 | /* The figures row: three cards at a fixed height, so first paint is final; the note wraps into two reserved lines. */ | |
| 23 | .kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 12px; } | |
| 24 | .kpi { display: grid; grid-template-rows: 20px 32px 40px 24px; align-content: start; gap: 2px; padding: 12px 14px; color: inherit; text-decoration: none; } | |
| 25 | .kpi:hover { border-color: var(--border-strong); } | |
| 26 | .kpi-value { font-size: 16px; line-height: 32px; font-weight: 600; } | |
| 27 | .kpi-note { line-height: 20px; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow-wrap: anywhere; } | |
| 28 | .kpi-spark { display: block; color: var(--muted-fg); max-width: 100%; } | |
| 29 | 22 | /* Your apps: a narrow column on a desk, a tab away on a phone. */ |
| 30 | 23 | .home-tabs { display: none; margin-bottom: 12px; } |
| 31 | 24 | .home-app { gap: 8px; } |
src/web/studio/kpi_row.ts +24 −27
| @@ -14,7 +14,7 @@ import { cachedKpis } from "./home_cache.ts"; | ||
| 14 | 14 | import { escapeHtml, html, raw, type Html } from "../html.ts"; |
| 15 | 15 | import { BOOTED } from "../../release/gate.ts"; |
| 16 | 16 | import { running } from "../../kernel/version.ts"; |
| 17 | import { sha, time } from "../ui.ts"; | |
| 17 | import { badge, listCard, sha, stat, time } from "../ui.ts"; | |
| 18 | 18 | |
| 19 | 19 | const W = 96; |
| 20 | 20 | const H = 24; |
| @@ -26,7 +26,7 @@ function at(i: number, n: number, v: number, top: number): [string, string] { | ||
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | function svg(label: string, body: string): Html { |
| 29 | return raw(`<svg class="kpi-spark" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" role="img" aria-label="${label}">${body}</svg>`); | |
| 29 | return raw(`<svg class="muted" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}" role="img" aria-label="${label}">${body}</svg>`); | |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** A series oldest first as a fixed-size SVG polyline; the numbers are the only input. */ |
| @@ -75,13 +75,8 @@ export function visitorsSpark(days: readonly number[]): Html { | ||
| 75 | 75 | return spark(days, `Distinct visitors each day over the last ${days.length} days`); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | function tile(label: string, href: string, value: Html | string, full: string, note: string | Html, title: string, extra: Html | null = null, tone: "attn" | null = null): Html { | |
| 79 | return html`<a class="card kpi" href="${href}"${tone === null ? "" : raw(` data-tone="${tone}"`)} aria-label="${label}: ${full}, ${title}"> | |
| 80 | <span class="small muted">${label}</span> | |
| 81 | <span class="kpi-value num" title="${full}">${value}</span> | |
| 82 | <span class="kpi-note small muted" title="${title}">${note}</span> | |
| 83 | ${extra} | |
| 84 | </a>`; | |
| 78 | function tile(label: string, href: string, value: Html | string, full: string, note: string | Html, title: string, spark: Html | null = null, flag: Html | null = null): Html { | |
| 79 | return stat({ label, href, value, full, note, title, spark, flag }); | |
| 85 | 80 | } |
| 86 | 81 | |
| 87 | 82 | /** The version this forge is running, and since when: the same source as `/releases`. */ |
| @@ -93,8 +88,9 @@ export function liveNow(): { sha: string; at: string } | null { | ||
| 93 | 88 | export function kpiRowFor(k: Kpis, live: { sha: string; at: string } | null, now: Date = new Date()): Html { |
| 94 | 89 | const overdue = backupOverdue(k.backupAt, now); |
| 95 | 90 | const rate = k.landed / k.landedHours.length; |
| 96 | return html`<section class="kpis" aria-label="The last 24 hours, as of this page load"> | |
| 97 | ${tile( | |
| 91 | return html`<section aria-label="The last 24 hours, as of this page load"> | |
| 92 | ${listCard([ | |
| 93 | tile( | |
| 98 | 94 | "Shipped per hour", |
| 99 | 95 | "/board", |
| 100 | 96 | rate.toFixed(1), |
| @@ -102,40 +98,40 @@ export function kpiRowFor(k: Kpis, live: { sha: string; at: string } | null, now | ||
| 102 | 98 | `${k.landed} ${k.landed === 1 ? "change" : "changes"} in 24 h`, |
| 103 | 99 | `${k.landed} ${k.landed === 1 ? "change" : "changes"} in 24 h`, |
| 104 | 100 | sparkline(k.landedHours), |
| 105 | )} | |
| 106 | ${tile( | |
| 101 | ), | |
| 102 | tile( | |
| 107 | 103 | "Live version", |
| 108 | 104 | "/releases", |
| 109 | 105 | live === null ? "—" : sha(live.sha), |
| 110 | 106 | live === null ? "Nothing live yet" : live.sha, |
| 111 | 107 | live === null ? "Nothing live yet" : html`live ${time(live.at)}`, |
| 112 | 108 | live === null ? "Nothing live yet" : `Live since ${live.at}`, |
| 113 | )} | |
| 114 | ${tile( | |
| 109 | ), | |
| 110 | tile( | |
| 115 | 111 | "Median check time", |
| 116 | 112 | "/boards", |
| 117 | 113 | checkTime(k.medianCheckMs), |
| 118 | 114 | k.medianCheckMs === null ? "No check finished in 24 h" : checkTime(k.medianCheckMs), |
| 119 | 115 | k.medianCheckMs === null ? "No check finished in 24 h" : "over the last 24 h", |
| 120 | 116 | k.medianCheckMs === null ? "No check finished in 24 h" : "over the last 24 h", |
| 121 | )} | |
| 122 | ${tile( | |
| 117 | ), | |
| 118 | tile( | |
| 123 | 119 | "Builders running", |
| 124 | 120 | "/settings/crew", |
| 125 | 121 | buildersValue(k.builders), |
| 126 | 122 | buildersValue(k.builders), |
| 127 | 123 | k.builders.slots === 0 ? "No slots set" : "running now", |
| 128 | 124 | k.builders.slots === 0 ? "No slots set" : `Crew builders running now, of ${k.builders.slots} ${k.builders.slots === 1 ? "slot" : "slots"}`, |
| 129 | )} | |
| 130 | ${tile( | |
| 125 | ), | |
| 126 | tile( | |
| 131 | 127 | "Crew spend today", |
| 132 | 128 | "/settings/crew", |
| 133 | 129 | spendValue(k.spend), |
| 134 | 130 | spendFull(k.spend), |
| 135 | 131 | k.spend.ceilingUsd === null ? "no ceiling" : "of the daily ceiling", |
| 136 | 132 | k.spend.ceilingUsd === null ? "No daily ceiling is set" : "Crew spend today (UTC), of the daily ceiling", |
| 137 | )} | |
| 138 | ${tile( | |
| 133 | ), | |
| 134 | tile( | |
| 139 | 135 | "Last off-box backup", |
| 140 | 136 | "/settings/backups", |
| 141 | 137 | backupAge(k.backupAt, now), |
| @@ -143,18 +139,19 @@ export function kpiRowFor(k: Kpis, live: { sha: string; at: string } | null, now | ||
| 143 | 139 | k.backupAt === null ? "no backup off the machine yet" : overdue ? "overdue, more than 24 h" : "off the machine", |
| 144 | 140 | overdue ? "Overdue: the last off-box backup is more than 24 h old" : "Age of the last off-box backup", |
| 145 | 141 | null, |
| 146 | overdue ? "attn" : null, | |
| 147 | )} | |
| 148 | ${tile("Visitors", "/boards/reach", visitorsValue(k.reach), `${visitorsValue(k.reach)}, ${visitorsNote(k.reach)}`, visitorsNote(k.reach), "Distinct browsers per day, summed over 7 days", visitorsSpark(k.reach.visitorDays))} | |
| 149 | ${tile("Accounts", "/boards/reach", usersValue(k.reach), usersValue(k.reach), "signed in today", "Accounts signed in today (UTC), of all accounts")} | |
| 150 | ${tile( | |
| 142 | overdue ? badge("overdue", { tone: "attn" }) : null, | |
| 143 | ), | |
| 144 | tile("Visitors", "/boards/reach", visitorsValue(k.reach), `${visitorsValue(k.reach)}, ${visitorsNote(k.reach)}`, visitorsNote(k.reach), "Distinct browsers per day, summed over 7 days", visitorsSpark(k.reach.visitorDays)), | |
| 145 | tile("Accounts", "/boards/reach", usersValue(k.reach), usersValue(k.reach), "signed in today", "Accounts signed in today (UTC), of all accounts"), | |
| 146 | tile( | |
| 151 | 147 | "Page speed", |
| 152 | 148 | "/boards/reach", |
| 153 | 149 | speedWords(k.reach.loadP75), |
| 154 | 150 | speedWords(k.reach.loadP75), |
| 155 | 151 | reactNote(k.reach), |
| 156 | 152 | "Page load, and delay after a tap, for the slowest quarter of views over 7 days", |
| 157 | )} | |
| 153 | ), | |
| 154 | ])} | |
| 158 | 155 | </section>`; |
| 159 | 156 | } |
| 160 | 157 |
src/web/ui.ts +11
| @@ -875,6 +875,17 @@ export function row(o: RowOptions): Html { | ||
| 875 | 875 | </li>`; |
| 876 | 876 | } |
| 877 | 877 | |
| 878 | /** One figure: its label, the value (with its whole form as a title), a note, and optionally a sparkline or badge. A `row()` that links to where the figure comes from. */ | |
| 879 | export function stat(o: { label: string; href: string; value: Html | string; full: string; note: Html | string; title: string; spark?: Html | null; flag?: Html | null }): Html { | |
| 880 | return row({ | |
| 881 | href: o.href, | |
| 882 | title: o.label, | |
| 883 | titleAttr: o.title, | |
| 884 | meta: html`${o.note}${o.flag ? html` ${o.flag}` : null}`, | |
| 885 | trail: html`${o.spark ?? null}<span class="num" title="${o.full}">${o.value}</span>`, | |
| 886 | }); | |
| 887 | } | |
| 888 | ||
| 878 | 889 | // ---- navigation ---- |
| 879 | 890 | |
| 880 | 891 | export interface TabItem { |
test/client-home.test.ts +2 −2
| @@ -244,8 +244,8 @@ describe("a client's first screen", () => { | ||
| 244 | 244 | }); |
| 245 | 245 | |
| 246 | 246 | test("a client sees no forge-wide figures, lean or whole", async () => { |
| 247 | expect(await page(owner)).not.toContain('class="kpis"'); | |
| 248 | expect(await page(owner, "/?all=1")).not.toContain('class="kpis"'); | |
| 247 | expect(await page(owner)).not.toContain('aria-label="The last 24 hours'); | |
| 248 | expect(await page(owner, "/?all=1")).not.toContain('aria-label="The last 24 hours'); | |
| 249 | 249 | }); |
| 250 | 250 | |
| 251 | 251 | test("queued agents and no running ones read as about to start", async () => { |
test/home-cache.test.ts +3 −3
| @@ -31,7 +31,7 @@ afterAll(async () => { | ||
| 31 | 31 | |
| 32 | 32 | test("a warm home reads neither the KPIs nor the panels again; a write does", async () => { |
| 33 | 33 | const a = await home(f.ownerCookie); |
| 34 | expect(a).toContain('class="kpis"'); | |
| 34 | expect(a).toContain('aria-label="The last 24 hours'); | |
| 35 | 35 | expect(a).toContain("<h2>Pin A</h2>"); |
| 36 | 36 | const kpi = kpiCache(f.app.db); |
| 37 | 37 | const panel = panelCache(f.app.db); |
| @@ -50,8 +50,8 @@ test("the owner's KPIs and panels never render for another viewer, warm or not", | ||
| 50 | 50 | await home(f.ownerCookie); |
| 51 | 51 | for (const cookie of [f.peerCookie, undefined]) { |
| 52 | 52 | const page = await home(cookie); |
| 53 | expect(page).not.toContain('class="kpis"'); | |
| 54 | expect(page).not.toContain('class="card kpi"'); | |
| 53 | expect(page).not.toContain('aria-label="The last 24 hours'); | |
| 54 | expect(page).not.toContain('aria-label="The last 24 hours'); | |
| 55 | 55 | expect(page).not.toContain("Pin A"); |
| 56 | 56 | } |
| 57 | 57 | }); |
test/home-kpi-page.test.ts +10 −6
| @@ -25,6 +25,8 @@ afterAll(async () => { | ||
| 25 | 25 | await rm(dataDir, { recursive: true, force: true }); |
| 26 | 26 | }); |
| 27 | 27 | |
| 28 | const FIGURES = 'aria-label="The last 24 hours, as of this page load"'; | |
| 29 | ||
| 28 | 30 | test("home renders the nine tiles; only an admin sees them", async () => { |
| 29 | 31 | const mk = async (username: string, first = false): Promise<User> => { |
| 30 | 32 | const r = await createUser(app.db, { |
| @@ -59,9 +61,11 @@ test("home renders the nine tiles; only an admin sees them", async () => { | ||
| 59 | 61 | view(day, "a", 1900, null); |
| 60 | 62 | view(yesterday, "z", 400, 160); |
| 61 | 63 | const a = await home(admin); |
| 62 | expect(a).toContain('class="kpis"'); | |
| 63 | expect((a.match(/class="card kpi"/g) ?? []).length).toBe(9); | |
| 64 | for (const href of ["/board", "/releases", "/boards", "/settings/crew"]) expect(a).toContain(`class="card kpi" href="${href}"`); | |
| 64 | expect(a).toContain(FIGURES); | |
| 65 | const section = a.slice(a.indexOf(FIGURES), a.indexOf("</section>", a.indexOf(FIGURES))); | |
| 66 | expect((section.match(/class="row"/g) ?? []).length).toBe(9); | |
| 67 | for (const href of ["/board", "/releases", "/boards", "/settings/crew"]) expect(section).toContain(`<a href="${href}"`); | |
| 68 | for (const name of ["kpis", "kpi", "kpi-note", "kpi-spark", "kpi-value"]) expect(a).not.toMatch(new RegExp(`class="[^"]*\\b${name}\\b`)); | |
| 65 | 69 | |
| 66 | 70 | // 2 accounts, the admin alone with a session today; visitors 3 today and 4 over 7 days; |
| 67 | 71 | // load p75 of [100,200,300,400,1900] is 400 ms, INP p75 of [40,80,120,160] is 120 ms. |
| @@ -70,14 +74,14 @@ test("home renders the nine tiles; only an admin sees them", async () => { | ||
| 70 | 74 | expect(a).toContain(">4 in 7 days<"); |
| 71 | 75 | expect(a).toContain(">400 ms<"); |
| 72 | 76 | expect(a).toContain(">reacts in 120 ms<"); |
| 73 | expect((a.match(/class="card kpi" href="\/boards\/reach"/g) ?? []).length).toBe(3); | |
| 77 | expect((a.match(/<a href="\/boards\/reach"/g) ?? []).length).toBe(3); | |
| 74 | 78 | |
| 75 | 79 | // The figures count every repository, so a non-admin sees none. |
| 76 | 80 | expect(a).toContain("no ceiling"); |
| 77 | 81 | expect(a).toContain("last 30 days"); |
| 78 | expect(await home(bob)).not.toContain('class="kpis"'); | |
| 82 | expect(await home(bob)).not.toContain(FIGURES); | |
| 79 | 83 | expect(await home(bob)).not.toContain("last 30 days"); |
| 80 | expect(await home()).not.toContain('class="kpis"'); | |
| 84 | expect(await home()).not.toContain(FIGURES); | |
| 81 | 85 | expect(await home()).not.toContain("last 30 days"); |
| 82 | 86 | }); |
| 83 | 87 |
test/home-kpi-row.test.ts +20 −22
| @@ -26,7 +26,7 @@ describe("home kpi row", () => { | ||
| 26 | 26 | for (const href of ["/board", "/releases", "/boards"]) expect(out).toContain(`href="${href}"`); |
| 27 | 27 | }); |
| 28 | 28 | |
| 29 | test("the whole figure is in the title and the link's label, rounded and in studio words", () => { | |
| 29 | test("the whole figure is in the title, rounded and in studio words", () => { | |
| 30 | 30 | const out = kpiRowFor( |
| 31 | 31 | { landedHours: hours(7), landed: 7, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: 185_000, backupAt: null, reach: NO_REACH }, |
| 32 | 32 | { sha: "abcdef0123456", at: "2026-10-19T11:00:00.000Z" }, |
| @@ -35,8 +35,8 @@ describe("home kpi row", () => { | ||
| 35 | 35 | expect(out).not.toContain("0.2916"); |
| 36 | 36 | expect(out).toContain('title="3m 05s"'); |
| 37 | 37 | expect(out).not.toContain(" ms"); |
| 38 | expect(out).toContain('aria-label="Live version: abcdef0123456, Live since 2026-10-19T11:00:00.000Z"'); | |
| 39 | expect(out).toContain('aria-label="Shipped per hour: 0.29, 7 changes in 24 h"'); | |
| 38 | expect(out).toContain('title="abcdef0123456"'); | |
| 39 | expect(out).toContain('title="7 changes in 24 h"'); | |
| 40 | 40 | }); |
| 41 | 41 | |
| 42 | 42 | test("empty figures say so", () => { |
| @@ -74,27 +74,25 @@ describe("home kpi row", () => { | ||
| 74 | 74 | expect(out).toContain('title="No check finished in 24 h"'); |
| 75 | 75 | }); |
| 76 | 76 | |
| 77 | test("the note wraps into two reserved lines instead of cutting off on a phone", () => { | |
| 78 | const rule = (sel: string) => new RegExp(`\\${sel} \\{([^}]*)\\}`).exec(feedCss)![1]!; | |
| 79 | expect(rule(".kpi-note")).not.toContain("nowrap"); | |
| 80 | expect(rule(".kpi-note")).toContain("line-height: 20px"); | |
| 81 | expect(rule(".kpi-note")).toContain("line-clamp: 2"); | |
| 82 | expect(rule(".kpi")).toContain("grid-template-rows: 20px 32px 40px 24px"); | |
| 77 | test("the old kpi classes are gone from the markup", () => { | |
| 78 | const out = kpiRowFor({ landedHours: hours(3), landed: 3, live: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 1, ceilingUsd: 4 }, medianCheckMs: 1000, backupAt: null, reach: NO_REACH }, { sha: "abcdef0123456", at: "2026-10-19T11:00:00.000Z" }).toString(); | |
| 79 | for (const name of ["kpis", "kpi", "kpi-note", "kpi-spark", "kpi-value"]) expect(out).not.toMatch(new RegExp(`class="[^"]*\\b${name}\\b`)); | |
| 80 | expect((out.match(/class="row"/g) ?? []).length).toBe(9); | |
| 81 | expect(feedCss).not.toMatch(/\.kpi/); | |
| 83 | 82 | }); |
| 84 | 83 | |
| 85 | 84 | test("the builders tile says running of slots, titles it, and links to the crew", () => { |
| 86 | 85 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 2, slots: 4 }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); |
| 87 | 86 | expect(out).toContain('href="/settings/crew"'); |
| 88 | expect(out).toContain('class="kpi-value num" title="2 of 4">2 of 4<'); | |
| 87 | expect(out).toContain('<span class="num" title="2 of 4">2 of 4</span>'); | |
| 89 | 88 | expect(out).toContain('title="Crew builders running now, of 4 slots"'); |
| 90 | expect(out).toContain('aria-label="Builders running: 2 of 4, Crew builders running now, of 4 slots"'); | |
| 91 | 89 | }); |
| 92 | 90 | |
| 93 | 91 | test("with no slots set the builders tile shows a dash and says so", () => { |
| 94 | 92 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach: NO_REACH, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); |
| 95 | expect(out).toContain('class="kpi-value num" title="—">—<'); | |
| 96 | expect(out).toContain('title="No slots set">No slots set<'); | |
| 97 | expect(out).toContain(`aria-label="Builders running: —, No slots set"`); | |
| 93 | expect(out).toContain('<span class="num" title="—">—</span>'); | |
| 94 | expect(out).toContain('title="No slots set"'); | |
| 95 | expect(out).toContain(">No slots set<"); | |
| 98 | 96 | expect(out).not.toContain("Builders running: 0 of 0"); |
| 99 | 97 | }); |
| 100 | 98 | |
| @@ -155,8 +153,8 @@ describe("the spend tile", () => { | ||
| 155 | 153 | |
| 156 | 154 | test("shows today's spend of the ceiling, the cents in the title, linking to the crew page", () => { |
| 157 | 155 | const out = row({ todayUsd: 12.34, ceilingUsd: 40 }); |
| 158 | expect(out).toContain('class="kpi-value num" title="$12.34 of $40.00">$12 of $40<'); | |
| 159 | expect(out).toContain('aria-label="Crew spend today: $12.34 of $40.00, Crew spend today (UTC), of the daily ceiling"'); | |
| 156 | expect(out).toContain('<span class="num" title="$12.34 of $40.00">$12 of $40</span>'); | |
| 157 | expect(out).toContain('title="Crew spend today (UTC), of the daily ceiling"'); | |
| 160 | 158 | expect(out).toContain(">of the daily ceiling<"); |
| 161 | 159 | }); |
| 162 | 160 | |
| @@ -166,7 +164,7 @@ describe("the spend tile", () => { | ||
| 166 | 164 | |
| 167 | 165 | test("without a ceiling it shows the spend alone and says no ceiling", () => { |
| 168 | 166 | const out = row({ todayUsd: 12.34, ceilingUsd: null }); |
| 169 | expect(out).toContain('title="$12.34">$12<'); | |
| 167 | expect(out).toContain('title="$12.34">$12</span>'); | |
| 170 | 168 | expect(out).toContain(">no ceiling<"); |
| 171 | 169 | expect(out).not.toContain(" of $"); |
| 172 | 170 | }); |
| @@ -198,26 +196,26 @@ describe("home kpi row: the last off-box backup", () => { | ||
| 198 | 196 | const hoursAgo = (h: number) => new Date(NOW.getTime() - h * 3_600_000).toISOString(); |
| 199 | 197 | const row = (backupAt: string | null) => |
| 200 | 198 | kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt, reach: NO_REACH, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null }, medianCheckMs: null }, null, NOW).toString(); |
| 201 | const tile = (out: string) => /<a class="card kpi"[^>]*href="\/settings\/backups"[^>]*>/.exec(out)![0]; | |
| 199 | const tile = (out: string) => /<li>\s*<a href="\/settings\/backups"[^]*?<\/li>/.exec(out)![0]; | |
| 202 | 200 | |
| 203 | 201 | test("a backup 2 h old reads its age, with the exact time, and is not flagged", () => { |
| 204 | 202 | const out = row(hoursAgo(2)); |
| 205 | 203 | expect(out).toContain("2 h ago"); |
| 206 | 204 | expect(out).toContain(`title="${hoursAgo(2)}"`); |
| 207 | expect(tile(out)).not.toContain("data-tone"); | |
| 205 | expect(tile(out)).not.toContain("badge"); | |
| 208 | 206 | expect(tile(out)).not.toContain("Overdue"); |
| 209 | 207 | }); |
| 210 | 208 | |
| 211 | 209 | test("a backup 25 h old is flagged and its label says overdue", () => { |
| 212 | 210 | const t = tile(row(hoursAgo(25))); |
| 213 | expect(t).toContain('data-tone="attn"'); | |
| 211 | expect(t).toContain('data-variant="attn"'); | |
| 214 | 212 | expect(t).toContain("Overdue"); |
| 215 | 213 | }); |
| 216 | 214 | |
| 217 | 215 | test("no backup at all reads never and is flagged", () => { |
| 218 | 216 | const out = row(null); |
| 219 | 217 | expect(out).toContain(">never<"); |
| 220 | expect(tile(out)).toContain('data-tone="attn"'); | |
| 218 | expect(tile(out)).toContain('data-variant="attn"'); | |
| 221 | 219 | expect(tile(out)).toContain("Overdue"); |
| 222 | 220 | }); |
| 223 | 221 | |
| @@ -246,7 +244,7 @@ describe("the reach tiles", () => { | ||
| 246 | 244 | const reach = { usersToday: 3, usersTotal: 12, visitorsToday: 5, visitors7d: 31, visitorDays: new Array<number>(30).fill(0), loadP75: 1250, inpP75: 180 }; |
| 247 | 245 | const out = kpiRowFor({ landedHours: hours(0), landed: 0, live: null, backupAt: null, reach, medianCheckMs: null, builders: { running: 0, slots: 0 }, spend: { todayUsd: 0, ceilingUsd: null } }, null).toString(); |
| 248 | 246 | for (const v of ["5 today", "31 in 7 days", "3 of 12", "signed in today", "1.3 s", "reacts in 180 ms"]) expect(out).toContain(`>${v}<`); |
| 249 | expect((out.match(/class="card kpi" href="\/boards\/reach"/g) ?? []).length).toBe(3); | |
| 247 | expect((out.match(/<a href="\/boards\/reach"/g) ?? []).length).toBe(3); | |
| 250 | 248 | expect(out).not.toContain("INP"); |
| 251 | 249 | expect(out).not.toContain("p75"); |
| 252 | 250 | }); |
test/home-kpis.test.ts +5 −5
| @@ -137,16 +137,16 @@ describe("home kpi row titles", () => { | ||
| 137 | 137 | ).toString(); |
| 138 | 138 | |
| 139 | 139 | test("every shortened value and note carries its whole text in a title", () => { |
| 140 | expect(full).toContain('class="kpi-value num" title="abcdef0123456789"'); | |
| 141 | expect(full).toContain('class="kpi-value num" title="0.25"'); | |
| 142 | expect(full).toContain('class="kpi-value num" title="3m 05s"'); | |
| 140 | expect(full).toContain('class="num" title="abcdef0123456789"'); | |
| 141 | expect(full).toContain('class="num" title="0.25"'); | |
| 142 | expect(full).toContain('class="num" title="3m 05s"'); | |
| 143 | 143 | expect(full).toContain('title="Live since 2026-10-19T11:00:00.000Z"'); |
| 144 | 144 | expect(full).toContain('title="6 changes in 24 h"'); |
| 145 | 145 | }); |
| 146 | 146 | |
| 147 | 147 | test("no value or note lacks a title, and none brings back a git word", () => { |
| 148 | expect(full.match(/class="kpi-(value num|note small muted)"/g)).toHaveLength(18); | |
| 149 | expect(full.match(/class="kpi-(value num|note small muted)" title=/g)).toHaveLength(18); | |
| 148 | expect(full.match(/class="num" title=/g)).toHaveLength(9); | |
| 149 | expect(full.match(/class="row-title"\s+title=/g)).toHaveLength(9); | |
| 150 | 150 | expect(full).not.toMatch(/commit|merge|branch|repositor|pull request/i); |
| 151 | 151 | }); |
| 152 | 152 | }); |
test/kpi-spark.test.ts +3 −3
| @@ -37,7 +37,7 @@ describe("daySpark", () => { | ||
| 37 | 37 | |
| 38 | 38 | test("it keeps the class, the box and currentColor, and adds no style or colour", () => { |
| 39 | 39 | const out = daySpark([0, null, 5], "Days")!.toString(); |
| 40 | expect(out).toStartWith('<svg class="kpi-spark" viewBox="0 0 96 24" width="96" height="24" role="img" aria-label="Days">'); | |
| 40 | expect(out).toStartWith('<svg class="muted" viewBox="0 0 96 24" width="96" height="24" role="img" aria-label="Days">'); | |
| 41 | 41 | expect(out).not.toContain("style="); |
| 42 | 42 | expect(out).not.toMatch(/#[0-9a-f]{3,8}\b|rgb|hsl/i); |
| 43 | 43 | }); |
| @@ -50,13 +50,13 @@ describe("daySpark", () => { | ||
| 50 | 50 | describe("the numbers-only sparklines are unchanged", () => { |
| 51 | 51 | test("visitorsSpark", () => { |
| 52 | 52 | expect(visitorsSpark([0, 2, 4]).toString()).toBe( |
| 53 | `<svg class="kpi-spark" viewBox="0 0 96 24" width="96" height="24" role="img" aria-label="Distinct visitors each day over the last 3 days"><polyline points="0.0,22.0 48.0,12.0 96.0,2.0" ${LINE}/></svg>`, | |
| 53 | `<svg class="muted" viewBox="0 0 96 24" width="96" height="24" role="img" aria-label="Distinct visitors each day over the last 3 days"><polyline points="0.0,22.0 48.0,12.0 96.0,2.0" ${LINE}/></svg>`, | |
| 54 | 54 | ); |
| 55 | 55 | }); |
| 56 | 56 | |
| 57 | 57 | test("sparkline, newest first in, oldest on the left", () => { |
| 58 | 58 | expect(sparkline([2, 0]).toString()).toBe( |
| 59 | `<svg class="kpi-spark" viewBox="0 0 96 24" width="96" height="24" role="img" aria-label="Shipped each hour over the last 24 hours"><polyline points="0.0,22.0 96.0,2.0" ${LINE}/></svg>`, | |
| 59 | `<svg class="muted" viewBox="0 0 96 24" width="96" height="24" role="img" aria-label="Shipped each hour over the last 24 hours"><polyline points="0.0,22.0 96.0,2.0" ${LINE}/></svg>`, | |
| 60 | 60 | ); |
| 61 | 61 | }); |
| 62 | 62 | }); |
new above
offline
Duplicate of the line above; drop it, or assert something different such as the 9-row count.