Skip to content

Commit

Permalink
feat(project): add root component
Browse files Browse the repository at this point in the history
  • Loading branch information
RCVZ committed Apr 29, 2021
1 parent 06df909 commit 5aa3458
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 9 deletions.
22 changes: 22 additions & 0 deletions src/components/Root/Root.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';

import { mockWindowLocation, render } from '../../testUtils';

import Root from './Root';

describe('<Root />', () => {
it('renders and matches snapshot', () => {
mockWindowLocation('/');
const { container } = render(<Root />);

expect(container).toMatchSnapshot();
});

it('renders error page when error prop is passed', () => {
mockWindowLocation('/');
const error = new Error();
const { container } = render(<Root error={error} />);

expect(container).toMatchSnapshot();
});
});
32 changes: 23 additions & 9 deletions src/components/Root/Root.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
import React, { FC } from 'react';
import { Route, Switch } from 'react-router-dom';

// import styles from './Root.module.scss';
import Home from '../../screens/Home/Home';
import Header from '../Header/Header';

const Home = () => {
return <span>Home</span>;
};
// Mock screens

const PlaylistScreen = () => {
return <span>PlaylistScreen</span>;
return (
<>
<Header></Header>
<span style={{ color: 'white' }}>PlaylistScreen</span>
</>
);
};
const Settings = () => {
return (
<>
<Header></Header> <span style={{ color: 'white' }}>Settings</span>{' '}
</>
);
};

interface RootProps {
error: Error | null;
}
// Mock screens

type RootProps = {
error?: Error | null;
};

const Root: FC<RootProps> = ({ error }: RootProps) => {
if (error) {
return <span>{error}</span>;
return <div>Error!</div>;
}

return (
<Switch>
<Route path="/" component={Home} exact />
<Route path="/p/:id" component={PlaylistScreen} exact />
<Route path="/u" component={Settings} exact />
</Switch>
);
};
Expand Down
11 changes: 11 additions & 0 deletions src/components/Root/__snapshots__/Root.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<Root /> renders and matches snapshot 1`] = `<div />`;

exports[`<Root /> renders error page when error prop is passed 1`] = `
<div>
<div>
Error!
</div>
</div>
`;

0 comments on commit 5aa3458

Please sign in to comment.