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:
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user