-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
97800fa
commit 8b6222b
Showing
16 changed files
with
3,702 additions
and
0 deletions.
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 @@ | ||
node_modules/ |
3 changes: 3 additions & 0 deletions
3
front-end/bloco-10-introducao-a-react/dia-1-hello-world-react/praticas/pratica1.js
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 @@ | ||
// Para fixar, crie um elemento JSX que recebe o valor "Hello, JSX" de uma constante chamada textJSX , e o incorpore em uma tag h1 . | ||
|
||
const textJSX = <h1>Hello, JSX</h1> |
32 changes: 32 additions & 0 deletions
32
...co-9-javascript-e-testes-assincronos/dia-1-javascript-assincrono/exercicios/exercicio1.js
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,32 @@ | ||
// 1 - Dado o código abaixo, qual a ordem de finalização de execução das linhas comentadas? | ||
|
||
const planetDistanceFromSun = ({ name, distanceFromSun: { value, measurementUnit } }) => | ||
`${name} is ${value} ${measurementUnit} apart from the Sun`; | ||
|
||
const mars = { | ||
name: "Mars", | ||
distanceFromSun: { | ||
value: 227900000, | ||
measurementUnit: "kilometers", | ||
}, | ||
}; | ||
|
||
const venus = { | ||
name: "Venus", | ||
distanceFromSun: { | ||
value: 108200000, | ||
measurementUnit: "kilometers", | ||
}, | ||
}; | ||
|
||
const jupiter = { | ||
name: "Jupiter", | ||
distanceFromSun: { | ||
value: 778500000, | ||
measurementUnit: "kilometers", | ||
}, | ||
}; | ||
|
||
console.log(planetDistanceFromSun(mars)); // A | ||
console.log(planetDistanceFromSun(venus)); // B | ||
console.log(planetDistanceFromSun(jupiter)); // C |
43 changes: 43 additions & 0 deletions
43
...oco-9-javascript-e-testes-assincronos/dia-1-javascript-assincrono/praticas /Assincrono.js
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 @@ | ||
setTimeout(() => { | ||
console.log('Comprar parafusos') // Comprar parafusos | ||
console.log('Adicionar ao estoque') // Adicionar ao estoque | ||
}, 2000); | ||
|
||
console.log('1 - Receber roda'); // 1 - Receber roda | ||
console.log('2 - Encaixar parafusos'); // 2 - Encaixar parafusos | ||
console.log('3 - Fixar roda no carro'); // 3 - Fixar roda no carro | ||
|
||
// Exemplo 2 | ||
// sem timeout | ||
|
||
const pushNumber = (list, number) => list.push(number); | ||
|
||
let numbers = []; | ||
|
||
pushNumber(numbers, 1); | ||
pushNumber(numbers, 2); | ||
pushNumber(numbers, 3); | ||
|
||
console.log(numbers); | ||
|
||
// com timeout | ||
const pushNumber = (list, number) => list.push(number); | ||
|
||
let numbers = []; | ||
|
||
setTimeout(() => pushNumber(numbers, 1), 3000); | ||
pushNumber(numbers, 2); | ||
pushNumber(numbers, 3); | ||
|
||
console.log(numbers); // O retorno é [2, 3] | ||
|
||
// | ||
const pushNumber = (list, number) => list.push(number); | ||
|
||
let numbers = []; | ||
|
||
setTimeout(() => pushNumber(numbers, 1), 3000); | ||
pushNumber(numbers, 2); | ||
pushNumber(numbers, 3); | ||
|
||
setTimeout(() => console.log(numbers), 3000); |
22 changes: 22 additions & 0 deletions
22
...oco-9-javascript-e-testes-assincronos/dia-1-javascript-assincrono/praticas /Callback-2.js
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 @@ | ||
|
||
|
||
const userFullName = ({ firstName, lastName }) => `Hello! My name is ${firstName} ${lastName}`; | ||
const userNationality = ({ firstName, nationality }) => `${firstName} is ${nationality}`; | ||
|
||
const delay = (maxMilliseconds = 5000) => Math.floor(Math.random() * maxMilliseconds); | ||
|
||
const getUser = (callback) => { | ||
setTimeout(() => { | ||
const user = { | ||
firstName: "Ivan", | ||
lastName: "Ivanovich", | ||
nationality: "Russian", | ||
}; | ||
// Retorne a `callback` passada como parâmetro na função `getUser` | ||
// Dica: você pode manter o `console.log()` | ||
console.log(callback(user)); | ||
}, delay()); | ||
}; | ||
|
||
getUser(userFullName); // deve imprimir "Hello! My name is Ivan Ivanovich" depois de um certo tempo | ||
getUser(userNationality); // deve imprimir "Ivan is Russian" depois de um certo tempo |
31 changes: 31 additions & 0 deletions
31
...os/bloco-9-javascript-e-testes-assincronos/dia-1-javascript-assincrono/praticas /Erros.js
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,31 @@ | ||
// 1 - Adicione uma callback e trate o erro retornado. | ||
|
||
const countryName = ({ name }) => console.log(`Returned country is ${name}`); | ||
const countryCurrency = ({ name, currency }) => console.log(`${name}'s currency is the ${currency}`); | ||
|
||
const delay = (maxMilliseconds = 5000) => Math.floor(Math.random() * maxMilliseconds); | ||
|
||
const printErrorMessage = (error) => console.log(`Error getting country: ${error}`); | ||
|
||
const getCountry = (onSuccess, onError) => { | ||
setTimeout(() => { | ||
const didOperationSucceed = Math.random() >= 0.5; | ||
if(didOperationSucceed) { | ||
const country = { | ||
name: "Brazil", | ||
hdi: 0.759, | ||
currency: "Real", | ||
}; | ||
onSuccess(country); | ||
} else { | ||
const errorMessage = "Country could not be found"; | ||
onError(errorMessage); | ||
} | ||
}, delay()); | ||
}; | ||
|
||
// Deve imprimir "Returned country is Brazil" no sucesso ou "Error getting country: Country could not be found" em caso de falha | ||
getCountry(countryName, printErrorMessage); | ||
|
||
// Deve imprimir "Brazil's currency is the Real" no sucesso, ou "Error getting country: Country could not be found" em caso de falha | ||
getCountry(countryCurrency, printErrorMessage); |
76 changes: 76 additions & 0 deletions
76
...vascript-e-testes-assincronos/dia-1-javascript-assincrono/praticas /SetupTeardown.test.js
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,76 @@ | ||
/* // cicles.test.js | ||
// array cities | ||
let cities = []; | ||
// adiciona cidades | ||
const addCity = (city) => { | ||
cities.push(city); | ||
}; | ||
// remove cidades | ||
const removeCity = (city) => { | ||
cities = cities.filter((eachCity) => eachCity !== city); | ||
}; | ||
test('Testa a função addCity', () => { | ||
expect.assertions(4); | ||
addCity('Campinas'); | ||
addCity('Goiania'); | ||
addCity('Recife'); | ||
expect(cities).toHaveLength(3); | ||
expect(cities).toContain('Campinas'); | ||
expect(cities).toContain('Goiania'); | ||
expect(cities).toContain('Recife'); | ||
}); | ||
test('Testa a função removeCity', () => { | ||
expect.assertions(4); | ||
removeCity('Campinas'); | ||
expect(cities).toHaveLength(2); | ||
expect(cities).not.toContain('Campinas'); | ||
expect(cities).toContain('Goiania'); | ||
expect(cities).toContain('Recife'); | ||
}); */ | ||
|
||
// ----------------------------------------- | ||
// Utilizando setup e teardown | ||
|
||
// cicles.test.js | ||
|
||
// let cities = []; | ||
|
||
// const addCity = (city) => { | ||
// cities.push(city); | ||
// }; | ||
|
||
// const removeCity = (city) => { | ||
// cities = cities.filter((eachCity) => eachCity !== city); | ||
// }; | ||
|
||
//setup | ||
beforeEach(() => { | ||
cities = ['Pindamonhangaba']; // configura o valor do array pra sempre ter essa cidade | ||
}); | ||
|
||
//teardown | ||
afterEach(() => { | ||
cities = []; // faz a limpeza dos dados do nosso array | ||
}); | ||
|
||
test('Testa a função addCity utilizando o beforeEach', () => { | ||
expect.assertions(3); | ||
addCity('Piraporinha'); | ||
expect(cities).toHaveLength(2); | ||
expect(cities).toContain('Pindamonhangaba'); | ||
expect(cities).toContain('Piraporinha'); | ||
}); | ||
|
||
test('Testa a função removeCity utilizando o beforeEach', () => { | ||
expect.assertions(2); | ||
removeCity('Pindamonhangaba'); | ||
expect(cities).not.toContain('Pindamonhangaba'); | ||
expect(cities).toHaveLength(0); | ||
}); | ||
|
||
|
60 changes: 60 additions & 0 deletions
60
...ascript-e-testes-assincronos/dia-1-javascript-assincrono/praticas /SetupTeardown2.test.js
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,60 @@ | ||
// cicles.test.js | ||
|
||
let cities = []; | ||
|
||
const addCity = (city) => { | ||
cities.push(city); | ||
}; | ||
|
||
const removeCity = (city) => { | ||
cities = cities.filter((eachCity) => eachCity !== city); | ||
}; | ||
|
||
describe('Agrupa o primeiro bloco de testes', () => { | ||
beforeEach(() => { | ||
cities = ['Pindamonhangaba']; | ||
}); | ||
|
||
afterEach(() => { | ||
cities = []; | ||
}); | ||
|
||
test('Testa a função addCity dentro do primeiro bloco de testes', () => { | ||
expect.assertions(3); | ||
addCity('Piraporinha'); | ||
expect(cities).toHaveLength(2); | ||
expect(cities).toContain('Pindamonhangaba'); | ||
expect(cities).toContain('Piraporinha'); | ||
}); | ||
|
||
test('Testa a função removeCity dentro do primeiro bloco de testes', () => { | ||
expect.assertions(2); | ||
removeCity('Pindamonhangaba'); | ||
expect(cities).not.toContain('Pindamonhangaba'); | ||
expect(cities).toHaveLength(0); | ||
}); | ||
}); | ||
|
||
describe('Agrupa o segundo bloco de testes', () => { | ||
beforeEach(() => { | ||
cities = ['Tangamandapio']; | ||
}); | ||
|
||
afterEach(() => { | ||
cities = []; | ||
}); | ||
|
||
test('Testa a função addCity dentro do segundo bloco de testes', () => { | ||
expect.assertions(3); | ||
expect(cities).toHaveLength(1); | ||
expect(cities).not.toContain('Pindamonhangaba'); | ||
expect(cities).toContain('Tangamandapio'); | ||
}); | ||
|
||
test('Testa a função removeCity dentro do segundo bloco de testes', () => { | ||
expect.assertions(2); | ||
removeCity('Tangamandapio'); | ||
expect(cities).not.toContain('Pindamonhangaba'); | ||
expect(cities).toHaveLength(0); | ||
}); | ||
}); |
91 changes: 91 additions & 0 deletions
91
...bloco-9-javascript-e-testes-assincronos/dia-1-javascript-assincrono/praticas /callback.js
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,91 @@ | ||
// Declaramos nossa variável de despesas | ||
const despesas = [ | ||
{ | ||
gym: 99, | ||
}, | ||
{ | ||
ifood: 200, | ||
}, | ||
{ | ||
phone: 60, | ||
}, | ||
{ | ||
internet: 100, | ||
}, | ||
]; | ||
|
||
// Declaramos nossa renda | ||
const renda = 1000; | ||
|
||
const despesaMensal = (renda, despesas, callback) => { | ||
// Definimos que a despesa total é igual ao valor retornado pela função callback (que é o parâmetro da nossa função) | ||
// que vai receber nosso parâmetro/variável "despesas" | ||
const despesaTotal = callback(despesas); | ||
// Definimos nosso saldo final, que é nossa renda - nossa despesa total | ||
const saldoFinal = renda - despesaTotal; | ||
|
||
console.log(`Balanço do mês: | ||
Recebido: R$${renda},00 | ||
Gasto: R$${despesaTotal},00 | ||
Saldo: R$${saldoFinal},00 `); | ||
}; | ||
|
||
// Definimos nossa função que será passada como parâmetro | ||
// essa função recebe o parâmetro despesas a partir da função principal despesaMensal | ||
const somaDespesas = (despesas) => { | ||
// Separamos cada item do nosso array de despesas | ||
// e fazemos um reduce para somar os valores | ||
const custoItem = despesas.map((item) => Object.values(item)); | ||
const despesaTotal = custoItem.reduce((acc, curr) => acc += curr[0], 0); | ||
return despesaTotal; | ||
}; | ||
|
||
// Executamos a função principal com as variáveis renda, despesas | ||
// e a nossa função somaDespesas | ||
// callback = somaDespesas | ||
despesaMensal(renda, despesas, somaDespesas); | ||
|
||
// Balanço do mês: | ||
// Recebido: R$1000,00 | ||
// Gasto: R$459,00 | ||
// Saldo: R$541,00 | ||
|
||
// Para fixar ----- | ||
|
||
// Exemplo: | ||
/* // Definição da função userFullName | ||
const userFullName = ({ firstName, lastName }) => `Hello! My name is ${firstName} ${lastName}`; | ||
// Definição da função getUser | ||
const getUser = (param) => { | ||
const userToReturn = { | ||
firstName: "Ivan", | ||
lastName: "Ivanovich", | ||
nationality: "Russian" | ||
}; | ||
// Retornamos nosso parâmetro, que será uma função (callback) | ||
return param(userToReturn); | ||
}; | ||
// Chamada/execução da função getUser, que vai receber como parâmetro nossa função userFullName. | ||
getUser(userFullName); */ | ||
|
||
// ---------------------------------------- | ||
|
||
// 1 - Adicione uma callback como parâmetro da funcão getUser . | ||
|
||
const userFullName = ({ firstName, lastName }) => `Hello! My name is ${firstName} ${lastName}`; | ||
const userNationality = ({ firstName, nationality }) => `${firstName} is ${nationality}`; | ||
|
||
const getUser = (callback) => { | ||
const userToReturn = { | ||
firstName: "Ivan", | ||
lastName: "Ivanovich", | ||
nationality: "Russian" | ||
}; | ||
// Insira o retorno da função `getUser` | ||
return callback(userToReturn); | ||
}; | ||
|
||
console.log(getUser(userFullName)); // complete a chamada da função getUser de modo que o retorno seja: "Hello! My name is Ivan Ivanovich" | ||
console.log(getUser(userNationality)); // complete a chamada da função getUser de modo que o retorno seja: "Ivan is Russian" |
Oops, something went wrong.