mirror of https://github.com/01-edu/public.git
2 changed files with 55 additions and 1 deletions
@ -0,0 +1,54 @@
|
||||
export const tests = [] |
||||
|
||||
export const setup = async ({ page }) => ({ |
||||
getNotes: async () => |
||||
await page.$$eval('.note', (nodes) => { |
||||
return nodes.map((note) => note.textContent) |
||||
}), |
||||
getNotesBg: async () => |
||||
await page.$$eval('.note', (nodes) => { |
||||
return nodes.map((note) => note.style.background) |
||||
}), |
||||
}) |
||||
|
||||
const characters = `did you handle the keydown event correctly ?` |
||||
|
||||
tests.push(async ({ page, eq, getNotes }) => { |
||||
// check that a note is created and matches the right letter when a key is pressed
|
||||
for (const [i, character] of characters.split('').entries()) { |
||||
await page.keyboard.down(character) |
||||
const typed = characters.slice(0, i + 1).split('') |
||||
eq(await getNotes(), typed) |
||||
} |
||||
}) |
||||
|
||||
tests.push(async ({ page, eq, getNotes }) => { |
||||
// check that the last note is removed when Backspace key is pressed
|
||||
let step = 1 |
||||
while (step < 10) { |
||||
await page.keyboard.down('Backspace') |
||||
const typed = characters.slice(0, characters.length - step).split('') |
||||
eq(await getNotes(), typed) |
||||
step++ |
||||
} |
||||
}) |
||||
|
||||
tests.push(async ({ page, eq, getNotes }) => { |
||||
// check that all the notes are cleared when Escape key is pressed
|
||||
await page.keyboard.down('Escape') |
||||
const cleared = (await getNotes()).length === 0 |
||||
eq(await cleared, true) |
||||
}) |
||||
|
||||
tests.push(async ({ page, eq, getNotesBg }) => { |
||||
// check that notes have different background colors
|
||||
const test = 'abcdefghijklmnopqrstuvwxyz' |
||||
let step = 0 |
||||
while (step < test.length) { |
||||
await page.keyboard.down(test[step]) |
||||
step++ |
||||
} |
||||
const colors = [...new Set(await getNotesBg())] |
||||
const allDifferent = colors.length === test.length |
||||
eq(allDifferent, true) |
||||
}) |
Loading…
Reference in new issue