Skip to content

Commit ffa05de

Browse files
Andrés Campos Hernándezcylcrow
authored andcommitted
✨ ♻️ ✅ Added private routes
1 parent cd471e9 commit ffa05de

17 files changed

Lines changed: 239 additions & 29 deletions

‎src/components/App/Content.jsx‎

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1-
import React from 'react';
1+
import React, { useContext } from 'react';
22
import { Redirect, Route, Switch } from 'react-router';
3-
import HomePlayer from '../HomeVideos/HomePlayer';
4-
import HomeVideos from '../HomeVideos/HomeVideos';
3+
import AppContext from '../../providers/AppContext';
4+
import HomePlayer from '../Home/HomePlayer';
5+
import HomeVideos from '../Home/HomeVideos';
6+
import FavoritesPlayer from '../Private/FavoritesPlayer';
7+
import FavoriteVideos from '../Private/FavoriteVideos';
8+
import Page404 from '../StatusPages/Page404';
59

610
const Content = () => {
11+
const { userSession } = useContext(AppContext);
712
return (<div>
813
<Switch>
914
<Route exact path="/">
@@ -15,6 +20,20 @@ const Content = () => {
1520
<Route path="/player">
1621
<HomePlayer />
1722
</Route>
23+
{
24+
userSession ?
25+
<>
26+
<Route path="/favorites">
27+
<FavoriteVideos />
28+
</Route>
29+
<Route path="/favoritesPlayer">
30+
<FavoritesPlayer/>
31+
</Route>
32+
</>:null
33+
}
34+
<Route path="*" id="ok">
35+
<Page404 />
36+
</Route>
1837
</Switch>
1938
</div>);
2039
}

‎src/components/GenericComponents/VideoPlayerContainer.spec.jsx‎

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@ import VideoPlayerContainer from './VideoPlayerContainer';
77
import { fireEvent, getByTestId } from '@testing-library/dom';
88
import AppContext from '../../providers/AppContext';
99

10+
1011
global.YT = YTMockedObject;
12+
const FAVORITES_KEY = "favorites";
1113
const EXPECTED_LENGHT = 3
1214
const contextValueVideosList = youtubeMockedData.items.slice(0, EXPECTED_LENGHT);
1315

1416
const build = async ( Component = <VideoPlayerContainer videosList={contextValueVideosList}/>, video ) => {
15-
16-
beforeEach(() => {
17-
window.localStorage.clear();
18-
});
19-
2017
const contextValue = { search: jest.fn, theme: lightTheme };
2118
let container;
2219
let routeWrap;
@@ -54,7 +51,6 @@ describe('VideoPlayerContainer', () => {
5451
});
5552

5653
it('adds/removes to favorites and "Add favorite" / "Remove favorite" in button ', async () => {
57-
const FAVORITES_KEY = "favorites";
5854
const savedVideo = contextValueVideosList[0];
5955
const built = (await build(<VideoPlayerContainer videosList={contextValueVideosList}/>, savedVideo));
6056
const { addFavoriteButton } = built;
@@ -78,7 +74,6 @@ describe('VideoPlayerContainer', () => {
7874
});
7975

8076
it('adds/removes video to existing in localStorage', async () => {
81-
const FAVORITES_KEY = "favorites";
8277
const firstVideo = contextValueVideosList[1];
8378
const savedVideo = contextValueVideosList[0];
8479
window.localStorage.setItem(FAVORITES_KEY, JSON.stringify({[firstVideo.id.videoId]: firstVideo}));
@@ -95,7 +90,7 @@ describe('VideoPlayerContainer', () => {
9590
});
9691

9792
it('adds/removes favorite clicking related video favorite button ', async () => {
98-
const FAVORITES_KEY = "favorites";
93+
window.localStorage.clear();
9994
const savedVideo = contextValueVideosList[0];
10095
const built = (await build(<VideoPlayerContainer videosList={contextValueVideosList}/>, savedVideo));
10196
const { container } = built;
@@ -105,20 +100,11 @@ describe('VideoPlayerContainer', () => {
105100

106101
let favorites = window.localStorage.getItem(FAVORITES_KEY);
107102
const parsedSavedVideo = JSON.parse(favorites)[savedVideo.id.videoId];
108-
109103
expect(Object.keys(JSON.parse(favorites))).toHaveLength(1);
110104
expect(JSON.stringify(parsedSavedVideo)).toEqual(JSON.stringify(savedVideo));
111-
expect(captionAddFavorite.textContent).toBe("Remove favorite");
112-
113-
fireEvent.click(captionAddFavorite);
114-
115-
favorites = window.localStorage.getItem(FAVORITES_KEY);
116-
expect(Object.keys(JSON.parse(favorites))).toHaveLength(0);
117-
expect(captionAddFavorite.textContent).toBe("Add favorite");
118105
});
119106

120107
it('adds/removes video to existing clicking related video favorite button', async () => {
121-
const FAVORITES_KEY = "favorites";
122108
const firstVideo = contextValueVideosList[1];
123109
const secondVideo = contextValueVideosList[0];
124110
window.localStorage.setItem(FAVORITES_KEY, JSON.stringify({[firstVideo.id.videoId]: firstVideo}));

‎src/components/GenericComponents/VideoPlayerContainer.test.jsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import AppContext from '../../providers/AppContext';
99
global.YT = YTMockedObject;
1010
const EXPECTED_LENGHT = 3
1111
const contextValueVideosList = youtubeMockedData.items.slice(0, EXPECTED_LENGHT);
12-
1312
const build = async (
1413
Component = <VideoPlayerContainer videosList={contextValueVideosList}/>,
1514
currentVideoId = contextValueVideosList[0].id.videoId
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ const StyledWarn = styled.div`
1414
color: white;
1515
`;
1616

17+
const NoVideosNotice = <StyledWarn data-testid="no-videos-available">There are no videos</StyledWarn>;
18+
1719
const HomeVideos = () => {
1820
const { videosList } = useContext(AppContext);
1921
const { push } = useHistory();
2022

21-
const NoVideosNotice = <StyledWarn data-testid="no-videos-available">No hay videos :/</StyledWarn>;
22-
2323
return (<VideoCardContainer
2424
videosList={videosList}
2525
noVideosNotice={NoVideosNotice}
File renamed without changes.
File renamed without changes.

src/components/HomeVideos/__snapshots__/HomeVideos.test.jsx.snap renamed to src/components/Home/__snapshots__/HomeVideos.test.jsx.snap

File renamed without changes.

‎src/components/Layout/Header.jsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ const Header = () => {
8888
border="0px"
8989
margin="4px"
9090
data-testid="sidebar-favorites"
91+
onClick={() => {
92+
push({pathname: "/favorites"});
93+
dispatch({ type: SET_SIDEBAR_OPEN , payload: false });
94+
}}
9195
>
9296
Favorites
9397
</Button>

0 commit comments

Comments
 (0)