forked from wizeline/react-certification-2020
-
Notifications
You must be signed in to change notification settings - Fork 73
Mini-Challenge 2: Intro to Testing #27
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
Open
Fetrelo
wants to merge
5
commits into
erickwize:master
Choose a base branch
from
Fetrelo:development
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
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a39400e
Initial changes. Components that will not be used for the first deliv…
Fetrelo 19de3c8
Challenge 1: UI Header and video list are getting rendered as expecte…
Fetrelo b938b4e
Added responsiveness to the page. Changed Dark mode legend into emojis
Fetrelo 2d08e15
Tests have been added
Fetrelo 5dd51e6
Refactorized code, after first and second deliverable
Fetrelo 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 hidden or 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 hidden or 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 hidden or 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,3 @@ | ||
| module.exports = { | ||
| presets: ['@babel/preset-env', '@babel/preset-react'], | ||
| }; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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,39 @@ | ||
| import React from 'react'; | ||
| import '@testing-library/jest-dom'; | ||
| import {cleanup, render, screen} from '@testing-library/react'; | ||
| import HomePage from "../pages/Home/Home.page"; | ||
| import youtubeVideos from "../mocks/youtube-videos"; | ||
|
|
||
| describe('Home page Tests', () => { | ||
| afterEach(cleanup); | ||
|
|
||
| describe('Ensure elements get rendered', () => { | ||
| it('Title', () => { | ||
| render(<HomePage />); | ||
| expect(screen.getByText(/YouTube video search app/, {selector: 'h1'})).toBeInTheDocument(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer to use |
||
| }); | ||
| }); | ||
|
|
||
| describe('Ensure there the info from the mock is being shown', () => { | ||
| it("A random video's information will be displayed if it has videoid", () => { | ||
| render(<HomePage />); | ||
| const randVideoIdx = Math.floor((Math.random() * youtubeVideos.items.length)); | ||
| const randomVideo = youtubeVideos.items[randVideoIdx]; | ||
|
|
||
| if(randomVideo.id.videoId) | ||
| expect(screen.getByTestId(randomVideo.etag)).toBeInTheDocument(); | ||
| else | ||
| expect(screen.getByTestId(randomVideo.etag)).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('A video that does not have any description, must show channel title followed by a hypen', () => { | ||
| // render(<HomePage />); | ||
|
Fetrelo marked this conversation as resolved.
Outdated
|
||
| // const videoWithDescription = youtubeVideos.items[2]; | ||
| // if(videoWithDescription.snippet.description === '') | ||
| // expect(screen.getByText('Wizeline -')).toBeInTheDocument(); | ||
| // else | ||
| // expect(screen.getByText('Wizeline -')).toBeInTheDocument(); | ||
| // There must be a way... Right now I'm short of time... | ||
| }); | ||
| }); | ||
| }); | ||
This file contains hidden or 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,70 @@ | ||
| import React from 'react'; | ||
| import '@testing-library/jest-dom'; | ||
| import {cleanup, fireEvent, render, screen} from '@testing-library/react'; | ||
| import Toggle from '../components/CustomInputs/Toggle'; | ||
| import Nav from '../components/Nav'; | ||
|
|
||
| describe('Nav tests', () => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could write fewer, longer tests. |
||
| afterEach(cleanup); | ||
|
|
||
| describe('Ensure components get rendered', () => { | ||
| it('Nav Header Wrapper', () => { | ||
| render(<Nav />); | ||
| expect(screen.getByTestId('homepage')).toBeInTheDocument(); | ||
|
Fetrelo marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| it('Left Nav Wrapper', () => { | ||
| render(<Nav />); | ||
| expect(screen.getByTestId('leftNav')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('Hamburger Menu Icon', () => { | ||
| render(<Nav />); | ||
| expect(screen.getByTestId('hamburger')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('Search Input', () => { | ||
| render(<Nav />); | ||
| expect(screen.getByTestId('searchTextWrapper')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('Right Nav Wrapper', () => { | ||
| render(<Nav />); | ||
| expect(screen.getByTestId('rightNav')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('Dark mode toggle', () => { | ||
| render(<Nav />); | ||
| expect(screen.getByTestId('toggleDarkMode')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('Login Button', () => { | ||
| render(<Nav />); | ||
| expect(screen.getByTestId('loginBtn')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Toggle component check', () => { | ||
| it('Toggle label onChange', () => { | ||
| const {queryByLabelText, getByLabelText} = render( | ||
| <Toggle labelOn="🌙" labelOff="☀️" /> | ||
| ); | ||
|
|
||
| expect(queryByLabelText(/☀️/i)).toBeTruthy(); | ||
| fireEvent.click(getByLabelText(/☀️/i)); | ||
| expect(queryByLabelText(/🌙/i)).toBeTruthy(); | ||
| }); | ||
|
|
||
| // it('Toggle UI changes when user clicks on it', () => { | ||
| // const {getByLabelText} = render(<Toggle labelOn="🌙" labelOff="☀️" />); | ||
| // expect(toJSON()).toMatchSnapshot(); | ||
|
|
||
| // fireEvent.click(getByLabelText(/☀️/i)); | ||
| // expect(toJSON()).toMatchSnapshot(); | ||
|
|
||
| // fireEvent.click(getByLabelText(/🌙/i)); | ||
| // expect(toJSON()).toMatchSnapshot(); | ||
| // }); | ||
| }); | ||
|
|
||
| }); | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,58 +1,8 @@ | ||
| import React, { useLayoutEffect } from 'react'; | ||
| import { BrowserRouter, Switch, Route } from 'react-router-dom'; | ||
|
|
||
| import AuthProvider from '../../providers/Auth'; | ||
| import React from 'react'; | ||
| import HomePage from '../../pages/Home'; | ||
| import LoginPage from '../../pages/Login'; | ||
| import NotFound from '../../pages/NotFound'; | ||
| import SecretPage from '../../pages/Secret'; | ||
| import Private from '../Private'; | ||
| import Fortune from '../Fortune'; | ||
| import Layout from '../Layout'; | ||
| import { random } from '../../utils/fns'; | ||
|
|
||
| function App() { | ||
| useLayoutEffect(() => { | ||
| const { body } = document; | ||
|
|
||
| function rotateBackground() { | ||
| const xPercent = random(100); | ||
| const yPercent = random(100); | ||
| body.style.setProperty('--bg-position', `${xPercent}% ${yPercent}%`); | ||
| } | ||
|
|
||
| const intervalId = setInterval(rotateBackground, 3000); | ||
| body.addEventListener('click', rotateBackground); | ||
|
|
||
| return () => { | ||
| clearInterval(intervalId); | ||
| body.removeEventListener('click', rotateBackground); | ||
| }; | ||
| }, []); | ||
|
|
||
| return ( | ||
| <BrowserRouter> | ||
| <AuthProvider> | ||
| <Layout> | ||
| <Switch> | ||
| <Route exact path="/"> | ||
| <HomePage /> | ||
| </Route> | ||
| <Route exact path="/login"> | ||
| <LoginPage /> | ||
| </Route> | ||
| <Private exact path="/secret"> | ||
| <SecretPage /> | ||
| </Private> | ||
| <Route path="*"> | ||
| <NotFound /> | ||
| </Route> | ||
| </Switch> | ||
| <Fortune /> | ||
| </Layout> | ||
| </AuthProvider> | ||
| </BrowserRouter> | ||
| ); | ||
| return <HomePage />; | ||
| } | ||
|
|
||
| export default App; |
This file contains hidden or 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,71 @@ | ||
| import React from 'react'; | ||
| import styled from 'styled-components'; | ||
|
|
||
| const InputTextIcon = ({ path }) => { | ||
| return ( | ||
| <Wrapper data-testid="searchTextWrapper"> | ||
| <SvgWrapper> | ||
| <StyledSvg focusable="false" viewBox="0 0 24 24"> | ||
| {path || ( | ||
| <path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" /> | ||
| )} | ||
| </StyledSvg> | ||
| </SvgWrapper> | ||
| <InputWrapper> | ||
| <StyledInputText /> | ||
| </InputWrapper> | ||
| </Wrapper> | ||
| ); | ||
| }; | ||
|
|
||
| export default InputTextIcon; | ||
|
|
||
| const Wrapper = styled.div` | ||
| position: relative; | ||
| background-color: #bebebe; | ||
| margin: 0% 3%; | ||
| border-radius: 25px; | ||
| @media screen and (max-width: 280px) { | ||
| width: 65%; | ||
| } | ||
| `; | ||
|
|
||
| const SvgWrapper = styled.div` | ||
| height: 100%; | ||
| display: flex; | ||
| padding: 0px 8px; | ||
| position: absolute; | ||
| align-items: center; | ||
| pointer-events: none; | ||
| justify-content: center; | ||
| `; | ||
|
|
||
| const StyledSvg = styled.svg` | ||
| fill: #525252; | ||
| width: 1em; | ||
| height: 1em; | ||
| display: inline-block; | ||
| font-size: 1.5rem; | ||
| transition: fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms; | ||
| flex-shrink: 0; | ||
| user-select: none; | ||
| `; | ||
|
|
||
| const InputWrapper = styled.div` | ||
| display: inline-flex; | ||
| position: relative; | ||
| align-items: center; | ||
| `; | ||
|
|
||
| const StyledInputText = styled.input` | ||
| width: 95%; | ||
| padding: 8px 5px; | ||
| font-size: 1em; | ||
| padding-left: calc(1em + 25px); | ||
| border: none; | ||
| background-color: transparent; | ||
| color: #424242; | ||
| &:focus { | ||
| outline: none; | ||
| } | ||
| `; |
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.
Uh oh!
There was an error while loading. Please reload this page.