2023-02-18 12:40:37 +03:00
|
|
|
import type { Placement } from '@popperjs/core';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { screen, waitFor } from '@testing-library/react';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { InfoTooltipProps } from '../../src/utils/InfoTooltip';
|
|
|
|
import { InfoTooltip } from '../../src/utils/InfoTooltip';
|
2022-07-10 20:44:49 +03:00
|
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
2021-08-23 19:26:15 +03:00
|
|
|
|
|
|
|
describe('<InfoTooltip />', () => {
|
2022-07-10 00:03:21 +03:00
|
|
|
const setUp = (props: Partial<InfoTooltipProps> = {}) => renderWithEvents(
|
|
|
|
<InfoTooltip placement="right" {...props} />,
|
|
|
|
);
|
2022-07-08 12:03:58 +03:00
|
|
|
|
2021-08-23 19:26:15 +03:00
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[undefined],
|
|
|
|
['foo'],
|
|
|
|
['bar'],
|
2021-08-23 19:26:15 +03:00
|
|
|
])('renders expected className on span', (className) => {
|
2022-07-08 12:03:58 +03:00
|
|
|
const { container } = setUp({ className });
|
2021-08-23 19:26:15 +03:00
|
|
|
|
2022-07-08 12:03:58 +03:00
|
|
|
if (className) {
|
|
|
|
expect(container.firstChild).toHaveClass(className);
|
|
|
|
} else {
|
|
|
|
expect(container.firstChild).toHaveAttribute('class', '');
|
|
|
|
}
|
2021-08-23 19:26:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-07-08 12:03:58 +03:00
|
|
|
[<span key={1}>foo</span>, 'foo'],
|
|
|
|
['Foo', 'Foo'],
|
|
|
|
['Hello', 'Hello'],
|
|
|
|
[['One', 'Two', <span key={3} />], 'OneTwo'],
|
|
|
|
])('passes children down to the nested tooltip component', async (children, expectedContent) => {
|
|
|
|
const { container, user } = setUp({ children });
|
2021-08-23 19:26:15 +03:00
|
|
|
|
2022-07-08 12:03:58 +03:00
|
|
|
container.firstElementChild && await user.hover(container.firstElementChild);
|
|
|
|
await waitFor(() => expect(screen.getByRole('tooltip')).toBeInTheDocument());
|
|
|
|
expect(screen.getByRole('tooltip')).toHaveTextContent(expectedContent);
|
2021-08-23 19:26:15 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
['right' as Placement],
|
|
|
|
['left' as Placement],
|
|
|
|
['top' as Placement],
|
|
|
|
['bottom' as Placement],
|
2022-07-08 12:03:58 +03:00
|
|
|
])('places tooltip where requested', async (placement) => {
|
|
|
|
const { container, user } = setUp({ placement });
|
2021-08-23 19:26:15 +03:00
|
|
|
|
2022-07-08 12:03:58 +03:00
|
|
|
container.firstElementChild && await user.hover(container.firstElementChild);
|
|
|
|
await waitFor(() => expect(screen.getByRole('tooltip')).toBeInTheDocument());
|
|
|
|
expect(screen.getByRole('tooltip').parentNode).toHaveAttribute('data-popper-placement', placement);
|
2021-08-23 19:26:15 +03:00
|
|
|
});
|
|
|
|
});
|