2023-03-18 10:17:17 +01:00
|
|
|
import { screen, waitFor } from '@testing-library/react';
|
2023-08-04 11:16:01 +02:00
|
|
|
import type { PropsWithChildren } from 'react';
|
2022-06-05 10:19:08 +02:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2023-08-02 09:01:44 +02:00
|
|
|
import type { HighlightCardProps } from '../../../src/overview/helpers/HighlightCard';
|
|
|
|
import { HighlightCard } from '../../../src/overview/helpers/HighlightCard';
|
2023-03-18 10:17:17 +01:00
|
|
|
import { renderWithEvents } from '../../__helpers__/setUpTest';
|
2022-02-05 10:04:34 +01:00
|
|
|
|
|
|
|
describe('<HighlightCard />', () => {
|
2023-08-04 11:16:01 +02:00
|
|
|
const setUp = (props: PropsWithChildren<Partial<HighlightCardProps>>) => renderWithEvents(
|
2022-06-05 10:19:08 +02:00
|
|
|
<MemoryRouter>
|
2023-08-04 11:16:01 +02:00
|
|
|
<HighlightCard link="" title="" {...props} />
|
2022-06-05 10:19:08 +02:00
|
|
|
</MemoryRouter>,
|
|
|
|
);
|
2022-02-05 10:04:34 +01:00
|
|
|
|
|
|
|
it.each([
|
2022-03-26 12:17:42 +01:00
|
|
|
['foo'],
|
|
|
|
['bar'],
|
|
|
|
['baz'],
|
2022-02-05 10:04:34 +01:00
|
|
|
])('renders provided title', (title) => {
|
2022-06-05 10:19:08 +02:00
|
|
|
setUp({ title });
|
2023-03-18 10:17:17 +01:00
|
|
|
expect(screen.getByText(title)).toHaveClass('highlight-card__title');
|
2022-02-05 10:04:34 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 12:17:42 +01:00
|
|
|
['foo'],
|
|
|
|
['bar'],
|
|
|
|
['baz'],
|
2022-02-05 10:04:34 +01:00
|
|
|
])('renders provided children', (children) => {
|
2022-06-05 10:19:08 +02:00
|
|
|
setUp({ title: 'title', children });
|
2023-03-18 10:17:17 +01:00
|
|
|
expect(screen.getByText(children)).toHaveClass('card-text');
|
2022-02-05 10:04:34 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 12:17:42 +01:00
|
|
|
['foo'],
|
|
|
|
['bar'],
|
|
|
|
['baz'],
|
2022-02-05 10:04:34 +01:00
|
|
|
])('adds extra props when a link is provided', (link) => {
|
2022-06-05 10:19:08 +02:00
|
|
|
setUp({ title: 'title', link });
|
2022-02-05 10:04:34 +01:00
|
|
|
|
2022-06-05 10:19:08 +02:00
|
|
|
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
|
|
|
|
expect(screen.getByRole('link')).toHaveAttribute('href', `/${link}`);
|
2022-02-05 10:04:34 +01:00
|
|
|
});
|
2023-03-18 10:17:17 +01:00
|
|
|
|
|
|
|
it('renders tooltip when provided', async () => {
|
|
|
|
const { user } = setUp({ title: 'title', children: 'Foo', tooltip: 'This is the tooltip' });
|
|
|
|
|
|
|
|
await user.hover(screen.getByText('Foo'));
|
|
|
|
await waitFor(() => expect(screen.getByText('This is the tooltip')).toBeInTheDocument());
|
|
|
|
});
|
2022-02-05 10:04:34 +01:00
|
|
|
});
|