2020-08-29 10:19:15 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2019-03-03 13:02:29 +03:00
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
import NotFound from '../../src/common/NotFound';
|
2020-12-13 22:57:00 +03:00
|
|
|
import { SimpleCard } from '../../src/utils/SimpleCard';
|
2019-03-03 13:02:29 +03:00
|
|
|
|
|
|
|
describe('<NotFound />', () => {
|
2020-08-29 10:19:15 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
2019-03-03 13:15:34 +03:00
|
|
|
const createWrapper = (props = {}) => {
|
2020-12-13 22:57:00 +03:00
|
|
|
wrapper = shallow(<NotFound {...props} />).find(SimpleCard);
|
2019-03-03 13:02:29 +03:00
|
|
|
|
2020-12-13 22:57:00 +03:00
|
|
|
return wrapper;
|
2019-03-03 13:15:34 +03:00
|
|
|
};
|
|
|
|
|
2020-08-29 10:19:15 +03:00
|
|
|
afterEach(() => wrapper?.unmount());
|
2019-03-03 13:02:29 +03:00
|
|
|
|
2019-03-03 13:15:34 +03:00
|
|
|
it('shows expected error title', () => {
|
2020-12-13 22:57:00 +03:00
|
|
|
const wrapper = createWrapper();
|
2019-03-03 13:02:29 +03:00
|
|
|
|
2020-12-13 22:57:00 +03:00
|
|
|
expect(wrapper.contains('Oops! We could not find requested route.')).toEqual(true);
|
2019-03-03 13:15:34 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows expected error message', () => {
|
2020-12-13 22:57:00 +03:00
|
|
|
const wrapper = createWrapper();
|
2019-03-03 13:02:29 +03:00
|
|
|
|
2020-12-13 22:57:00 +03:00
|
|
|
expect(wrapper.contains(
|
2020-08-22 09:10:31 +03:00
|
|
|
'Use your browser\'s back button to navigate to the page you have previously come from, or just press this button.',
|
2020-12-13 22:57:00 +03:00
|
|
|
)).toEqual(true);
|
2019-03-03 13:15:34 +03:00
|
|
|
});
|
2019-03-03 13:02:29 +03:00
|
|
|
|
|
|
|
it('shows a link to the home', () => {
|
2020-12-13 22:57:00 +03:00
|
|
|
const wrapper = createWrapper();
|
2019-03-03 13:02:29 +03:00
|
|
|
const link = wrapper.find(Link);
|
|
|
|
|
|
|
|
expect(link.prop('to')).toEqual('/');
|
|
|
|
expect(link.prop('className')).toEqual('btn btn-outline-primary btn-lg');
|
2019-03-03 13:15:34 +03:00
|
|
|
expect(link.prop('children')).toEqual('Home');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows a link with provided props', () => {
|
2020-12-13 22:57:00 +03:00
|
|
|
const wrapper = createWrapper({ to: '/foo/bar', children: 'Hello' });
|
2019-03-03 13:15:34 +03:00
|
|
|
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');
|
2019-03-03 13:02:29 +03:00
|
|
|
});
|
|
|
|
});
|