2022-06-05 11:19:08 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2022-02-05 12:04:34 +03:00
|
|
|
import { ReactNode } from 'react';
|
2022-06-05 11:19:08 +03:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2022-02-05 12:04:34 +03:00
|
|
|
import { HighlightCard, HighlightCardProps } from '../../../src/servers/helpers/HighlightCard';
|
|
|
|
|
|
|
|
describe('<HighlightCard />', () => {
|
2022-06-05 11:19:08 +03:00
|
|
|
const setUp = (props: HighlightCardProps & { children?: ReactNode }) => render(
|
|
|
|
<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],
|
|
|
|
[false],
|
2022-06-05 11:19:08 +03:00
|
|
|
])('does not render icon when there is no link', (link) => {
|
|
|
|
setUp({ title: 'foo', link: link as undefined | false });
|
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 });
|
|
|
|
expect(screen.getByText(title)).toHaveAttribute('class', expect.stringContaining('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 });
|
|
|
|
expect(screen.getByText(children)).toHaveAttribute('class', expect.stringContaining('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
|
|
|
});
|
|
|
|
});
|