Skip to content

Commit cf4b6b3

Browse files
committed
test: test that scroll is unblocked when second modal has blockScroll set to false
1 parent fba3593 commit cf4b6b3

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

__tests__/index.test.tsx

+38-3
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ describe('modal', () => {
152152
() => {
153153
expect(queryByTestId('modal')).not.toBeInTheDocument();
154154
},
155-
{ timeout: 10 }
155+
{ timeout: 1 }
156156
);
157157

158158
expect(document.documentElement.style.position).toBe('');
@@ -200,7 +200,7 @@ describe('modal', () => {
200200
() => {
201201
expect(queryByText(/second modal/)).not.toBeInTheDocument();
202202
},
203-
{ timeout: 10 }
203+
{ timeout: 1 }
204204
);
205205
expect(document.documentElement.style.position).toBe('fixed');
206206

@@ -221,7 +221,42 @@ describe('modal', () => {
221221
() => {
222222
expect(queryByText(/first modal/)).not.toBeInTheDocument();
223223
},
224-
{ timeout: 10 }
224+
{ timeout: 1 }
225+
);
226+
expect(document.documentElement.style.position).toBe('');
227+
});
228+
229+
it('should unblock scroll when one modal is closed and the one still open has blockScroll set to false', async () => {
230+
const { rerender, getAllByTestId, queryByText } = render(
231+
<React.Fragment>
232+
<Modal open blockScroll={false} onClose={() => null}>
233+
<div>first modal</div>
234+
</Modal>
235+
<Modal open onClose={() => null}>
236+
<div>second modal</div>
237+
</Modal>
238+
</React.Fragment>
239+
);
240+
expect(document.documentElement.style.position).toBe('fixed');
241+
242+
// We close one modal, the scroll should be unlocked as remaining modal is not locking the scroll
243+
rerender(
244+
<React.Fragment>
245+
<Modal open blockScroll={false} onClose={() => null}>
246+
<div>first modal</div>
247+
</Modal>
248+
<Modal open={false} onClose={() => null}>
249+
<div>second modal</div>
250+
</Modal>
251+
</React.Fragment>
252+
);
253+
254+
fireEvent.animationEnd(getAllByTestId('overlay')[1]);
255+
await waitFor(
256+
() => {
257+
expect(queryByText(/second modal/)).not.toBeInTheDocument();
258+
},
259+
{ timeout: 1 }
225260
);
226261
expect(document.documentElement.style.position).toBe('');
227262
});

0 commit comments

Comments
 (0)