feat(drill): PeekModal — centered Radix Dialog with eyebrow + title

This commit is contained in:
Tyler
2026-06-21 11:52:39 -06:00
parent 7dd6a5d025
commit fb7a5c6d2e
2 changed files with 87 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
// @vitest-environment happy-dom
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
import { afterEach, describe, it, expect, vi } from "vitest";
import { cleanup, render, screen, fireEvent } from "@testing-library/react";
import { PeekModal } from "@/components/drill/PeekModal";
// happy-dom keeps `document.body` between tests; without cleanup,
// `screen.getByRole(...)` finds buttons from earlier renders.
afterEach(() => cleanup());
describe("PeekModal", () => {
it("renders title and body when open; close button fires onClose", () => {
const onClose = vi.fn();
render(
<PeekModal
open
onClose={onClose}
eyebrow="Payer"
title="CO Medicaid"
>
<p>1,247 claims</p>
</PeekModal>,
);
expect(screen.getByText("Payer")).toBeTruthy();
expect(screen.getByText("CO Medicaid")).toBeTruthy();
expect(screen.getByText("1,247 claims")).toBeTruthy();
fireEvent.click(screen.getByRole("button", { name: /close/i }));
expect(onClose).toHaveBeenCalledOnce();
});
it("renders nothing when closed", () => {
const { container } = render(
<PeekModal open={false} onClose={() => {}} title="hidden">
<p>should not appear</p>
</PeekModal>,
);
// jest-dom's toBeEmptyDOMElement is not installed; assert via raw DOM.
expect(container.firstChild).toBeNull();
});
it("esc key closes", () => {
const onClose = vi.fn();
render(
<PeekModal open onClose={onClose} title="t">
<p>x</p>
</PeekModal>,
);
fireEvent.keyDown(document.body, { key: "Escape" });
expect(onClose).toHaveBeenCalledOnce();
});
});