import { describe, it, expect, vi } from "vitest";
import userEvent from "@testing-library/user-event";
import { renderWithProviders as render, screen } from "../../utils/test-utils";
import "@testing-library/jest-dom/vitest";
import DeleteAccount from "../../../app/components/modals/DeleteAccount";
describe("DeleteAccount modal", () => {
it("does not render dialog when closed", () => {
render(
,
);
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
});
it("keeps Delete account disabled until the box is ticked", async () => {
const user = userEvent.setup();
const onConfirm = vi.fn();
const onExportPdf = vi.fn();
render(
,
);
expect(
screen.getByRole("heading", { level: 1, name: "Delete your account" }),
).toBeInTheDocument();
expect(screen.getByText("Juniper Street Food Share")).toBeInTheDocument();
const confirm = screen.getByRole("button", { name: "Delete account" });
expect(confirm).toBeDisabled();
await user.click(screen.getByRole("button", { name: "PDF" }));
expect(onExportPdf).toHaveBeenCalledWith("rule-1");
await user.click(
screen.getByRole("checkbox", {
name: "I understand this can’t be undone",
}),
);
expect(confirm).toBeEnabled();
await user.click(confirm);
expect(onConfirm).toHaveBeenCalledTimes(1);
});
});