Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a8b259f
:white_check_mark: :heavy_plus_sign: :art: :fire: Fork, cleanup and f…
cylcrow Feb 19, 2021
6466b34
:construction: :white_check_mark: :art: Added tests to assert compone…
cylcrow Feb 19, 2021
dca62d2
:recycle: Refactored names to comply with the specified in the challe…
cylcrow Feb 19, 2021
07be5b1
:recycle: :white_check_mark: :sparkles: :lipstick: Added base compone…
cylcrow Feb 20, 2021
d48c4e1
:sparkles: :recycle: :white_check_mark: :lipstick: Added Card component
cylcrow Feb 20, 2021
88e5f76
:sparkles: :recycle: :white_check_mark: :lipstick: Added Card component
cylcrow Feb 20, 2021
a3c7089
:lipstick: :art: Polished styles for Card component
cylcrow Feb 20, 2021
f7b8cf8
testing-libraries-cleanup: :recycle: Removed unnecesary dependencies …
cylcrow Feb 24, 2021
e5c9eac
:bento: :wheelchair: :recycle: Added roles to each element
cylcrow Mar 1, 2021
4547dca
:white_check_mark: :recycle: :sparkles: Added theming prototype
Mar 4, 2021
436964f
:construction: :recycle: Added theme wrapper for testing purposes
Mar 5, 2021
991f0b5
:recycle: :building_construction: :construction: Components isolation
Mar 5, 2021
be967d3
:recycle: :sparkles: :wheelchair: :alembic: Added VideoCards
Mar 5, 2021
7ed4920
:recycle: :wheelchair: :construction: Improved accesibility for Card …
Mar 5, 2021
671b550
:sparkles: :fire: :truck: :recycle: :art: :bug: :white_check_mark: Ad…
Mar 8, 2021
233f180
:recycle: :art: :sparkles: :truck: Adding youtube playback iframe
Mar 8, 2021
0fb5003
:recycle: :bug: :sparkles: :white_check_mark: Added video player and …
Mar 8, 2021
c1c945a
:sparkles: :bug: :construction: Added VideoPlayer feature to return t…
Mar 8, 2021
d3123dc
:white_check_mark: :fire: :art: Added remaining tests for mini ch 3
Mar 16, 2021
510fd3a
:fire: :recycle: :white_check_mark: Removed unnecessary ThemeContext …
Mar 16, 2021
cb565b0
:recycle: :fire: :white_check_mark: Added reducer for App, removed un…
Mar 17, 2021
c7c7f5e
:fire: :white_check_mark: Updated properties names
Mar 17, 2021
bbf8b0d
:bug: :white_check_mark: Solved issues loading videos by id on iframe
Mar 17, 2021
56c3147
:art: :lipstick: :white_check_mark: Added test for theme behavior for…
Mar 18, 2021
bb045c2
:art: :lipstick: :white_check_mark: Added test for theme behavior for…
Mar 18, 2021
9fb8e46
:art: :lipstick: :white_check_mark: Added test for theme behavior for…
Mar 18, 2021
f3239a6
:recycle: :white_check_mark: :art: Added tests for youtube search ser…
Mar 18, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_YOUTUBE_KEY=AIzaSyDFnO9VgkkdOBvHDq4NtEStIng-fAkEkEY
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"plugins": ["prettier"],
"rules": {
"prettier/prettier": "error",
"react/jsx-filename-extension": "error",
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }],
"react-hooks/exhaustive-deps": "warn",
"import/no-unresolved": ["off", { "ignore": [".css$"] }],
"import/prefer-default-export": "off",
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
# misc
.DS_Store
.env.local
.env.development
.env.development.local
.env.test
.env.test.local
.env.production.local

