mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-03 23:07:26 +03:00
Migrated NotFound test to react testing library
This commit is contained in:
parent
fcbb9cda12
commit
37adcb52cf
1 changed files with 18 additions and 33 deletions
|
@ -1,47 +1,32 @@
|
||||||
import { shallow, ShallowWrapper } from 'enzyme';
|
import { render, screen } from '@testing-library/react';
|
||||||
import { Link } from 'react-router-dom';
|
import { MemoryRouter } from 'react-router-dom';
|
||||||
import { NotFound } from '../../src/common/NotFound';
|
import { NotFound } from '../../src/common/NotFound';
|
||||||
import { SimpleCard } from '../../src/utils/SimpleCard';
|
|
||||||
|
|
||||||
describe('<NotFound />', () => {
|
describe('<NotFound />', () => {
|
||||||
let wrapper: ShallowWrapper;
|
const setUp = (props = {}) => render(<MemoryRouter><NotFound {...props} /></MemoryRouter>);
|
||||||
const createWrapper = (props = {}) => {
|
|
||||||
wrapper = shallow(<NotFound {...props} />).find(SimpleCard);
|
|
||||||
|
|
||||||
return wrapper;
|
|
||||||
};
|
|
||||||
|
|
||||||
afterEach(() => wrapper?.unmount());
|
|
||||||
|
|
||||||
it('shows expected error title', () => {
|
it('shows expected error title', () => {
|
||||||
const wrapper = createWrapper();
|
setUp();
|
||||||
|
expect(screen.getByText('Oops! We could not find requested route.')).toBeInTheDocument();
|
||||||
expect(wrapper.contains('Oops! We could not find requested route.')).toEqual(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows expected error message', () => {
|
it('shows expected error message', () => {
|
||||||
const wrapper = createWrapper();
|
setUp();
|
||||||
|
expect(screen.getByText(
|
||||||
expect(wrapper.contains(
|
|
||||||
'Use your browser\'s back button to navigate to the page you have previously come from, or just press this button.',
|
'Use your browser\'s back button to navigate to the page you have previously come from, or just press this button.',
|
||||||
)).toEqual(true);
|
)).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('shows a link to the home', () => {
|
it.each([
|
||||||
const wrapper = createWrapper();
|
[{}, '/', 'Home'],
|
||||||
const link = wrapper.find(Link);
|
[{ to: '/foo/bar', children: 'Hello' }, '/foo/bar', 'Hello'],
|
||||||
|
[{ to: '/baz-bar', children: <>Foo</> }, '/baz-bar', 'Foo'],
|
||||||
|
])('shows expected link and text', (props, expectedLink, expectedText) => {
|
||||||
|
setUp(props);
|
||||||
|
const link = screen.getByRole('link');
|
||||||
|
|
||||||
expect(link.prop('to')).toEqual('/');
|
expect(link).toHaveAttribute('href', expectedLink);
|
||||||
expect(link.prop('className')).toEqual('btn btn-outline-primary btn-lg');
|
expect(link).toHaveTextContent(expectedText);
|
||||||
expect(link.prop('children')).toEqual('Home');
|
expect(link).toHaveAttribute('class', 'btn btn-outline-primary btn-lg');
|
||||||
});
|
|
||||||
|
|
||||||
it('shows a link with provided props', () => {
|
|
||||||
const wrapper = createWrapper({ to: '/foo/bar', children: 'Hello' });
|
|
||||||
const link = wrapper.find(Link);
|
|
||||||
|
|
||||||
expect(link.prop('to')).toEqual('/foo/bar');
|
|
||||||
expect(link.prop('className')).toEqual('btn btn-outline-primary btn-lg');
|
|
||||||
expect(link.prop('children')).toEqual('Hello');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue