-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
murillo wolf cavalheiro
authored and
murillo wolf cavalheiro
committed
Nov 3, 2021
1 parent
38be0d6
commit f88b371
Showing
22 changed files
with
1,040 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -1 +1,26 @@ | ||
# react-and-mocky | ||
# React and Mocky | ||
|
||
Nessa aplicação nós utilizamos a [API do Rick](https://rickandmortyapi.com/) and Morty para buscar os personagens. O endpoint utilizado é o `[https://rickandmortyapi.com/api/character](https://rickandmortyapi.com/api/character)` | ||
|
||
O objetivo é escrever os testes para a aplicação utilizando o RTL - React Testing Library. Todos os testes devem utilizar o `ByRole` | ||
|
||
|
||
### Setup para os testes | ||
|
||
***A primeira coisa que deve ser feita antes de escrever os testes, é realizar o mock da função fetch.*** | ||
|
||
Esse mock deve ser feito dentro do `beforeEach()` antes de chamar a função `render(<App/>)`. A resposta da API que vai ser mockada está dentro da pasta `/tests/mocks.js`. Basta importar o `responseAPI` e utilizar da maneira que achar necessário. | ||
|
||
|
||
|
||
### Teste 1 | ||
|
||
Verificar se ao renderizar o App aparece um card com um `h3` escrito "Rick Sanchez" dentro. | ||
|
||
### Teste 2 | ||
|
||
Verificar se ao renderizar o App está presente na tela o `input` de texto e o `button` com o texto "Buscar" | ||
|
||
### Teste 3 | ||
|
||
Verificar se ao buscar pelo nome "smith" aparecem 4 cards na tela. |
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,38 @@ | ||
{ | ||
"name": "react-and-mocky", | ||
"version": "0.1.0", | ||
"private": true, | ||
"dependencies": { | ||
"@testing-library/jest-dom": "^5.11.4", | ||
"@testing-library/react": "^11.1.0", | ||
"@testing-library/user-event": "^12.1.10", | ||
"react": "^17.0.2", | ||
"react-dom": "^17.0.2", | ||
"react-scripts": "4.0.3", | ||
"web-vitals": "^1.0.1" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"react-app", | ||
"react-app/jest" | ||
] | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
Binary file not shown.
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,43 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<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" /> | ||
<!-- | ||
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/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>React App</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> |
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 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,25 @@ | ||
{ | ||
"short_name": "React App", | ||
"name": "Create React App Sample", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
}, | ||
{ | ||
"src": "logo192.png", | ||
"type": "image/png", | ||
"sizes": "192x192" | ||
}, | ||
{ | ||
"src": "logo512.png", | ||
"type": "image/png", | ||
"sizes": "512x512" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
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,3 @@ | ||
# https://www.robotstxt.org/robotstxt.html | ||
User-agent: * | ||
Disallow: |
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,47 @@ | ||
*{ | ||
margin: 0; | ||
padding: 0; | ||
box-sizing: border-box; | ||
} | ||
|
||
html, body, #root { | ||
width: 100vw; | ||
height: 100vh; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
.App{ | ||
width: 100vw; | ||
height: 100vh; | ||
} | ||
|
||
input[type=text]{ | ||
padding: 1rem; | ||
width:70%; | ||
font-size: 14px !important; | ||
} | ||
button { | ||
background-color: #2d6a4f; | ||
width: 30%; | ||
padding: 1rem; | ||
color: white; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover{ | ||
background-color: #40916c; | ||
} | ||
|
||
.card-list{ | ||
width: 100%; | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-evenly; | ||
flex-wrap: wrap; | ||
} | ||
|
||
form { | ||
margin: 3rem auto 1rem auto; | ||
width: 50%; | ||
} |
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,56 @@ | ||
import React from 'react' | ||
import './App.css'; | ||
import CharacterCard from './components/CharacterCard'; | ||
import Loading from './components/Loading'; | ||
|
||
class App extends React.Component { | ||
constructor(props){ | ||
super(props); | ||
this.state={ | ||
characters:[], | ||
filteredCharacters:[], | ||
isLoading:true, | ||
search:'' | ||
} | ||
} | ||
getCharacters = async () => { | ||
const endpoint = 'https://rickandmortyapi.com/api/character'; | ||
const {results} = await fetch(endpoint).then(response => response.json()) | ||
this.setState({isLoading:false, characters:results, filteredCharacters:results}) | ||
} | ||
|
||
|
||
componentDidMount(){ | ||
this.getCharacters() | ||
} | ||
|
||
handleOnChange = ({target:{value}}) => { | ||
this.setState({search:value}) | ||
} | ||
|
||
handleFilterCharacters = () => { | ||
const { characters, search} = this.state; | ||
const filteredArray = characters.filter(({name})=> name.toUpperCase().includes(search.toUpperCase())) | ||
this.setState({filteredCharacters:filteredArray}) | ||
} | ||
|
||
render(){ | ||
const {filteredCharacters, isLoading} = this.state | ||
return ( | ||
<div className="App"> | ||
<form> | ||
<input type='text' placeholder='Rick Sanches...' onChange={this.handleOnChange}/> | ||
<button type='button' onClick={this.handleFilterCharacters}>Buscar</button> | ||
</form> | ||
{ | ||
isLoading ? <Loading/> : | ||
<section className='card-list'> | ||
{filteredCharacters.map(item=> <CharacterCard character={item} key={Math.random()} />)} | ||
</section> | ||
} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
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,15 @@ | ||
import React from 'react' | ||
import './styles.css' | ||
class CharacterCard extends React.Component { | ||
render(){ | ||
const { character : {name, image, status}} = this.props | ||
return( | ||
<article className='card'> | ||
<img alt={name} src={image} /> | ||
<h3 className='card-name'>{name}</h3> | ||
<p className='card-status'>{status}</p> | ||
</article> | ||
) | ||
} | ||
} | ||
export default CharacterCard; |
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,11 @@ | ||
.card{ | ||
max-width: 350px; | ||
width: 100%; | ||
margin: 2rem 0; | ||
|
||
} | ||
|
||
.card-name{ | ||
color:#2d6a4f; | ||
|
||
} |
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,10 @@ | ||
import React from 'react' | ||
import './styles.css' | ||
class Loading extends React.Component{ | ||
render(){ | ||
return( | ||
<h3 className='loading'>Carregando...</h3> | ||
) | ||
} | ||
} | ||
export default Loading |
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,3 @@ | ||
.loading { | ||
|
||
} |
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,13 @@ | ||
body { | ||
margin: 0; | ||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', | ||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', | ||
sans-serif; | ||
-webkit-font-smoothing: antialiased; | ||
-moz-osx-font-smoothing: grayscale; | ||
} | ||
|
||
code { | ||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', | ||
monospace; | ||
} |
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,17 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import './index.css'; | ||
import App from './App'; | ||
import reportWebVitals from './reportWebVitals'; | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
document.getElementById('root') | ||
); | ||
|
||
// If you want to start measuring performance in your app, pass a function | ||
// to log results (for example: reportWebVitals(console.log)) | ||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals | ||
reportWebVitals(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,13 @@ | ||
const reportWebVitals = onPerfEntry => { | ||
if (onPerfEntry && onPerfEntry instanceof Function) { | ||
import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { | ||
getCLS(onPerfEntry); | ||
getFID(onPerfEntry); | ||
getFCP(onPerfEntry); | ||
getLCP(onPerfEntry); | ||
getTTFB(onPerfEntry); | ||
}); | ||
} | ||
}; | ||
|
||
export default reportWebVitals; |
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,5 @@ | ||
// jest-dom adds custom jest matchers for asserting on DOM nodes. | ||
// allows you to do things like: | ||
// expect(element).toHaveTextContent(/react/i) | ||
// learn more: https://github.com/testing-library/jest-dom | ||
import '@testing-library/jest-dom'; |
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,18 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import App from '../App'; | ||
|
||
describe('Test Rick & Morty API', () => { | ||
|
||
test('Verifica se aparece o card com titulo de "Rick Sanchez"', () => { | ||
|
||
}) | ||
|
||
test('Verifica se existem o input de texto e o botão "Buscar"', () => { | ||
|
||
}) | ||
|
||
test('Verifica se ao buscar por "Smith" aparecem 4 cards', () => { | ||
|
||
}) | ||
|
||
}) |
Oops, something went wrong.