2022-12-19 20:43:55 +01:00
|
|
|
import { render, screen, waitFor } from '@testing-library/react';
|
2023-02-18 11:11:01 +01:00
|
|
|
import userEvent from '@testing-library/user-event';
|
2023-04-13 21:48:29 +02:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2023-08-07 10:51:08 +02:00
|
|
|
import type { ShlinkShortUrl, ShlinkShortUrlMeta, ShlinkVisitsSummary } from '../../../src/api-contract';
|
2023-08-02 09:01:44 +02:00
|
|
|
import { ShortUrlStatus } from '../../../src/short-urls/helpers/ShortUrlStatus';
|
2022-12-19 20:43:55 +01:00
|
|
|
|
|
|
|
describe('<ShortUrlStatus />', () => {
|
2023-08-06 21:27:57 +02:00
|
|
|
const setUp = (shortUrl: ShlinkShortUrl) => ({
|
2022-12-19 20:43:55 +01:00
|
|
|
user: userEvent.setup(),
|
|
|
|
...render(<ShortUrlStatus shortUrl={shortUrl} />),
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
|
|
|
[
|
2023-08-06 21:27:57 +02:00
|
|
|
fromPartial<ShlinkShortUrlMeta>({ validSince: '2099-01-01T10:30:15' }),
|
2022-12-19 20:43:55 +01:00
|
|
|
{},
|
|
|
|
'This short URL will start working on 2099-01-01 10:30.',
|
|
|
|
],
|
|
|
|
[
|
2023-08-06 21:27:57 +02:00
|
|
|
fromPartial<ShlinkShortUrlMeta>({ validUntil: '2020-01-01T10:30:15' }),
|
2022-12-19 20:43:55 +01:00
|
|
|
{},
|
|
|
|
'This short URL cannot be visited since 2020-01-01 10:30.',
|
|
|
|
],
|
|
|
|
[
|
2023-08-06 21:27:57 +02:00
|
|
|
fromPartial<ShlinkShortUrlMeta>({ maxVisits: 10 }),
|
2023-04-13 21:48:29 +02:00
|
|
|
fromPartial<ShlinkVisitsSummary>({ total: 10 }),
|
2022-12-19 20:43:55 +01:00
|
|
|
'This short URL cannot be currently visited because it has reached the maximum amount of 10 visits.',
|
|
|
|
],
|
|
|
|
[
|
2023-08-06 21:27:57 +02:00
|
|
|
fromPartial<ShlinkShortUrlMeta>({ maxVisits: 1 }),
|
2023-04-13 21:48:29 +02:00
|
|
|
fromPartial<ShlinkVisitsSummary>({ total: 1 }),
|
2022-12-19 20:43:55 +01:00
|
|
|
'This short URL cannot be currently visited because it has reached the maximum amount of 1 visit.',
|
|
|
|
],
|
|
|
|
[{}, {}, 'This short URL can be visited normally.'],
|
2023-08-06 21:27:57 +02:00
|
|
|
[fromPartial<ShlinkShortUrlMeta>({ validUntil: '2099-01-01T10:30:15' }), {}, 'This short URL can be visited normally.'],
|
|
|
|
[fromPartial<ShlinkShortUrlMeta>({ validSince: '2020-01-01T10:30:15' }), {}, 'This short URL can be visited normally.'],
|
2022-12-19 20:43:55 +01:00
|
|
|
[
|
2023-08-06 21:27:57 +02:00
|
|
|
fromPartial<ShlinkShortUrlMeta>({ maxVisits: 10 }),
|
2023-04-13 21:48:29 +02:00
|
|
|
fromPartial<ShlinkVisitsSummary>({ total: 1 }),
|
2022-12-19 20:43:55 +01:00
|
|
|
'This short URL can be visited normally.',
|
|
|
|
],
|
|
|
|
])('shows expected tooltip', async (meta, visitsSummary, expectedTooltip) => {
|
2023-04-13 21:48:29 +02:00
|
|
|
const { user } = setUp(fromPartial({ meta, visitsSummary }));
|
2022-12-19 20:43:55 +01:00
|
|
|
|
|
|
|
await user.hover(screen.getByRole('img', { hidden: true }));
|
|
|
|
await waitFor(() => expect(screen.getByRole('tooltip')).toHaveTextContent(expectedTooltip));
|
|
|
|
});
|
|
|
|
});
|