Skip to content

Commit

Permalink
test: add case
Browse files Browse the repository at this point in the history
  • Loading branch information
linxianxi committed Aug 1, 2023
1 parent 7a900f0 commit bf33250
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/preview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -861,4 +861,33 @@ describe('Preview', () => {

expect(document.querySelector('video')).toBeTruthy();
});

it('should be closed when press esc after click portal', () => {
const onVisibleChange = jest.fn();
const { container } = render(
<Image
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
preview={{
onVisibleChange,
}}
/>,
);

fireEvent.click(container.querySelector('.rc-image'));
act(() => {
jest.runAllTimers();
});

expect(document.querySelector('.rc-image-preview')).toBeTruthy();

expect(onVisibleChange).toBeCalledWith(true, false);

fireEvent.click(document.querySelector('.rc-image-preview-operations'));

fireEvent.keyDown(window, { key: 'Escape', keyCode: 27 });

expect(onVisibleChange).toBeCalledWith(false, true);

onVisibleChange.mockRestore();
});
});

0 comments on commit bf33250

Please sign in to comment.