Files
archie/ui/test/chat-app.test.js
T
sam 227cc6bb36 test(webui): migrate UI tests to Preact testing library and fix tasks Fragment render
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.
2026-09-03 00:52:20 +10:00

35 lines
1.6 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { render, cleanup } from "@testing-library/preact";
import { ChatApp, chatPage } from "../src/chat/chat.jsx";
test("ChatApp renders structure with topbar, sidebar, transcript and composer", () => {
const { container, unmount } = render(<ChatApp />);
assert.ok(container.querySelector(".chat-topbar"), "topbar should render");
assert.ok(container.querySelector(".chat-sidebar"), "sidebar should render");
assert.ok(container.querySelector(".chat-transcript"), "transcript should render");
assert.ok(container.querySelector(".chat-composer"), "composer textarea should render");
assert.ok(container.querySelector(".chat-sidebar button"), "+ New chat button should exist");
unmount();
});
test("ChatApp renders empty state with prompt chips when messages are empty", () => {
const { container, unmount } = render(<ChatApp />);
const emptyState = container.querySelector(".chat-empty-state");
assert.ok(emptyState, "empty state should be present");
const prompts = container.querySelectorAll(".chat-prompt");
assert.ok(prompts.length >= 3, "should have prompt buttons");
unmount();
});
test("chatPage bridge function returns a DOM element containing the ChatApp", () => {
// chatPage() renders a Preact ChatApp into a container and returns that
// container as a real DOM node (used by the chat drawer / router).
const node = chatPage();
assert.ok(node instanceof HTMLElement, "chatPage should return a DOM element");
assert.ok(node.querySelector(".chat-page-content"), "chat-page-content should be inside node");
cleanup();
});