mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-08 17:27:32 +03:00
Created NotFound component
This commit is contained in:
parent
4f0ee79409
commit
d23ddd0e0b
4 changed files with 57 additions and 5 deletions
|
@ -1,6 +1,7 @@
|
|||
import React from 'react';
|
||||
import { Route, Switch } from 'react-router-dom';
|
||||
import './App.scss';
|
||||
import NotFound from './common/NotFound';
|
||||
|
||||
const App = (MainHeader, Home, MenuLayout, CreateServer) => () => (
|
||||
<div className="container-fluid app-container">
|
||||
|
@ -11,6 +12,7 @@ const App = (MainHeader, Home, MenuLayout, CreateServer) => () => (
|
|||
<Route exact path="/server/create" component={CreateServer} />
|
||||
<Route exact path="/" component={Home} />
|
||||
<Route path="/server/:serverId" component={MenuLayout} />
|
||||
<Route component={NotFound} />
|
||||
</Switch>
|
||||
</div>
|
||||
</div>
|
||||
|
|
15
src/common/NotFound.js
Normal file
15
src/common/NotFound.js
Normal file
|
@ -0,0 +1,15 @@
|
|||
import React from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
const NotFound = () => (
|
||||
<div className="home">
|
||||
<h2>Oops! We could not find requested route.</h2>
|
||||
<p>
|
||||
Use your browser{'\''}s back button to navigate to the page you have previously come from, or just press this button.
|
||||
</p>
|
||||
<br />
|
||||
<Link to="/" className="btn btn-outline-primary btn-lg">Home</Link>
|
||||
</div>
|
||||
);
|
||||
|
||||
export default NotFound;
|
|
@ -19,12 +19,17 @@ describe('<App />', () => {
|
|||
|
||||
it('renders app main routes', () => {
|
||||
const routes = wrapper.find(Route);
|
||||
const expectedRoutesCount = 3;
|
||||
const second = 2;
|
||||
const expectedRoutesCount = 4;
|
||||
const expectedPaths = [
|
||||
'/server/create',
|
||||
'/',
|
||||
'/server/:serverId',
|
||||
];
|
||||
|
||||
expect.assertions(expectedPaths.length + 1);
|
||||
expect(routes).toHaveLength(expectedRoutesCount);
|
||||
expect(routes.at(0).prop('path')).toEqual('/server/create');
|
||||
expect(routes.at(1).prop('path')).toEqual('/');
|
||||
expect(routes.at(second).prop('path')).toEqual('/server/:serverId');
|
||||
expectedPaths.forEach((path, index) => {
|
||||
expect(routes.at(index).prop('path')).toEqual(path);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
30
test/common/NotFound.test.js
Normal file
30
test/common/NotFound.test.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
import React from 'react';
|
||||
import { shallow } from 'enzyme';
|
||||
import { Link } from 'react-router-dom';
|
||||
import NotFound from '../../src/common/NotFound';
|
||||
|
||||
describe('<NotFound />', () => {
|
||||
let wrapper;
|
||||
let content;
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(<NotFound />);
|
||||
content = wrapper.text();
|
||||
});
|
||||
|
||||
afterEach(() => wrapper.unmount());
|
||||
|
||||
it('shows expected error title', () => expect(content).toContain('Oops! We could not find requested route.'));
|
||||
|
||||
it('shows expected error message', () =>
|
||||
expect(content).toContain(
|
||||
'Use your browser\'s back button to navigate to the page you have previously come from, or just press this button.'
|
||||
));
|
||||
|
||||
it('shows a link to the home', () => {
|
||||
const link = wrapper.find(Link);
|
||||
|
||||
expect(link.prop('to')).toEqual('/');
|
||||
expect(link.prop('className')).toEqual('btn btn-outline-primary btn-lg');
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue