Browse Source

Merge pull request #989 from 01-edu/public-issues-01-673

fixing public issues
pull/1001/head
MSilva95 2 years ago committed by GitHub
parent
commit
862d8b9178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      dom/pick-and-click_test.js
  2. 8
      js/tests/is-winner_test.js
  3. 10
      js/tests/throttle_test.js
  4. 7
      subjects/is-winner/README.md
  5. 2
      subjects/keep-trying-or-giveup/README.md
  6. 1
      subjects/manipulate-values/README.md

36
dom/pick-and-click_test.js

@ -5,7 +5,7 @@ const between = (expected, min, max) => expected >= min && expected <= max
export const setup = async ({ page, rgbToHsl }) => { export const setup = async ({ page, rgbToHsl }) => {
return { return {
bodyBgRgb: async () => bodyBgRgb: async () =>
rgbToHsl(await page.$eval("body", (body) => body.style.background)), rgbToHsl(await page.$eval('body', (body) => body.style.background)),
} }
} }
@ -19,8 +19,8 @@ tests.push(async ({ page, eq }) => {
const x = move const x = move
const y = move * 2 const y = move * 2
await page.mouse.move(x, y) await page.mouse.move(x, y)
const bodyBg = await page.$eval("body", (body) => body.style.background) const bodyBg = await page.$eval('body', (body) => body.style.background)
const validColor = bodyBg.includes("rgb") const validColor = bodyBg.includes('rgb')
if (!validColor) continue if (!validColor) continue
bgs.push(bodyBg) bgs.push(bodyBg)
} }
@ -29,7 +29,7 @@ tests.push(async ({ page, eq }) => {
}) })
const near = (a, b) => a < b + 2.5 && a > b - 2.5 const near = (a, b) => a < b + 2.5 && a > b - 2.5
const numVal = (n) => n.textContent.replace(/[^0-9,]/g, "") const numVal = (n) => n.textContent.replace(/[^0-9,]/g, '')
const generateCoords = (random) => [ const generateCoords = (random) => [
[random(125, 500), random(125, 400)], [random(125, 500), random(125, 400)],
[random(125, 500), random(125, 400)], [random(125, 500), random(125, 400)],
@ -41,7 +41,7 @@ tests.push(async ({ page, eq, bodyBgRgb, random }) => {
for (const move of generateCoords(random)) { for (const move of generateCoords(random)) {
await page.mouse.move(...move) await page.mouse.move(...move)
const a = await bodyBgRgb() const a = await bodyBgRgb()
const b = (await page.$eval(".hsl", numVal)).split(",") const b = (await page.$eval('.hsl', numVal)).split(',')
if (a.every((v, i) => near(v, Number(b[i])))) continue if (a.every((v, i) => near(v, Number(b[i])))) continue
throw Error(`hsl(${a.map(Math.round)}) to far from hsl(${b})`) throw Error(`hsl(${a.map(Math.round)}) to far from hsl(${b})`)
} }
@ -52,7 +52,7 @@ tests.push(async ({ page, eq, bodyBgRgb, random }) => {
for (const move of generateCoords(random)) { for (const move of generateCoords(random)) {
await page.mouse.move(...move) await page.mouse.move(...move)
const [h] = await bodyBgRgb() const [h] = await bodyBgRgb()
const hue = await page.$eval(".hue", numVal) const hue = await page.$eval('.hue', numVal)
if (!near(h, Number(hue))) { if (!near(h, Number(hue))) {
console.log({ h, hue, c: near(h, Number(hue)) }) console.log({ h, hue, c: near(h, Number(hue)) })
@ -66,7 +66,7 @@ tests.push(async ({ page, eq, bodyBgRgb, random }) => {
for (const move of generateCoords(random)) { for (const move of generateCoords(random)) {
await page.mouse.move(...move) await page.mouse.move(...move)
const [, , l] = await bodyBgRgb() const [, , l] = await bodyBgRgb()
const lum = await page.$eval(".luminosity", numVal) const lum = await page.$eval('.luminosity', numVal)
if (!near(l, Number(lum))) { if (!near(l, Number(lum))) {
throw Error(`luminosity ${Math.round(l)} to far from ${lum}`) throw Error(`luminosity ${Math.round(l)} to far from ${lum}`)
@ -79,16 +79,16 @@ tests.push(async ({ page, eq, bodyBgRgb, random }) => {
for (const move of generateCoords(random)) { for (const move of generateCoords(random)) {
await page.evaluate(() => { await page.evaluate(() => {
let clipboardText = null let clipboardText = null
window.navigator.clipboard.readText = () => window.navigator.clipboard.readText = async () => clipboardText
new Promise((resolve) => resolve(clipboardText)) window.navigator.clipboard.writeText = async (text) => {
window.navigator.clipboard.writeText = (text) => clipboardText = text
new Promise(() => (clipboardText = text)) }
}) })
await page.mouse.click(...move) await page.mouse.click(...move)
const clipboard = await page.evaluate(() => const clipboard = await page.evaluate(() =>
window.navigator.clipboard.readText() window.navigator.clipboard.readText()
) )
const hslValue = await page.$eval(".hsl", (hsl) => hsl.textContent) const hslValue = await page.$eval('.hsl', (hsl) => hsl.textContent)
eq(hslValue, clipboard) eq(hslValue, clipboard)
} }
}) })
@ -97,13 +97,13 @@ tests.push(async ({ page, eq, bodyBgRgb, random }) => {
// check that each svg axis is following the mouse // check that each svg axis is following the mouse
const [[mouseX, mouseY]] = generateCoords(random) const [[mouseX, mouseY]] = generateCoords(random)
await page.mouse.move(mouseX, mouseY) await page.mouse.move(mouseX, mouseY)
const axisX = await page.$eval("#axisX", (line) => [ const axisX = await page.$eval('#axisX', (line) => [
line.getAttribute("x1"), line.getAttribute('x1'),
line.getAttribute("x2"), line.getAttribute('x2'),
]) ])
const axisY = await page.$eval("#axisY", (line) => [ const axisY = await page.$eval('#axisY', (line) => [
line.getAttribute("y1"), line.getAttribute('y1'),
line.getAttribute("y2"), line.getAttribute('y2'),
]) ])
const checkAxisCoords = (coords) => Number([...new Set(coords)].join()) const checkAxisCoords = (coords) => Number([...new Set(coords)].join())

8
js/tests/is-winner_test.js

@ -99,6 +99,14 @@ t(async ({ eq }) =>
) )
) )
t(async ({ eq }) =>
// testing France
eq(
await isWinner('France'),
'France is not what we are looking for because of the number of times it was champion'
)
)
t(async ({ eq, ctx }) => t(async ({ eq, ctx }) =>
// testing correct number of times and correct continent, for the fake country // testing correct number of times and correct continent, for the fake country
eq( eq(

10
js/tests/throttle_test.js

@ -1,7 +1,7 @@
export const tests = [] export const tests = []
const t = (f) => tests.push(f) const t = (f) => tests.push(f)
const add = (arr, el) => arr.push(el) const add = (arr, el) => arr?.push(el)
const run = (callback, callLimit, nbr) => const run = (callback, callLimit, nbr) =>
new Promise((r) => { new Promise((r) => {
let arr = [] let arr = []
@ -28,13 +28,13 @@ t(async ({ eq }) =>
) )
t(async ({ eq }) => t(async ({ eq }) =>
// it works concurently // it works concurrently
eq( eq(
await Promise.all([ await Promise.all([
run(throttle(add, 16), 26, 5), run(throttle(add, 16), 26, 6),
run(throttle(add, 16), 26, 5), run(throttle(add, 16), 26, 6),
]), ]),
[4, 4] [5, 5]
) )
) )

7
subjects/is-winner/README.md

@ -16,12 +16,13 @@ return a resolved Promise with the string:
- `<country> + ' won the FIFA World Cup in ' + <year(s)> + 'winning by ' + <results>`, otherwise. - `<country> + ' won the FIFA World Cup in ' + <year(s)> + 'winning by ' + <results>`, otherwise.
If the country was champion in more than one year, the years should be The years and results should be displayed like bellow:
displayed like : '1000, 1004, 1008'. The same goes for the results
```<country> + ' won the FIFA World Cup in 1000, 1004, 1008 winning by 4-3, 5-2, 1-0```
### Code provided ### Code provided
> all code provided will be added to your solution and doesn't need to be submited. > all code provided will be added to your solution and doesn't need to be submitted.
```js ```js
const db = (() => { const db = (() => {

2
subjects/keep-trying-or-giveup/README.md

@ -27,5 +27,5 @@ resolve before `delay` time has reached.
### Notions ### Notions
- [nan-academy.github.io/js-training/examples/promise.js](https://nan-academy.github.io/js-training/examples/promises.js) - [nan-academy.github.io/js-training/examples/promise.js](https://nan-academy.github.io/js-training/examples/promises.js)
- [devdocs.io/dom/windoworworkerglobalscope/settimeout](https://devdocs.io/dom/windoworworkerglobalscope/settimeout) - [devdocs.io/dom/settimeout]( https://devdocs.io/dom/settimeout)
- [devdocs.io/javascript/global_objects/promise/race](https://devdocs.io/javascript/global_objects/promise/race) - [devdocs.io/javascript/global_objects/promise/race](https://devdocs.io/javascript/global_objects/promise/race)

1
subjects/manipulate-values/README.md

@ -47,6 +47,7 @@ You will have a small database to help you with the groceries.
```js ```js
// small database with nutrition facts, per 100 grams // small database with nutrition facts, per 100 grams
// In this exercise this is used for testing purposes only
// prettier-ignore // prettier-ignore
const nutritionDB = { const nutritionDB = {
tomato: { calories: 18, protein: 0.9, carbs: 3.9, sugar: 2.6, fiber: 1.2, fat: 0.2 }, tomato: { calories: 18, protein: 0.9, carbs: 3.9, sugar: 2.6, fiber: 1.2, fat: 0.2 },

Loading…
Cancel
Save