import { render, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { MemoryRouter } from 'react-router-dom';
import type { ShortUrl } from '../../../shlink-web-component/short-urls/data';
import type { LinkSuffix } from '../../../shlink-web-component/short-urls/helpers/ShortUrlDetailLink';
import { ShortUrlDetailLink } from '../../../shlink-web-component/short-urls/helpers/ShortUrlDetailLink';
import type { NotFoundServer, ReachableServer } from '../../../src/servers/data';
describe('', () => {
it.each([
[undefined, undefined],
[null, null],
[fromPartial({ id: '1' }), null],
[fromPartial({ id: '1' }), undefined],
[fromPartial({}), fromPartial({})],
[null, fromPartial({})],
[undefined, fromPartial({})],
])('only renders a plain span when either server or short URL are not set', (selectedServer, shortUrl) => {
render(
Something
,
);
expect(screen.queryByRole('link')).not.toBeInTheDocument();
expect(screen.getByText('Something')).toBeInTheDocument();
});
it.each([
[
fromPartial({ id: '1' }),
fromPartial({ shortCode: 'abc123' }),
'visits' as LinkSuffix,
'/server/1/short-code/abc123/visits',
],
[
fromPartial({ id: '3' }),
fromPartial({ shortCode: 'def456', domain: 'example.com' }),
'visits' as LinkSuffix,
'/server/3/short-code/def456/visits?domain=example.com',
],
[
fromPartial({ id: '1' }),
fromPartial({ shortCode: 'abc123' }),
'edit' as LinkSuffix,
'/server/1/short-code/abc123/edit',
],
[
fromPartial({ id: '3' }),
fromPartial({ shortCode: 'def456', domain: 'example.com' }),
'edit' as LinkSuffix,
'/server/3/short-code/def456/edit?domain=example.com',
],
])('renders link with expected query when', (selectedServer, shortUrl, suffix, expectedLink) => {
render(
Something
,
);
expect(screen.getByRole('link')).toHaveProperty('href', expect.stringContaining(expectedLink));
});
});