Expand Down
16 changes: 15 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/dom": "^7.29.6",
"@testing-library/jest-dom": "^5.11.4",
"@testing-library/react": "^10.4.9",
"@testing-library/react-hooks": "^5.1.0",
"@testing-library/user-event": "^12.1.3",
"debounce": "^1.2.0",
"jest-styled-components": "6.0.0",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-scripts": "3.4.3"
"react-scripts": "3.4.3",
"react-test-renderer": "^17.0.1",
"styled-components": "4.4.1"
},
"scripts": {
"start": "react-scripts start",
Expand All @@ -21,6 +27,7 @@
"lint:fix": "eslint ./src --ext .js,.jsx --fix"
},
"devDependencies": {
"@sheerun/mutationobserver-shim": "^0.3.3",
"eslint-config-airbnb": "^18.2.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-eslint-comments": "^3.2.0",
Expand Down Expand Up @@ -57,5 +64,12 @@
"hooks": {
"pre-commit": "lint-staged"
}
},
"jest": {
"coveragePathIgnorePatterns": [
"src/utils/testing/helpers",
"src/utils/index.js",
"src/index.js"
]
}
}
13 changes: 13 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />

<script src="https://apis.google.com/js/api.js"></script>
<script>
gapi.load('client');
</script>
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
Expand All @@ -25,6 +30,14 @@
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');

tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
</script>
<div id="root"></div>
<!--
This HTML file is a template.
Expand Down
Binary file added src/assets/icons/default_user.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/icons/hamburguer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 0 additions & 58 deletions src/components/App/App.component.jsx

This file was deleted.

92 changes: 92 additions & 0 deletions src/components/App/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React, { useReducer } from 'react';
import styled from 'styled-components';
import { LayoutWrapper } from '../Layout';
import { appReducer } from '../../reducers/appReducer';
import { lightTheme, darkTheme } from '../../providers/themes';
import youtubeSearchService from '../../services/youtubeSearchService';
import VideoPlayerContainer from '../VideoPlayer/VideoPlayerContainer';
import AppContext from '../../providers/AppContext';
import HomeVideos from '../HomeVideos/HomeVideos';
import {
SET_CURRENT_VIDEO_PLAYBACK,
SET_IS_FIRST_LOAD,
SET_VIDEOS_LIST,
SWITCH_THEME
} from '../../reducers/actionTypes'

const StyledWelcome = styled.div`
text-align: center;
`;

const initialState = {
videosList: [],
currentVideoId: undefined,
isLightTheme: true,
isFirstLoad: true,
};

function App() {

const [{
videosList,
currentVideoId,
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;
while(!gapi || !gapi.client && counter < 10){
counter++;
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,
setHomeVideosView: () => dispatch({ type: SET_CURRENT_VIDEO_PLAYBACK, payload: null }),
playVideoById: (id) => dispatch({type: SET_CURRENT_VIDEO_PLAYBACK, payload: id})
}
}>
<LayoutWrapper>
{ currentVideoId ? (
<div data-testid="video-player-container">
<VideoPlayerContainer videoId={currentVideoId} />
</div>
) : (
<div>
<StyledWelcome>
<h1>Welcome to the challenge!</h1>
</StyledWelcome>
<HomeVideos />
</div>
)}
</LayoutWrapper>
</AppContext.Provider>
);
}

export default App;
95 changes: 95 additions & 0 deletions src/components/App/App.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import React from 'react';
import { fireEvent, getByRole, act, render } from '@testing-library/react';
import { darkTheme, lightTheme } from '../../providers/themes';
import { contextWrapper, googleMockedAPIObject, youtubeMockedData, YTMockedObject } from '../../utils';
import AppContext from '../../providers/AppContext';
import App from './index';
import { getAllByTestId, getByTestId } from '@testing-library/dom';

global.gapi = googleMockedAPIObject();
global.YT = YTMockedObject;

const for400Miliseconds = () => new Promise((resolve) => {
setTimeout(() => resolve(), 400)
})

const build = async (Component = <App />) => {
let container;
await act(async () => {
const wrapped = contextWrapper(AppContext, { videos: youtubeMockedData.items, theme: lightTheme }, 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 :/" legeng 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();
});

});
30 changes: 30 additions & 0 deletions src/components/App/App.test.jsx
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();
});
});
Loading