Use @testing-library/preact rendered under jsdom (registered via test/register.js) so the Post-Preact .jsx components and pages are exercised through the real automatic-runtime render path instead of the legacy el() DOM-helper API the tests were written against. - Add jsdom + @testing-library/preact dev deps and a jsdom globals setup in ui/test/register.js (window/document/navigator/getComputedStyle/...). - Switch the .jsx loader hook to the automatic JSX runtime to match @preact/preset-vite, so source files that shadow h (mapping-editor) and Fragment/children arrays work exactly as in the Vite build. - Migrate captures, config-row, mappings, settings-update-status, task-logs, settings-lifecycle, settings-schema, tasks-actions and the chat-app tests to render the Preact components and query the DOM via testing-library. - Fix a real render bug in tasks.jsx: <h.Fragment> is not rendered by the automatic runtime (rows came out as [object Object]); use the imported <Fragment> instead, matching the other migrated modules.
43 lines
1.9 KiB
JavaScript
43 lines
1.9 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { render, cleanup } from "@testing-library/preact";
|
|
import { UpdateStatusCard } from "../src/settings/update-status.jsx";
|
|
|
|
function renderCard(components) {
|
|
const { container, unmount } = render(<UpdateStatusCard components={components} />);
|
|
return { root: container, unmount };
|
|
}
|
|
|
|
test("update status card shows an empty state with no components", () => {
|
|
const { root } = renderCard([]);
|
|
assert.equal(root.querySelector("table"), null);
|
|
});
|
|
|
|
test("update status card renders one row per component with its status pill", () => {
|
|
const { root } = renderCard([
|
|
{ id: "daemon", label: "Gateway", install_type: "binary", running_version: "1.0.0", latest_available: "1.1.0", status: "update_available" },
|
|
{ id: "agent", label: "Runtime", install_type: "container", running_version: "1.0.0", status: "ok" },
|
|
]);
|
|
const rows = root.querySelector("tbody").children;
|
|
assert.equal(rows.length, 2);
|
|
assert.match(rows[0].textContent, /Gateway/);
|
|
assert.match(rows[0].textContent, /Update available/);
|
|
assert.match(rows[1].textContent, /OK/);
|
|
});
|
|
|
|
test("update status card's row title carries the comparison basis", () => {
|
|
const { root } = renderCard([
|
|
{ id: "agent", label: "Runtime", installed_claim: "1.1.0", running_version: "1.0.0", reference: "img@sha256:abc", status: "drift" },
|
|
]);
|
|
const row = root.querySelector("tbody").children[0];
|
|
assert.match(row.getAttribute("title"), /Installed claim: 1\.1\.0/);
|
|
assert.match(row.getAttribute("title"), /Running: 1\.0\.0/);
|
|
assert.match(row.getAttribute("title"), /Reference: img@sha256:abc/);
|
|
});
|
|
|
|
test("update status card shows an unrecognised status as its own label rather than crashing", () => {
|
|
const { root } = renderCard([{ id: "x", status: "something-new" }]);
|
|
const row = root.querySelector("tbody").children[0];
|
|
assert.match(row.textContent, /something-new/);
|
|
});
|