Skip to content

Commit 85d3472

Browse files
committed
test: add test case
1 parent b7462b3 commit 85d3472

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

tests/basic.test.jsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,4 +936,56 @@ describe('Trigger.Basic', () => {
936936
await awaitFakeTimer();
937937
expect(document.querySelector('.rc-trigger-popup-hidden')).toBeTruthy();
938938
});
939+
940+
describe('click window to hide', () => {
941+
it('should hide', async () => {
942+
const onPopupVisibleChange = jest.fn();
943+
944+
const { container } = render(
945+
<Trigger
946+
onPopupVisibleChange={onPopupVisibleChange}
947+
action="click"
948+
popup={<strong>trigger</strong>}
949+
>
950+
<div className="target" />
951+
</Trigger>,
952+
);
953+
954+
fireEvent.click(container.querySelector('.target'));
955+
await awaitFakeTimer();
956+
expect(onPopupVisibleChange).toHaveBeenCalledWith(true);
957+
onPopupVisibleChange.mockReset();
958+
959+
// Click outside to close
960+
fireEvent.mouseDown(document.body);
961+
fireEvent.click(document.body);
962+
await awaitFakeTimer();
963+
expect(onPopupVisibleChange).toHaveBeenCalledWith(false);
964+
});
965+
966+
it('should not hide when mouseDown inside but mouseUp outside', async () => {
967+
const onPopupVisibleChange = jest.fn();
968+
969+
const { container } = render(
970+
<Trigger
971+
onPopupVisibleChange={onPopupVisibleChange}
972+
action="click"
973+
popup={<strong>trigger</strong>}
974+
>
975+
<div className="target" />
976+
</Trigger>,
977+
);
978+
979+
fireEvent.click(container.querySelector('.target'));
980+
await awaitFakeTimer();
981+
expect(onPopupVisibleChange).toHaveBeenCalledWith(true);
982+
onPopupVisibleChange.mockReset();
983+
984+
// Click outside to close
985+
fireEvent.mouseDown(document.querySelector('strong'));
986+
fireEvent.click(document.body);
987+
await awaitFakeTimer();
988+
expect(onPopupVisibleChange).not.toHaveBeenCalled();
989+
});
990+
});
939991
});

0 commit comments

Comments
 (0)