// @vitest-environment jsdom
import { readFileSync } from "node:fs";
import { act, render, screen } from "@testing-library/react";
import { createRoot } from "react-dom/client";
import { describe, expect, it } from "vitest";
function TestShell() {
return ready;
}
describe("component test level", () => {
it("renders an accessible application shell", () => {
render();
expect(screen.getByRole("main", { name: "application shell" })).toHaveTextContent(
"ready",
);
});
});
describe("static boot shell (Q-6.9-8)", () => {
function loadIndexBody(): HTMLElement {
const html = readFileSync("index.html", "utf8");
document.body.innerHTML = new DOMParser()
.parseFromString(html, "text/html")
.body.innerHTML;
const root = document.getElementById("root");
if (!root) throw new Error("index.html has no #root");
return root;
}
it("shows a busy loading status before boot renders anything", () => {
const root = loadIndexBody();
const status = root.querySelector('[role="status"]');
expect(status?.getAttribute("aria-busy")).toBe("true");
expect(status?.textContent?.trim()).not.toBe("");
});
it("is replaced by the first render of the real app", async () => {
const root = loadIndexBody();
const reactRoot = createRoot(root);
await act(async () => {
reactRoot.render();
});
expect(root.querySelector('[aria-busy="true"]')).toBeNull();
expect(screen.getByRole("main", { name: "application shell" })).toBeTruthy();
await act(async () => {
reactRoot.unmount();
});
});
});