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
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { h } from "preact";
|
|
import { render, cleanup } from "@testing-library/preact";
|
|
import { ChatMarkdown } from "../src/chat/markdown.jsx";
|
|
|
|
test("chat Markdown renders Telegram-style rich blocks as semantic HTML", () => {
|
|
const { container } = render(
|
|
<ChatMarkdown
|
|
text={
|
|
"# Summary\n\n**bold**, *italic*, ~~removed~~, and [docs](https://example.com)\n\n- first\n- second\n\n> quoted\n\n```go\nfmt.Println(\"hi\")\n```\n\n| Name | State |\n| --- | --- |\n| Archie | **live** |"
|
|
}
|
|
/>,
|
|
);
|
|
const rendered = container.querySelector(".chat-bubble-text");
|
|
|
|
assert.equal(rendered.querySelector("h1").textContent, "Summary");
|
|
assert.equal(rendered.querySelector("strong").textContent, "bold");
|
|
assert.equal(rendered.querySelector("em").textContent, "italic");
|
|
assert.equal(rendered.querySelector("del").textContent, "removed");
|
|
assert.equal(rendered.querySelector("a").getAttribute("href"), "https://example.com");
|
|
assert.equal(rendered.querySelector("ul").children.length, 2);
|
|
assert.equal(rendered.querySelector("blockquote").textContent, "quoted");
|
|
assert.match(rendered.querySelector("pre").textContent, /fmt\.Println/);
|
|
assert.equal(rendered.querySelector("table").querySelector("th").textContent, "Name");
|
|
assert.equal(rendered.querySelector("table").querySelector("td").textContent, "Archie");
|
|
cleanup();
|
|
});
|
|
|
|
test("chat Markdown renders images as img elements with src and alt", () => {
|
|
const { container } = render(
|
|
<ChatMarkdown text="Here is the generated image: " />,
|
|
);
|
|
const img = container.querySelector("img");
|
|
assert.ok(img, "img element should be present");
|
|
assert.equal(img.getAttribute("src"), "https://example.com/image.png");
|
|
assert.equal(img.getAttribute("alt"), "generated preview");
|
|
cleanup();
|
|
});
|
|
|
|
// The blocks are keyed, so a streamed reply that grows by one line re-renders
|
|
// only what changed. Preact reports a duplicate-key mistake by rendering the
|
|
// wrong thing, so the shapes with sibling lists and tables are worth pinning.
|
|
test("chat Markdown keeps sibling blocks distinct when the text grows", () => {
|
|
const { container, rerender } = render(<ChatMarkdown text={"- one\n- two"} />);
|
|
assert.equal(container.querySelectorAll("ul").length, 1);
|
|
rerender(<ChatMarkdown text={"- one\n- two\n- three"} />);
|
|
assert.equal(container.querySelectorAll("ul").length, 1);
|
|
assert.equal(container.querySelector("ul").children.length, 3);
|
|
|
|
rerender(<ChatMarkdown text={"- one\n\n1. first\n2. second"} />);
|
|
assert.equal(container.querySelectorAll("ul").length, 1);
|
|
assert.equal(container.querySelectorAll("ol").length, 1);
|
|
cleanup();
|
|
});
|