Files
initiative/apps/web/src/components/__tests__/dialog.test.tsx
Lukas b6ee4c8c86
All checks were successful
CI / check (push) Successful in 1m38s
CI / build-image (push) Has been skipped
Fix oxlint warnings, extract dialog polyfill, deny warnings in gate
Adds void to floating promise in bestiary-cache.ts, extracts shared
polyfillDialog() helper to eliminate unbound-method warnings in 3 test
files. Adds --deny warnings to oxlint so future warnings fail the
build.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 22:38:57 +02:00

64 lines
1.6 KiB
TypeScript

// @vitest-environment jsdom
import { cleanup, render, screen } from "@testing-library/react";
import { userEvent } from "@testing-library/user-event";
import { afterEach, beforeAll, describe, expect, it, vi } from "vitest";
import { polyfillDialog } from "../../__tests__/polyfill-dialog.js";
import { Dialog, DialogHeader } from "../ui/dialog.js";
beforeAll(() => {
polyfillDialog();
});
afterEach(cleanup);
describe("Dialog", () => {
it("opens when open=true", () => {
render(
<Dialog open={true} onClose={() => {}}>
Content
</Dialog>,
);
expect(screen.getByText("Content")).toBeDefined();
});
it("closes when open changes from true to false", () => {
const { rerender } = render(
<Dialog open={true} onClose={() => {}}>
Content
</Dialog>,
);
const dialog = document.querySelector("dialog");
expect(dialog?.hasAttribute("open")).toBe(true);
rerender(
<Dialog open={false} onClose={() => {}}>
Content
</Dialog>,
);
expect(dialog?.hasAttribute("open")).toBe(false);
});
it("calls onClose on cancel event", () => {
const onClose = vi.fn();
render(
<Dialog open={true} onClose={onClose}>
Content
</Dialog>,
);
const dialog = document.querySelector("dialog");
dialog?.dispatchEvent(new Event("cancel"));
expect(onClose).toHaveBeenCalledOnce();
});
});
describe("DialogHeader", () => {
it("renders title and close button", async () => {
const onClose = vi.fn();
render(<DialogHeader title="Test Title" onClose={onClose} />);
expect(screen.getByText("Test Title")).toBeDefined();
await userEvent.click(screen.getByRole("button"));
expect(onClose).toHaveBeenCalledOnce();
});
});