public/dom/action-reaction_test.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-03-02 21:06:06 +00:00
export const tests = []
tests.push(async ({ eq, page }) => {
// check the initial class name of the eye left
const eyeLeft = await page.$eval('#eye-left', (node) => node.className)
eq(eyeLeft, 'eye')
// check that the text of the button says 'close'
2021-03-03 15:31:49 +00:00
const buttonText = await page.$eval('button', (node) => node.textContent)
eq(buttonText, 'Click to close the left eye')
2021-03-02 21:06:06 +00:00
})
tests.push(async ({ eq, page }) => {
// click the button to close the left eye
const button = await page.$('button')
button.click()
// check that the class has been added
2021-03-03 15:31:49 +00:00
await page.waitForSelector('#eye-left.eye.eye-closed', { timeout: 150 })
// check the background color has changed
const eyeLeft = await page.$eval(
'#eye-left.eye.eye-closed',
(node) => node.style.backgroundColor,
)
eq(eyeLeft, 'black')
// check that the text of the button changed to 'open'
const buttonText = await page.$eval('button', (node) => node.textContent)
eq(buttonText, 'Click to open the left eye')
2021-03-02 21:06:06 +00:00
})
tests.push(async ({ eq, page }) => {
// click the button a second time to open the left eye
const button = await page.$('button')
button.click()
// check that the class has been removed
2021-03-03 15:31:49 +00:00
await page.waitForSelector('#eye-left.eye:not(.eye-closed)', { timeout: 150 })
// check the background color has changed
const eyeLeft = await page.$eval(
'#eye-left.eye:not(.eye-closed)',
(node) => node.style.backgroundColor,
)
eq(eyeLeft, 'red')
// check that the text of the button changed to 'close'
2021-03-03 15:31:49 +00:00
const buttonText = await page.$eval('button', (node) => node.textContent)
eq(buttonText, 'Click to close the left eye')
2021-03-02 21:06:06 +00:00
})