-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated unit tests for checkbox, dialog and listbox to use the `domIn…
…fo` variable as standard for data returned from page.evaluate() calls.
- Loading branch information
1 parent
00f9525
commit d346406
Showing
3 changed files
with
179 additions
and
75 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,104 @@ | ||
'use strict' | ||
|
||
import e from 'express'; | ||
import config from './test-config.js'; | ||
import testHelpers from './test-helpers.js'; | ||
|
||
|
||
|
||
|
||
describe('ARIA Checkbox Tests', () => { | ||
beforeAll(async () => { | ||
}); | ||
|
||
async function getCheckboxValue(el) { | ||
return await page.evaluate(() => { | ||
const checkboxEl = document.querySelector('#example-role-checkbox [role="checkbox"]'); | ||
let r; | ||
|
||
return checkboxEl.getAttribute('aria-checked'); | ||
}); | ||
} | ||
|
||
it('See if checkbox is keyboard accessible', async () => { | ||
let ariaChecked; | ||
|
||
await page.goto(`${config.BASE_URL}/checkbox.php`); | ||
|
||
// wait until all content loads | ||
await page.waitForSelector('#example-role-checkbox'); | ||
await page.focus('#example-role-checkbox [role="checkbox"]') | ||
|
||
// check to see if checked by default | ||
ariaChecked = await getCheckboxValue(); | ||
expect(ariaChecked).toBe('true'); | ||
|
||
// press space and check if it's unchecked. | ||
await page.keyboard.press('Space'); | ||
await new Promise(res => setTimeout(res, config.KEYPRESS_FAST_TIMEOUT)); | ||
ariaChecked = await getCheckboxValue(); | ||
expect(ariaChecked).toBe('false') | ||
|
||
// press space again and check if it's unchecked. | ||
await page.keyboard.press('Space'); | ||
await new Promise(res => setTimeout(res, config.KEYPRESS_FAST_TIMEOUT)); | ||
ariaChecked = await getCheckboxValue(); | ||
expect(ariaChecked).toBe('true') | ||
}); | ||
|
||
it('Ensure checkbox has proper label', async () => { | ||
let domInfo; | ||
|
||
await page.goto(`${config.BASE_URL}/checkbox.php`); | ||
|
||
// wait until all content loads | ||
await page.waitForSelector('#example-role-checkbox'); | ||
domInfo = await page.evaluate(() => { | ||
const checkboxEl = document.querySelector('#example-role-checkbox [role="checkbox"]'); | ||
let ariaLabel; | ||
|
||
if (checkboxEl) { | ||
const ariaLabelledby = checkboxEl.getAttribute('aria-labelledby'); | ||
const ariaLabelledByEl = document.getElementById(ariaLabelledby); | ||
|
||
if (ariaLabelledByEl !== null) { | ||
ariaLabel = ariaLabelledByEl.innerText; | ||
} else { | ||
ariaLabel = checkboxEl.getAttribute('aria-label'); | ||
} | ||
} else { | ||
ariaLabel = ''; | ||
} | ||
|
||
return { | ||
ariaLabel: ariaLabel.trim() | ||
} | ||
}); | ||
|
||
expect(domInfo.ariaLabel).not.toBe(''); | ||
|
||
}); | ||
|
||
it('Ensure checkbox ::after element that has content set (i.e. visible)', async () => { | ||
let domInfo; | ||
|
||
await page.goto(`${config.BASE_URL}/checkbox.php`); | ||
|
||
// wait until all content loads | ||
await page.waitForSelector('#example-role-checkbox'); | ||
domInfo = await page.evaluate(() => { | ||
const checkboxEl = document.querySelector('#example-role-checkbox [role="checkbox"]'); | ||
|
||
const afterStyle = window.getComputedStyle(checkboxEl, '::after'); | ||
const content = afterStyle.content; | ||
|
||
return { | ||
hasContent: (content !== null) && (typeof(content) === 'string') && (content.trim() !== '') | ||
} | ||
}); | ||
|
||
expect(domInfo.hasContent).toBe(true); | ||
|
||
}); | ||
|
||
}); |
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
Oops, something went wrong.