import { describe, expect, it, vi } from "vitest"; import { render, screen } from "~/test-utils.js"; import userEvent from "@testing-library/user-event"; import { EmptyState } from "./EmptyState.js"; describe("EmptyState", () => { it("renders the title", () => { render(); expect(screen.getByText("No results")).toBeInTheDocument(); }); it("renders detail text when provided", () => { render(); expect(screen.getByText("Try adjusting your filters")).toBeInTheDocument(); }); it("does not render detail when not provided", () => { const { container } = render(); const paragraphs = container.querySelectorAll("p"); expect(paragraphs).toHaveLength(1); }); it("renders an action button when action is provided", () => { const action = { label: "Create new", onClick: vi.fn() }; render(); expect(screen.getByRole("button", { name: "Create new" })).toBeInTheDocument(); }); it("calls action onClick when button is clicked", async () => { const onClick = vi.fn(); render(); await userEvent.click(screen.getByRole("button", { name: "Add" })); expect(onClick).toHaveBeenCalledOnce(); }); it("does not render action button when not provided", () => { render(); expect(screen.queryByRole("button")).not.toBeInTheDocument(); }); it("renders icon when provided", () => { render(Icon} />); expect(screen.getByTestId("icon")).toBeInTheDocument(); }); it("applies testId to the container", () => { render(); expect(screen.getByTestId("empty-state")).toBeInTheDocument(); }); });