Warn on tab close when create-flow module or wizard edits have not been saved.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
adilallo
2026-08-31 11:00:40 -06:00
co-authored by Cursor
parent a820739d07
commit 7f67cc6271
19 changed files with 350 additions and 1 deletions
@@ -0,0 +1,44 @@
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(
<CustomMethodCardWizard
isOpen
onClose={() => {
/* noop */
}}
onFinalize={() => {
/* noop */
}}
/>,
);
await screen.findByPlaceholderText("Policy name");
expect(dispatchBeforeUnload()).toBe(false);
});
it("blocks unload after the user types a policy name", async () => {
render(
<CustomMethodCardWizard
isOpen
onClose={() => {
/* noop */
}}
onFinalize={() => {
/* noop */
}}
/>,
);
const name = await screen.findByPlaceholderText("Policy name");
fireEvent.change(name, { target: { value: "Garden hours" } });
expect(dispatchBeforeUnload()).toBe(true);
});
});