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.
81 lines
3.0 KiB
JavaScript
81 lines
3.0 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { register } from "node:module";
|
|
import { render } from "@testing-library/preact";
|
|
|
|
const cssLoad = "data:text/javascript," + encodeURIComponent(`
|
|
export async function load(url, context, nextLoad) {
|
|
if (url.endsWith(".css")) {
|
|
return { format: "module", shortCircuit: true, source: "export default {};" };
|
|
}
|
|
return nextLoad(url, context);
|
|
}
|
|
`);
|
|
register(cssLoad, import.meta.url);
|
|
|
|
const { api } = await import("../src/base/api.jsx");
|
|
const { settingsPage } = await import("../src/settings/settings.jsx");
|
|
|
|
async function renderSettings(meta) {
|
|
const original = { config: api.config, version: api.version, taskMeta: api.taskMeta };
|
|
api.config = async () => ({});
|
|
api.version = async () => ({ components: [] });
|
|
api.taskMeta = async () => meta;
|
|
try {
|
|
const vnode = settingsPage(new URLSearchParams());
|
|
const { container } = render(vnode);
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
return container;
|
|
} finally {
|
|
api.config = original.config;
|
|
api.version = original.version;
|
|
api.taskMeta = original.taskMeta;
|
|
}
|
|
}
|
|
|
|
test("work lifecycle card renders a status pill and an action button from /api/task-meta", async () => {
|
|
const root = await renderSettings({
|
|
statuses: [
|
|
{ id: "waiting_human", label: "Waiting for you", kind: "warn", needs_you: true },
|
|
{ id: "queued", label: "Queued", kind: "idle" },
|
|
],
|
|
actions: [
|
|
{ id: "cancel", label: "Cancel", kind: "quiet" },
|
|
{ id: "approve", label: "Approve", kind: "primary" },
|
|
],
|
|
});
|
|
|
|
const text = root.textContent;
|
|
assert.ok(text.includes("Work lifecycle"), "the lifecycle card should be present");
|
|
|
|
const warnPill = root.querySelector(".pill-warn");
|
|
assert.ok(warnPill, "a warn-kind status should render a warn pill");
|
|
assert.equal(warnPill.textContent, "Waiting for you");
|
|
assert.ok(text.includes("Queued"), "a second status should render its label");
|
|
|
|
const cancelBtn = root.querySelector(".btn-quiet");
|
|
assert.ok(cancelBtn, "a quiet action should render a quiet-variant button");
|
|
assert.equal(cancelBtn.textContent, "Cancel");
|
|
assert.ok(text.includes("Approve"), "a primary action should render its label");
|
|
});
|
|
|
|
test("work lifecycle card shows a quiet empty state when the catalog fetch fails", async () => {
|
|
const original = { config: api.config, version: api.version, taskMeta: api.taskMeta };
|
|
api.config = async () => ({});
|
|
api.version = async () => ({ components: [] });
|
|
api.taskMeta = async () => {
|
|
throw new Error("boom");
|
|
};
|
|
try {
|
|
const vnode = settingsPage(new URLSearchParams());
|
|
const { container: root } = render(vnode);
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
assert.ok(root.textContent.includes("Work lifecycle"), "the card should still render");
|
|
assert.ok(root.textContent.includes("Lifecycle unavailable"), "a failure should show the empty/error state");
|
|
} finally {
|
|
api.config = original.config;
|
|
api.version = original.version;
|
|
api.taskMeta = original.taskMeta;
|
|
}
|
|
});
|