-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathTooltip.test.tsx
More file actions
47 lines (35 loc) · 1.59 KB
/
Tooltip.test.tsx
File metadata and controls
47 lines (35 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { renderWithAppContext } from '../../__helpers__/test-utils';
import { Tooltip, type TooltipProps } from './Tooltip';
describe('renderer/components/fields/Tooltip.tsx', () => {
const props: TooltipProps = {
name: 'test',
tooltip: 'This is some tooltip text',
};
it('should render', () => {
renderWithAppContext(<Tooltip {...props} />);
expect(screen.getByTestId('tooltip-icon-test')).toBeInTheDocument();
expect(screen.queryByText(props.tooltip as string)).not.toBeInTheDocument();
});
it('should toggle (show/hide) tooltip on clicking tooltip icon', async () => {
renderWithAppContext(<Tooltip {...props} />);
const tooltipIconElement = screen.getByTestId('tooltip-icon-test');
// Open tooltip
await userEvent.click(tooltipIconElement);
expect(screen.queryByText(props.tooltip as string)).toBeInTheDocument();
// Close tooltip
await userEvent.click(tooltipIconElement);
expect(screen.queryByText(props.tooltip as string)).not.toBeInTheDocument();
});
it('should hide tooltip when clicking outside', async () => {
renderWithAppContext(<Tooltip {...props} />);
const tooltipIconElement = screen.getByTestId('tooltip-icon-test');
// Open tooltip
await userEvent.click(tooltipIconElement);
expect(screen.queryByText(props.tooltip as string)).toBeInTheDocument();
// Click outside to close
await userEvent.click(document.body);
expect(screen.queryByText(props.tooltip as string)).not.toBeInTheDocument();
});
});