The dashboard was a hybrid: a Preact page per route rendered into a shell built by a hand-rolled el() helper. Every route was Preact and the shell was not, which is why nothing failed -- the last of the vanilla layer was the part that composed the app. Removed: - ui/src/base/dom.jsx -- el/append/mount, the unused pill/empty pair, and a statusKind re-export that duplicated task-meta for one caller - ui/src/chat/chat-tools.jsx and the el-based bubble builders in chat-render.jsx: nothing in src/ called them, only their own tests did - the chatPage() DOM bridge, which existed so an imperative shell could embed a VNode Ported: - base/icons.jsx: icon() -> <Icon>; the glyph path table stays data - base/gauge.jsx, base/statTile.jsx, base/log-row.jsx: DOM builders -> components, with inline SVG instead of innerHTML - base/format.jsx: ago/compact, which never were DOM - chat/markdown.jsx: renderMarkdown() -> <ChatMarkdown>, so a streamed reply is diffed rather than rebuilt block by block - main.jsx: shell, nav, jump-to search, theme and chat drawer are one App; pages still render into one long-lived outlet Routing stays wired at import rather than from an effect. A page installs its own hash-sensitive state as it mounts, and task detail writes its tab selection back with replaceState as it settles: if the outgoing page is still mounted when the hashchange lands it canonicalises the URL back to its own route and the navigation is silently lost. The outlet and the two navigation-owned pieces of chrome are published through a callback ref, which runs at commit time, before any page effect. Tests: dom.test.js (el) and chat-tools.test.js are gone. The statTile cases in dom.test.js were not dropped -- they pinned the zero-value headline bug that made fresh installs look broken, and moved to test/statTile.test.js against the component. log-row and chat-markdown render their components. ui/dist rebuilt: index.js 146977 -> 146010 bytes. Closes archie-core-v9gv.2 and archie-core-v9gv.
56 lines
2.7 KiB
JavaScript
56 lines
2.7 KiB
JavaScript
// KPI tile regression coverage, moved here when base/statTile.jsx stopped
|
|
// building DOM by hand.
|
|
//
|
|
// The regression this pins: `el("div.stat-value", 0, ...)` treated a falsy
|
|
// first child (0, "", false) as "no attributes" and dropped it, so stat tiles
|
|
// rendered an empty headline whenever the value was zero. The dashboards of
|
|
// fresh installs showed exactly that -- labels and comparison text, no number.
|
|
// JSX does not have that bug, which is precisely why the case is worth keeping:
|
|
// it is what a future `value && <div>` refactor would break.
|
|
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { h } from "preact";
|
|
import { render, cleanup } from "@testing-library/preact";
|
|
import { StatTile, Sparkline } from "../src/base/statTile.jsx";
|
|
|
|
test("StatTile renders a zero headline value", () => {
|
|
const { container } = render(<StatTile label="Working now" value={0} compare="Nothing running" />);
|
|
const tile = container.querySelector(".card.stat");
|
|
assert.equal(tile.querySelector(".stat-label").textContent, "Working now");
|
|
assert.equal(tile.querySelector(".stat-value").textContent, "0");
|
|
assert.equal(tile.querySelector(".stat-compare").textContent, "Nothing running");
|
|
cleanup();
|
|
});
|
|
|
|
test("StatTile renders an empty-string headline value without dropping it", () => {
|
|
const { container } = render(<StatTile label="Tokens used" value="" compare="Across 14 days" />);
|
|
assert.equal(container.querySelector(".stat-value").textContent, "");
|
|
assert.equal(container.querySelector(".stat-compare").textContent, "Across 14 days");
|
|
cleanup();
|
|
});
|
|
|
|
test("StatTile renders a string headline value", () => {
|
|
const { container } = render(<StatTile label="Tokens used" value="2.4M" compare="Across 14 days" />);
|
|
assert.equal(container.querySelector(".stat-value").textContent, "2.4M");
|
|
cleanup();
|
|
});
|
|
|
|
test("StatTile shows a trend direction only when a trend is supplied", () => {
|
|
const plain = render(<StatTile label="Delivered" value={3} compare="3% of all tasks" />);
|
|
assert.equal(plain.container.querySelector(".stat-trend"), null);
|
|
cleanup();
|
|
const trended = render(<StatTile label="Tokens used" value={5} trend={12.5} compare="x" goodDirection="down" />);
|
|
assert.match(trended.container.querySelector(".stat-trend").textContent, /12\.5/);
|
|
cleanup();
|
|
});
|
|
|
|
test("StatTile draws a sparkline only when a series has a shape to show", () => {
|
|
const flat = render(<StatTile label="Delivered" value={3} compare="x" series={[1]} />);
|
|
assert.equal(flat.container.querySelector("svg.spark"), null);
|
|
cleanup();
|
|
const shaped = render(<StatTile label="Delivered" value={3} compare="x" series={[1, 4, 2]} />);
|
|
assert.ok(shaped.container.querySelector("svg.spark polyline"));
|
|
cleanup();
|
|
});
|