import { render, screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { fromPartial } from '@total-typescript/shoehorn';
import type { ShortUrl, ShortUrlMeta } from '../../../shlink-web-component/src/short-urls/data';
import { ShortUrlStatus } from '../../../shlink-web-component/src/short-urls/helpers/ShortUrlStatus';
import type { ShlinkVisitsSummary } from '../../../src/api/types';
describe('', () => {
const setUp = (shortUrl: ShortUrl) => ({
user: userEvent.setup(),
...render(),
});
it.each([
[
fromPartial({ validSince: '2099-01-01T10:30:15' }),
{},
'This short URL will start working on 2099-01-01 10:30.',
],
[
fromPartial({ validUntil: '2020-01-01T10:30:15' }),
{},
'This short URL cannot be visited since 2020-01-01 10:30.',
],
[
fromPartial({ maxVisits: 10 }),
fromPartial({ total: 10 }),
'This short URL cannot be currently visited because it has reached the maximum amount of 10 visits.',
],
[
fromPartial({ maxVisits: 1 }),
fromPartial({ total: 1 }),
'This short URL cannot be currently visited because it has reached the maximum amount of 1 visit.',
],
[{}, {}, 'This short URL can be visited normally.'],
[fromPartial({ validUntil: '2099-01-01T10:30:15' }), {}, 'This short URL can be visited normally.'],
[fromPartial({ validSince: '2020-01-01T10:30:15' }), {}, 'This short URL can be visited normally.'],
[
fromPartial({ maxVisits: 10 }),
fromPartial({ total: 1 }),
'This short URL can be visited normally.',
],
])('shows expected tooltip', async (meta, visitsSummary, expectedTooltip) => {
const { user } = setUp(fromPartial({ meta, visitsSummary }));
await user.hover(screen.getByRole('img', { hidden: true }));
await waitFor(() => expect(screen.getByRole('tooltip')).toHaveTextContent(expectedTooltip));
});
});