Skip to content

Commit eb8ed86

Browse files
test(Popover.unit.test.jsx): Added test to validate click behavior outside the popover to close the
1 parent caac76f commit eb8ed86

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

components/Popover/Popover.unit.test.jsx

+28
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,32 @@ describe('Popover component', () => {
7878

7979
expect(onCLoseEventMock).toHaveBeenCalled();
8080
});
81+
82+
it('should call in the close event callback when the closeOnClickOut prop is true and there is a click outside the element', () => {
83+
const onCLoseEventMock = jest.fn();
84+
const sampleText = 'Another element on the page...';
85+
86+
render(
87+
<div>
88+
<Popover
89+
skin="success"
90+
trigger={POPOVER_TRIGGER_TEXT}
91+
onClose={onCLoseEventMock}
92+
closeOnClickOut
93+
>
94+
{POPOVER_TEXT}
95+
</Popover>
96+
<div>{sampleText}</div>
97+
</div>,
98+
);
99+
const trigger = screen.getByText(POPOVER_TRIGGER_TEXT);
100+
fireEvent.click(trigger);
101+
102+
expect(screen.queryByText(POPOVER_TEXT)).toBeInTheDocument();
103+
104+
const anyElement = screen.getByText(sampleText);
105+
fireEvent.click(anyElement);
106+
107+
expect(screen.queryByText(POPOVER_TEXT)).not.toBeInTheDocument();
108+
});
81109
});

0 commit comments

Comments
 (0)