Files
community-rule/tests/components/modals/DeleteAccount.test.tsx
T
adilallo b6795c1f18 Rebuild Share and Delete Account from the privacy designs.
Share asks the person who holds the pen to confirm their community agreed before a link turns on, and deleting an account lists each owned Rule with PDF and RULE.md export. Case-study Share copies the page link instead of opening the privacy modal, and the sign-in banner stays below the header so Share remains clickable.
2026-11-09 19:54:09 -07:00

54 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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(
<DeleteAccount
isOpen={false}
onClose={vi.fn()}
onConfirm={vi.fn()}
rules={[]}
onExportPdf={vi.fn()}
onExportMarkdown={vi.fn()}
/>,
);
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(
<DeleteAccount
isOpen
onClose={vi.fn()}
onConfirm={onConfirm}
rules={[{ id: "rule-1", title: "Juniper Street Food Share" }]}
onExportPdf={onExportPdf}
onExportMarkdown={vi.fn()}
/>,
);
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);
});
});