From cf4b6b37ec55c24003d085cd5ad4d3bccc031bec Mon Sep 17 00:00:00 2001 From: pradel Date: Sun, 8 Nov 2020 01:41:23 +0100 Subject: [PATCH] test: test that scroll is unblocked when second modal has blockScroll set to false --- __tests__/index.test.tsx | 41 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/__tests__/index.test.tsx b/__tests__/index.test.tsx index 4f1a0b10..27aececc 100644 --- a/__tests__/index.test.tsx +++ b/__tests__/index.test.tsx @@ -152,7 +152,7 @@ describe('modal', () => { () => { expect(queryByTestId('modal')).not.toBeInTheDocument(); }, - { timeout: 10 } + { timeout: 1 } ); expect(document.documentElement.style.position).toBe(''); @@ -200,7 +200,7 @@ describe('modal', () => { () => { expect(queryByText(/second modal/)).not.toBeInTheDocument(); }, - { timeout: 10 } + { timeout: 1 } ); expect(document.documentElement.style.position).toBe('fixed'); @@ -221,7 +221,42 @@ describe('modal', () => { () => { expect(queryByText(/first modal/)).not.toBeInTheDocument(); }, - { timeout: 10 } + { timeout: 1 } + ); + expect(document.documentElement.style.position).toBe(''); + }); + + it('should unblock scroll when one modal is closed and the one still open has blockScroll set to false', 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 unlocked as remaining modal is not locking the scroll + rerender( + + null}> +
first modal
+
+ null}> +
second modal
+
+
+ ); + + fireEvent.animationEnd(getAllByTestId('overlay')[1]); + await waitFor( + () => { + expect(queryByText(/second modal/)).not.toBeInTheDocument(); + }, + { timeout: 1 } ); expect(document.documentElement.style.position).toBe(''); });