mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-05-01 17:30:33 +03:00
Migrated ShortUrlDetailLink test to react testing library
This commit is contained in:
parent
879017ecca
commit
f97fce873b
1 changed files with 12 additions and 19 deletions
|
@ -1,15 +1,11 @@
|
||||||
import { shallow, ShallowWrapper } from 'enzyme';
|
import { render, screen } from '@testing-library/react';
|
||||||
import { Link } from 'react-router-dom';
|
|
||||||
import { Mock } from 'ts-mockery';
|
import { Mock } from 'ts-mockery';
|
||||||
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import { ShortUrlDetailLink, LinkSuffix } from '../../../src/short-urls/helpers/ShortUrlDetailLink';
|
import { ShortUrlDetailLink, LinkSuffix } from '../../../src/short-urls/helpers/ShortUrlDetailLink';
|
||||||
import { NotFoundServer, ReachableServer } from '../../../src/servers/data';
|
import { NotFoundServer, ReachableServer } from '../../../src/servers/data';
|
||||||
import { ShortUrl } from '../../../src/short-urls/data';
|
import { ShortUrl } from '../../../src/short-urls/data';
|
||||||
|
|
||||||
describe('<ShortUrlDetailLink />', () => {
|
describe('<ShortUrlDetailLink />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
|
||||||
|
|
||||||
afterEach(() => wrapper?.unmount());
|
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
[undefined, undefined],
|
[undefined, undefined],
|
||||||
[null, null],
|
[null, null],
|
||||||
|
@ -19,15 +15,14 @@ describe('<ShortUrlDetailLink />', () => {
|
||||||
[null, Mock.all<ShortUrl>()],
|
[null, Mock.all<ShortUrl>()],
|
||||||
[undefined, Mock.all<ShortUrl>()],
|
[undefined, Mock.all<ShortUrl>()],
|
||||||
])('only renders a plain span when either server or short URL are not set', (selectedServer, shortUrl) => {
|
])('only renders a plain span when either server or short URL are not set', (selectedServer, shortUrl) => {
|
||||||
wrapper = shallow(
|
render(
|
||||||
<ShortUrlDetailLink selectedServer={selectedServer} shortUrl={shortUrl} suffix="visits">
|
<ShortUrlDetailLink selectedServer={selectedServer} shortUrl={shortUrl} suffix="visits">
|
||||||
Something
|
Something
|
||||||
</ShortUrlDetailLink>,
|
</ShortUrlDetailLink>,
|
||||||
);
|
);
|
||||||
const link = wrapper.find(Link);
|
|
||||||
|
|
||||||
expect(link).toHaveLength(0);
|
expect(screen.queryByRole('link')).not.toBeInTheDocument();
|
||||||
expect(wrapper.html()).toEqual('<span>Something</span>');
|
expect(screen.getByText('Something')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
|
@ -56,15 +51,13 @@ describe('<ShortUrlDetailLink />', () => {
|
||||||
'/server/3/short-code/def456/edit?domain=example.com',
|
'/server/3/short-code/def456/edit?domain=example.com',
|
||||||
],
|
],
|
||||||
])('renders link with expected query when', (selectedServer, shortUrl, suffix, expectedLink) => {
|
])('renders link with expected query when', (selectedServer, shortUrl, suffix, expectedLink) => {
|
||||||
wrapper = shallow(
|
render(
|
||||||
<ShortUrlDetailLink selectedServer={selectedServer} shortUrl={shortUrl} suffix={suffix}>
|
<MemoryRouter>
|
||||||
Something
|
<ShortUrlDetailLink selectedServer={selectedServer} shortUrl={shortUrl} suffix={suffix}>
|
||||||
</ShortUrlDetailLink>,
|
Something
|
||||||
|
</ShortUrlDetailLink>
|
||||||
|
</MemoryRouter>,
|
||||||
);
|
);
|
||||||
const link = wrapper.find(Link);
|
expect(screen.getByRole('link')).toHaveProperty('href', expect.stringContaining(expectedLink));
|
||||||
const to = link.prop('to');
|
|
||||||
|
|
||||||
expect(link).toHaveLength(1);
|
|
||||||
expect(to).toEqual(expectedLink);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue