diff --git a/src/components/ConfirmationModal/ConfirmationModal.test.tsx b/src/components/ConfirmationModal/ConfirmationModal.test.tsx index a984f374d..aca3cf9da 100644 --- a/src/components/ConfirmationModal/ConfirmationModal.test.tsx +++ b/src/components/ConfirmationModal/ConfirmationModal.test.tsx @@ -55,4 +55,73 @@ describe("ConfirmationModal ", () => { await userEvent.click(screen.getByText("Proceed")); expect(onConfirm).toHaveBeenCalled(); }); + + it("should stop click event propagation on cancel by default", async () => { + const handleExternalClick = jest.fn(); + render( +
+ + Test click propagation + +
+ ); + + await userEvent.click(screen.getByText("Go back")); + expect(handleExternalClick).toHaveBeenCalledTimes(0); + }); + + it("should propagate click event on cancel", async () => { + const handleExternalClick = jest.fn(); + render( +
+ + Test click propagation + +
+ ); + + await userEvent.click(screen.getByText("Go back")); + expect(handleExternalClick).toHaveBeenCalledTimes(1); + }); + + it("should stop click event propagation on confirm by default", async () => { + const handleExternalClick = jest.fn(); + render( +
+ + Test click propagation + +
+ ); + + await userEvent.click(screen.getByText("Proceed")); + expect(handleExternalClick).toHaveBeenCalledTimes(0); + }); + + it("should propagate click event on confirm", async () => { + const handleExternalClick = jest.fn(); + render( +
+ + Test click propagation + +
+ ); + + await userEvent.click(screen.getByText("Proceed")); + expect(handleExternalClick).toHaveBeenCalledTimes(1); + }); }); diff --git a/src/components/Modal/Modal.test.tsx b/src/components/Modal/Modal.test.tsx index e6a61eb25..e080c8522 100644 --- a/src/components/Modal/Modal.test.tsx +++ b/src/components/Modal/Modal.test.tsx @@ -139,4 +139,36 @@ describe("Modal ", () => { expect(mockHandleModalClose).toHaveBeenCalledTimes(1); expect(mockHandleEscPress).not.toHaveBeenCalled(); }); + + it("should stop click event propagation on close by default", async () => { + const handleExternalClick = jest.fn(); + const { container } = render( +
+ + Bare bones + +
+ ); + + const closeButton = container.querySelector("button.p-modal__close"); + expect(closeButton).not.toBeNull(); + await userEvent.click(closeButton!); + expect(handleExternalClick).toHaveBeenCalledTimes(0); + }); + + it("should propagate click event on close", async () => { + const handleExternalClick = jest.fn(); + const { container } = render( +
+ + Bare bones + +
+ ); + + const closeButton = container.querySelector("button.p-modal__close"); + expect(closeButton).not.toBeNull(); + await userEvent.click(closeButton!); + expect(handleExternalClick).toHaveBeenCalledTimes(1); + }); });