import { cleanup, fireEvent, render, screen } from "@testing-library/react"; import { useRef, useState } from "react"; import { afterEach, describe, expect, it, vi } from "vitest"; vi.mock("@/components/confirmation/action-confirm-popover", () => ({ ActionConfirmPopover: ({ onConfirm }: { onConfirm: () => void }) => (
), })); import { DiscardDialog } from "./changes-panel-dialogs"; afterEach(cleanup); function DiscardHarness({ fileToDiscard, filesToDiscard, }: { fileToDiscard: string | null; filesToDiscard: string[] | null; }) { const [open, setOpen] = useState(true); const anchorRef = useRef(null); return ( <> ); } describe("DiscardDialog target scope", () => { it.each([ ["direct file", "src/one.ts", null], ["one selected file", null, ["src/one.ts"]], ] as const)("uses local confirmation for a %s", (_kind, fileToDiscard, filesToDiscard) => { render( , ); expect(screen.queryByRole("alertdialog")).toBeNull(); expect(screen.getByTestId("discard-local-confirmation")).toBeTruthy(); }); it("keeps discard-all scope in the existing modal", () => { render(); expect(screen.getByRole("alertdialog")).toBeTruthy(); expect(screen.queryByTestId("discard-local-confirmation")).toBeNull(); }); it("does not invoke confirmation mutation before local confirm", () => { const onConfirm = vi.fn(); function Harness() { const [open, setOpen] = useState(true); const anchorRef = useRef(null); return ( <> ); } render(); expect(onConfirm).not.toHaveBeenCalled(); fireEvent.click(screen.getByRole("button", { name: "confirm" })); expect(onConfirm).toHaveBeenCalledTimes(1); }); });