Skip to content
This repository was archived by the owner on Jan 16, 2022. It is now read-only.

Commit fdbdb63

Browse files
priscilawebdevjuanpicado
authored andcommitted
feat: new not found component (#170)
* refactor: updated not found component * chore: removed react-router * refactored: applied feedbacks * fix: removed doc folder * refactor: rollback yarn.lock
1 parent 7529c02 commit fdbdb63

File tree

10 files changed

+72
-86
lines changed

10 files changed

+72
-86
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ Dockerfile
1111
*.html
1212
*.scss
1313
*.png
14+
doc

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ npm-debug.log
22
verdaccio-*.tgz
33
.DS_Store
44
build/
5+
doc
6+
57
###
68
node_modules
79
package-lock.json
Lines changed: 30 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,47 @@
1-
import ListItem from '@material-ui/core/ListItem';
1+
import Box from '@material-ui/core/Box';
22
import Typography from '@material-ui/core/Typography';
3-
import withWidth, { isWidthUp, WithWidthProps } from '@material-ui/core/withWidth';
3+
import styled from 'react-emotion';
44
import React, { useCallback } from 'react';
5-
import { RouteComponentProps, withRouter } from 'react-router-dom';
5+
import { useHistory } from 'react-router-dom';
6+
7+
import Button from '../../muiComponents/Button';
8+
import colors from '../../utils/styles/colors';
9+
import { spacings } from '../../utils/styles/spacings';
610

711
import PackageImg from './img/package.svg';
8-
import { Card, EmptyPackage, Heading, Inner, List, Wrapper } from './styles';
912

10-
export const NOT_FOUND_TEXT = `Sorry, we couldn't find it...`;
11-
export const LABEL_NOT_FOUND = `The page you're looking for doesn't exist.`;
12-
export const LABEL_FOOTER_NOT_FOUND = 'Perhaps these links will help find what you are looking for:';
13+
export const NOT_FOUND_TEXT = "Sorry, we couldn't find it...";
14+
export const LABEL_NOT_FOUND = "The page you're looking for doesn't exist.";
15+
export const GO_TO_HOME_PAGE = 'Go to the home page';
1316

14-
export type NotFoundProps = RouteComponentProps & WithWidthProps;
17+
const EmptyPackage = styled('img')({
18+
width: '150px',
19+
margin: '0 auto',
20+
});
1521

16-
const HOME_LABEL = 'Home';
22+
const StyledHeading = styled(Typography)({
23+
color: colors.primary,
24+
marginBottom: spacings.sm,
25+
});
1726

18-
const renderSubTitle = (): JSX.Element => (
19-
<Typography variant="subtitle1">
20-
<div>{LABEL_NOT_FOUND}</div>
21-
<div>{LABEL_FOOTER_NOT_FOUND}</div>
22-
</Typography>
23-
);
27+
const NotFound: React.FC = () => {
28+
const history = useHistory();
2429

25-
const NotFound: React.FC<NotFoundProps> = ({ history, width }) => {
2630
const handleGomHome = useCallback(() => {
2731
history.push('/');
2832
}, [history]);
2933

30-
const renderList = (): JSX.Element => (
31-
<List>
32-
<ListItem button={true} divider={true} onClick={handleGomHome}>
33-
{HOME_LABEL}
34-
</ListItem>
35-
</List>
36-
);
37-
38-
/* eslint-disable @typescript-eslint/no-non-null-assertion */
3934
return (
40-
<Wrapper data-testid="404">
41-
<Inner>
42-
<EmptyPackage alt="404 - Page not found" src={PackageImg} />
43-
<Heading className="not-found-text" variant={isWidthUp('sm', width!) ? 'h2' : 'h4'}>
44-
{NOT_FOUND_TEXT}
45-
</Heading>
46-
{renderSubTitle()}
47-
<Card>{renderList()}</Card>
48-
</Inner>
49-
</Wrapper>
35+
<Box alignItems="center" data-testid="404" display="flex" flexDirection="column" flexGrow={1} justifyContent="center" p={2}>
36+
<EmptyPackage alt="404 - Page not found" src={PackageImg} />
37+
<StyledHeading className="not-found-text" variant="h4">
38+
{NOT_FOUND_TEXT}
39+
</StyledHeading>
40+
<Button onClick={handleGomHome} variant="contained">
41+
{GO_TO_HOME_PAGE}
42+
</Button>
43+
</Box>
5044
);
5145
};
5246

53-
export default withRouter<NotFoundProps, React.ComponentType<NotFoundProps>>(withWidth()(NotFound));
47+
export default NotFound;
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import React from 'react';
22
import { BrowserRouter as Router } from 'react-router-dom';
3-
import { shallow } from 'enzyme';
3+
import { render } from '@testing-library/react';
44

55
import NotFound from './NotFound';
66

7-
console.error = jest.fn();
8-
97
describe('<NotFound /> component', () => {
108
test('should load the component in default state', () => {
11-
const routerWrapper = shallow(
9+
const { container } = render(
1210
<Router>
1311
<NotFound />
1412
</Router>
1513
);
16-
expect(routerWrapper.find(NotFound)).toMatchSnapshot();
14+
expect(container.firstChild).toMatchSnapshot();
1715
});
16+
test.todo('Test Button Click');
1817
});
Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`<NotFound /> component should load the component in default state 1`] = `<withRouter(WithWidth(NotFound)) />`;
3+
exports[`<NotFound /> component should load the component in default state 1`] = `
4+
<div
5+
class="MuiBox-root MuiBox-root-2"
6+
data-testid="404"
7+
>
8+
<img
9+
alt="404 - Page not found"
10+
class="css-17y48z2 emotion-0"
11+
src="[object Object]"
12+
/>
13+
<h4
14+
class="MuiTypography-root not-found-text css-7pe7kh emotion-1 MuiTypography-h4"
15+
>
16+
Sorry, we couldn't find it...
17+
</h4>
18+
<button
19+
class="MuiButtonBase-root MuiButton-root MuiButton-contained"
20+
tabindex="0"
21+
type="button"
22+
>
23+
<span
24+
class="MuiButton-label"
25+
>
26+
Go to the home page
27+
</span>
28+
<span
29+
class="MuiTouchRipple-root"
30+
/>
31+
</button>
32+
</div>
33+
`;

src/components/NotFound/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default } from './NotFound';
1+
export { default, NOT_FOUND_TEXT } from './NotFound';

src/components/NotFound/styles.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/components/Versions/Versions.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { mount } from 'enzyme';
3-
import { MemoryRouter } from 'react-router';
3+
import { MemoryRouter } from 'react-router-dom';
44
import { render, cleanup } from '@testing-library/react';
55

66
import { DetailContext, DetailContextProps } from '../../pages/Version';

src/utils/styles/spacings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
export const spacings = {
55
lg: '30px',
6+
sm: '16px',
67
};

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14023,4 +14023,4 @@ yup@^0.27.0:
1402314023
lodash "^4.17.11"
1402414024
property-expr "^1.5.0"
1402514025
synchronous-promise "^2.0.6"
14026-
toposort "^2.0.2"
14026+
toposort "^2.0.2"

0 commit comments

Comments
 (0)