2023-03-18 12:17:17 +03:00
|
|
|
import { screen, waitFor } from '@testing-library/react';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { ReactNode } from 'react';
|
2022-06-05 11:19:08 +03:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2023-07-24 19:03:59 +03:00
|
|
|
import type { HighlightCardProps } from '../../../src/shlink-web-component/overview/helpers/HighlightCard';
|
|
|
|
import { HighlightCard } from '../../../src/shlink-web-component/overview/helpers/HighlightCard';
|
2023-03-18 12:17:17 +03:00
|
|
|
import { renderWithEvents } from '../../__helpers__/setUpTest';
|
2022-02-05 12:04:34 +03:00
|
|
|
|
|
|
|
describe('<HighlightCard />', () => {
|
2023-03-18 12:17:17 +03:00
|
|
|
const setUp = (props: HighlightCardProps & { children?: ReactNode }) => renderWithEvents(
|
2022-06-05 11:19:08 +03:00
|
|
|
<MemoryRouter>
|
|
|
|
<HighlightCard {...props} />
|
|
|
|
</MemoryRouter>,
|
|
|
|
);
|
2022-02-05 12:04:34 +03:00
|
|
|
|
2022-02-05 15:37:49 +03:00
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[undefined],
|
2023-03-18 12:17:17 +03:00
|
|
|
[''],
|
2022-06-05 11:19:08 +03:00
|
|
|
])('does not render icon when there is no link', (link) => {
|
2023-03-18 12:17:17 +03:00
|
|
|
setUp({ title: 'foo', link });
|
2022-02-05 12:04:34 +03:00
|
|
|
|
2022-06-05 11:19:08 +03:00
|
|
|
expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
|
|
|
|
expect(screen.queryByRole('link')).not.toBeInTheDocument();
|
2022-02-05 12:04:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
['foo'],
|
|
|
|
['bar'],
|
|
|
|
['baz'],
|
2022-02-05 12:04:34 +03:00
|
|
|
])('renders provided title', (title) => {
|
2022-06-05 11:19:08 +03:00
|
|
|
setUp({ title });
|
2023-03-18 12:17:17 +03:00
|
|
|
expect(screen.getByText(title)).toHaveClass('highlight-card__title');
|
2022-02-05 12:04:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
['foo'],
|
|
|
|
['bar'],
|
|
|
|
['baz'],
|
2022-02-05 12:04:34 +03:00
|
|
|
])('renders provided children', (children) => {
|
2022-06-05 11:19:08 +03:00
|
|
|
setUp({ title: 'title', children });
|
2023-03-18 12:17:17 +03:00
|
|
|
expect(screen.getByText(children)).toHaveClass('card-text');
|
2022-02-05 12:04:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
['foo'],
|
|
|
|
['bar'],
|
|
|
|
['baz'],
|
2022-02-05 12:04:34 +03:00
|
|
|
])('adds extra props when a link is provided', (link) => {
|
2022-06-05 11:19:08 +03:00
|
|
|
setUp({ title: 'title', link });
|
2022-02-05 12:04:34 +03:00
|
|
|
|
2022-06-05 11:19:08 +03:00
|
|
|
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
|
|
|
|
expect(screen.getByRole('link')).toHaveAttribute('href', `/${link}`);
|
2022-02-05 12:04:34 +03:00
|
|
|
});
|
2023-03-18 12:17:17 +03: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 12:04:34 +03:00
|
|
|
});
|