From fba35933ec6f270bbeb1fd779a6feef97b65bb82 Mon Sep 17 00:00:00 2001 From: pradel Date: Sun, 8 Nov 2020 01:35:16 +0100 Subject: [PATCH] test: test that scroll is unblocked when multiple modals are closed --- __tests__/index.test.tsx | 56 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/__tests__/index.test.tsx b/__tests__/index.test.tsx index a4e87102..4f1a0b10 100644 --- a/__tests__/index.test.tsx +++ b/__tests__/index.test.tsx @@ -169,6 +169,62 @@ describe('modal', () => { unmount(); expect(document.documentElement.style.position).toBe(''); }); + + it('should unblock scroll when multiple modals are opened and then closed', async () => { + const { rerender, getAllByTestId, queryByText } = render( + + null}> +
first modal
+
+ null}> +
second modal
+
+
+ ); + expect(document.documentElement.style.position).toBe('fixed'); + + // We close one modal, the scroll should be locked + rerender( + + null}> +
first modal
+
+ null}> +
second modal
+
+
+ ); + + fireEvent.animationEnd(getAllByTestId('overlay')[1]); + await waitFor( + () => { + expect(queryByText(/second modal/)).not.toBeInTheDocument(); + }, + { timeout: 10 } + ); + expect(document.documentElement.style.position).toBe('fixed'); + + // We close the second modal, the scroll should be unlocked + rerender( + + null}> +
first modal
+
+ null}> +
second modal
+
+
+ ); + + fireEvent.animationEnd(getAllByTestId('overlay')[0]); + await waitFor( + () => { + expect(queryByText(/first modal/)).not.toBeInTheDocument(); + }, + { timeout: 10 } + ); + expect(document.documentElement.style.position).toBe(''); + }); }); describe('closeIcon', () => {