Skip to content

Commit

Permalink
test: test that scroll is unblocked when second modal has blockScroll…
Browse files Browse the repository at this point in the history
… set to false
  • Loading branch information
pradel committed Nov 8, 2020
1 parent fba3593 commit cf4b6b3
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions __tests__/index.test.tsx
Expand Up @@ -152,7 +152,7 @@ describe('modal', () => {
() => {
expect(queryByTestId('modal')).not.toBeInTheDocument();
},
{ timeout: 10 }
{ timeout: 1 }
);

expect(document.documentElement.style.position).toBe('');
Expand Down Expand Up @@ -200,7 +200,7 @@ describe('modal', () => {
() => {
expect(queryByText(/second modal/)).not.toBeInTheDocument();
},
{ timeout: 10 }
{ timeout: 1 }
);
expect(document.documentElement.style.position).toBe('fixed');

Expand All @@ -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(
<React.Fragment>
<Modal open blockScroll={false} onClose={() => null}>
<div>first modal</div>
</Modal>
<Modal open onClose={() => null}>
<div>second modal</div>
</Modal>
</React.Fragment>
);
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(
<React.Fragment>
<Modal open blockScroll={false} onClose={() => null}>
<div>first modal</div>
</Modal>
<Modal open={false} onClose={() => null}>
<div>second modal</div>
</Modal>
</React.Fragment>
);

fireEvent.animationEnd(getAllByTestId('overlay')[1]);
await waitFor(
() => {
expect(queryByText(/second modal/)).not.toBeInTheDocument();
},
{ timeout: 1 }
);
expect(document.documentElement.style.position).toBe('');
});
Expand Down

0 comments on commit cf4b6b3

Please sign in to comment.