Skip to content

Commit

Permalink
test: test that scroll is unblocked when multiple modals are closed
Browse files Browse the repository at this point in the history
  • Loading branch information
pradel committed Nov 8, 2020
1 parent 3d909b6 commit fba3593
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions __tests__/index.test.tsx
Expand Up @@ -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(
<React.Fragment>
<Modal open 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 locked
rerender(
<React.Fragment>
<Modal open 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: 10 }
);
expect(document.documentElement.style.position).toBe('fixed');

// We close the second modal, the scroll should be unlocked
rerender(
<React.Fragment>
<Modal open={false} onClose={() => null}>
<div>first modal</div>
</Modal>
<Modal open={false} onClose={() => null}>
<div>second modal</div>
</Modal>
</React.Fragment>
);

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

describe('closeIcon', () => {
Expand Down

0 comments on commit fba3593

Please sign in to comment.