import { describe, it, expect } from "vitest"; import { renderWithProviders as render, screen, fireEvent, dispatchBeforeUnload, } from "../utils/test-utils"; import "@testing-library/jest-dom/vitest"; import CustomMethodCardWizard from "../../app/(app)/create/components/CustomMethodCardWizard"; describe("CustomMethodCardWizard — tab close guard", () => { it("does not block unload when the wizard is open but unchanged", async () => { render( { /* noop */ }} onFinalize={() => { /* noop */ }} />, ); await screen.findByPlaceholderText("Policy name"); expect(dispatchBeforeUnload()).toBe(false); }); it("blocks unload after the user types a policy name", async () => { render( { /* noop */ }} onFinalize={() => { /* noop */ }} />, ); const name = await screen.findByPlaceholderText("Policy name"); fireEvent.change(name, { target: { value: "Garden hours" } }); expect(dispatchBeforeUnload()).toBe(true); }); });