forked from wizeline/react-certification-2020
-
Notifications
You must be signed in to change notification settings - Fork 52
Mini challenge 2 #33
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
j-polanco
wants to merge
9
commits into
wdonet:master
Choose a base branch
from
j-polanco:Mini-Challenge-2
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 challenge 2 #33
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
51ee033
- Remove unnecessary code
2d25e0f
- sync changes
1587d0d
- add generic components
443412c
- add unit testing to the components
bfbcf9b
Revert "- add unit testing to the components"
107d429
fix export
7d289d0
- wrap HomeSection component inside a div
ffaae0e
- add testing files
b6f7f89
update package json to add test:coveraje script
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "trailingComma": "es5", | ||
| "tabWidth": 2, | ||
| "tabWidth": 4, | ||
| "printWidth": 90, | ||
| "semi": true, | ||
| "singleQuote": true, | ||
|
|
||
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 |
|---|---|---|
| @@ -1,58 +1,41 @@ | ||
| import React, { useLayoutEffect } from 'react'; | ||
| import { BrowserRouter, Switch, Route } from 'react-router-dom'; | ||
|
|
||
| import AuthProvider from '../../providers/Auth'; | ||
| import React, { useState } from 'react'; | ||
| import { ThemeProvider, createGlobalStyle } from 'styled-components'; | ||
| 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'; | ||
| import Button from '../Button'; | ||
|
|
||
| function App() { | ||
| useLayoutEffect(() => { | ||
| const { body } = document; | ||
| const lightTheme = { | ||
| bg: '#fff', | ||
| text: '#121212', | ||
| }; | ||
|
|
||
| function rotateBackground() { | ||
| const xPercent = random(100); | ||
| const yPercent = random(100); | ||
| body.style.setProperty('--bg-position', `${xPercent}% ${yPercent}%`); | ||
| } | ||
| const darkTheme = { | ||
| bg: '#121212', | ||
| text: '#fff', | ||
| }; | ||
|
|
||
| const intervalId = setInterval(rotateBackground, 3000); | ||
| body.addEventListener('click', rotateBackground); | ||
| const GlobalStyles = createGlobalStyle`body{ | ||
| color: ${(props) => props.theme.text}; | ||
| background-color: ${(props) => props.theme.bg}; | ||
| transition: 0.5s; | ||
| }`; | ||
|
|
||
| return () => { | ||
| clearInterval(intervalId); | ||
| body.removeEventListener('click', rotateBackground); | ||
| }; | ||
| }, []); | ||
| function App() { | ||
| const [mode, setMode] = useState('light'); | ||
|
|
||
| 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 ( | ||
| <ThemeProvider theme={mode === 'light' ? lightTheme : darkTheme}> | ||
| <GlobalStyles /> | ||
| <Button | ||
| size="10px" | ||
| onClick={() => setMode(mode === 'light' ? 'dark' : 'light')} | ||
| > | ||
| Change Theme | ||
| </Button> | ||
| <div id="home-section"> | ||
| <HomePage /> | ||
| </div> | ||
| </ThemeProvider> | ||
| ); | ||
| } | ||
|
|
||
| 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,15 @@ | ||
| import React from 'react'; | ||
| import { render, screen, queryByAttribute } from '@testing-library/react'; | ||
| import App from '.'; | ||
|
|
||
| describe('App Component tests', () => { | ||
| it('App Contains change theme defined', () => { | ||
| render(<App />); | ||
| expect(screen.getByText('Change Theme')).toBeDefined(); | ||
| }); | ||
| it('App Contains home section defined', () => { | ||
| const getById = queryByAttribute.bind(null, 'id'); | ||
| const dom = render(<App />); | ||
| expect(getById(dom.container, 'home-section')).toBeDefined(); | ||
| }); | ||
| }); |
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,11 @@ | ||
| import styled from 'styled-components'; | ||
|
|
||
| const Button = styled.button` | ||
| background: transparent; | ||
| border: none; | ||
| font-size: ${(props) => props.size}; | ||
| cursor: pointer; | ||
| color: #919191; | ||
| `; | ||
|
|
||
| export default Button; |
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 @@ | ||
| export { default } from './Button'; |
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,14 @@ | ||
| import React from 'react'; | ||
|
|
||
| const Emoji = (props) => ( | ||
| <span | ||
| className="emoji" | ||
| role="img" | ||
| aria-label={props.label ? props.label : ''} | ||
| aria-hidden={props.label ? 'false' : 'true'} | ||
| > | ||
| {props.symbol} | ||
| </span> | ||
| ); | ||
|
|
||
| export default Emoji; |
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,14 @@ | ||
| import React from 'react'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import Emoji from '.'; | ||
|
|
||
| describe('Emoji Component tests', () => { | ||
| it('Emoji span Contains the right emoji', () => { | ||
| render(<Emoji symbol="👍" />); | ||
| expect(screen.getByText('👍')).toBeDefined(); | ||
| }); | ||
| it('Emoji span shoul be span', () => { | ||
| render(<Emoji symbol="👍" />); | ||
| expect(screen.getByText('👍').tagName).toBe('SPAN'); | ||
| }); | ||
| }); |
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 @@ | ||
| export { default } from './Emoji'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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.
Nice use of the APIs!