import { describe, it, expect, vi } from "vitest";
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { ConfirmDialog } from "../ConfirmDialog";
describe("ConfirmDialog", () => {
it("renders the title and message and wires confirm/cancel", async () => {
const onCancel = vi.fn();
const onConfirm = vi.fn();
render(
,
);
expect(screen.getByText("Delete machine?")).toBeInTheDocument();
expect(screen.getByText("This cannot be undone.")).toBeInTheDocument();
await userEvent.click(screen.getByRole("button", { name: "Delete" }));
expect(onConfirm).toHaveBeenCalledTimes(1);
await userEvent.click(screen.getByRole("button", { name: "Cancel" }));
expect(onCancel).toHaveBeenCalledTimes(1);
});
it("renders nothing when closed", () => {
render(
{}}
onConfirm={() => {}}
/>,
);
expect(screen.queryByText("Hidden")).not.toBeInTheDocument();
});
});