2022-07-10 20:58:27 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2023-04-13 22:48:29 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2022-07-10 20:58:27 +03:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
2023-02-18 12:40:37 +03:00
|
|
|
import type { NotFoundServer, ReachableServer } from '../../../src/servers/data';
|
2023-07-16 09:47:10 +03:00
|
|
|
import type { ShortUrl } from '../../../src/shlink-web-component/short-urls/data';
|
|
|
|
import type { LinkSuffix } from '../../../src/shlink-web-component/short-urls/helpers/ShortUrlDetailLink';
|
|
|
|
import { ShortUrlDetailLink } from '../../../src/shlink-web-component/short-urls/helpers/ShortUrlDetailLink';
|
2020-02-08 11:20:19 +03:00
|
|
|
|
2021-03-20 18:32:12 +03:00
|
|
|
describe('<ShortUrlDetailLink />', () => {
|
2020-02-17 20:21:52 +03:00
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[undefined, undefined],
|
|
|
|
[null, null],
|
2023-04-13 22:48:29 +03:00
|
|
|
[fromPartial<ReachableServer>({ id: '1' }), null],
|
|
|
|
[fromPartial<ReachableServer>({ id: '1' }), undefined],
|
|
|
|
[fromPartial<NotFoundServer>({}), fromPartial<ShortUrl>({})],
|
|
|
|
[null, fromPartial<ShortUrl>({})],
|
|
|
|
[undefined, fromPartial<ShortUrl>({})],
|
2020-08-30 10:59:14 +03:00
|
|
|
])('only renders a plain span when either server or short URL are not set', (selectedServer, shortUrl) => {
|
2022-07-10 20:58:27 +03:00
|
|
|
render(
|
2021-03-20 18:32:12 +03:00
|
|
|
<ShortUrlDetailLink selectedServer={selectedServer} shortUrl={shortUrl} suffix="visits">
|
|
|
|
Something
|
|
|
|
</ShortUrlDetailLink>,
|
|
|
|
);
|
2020-02-08 11:20:19 +03:00
|
|
|
|
2022-07-10 20:58:27 +03:00
|
|
|
expect(screen.queryByRole('link')).not.toBeInTheDocument();
|
|
|
|
expect(screen.getByText('Something')).toBeInTheDocument();
|
2020-02-08 11:20:19 +03:00
|
|
|
});
|
|
|
|
|
2020-02-17 20:21:52 +03:00
|
|
|
it.each([
|
2020-02-08 11:20:19 +03:00
|
|
|
[
|
2023-04-13 22:48:29 +03:00
|
|
|
fromPartial<ReachableServer>({ id: '1' }),
|
|
|
|
fromPartial<ShortUrl>({ shortCode: 'abc123' }),
|
2021-03-20 18:32:12 +03:00
|
|
|
'visits' as LinkSuffix,
|
2020-08-30 10:59:14 +03:00
|
|
|
'/server/1/short-code/abc123/visits',
|
|
|
|
],
|
|
|
|
[
|
2023-04-13 22:48:29 +03:00
|
|
|
fromPartial<ReachableServer>({ id: '3' }),
|
|
|
|
fromPartial<ShortUrl>({ shortCode: 'def456', domain: 'example.com' }),
|
2021-03-20 18:32:12 +03:00
|
|
|
'visits' as LinkSuffix,
|
2020-02-08 11:20:19 +03:00
|
|
|
'/server/3/short-code/def456/visits?domain=example.com',
|
|
|
|
],
|
2021-03-20 18:32:12 +03:00
|
|
|
[
|
2023-04-13 22:48:29 +03:00
|
|
|
fromPartial<ReachableServer>({ id: '1' }),
|
|
|
|
fromPartial<ShortUrl>({ shortCode: 'abc123' }),
|
2021-03-20 18:32:12 +03:00
|
|
|
'edit' as LinkSuffix,
|
|
|
|
'/server/1/short-code/abc123/edit',
|
|
|
|
],
|
|
|
|
[
|
2023-04-13 22:48:29 +03:00
|
|
|
fromPartial<ReachableServer>({ id: '3' }),
|
|
|
|
fromPartial<ShortUrl>({ shortCode: 'def456', domain: 'example.com' }),
|
2021-03-20 18:32:12 +03:00
|
|
|
'edit' as LinkSuffix,
|
|
|
|
'/server/3/short-code/def456/edit?domain=example.com',
|
|
|
|
],
|
|
|
|
])('renders link with expected query when', (selectedServer, shortUrl, suffix, expectedLink) => {
|
2022-07-10 20:58:27 +03:00
|
|
|
render(
|
|
|
|
<MemoryRouter>
|
|
|
|
<ShortUrlDetailLink selectedServer={selectedServer} shortUrl={shortUrl} suffix={suffix}>
|
|
|
|
Something
|
|
|
|
</ShortUrlDetailLink>
|
|
|
|
</MemoryRouter>,
|
2021-03-20 18:32:12 +03:00
|
|
|
);
|
2022-07-10 20:58:27 +03:00
|
|
|
expect(screen.getByRole('link')).toHaveProperty('href', expect.stringContaining(expectedLink));
|
2020-02-08 11:20:19 +03:00
|
|
|
});
|
|
|
|
});
|