forked from wizeline/react-certification-2020
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mini ch 5 #66
Open
cylcrow
wants to merge
43
commits into
wdonet:master
Choose a base branch
from
cylcrow:mini-ch-5
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Mini ch 5 #66
Changes from 29 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
a8b259f
:white_check_mark: :heavy_plus_sign: :art: :fire: Fork, cleanup and f…
cylcrow 6466b34
:construction: :white_check_mark: :art: Added tests to assert compone…
cylcrow dca62d2
:recycle: Refactored names to comply with the specified in the challe…
cylcrow 07be5b1
:recycle: :white_check_mark: :sparkles: :lipstick: Added base compone…
cylcrow d48c4e1
:sparkles: :recycle: :white_check_mark: :lipstick: Added Card component
cylcrow 88e5f76
:sparkles: :recycle: :white_check_mark: :lipstick: Added Card component
cylcrow a3c7089
:lipstick: :art: Polished styles for Card component
cylcrow f7b8cf8
testing-libraries-cleanup: :recycle: Removed unnecesary dependencies …
cylcrow e5c9eac
:bento: :wheelchair: :recycle: Added roles to each element
cylcrow 4547dca
:white_check_mark: :recycle: :sparkles: Added theming prototype
436964f
:construction: :recycle: Added theme wrapper for testing purposes
991f0b5
:recycle: :building_construction: :construction: Components isolation
be967d3
:recycle: :sparkles: :wheelchair: :alembic: Added VideoCards
7ed4920
:recycle: :wheelchair: :construction: Improved accesibility for Card …
671b550
:sparkles: :fire: :truck: :recycle: :art: :bug: :white_check_mark: Ad…
233f180
:recycle: :art: :sparkles: :truck: Adding youtube playback iframe
0fb5003
:recycle: :bug: :sparkles: :white_check_mark: Added video player and …
c1c945a
:sparkles: :bug: :construction: Added VideoPlayer feature to return t…
d3123dc
:white_check_mark: :fire: :art: Added remaining tests for mini ch 3
510fd3a
:fire: :recycle: :white_check_mark: Removed unnecessary ThemeContext …
cb565b0
:recycle: :fire: :white_check_mark: Added reducer for App, removed un…
c7c7f5e
:fire: :white_check_mark: Updated properties names
bbf8b0d
:bug: :white_check_mark: Solved issues loading videos by id on iframe
56c3147
:art: :lipstick: :white_check_mark: Added test for theme behavior for…
bb045c2
:art: :lipstick: :white_check_mark: Added test for theme behavior for…
9fb8e46
:art: :lipstick: :white_check_mark: Added test for theme behavior for…
f3239a6
:recycle: :white_check_mark: :art: Added tests for youtube search ser…
6a31647
:recycle: Moved generic components to higher path
24ac659
:sparkles: :recycle: :construction: Added routes for each feature
1380c53
:sparkles: Added login screen
a529834
:recycle: :zap: :bug: Fixed bug when videoId was updated on VideoPlay…
d35c358
:bug: Solved bug loading videos VideoPlayer>Home>VideoPlayer
5a2f82a
:sparkles: :recycle: :white_check_mark: Added Overlay and Menu compon…
2e93c5b
:sparkles: :recycle: :white_check_mark: Added Sidebar and buttons wit…
7de97f4
:sparkles: :recycle: :white_check_mark: Added favorites Add/Remove fe…
fb5c606
:sparkles: :recycle: :white_check_mark: Added tests and features to s…
b4808e1
:bug: Solved issues parsing/saving data from/to localStorage/sessionS…
c27bcd8
:recycle: :fire: Moved feature to generic component
49e9010
:recycle: :fire: :white_check_mark: Moved VideoPlayerContainer to gen…
72a6c2e
:sparkles: :recycle: :white_check_mark: Added login to a react portal
cd471e9
:sparkles: :recycle: :white_check_mark: Added favorites button to Sma…
ffa05de
:sparkles: :recycle: :white_check_mark: Added private routes
c8fff2a
:sparkles: :recycle: :rocket: Added last features
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
REACT_APP_YOUTUBE_KEY=AIzaSyDFnO9VgkkdOBvHDq4NtEStIng-fAkEkEY |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React, { useReducer } from 'react'; | ||
import { LayoutWrapper } from '../Layout'; | ||
import { appReducer } from '../../reducers/appReducer'; | ||
import { lightTheme, darkTheme } from '../../providers/themes'; | ||
import youtubeSearchService from '../../services/youtubeSearchService'; | ||
import AppContext from '../../providers/AppContext'; | ||
import { createBrowserHistory } from "history"; | ||
import { Router } from 'react-router-dom'; | ||
import { | ||
SET_CURRENT_VIDEO_PLAYBACK, | ||
SET_IS_FIRST_LOAD, | ||
SET_VIDEOS_LIST, | ||
SWITCH_THEME | ||
} from '../../reducers/actionTypes'; | ||
import Content from './Content'; | ||
|
||
const initialState = { | ||
videosList: [], | ||
currentVideoId: undefined, | ||
isLightTheme: true, | ||
isFirstLoad: true, | ||
}; | ||
|
||
const history = createBrowserHistory(); | ||
|
||
function App() { | ||
const [{ | ||
videosList, | ||
isLightTheme, | ||
isFirstLoad }, | ||
dispatch] = useReducer(appReducer, initialState); | ||
|
||
const getThemeConfig = () => ({ | ||
theme: isLightTheme ? lightTheme : darkTheme, | ||
switchTheme: () => dispatch({type: SWITCH_THEME}), | ||
}); | ||
|
||
const search = async (query) => { | ||
const serviceResponse = await youtubeSearchService.search(query); | ||
serviceResponse.error | ||
? dispatch({ type: SET_VIDEOS_LIST, payload: [] }) | ||
: dispatch({ type: SET_VIDEOS_LIST, payload: serviceResponse }); | ||
} | ||
|
||
const firstSearch = async () => { | ||
let counter = 0; | ||
/* global gapi */ | ||
/* eslint no-undef: "error" */ | ||
while((!gapi || !gapi.client) && counter < 10){ | ||
counter+=1; | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
} | ||
((!gapi || !gapi.client) || counter >= 10) | ||
? dispatch({ type: SET_VIDEOS_LIST, payload: [] }) | ||
: search() | ||
} | ||
|
||
if(isFirstLoad){ | ||
dispatch({ type: SET_IS_FIRST_LOAD, payload: false }); | ||
firstSearch(); | ||
} | ||
|
||
return ( | ||
<AppContext.Provider value={ | ||
{ ...getThemeConfig(), | ||
search, | ||
videosList, | ||
playVideoById: (id) => dispatch({type: SET_CURRENT_VIDEO_PLAYBACK, payload: id}) | ||
} | ||
}> | ||
<Router history={history}> | ||
<LayoutWrapper> | ||
<Content /> | ||
</LayoutWrapper> | ||
</Router> | ||
</AppContext.Provider> | ||
); | ||
} | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React from 'react'; | ||
import { fireEvent, getByRole, act, render } from '@testing-library/react'; | ||
import { contextWrapper, googleMockedAPIObject, youtubeMockedData, YTMockedObject } from '../../utils'; | ||
import { getAllByTestId, getByTestId } from '@testing-library/dom'; | ||
import { darkTheme, lightTheme } from '../../providers/themes'; | ||
import AppContext from '../../providers/AppContext'; | ||
import App from './index'; | ||
|
||
global.gapi = googleMockedAPIObject(); | ||
global.YT = YTMockedObject; | ||
|
||
const for400Miliseconds = () => new Promise((resolve) => { | ||
setTimeout(() => resolve(), 400) | ||
}) | ||
|
||
const build = async (Component = <App />) => { | ||
let container; | ||
const contextValue = { videos: youtubeMockedData.items, theme: lightTheme }; | ||
await act(async () => { | ||
const wrapped = contextWrapper(AppContext, contextValue, Component); | ||
container = render(wrapped).container; | ||
}); | ||
return { | ||
container, | ||
LayoutWrapper: () => getByRole(container, 'application'), | ||
ThemeSwitch: () => getByRole(container, 'switch'), | ||
videosList: () => getAllByTestId(container, (testID) => testID.includes('video-card-') ), | ||
noVideosAvailableCaption: () => getByTestId(container, 'no-videos-available' ), | ||
unableToLoadVideos: () => getByTestId(container, 'unable-to-load-videos' ), | ||
}; | ||
}; | ||
|
||
describe('App theme', () => { | ||
it('applies "light" theme if none selected', async () => { | ||
const wrapper = await build(); | ||
expect(wrapper.LayoutWrapper()).toHaveStyle( | ||
`background: ${lightTheme.color.background}` | ||
); | ||
}); | ||
|
||
it('changes "light" theme to "dark" theme', async () => { | ||
const wrapper = await build(); | ||
|
||
expect(wrapper.LayoutWrapper()).toHaveStyle( | ||
`background: ${lightTheme.color.background}` | ||
); | ||
await act(async () => { | ||
fireEvent.click(wrapper.ThemeSwitch()); | ||
}); | ||
expect(wrapper.LayoutWrapper()).toHaveStyle( | ||
`background: ${darkTheme.color.background}` | ||
); | ||
}); | ||
|
||
it('shows videos list after successful fetch', async () => { | ||
const built = (await build()); | ||
const { videosList } = built; | ||
expect(videosList()).toHaveLength(youtubeMockedData.items.length); | ||
}); | ||
|
||
it('shows "No hay videos :/" legend after failed fetch', async () => { | ||
global.gapi = googleMockedAPIObject(false); | ||
const built = (await build()); | ||
const { noVideosAvailableCaption } = built; | ||
expect( noVideosAvailableCaption() ).toBeTruthy(); | ||
}); | ||
|
||
it('waits until `gapi` object is defined before first search', async () => { | ||
global.gapi = undefined; | ||
const built = await build(); | ||
|
||
await for400Miliseconds(); | ||
global.gapi = googleMockedAPIObject(); | ||
await act( async () => { await for400Miliseconds(); }); | ||
|
||
const { videosList } = built; | ||
expect(videosList()).toHaveLength(youtubeMockedData.items.length); | ||
}); | ||
|
||
it('shows "Couldn\'t load videos" when "gapi" object is not loaded after 1 second', async () => { | ||
global.gapi = undefined; | ||
const built = await build(); | ||
|
||
await for400Miliseconds(); | ||
await for400Miliseconds(); | ||
|
||
await act( async () => { | ||
await for400Miliseconds(); | ||
global.gapi = googleMockedAPIObject(); | ||
}); | ||
|
||
const { noVideosAvailableCaption } = built; | ||
expect(noVideosAvailableCaption()).toBeTruthy(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { act, getByRole, render } from '@testing-library/react'; | ||
import { googleMockedAPIObject } from '../../utils'; | ||
import App from './index'; | ||
|
||
global.gapi = googleMockedAPIObject(); | ||
|
||
const build = async (Component = <App />) => { | ||
let container; | ||
await act(async () => { | ||
container = render(Component).container; | ||
}); | ||
return { | ||
container, | ||
LayoutWrapper: () => getByRole(container, 'application'), | ||
ThemeSwitch: () => getByRole(container, 'switch'), | ||
}; | ||
}; | ||
|
||
describe('App layout', () => { | ||
it('renders', async () => { | ||
const wrapper = await build(); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
it('displays layout wrapper', async () => { | ||
const wrapper = await build(); | ||
expect(wrapper.LayoutWrapper()).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import { Redirect, Route, Switch } from 'react-router'; | ||
import HomeVideos from '../HomeVideos/HomeVideos'; | ||
import VideoPlayerContainer from '../VideoPlayer/VideoPlayerContainer'; | ||
|
||
const Content = () => { | ||
return (<div> | ||
<Switch> | ||
<Route exact path="/"> | ||
<Redirect to="/home"/> | ||
</Route> | ||
<Route path="/home"> | ||
<HomeVideos /> | ||
</Route> | ||
<Route path="/player"> | ||
<VideoPlayerContainer /> | ||
</Route> | ||
</Switch> | ||
</div>); | ||
} | ||
|
||
export default Content; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent 👏🏻