Move shlink-web-component tests to their own folder

This commit is contained in:
Alejandro Celaya
2023-08-02 09:01:44 +02:00
parent c48facc863
commit c794ff8b58
124 changed files with 455 additions and 371 deletions

View File

@@ -1,60 +0,0 @@
import { screen, waitFor } from '@testing-library/react';
import type { ReactNode } from 'react';
import { MemoryRouter } from 'react-router-dom';
import type { HighlightCardProps } from '../../../shlink-web-component/src/overview/helpers/HighlightCard';
import { HighlightCard } from '../../../shlink-web-component/src/overview/helpers/HighlightCard';
import { renderWithEvents } from '../../__helpers__/setUpTest';
describe('<HighlightCard />', () => {
const setUp = (props: HighlightCardProps & { children?: ReactNode }) => renderWithEvents(
<MemoryRouter>
<HighlightCard {...props} />
</MemoryRouter>,
);
it.each([
[undefined],
[''],
])('does not render icon when there is no link', (link) => {
setUp({ title: 'foo', link });
expect(screen.queryByRole('img', { hidden: true })).not.toBeInTheDocument();
expect(screen.queryByRole('link')).not.toBeInTheDocument();
});
it.each([
['foo'],
['bar'],
['baz'],
])('renders provided title', (title) => {
setUp({ title });
expect(screen.getByText(title)).toHaveClass('highlight-card__title');
});
it.each([
['foo'],
['bar'],
['baz'],
])('renders provided children', (children) => {
setUp({ title: 'title', children });
expect(screen.getByText(children)).toHaveClass('card-text');
});
it.each([
['foo'],
['bar'],
['baz'],
])('adds extra props when a link is provided', (link) => {
setUp({ title: 'title', link });
expect(screen.getByRole('img', { hidden: true })).toBeInTheDocument();
expect(screen.getByRole('link')).toHaveAttribute('href', `/${link}`);
});
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());
});
});

View File

@@ -1,60 +0,0 @@
import { screen, waitFor } from '@testing-library/react';
import type { VisitsHighlightCardProps } from '../../../shlink-web-component/src/overview/helpers/VisitsHighlightCard';
import { VisitsHighlightCard } from '../../../shlink-web-component/src/overview/helpers/VisitsHighlightCard';
import { renderWithEvents } from '../../__helpers__/setUpTest';
describe('<VisitsHighlightCard />', () => {
const setUp = (props: Partial<VisitsHighlightCardProps> = {}) => renderWithEvents(
<VisitsHighlightCard loading={false} visitsSummary={{ total: 0 }} excludeBots={false} title="" {...props} />,
);
it.each([
[true, () => expect(screen.getByText('Loading...')).toBeInTheDocument()],
[false, () => expect(screen.queryByText('Loading...')).not.toBeInTheDocument()],
])('displays loading message on loading', (loading, assert) => {
setUp({ loading });
assert();
});
it('does not render tooltip when summary has no bots', async () => {
const { user } = setUp({ title: 'Foo' });
await user.hover(screen.getByText('Foo'));
await waitFor(() => expect(screen.queryByText(/potential bot visits$/)).not.toBeInTheDocument());
});
it('renders tooltip when summary has bots', async () => {
const { user } = setUp({
title: 'Foo',
visitsSummary: { total: 50, bots: 30 },
});
await user.hover(screen.getByText('Foo'));
await waitFor(() => expect(screen.getByText(/potential bot visits$/)).toBeInTheDocument());
});
it.each([
[true, 20, () => {
expect(screen.getByText('20')).toBeInTheDocument();
expect(screen.queryByText('50')).not.toBeInTheDocument();
}],
[true, undefined, () => {
expect(screen.getByText('50')).toBeInTheDocument();
expect(screen.queryByText('20')).not.toBeInTheDocument();
}],
[false, 20, () => {
expect(screen.getByText('50')).toBeInTheDocument();
expect(screen.queryByText('20')).not.toBeInTheDocument();
}],
[false, undefined, () => {
expect(screen.getByText('50')).toBeInTheDocument();
expect(screen.queryByText('20')).not.toBeInTheDocument();
}],
])('displays non-bots when present and bots are excluded', (excludeBots, nonBots, assert) => {
setUp({
excludeBots,
visitsSummary: { total: 50, nonBots },
});
assert();
});
});