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.
83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { register } from "node:module";
|
|
import { render, waitFor } 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 { tasksPage } = await import("../src/tasks/tasks.jsx");
|
|
|
|
async function renderTask(task) {
|
|
const original = api.tasks;
|
|
api.tasks = async () => [task];
|
|
try {
|
|
const vnode = tasksPage(new URLSearchParams());
|
|
const { container } = render(vnode);
|
|
await waitFor(() => {
|
|
assert.ok(container.querySelector(".task-row"), "Wait for task to render");
|
|
});
|
|
return container;
|
|
} finally {
|
|
api.tasks = original;
|
|
}
|
|
}
|
|
|
|
test("an action present in the catalog renders a button, not null", async () => {
|
|
const task = {
|
|
id: 7,
|
|
title: "Fix the flaky test",
|
|
status: "waiting_human",
|
|
repo: "sam/archie",
|
|
workflow: "tdd",
|
|
actions: ["cancel"],
|
|
};
|
|
const root = await renderTask(task);
|
|
const container = root.querySelector(".task-actions");
|
|
assert.ok(container, "a known action should render a .task-actions container");
|
|
const btn = container.querySelector("button");
|
|
assert.ok(btn, "a button should be rendered for a catalog action");
|
|
assert.ok(btn.className.includes("btn-quiet"), "cancel maps to the quiet variant");
|
|
assert.equal(btn.textContent, "Cancel");
|
|
});
|
|
|
|
test("an id NOT in the catalog renders nothing", async () => {
|
|
const task = {
|
|
id: 8,
|
|
title: "Poltergeist task",
|
|
status: "waiting_human",
|
|
repo: "sam/archie",
|
|
workflow: "boot",
|
|
actions: ["teleport"],
|
|
};
|
|
const root = await renderTask(task);
|
|
assert.equal(root.querySelector(".task-actions"), null, "unknown action renders nothing");
|
|
});
|
|
|
|
test("a link-kind action renders an anchor to the forge", async () => {
|
|
const task = {
|
|
id: 9,
|
|
title: "Open the PR",
|
|
status: "pr_open",
|
|
repo: "sam/archie",
|
|
workflow: "tdd",
|
|
issue_number: 12,
|
|
pr_number: 42,
|
|
pr_url: "https://forge.example.internal/sam/archie/pull/42",
|
|
actions: ["open_pr"],
|
|
};
|
|
const root = await renderTask(task);
|
|
const link = root.querySelector(".task-actions")?.querySelector("a");
|
|
assert.ok(link, "open_pr should render an <a> not a <button>");
|
|
assert.equal(link.textContent, "Open PR");
|
|
assert.equal(link.getAttribute("href"), "https://forge.example.internal/sam/archie/pull/42");
|
|
});
|