Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get proper contrast when hovering over svg (#388)
* get fill & stroke colors for checking a11y of svg * hide a11y tooltip when mouseover svg node * check whether element can have fill & stroke for real * change variable name to `foreground` to go with `background` * add test cases for a11y tool * fix unchnaged variables causing error * get coordinates in test based on target element
- Loading branch information
Showing
2 changed files
with
72 additions
and
6 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
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,62 @@ | ||
import test from 'ava' | ||
import { setupPptrTab, teardownPptrTab, getActiveTool, changeMode } from '../../tests/helpers' | ||
|
||
test.beforeEach(setupPptrTab) | ||
|
||
const contrastValueSelector = `document.querySelector('visbug-ally').$shadow.querySelector('span[contrast]').textContent.trim()` | ||
|
||
test('Can be activated', async t => { | ||
const {page} = t.context; | ||
await changeMode({page, tool: 'accessibility'}) | ||
|
||
t.is(await getActiveTool(page), 'accessibility') | ||
t.pass() | ||
}) | ||
|
||
test('Can reveal color contrasts between html nodes and backgrounds', async t => { | ||
const {page} = t.context; | ||
await changeMode({page, tool: 'accessibility'}) | ||
|
||
await page.hover('.google-blue') | ||
const blueContrastValue = await page.evaluate(contrastValueSelector) | ||
t.is(blueContrastValue, "3.56") | ||
t.pass() | ||
|
||
|
||
await page.hover('.google-red') | ||
const redContrastValue = await page.evaluate(contrastValueSelector) | ||
t.is(redContrastValue, "4.29") | ||
t.pass() | ||
|
||
await page.hover('.google-yellow') | ||
const yellowContrastValue = await page.evaluate(contrastValueSelector) | ||
t.is(yellowContrastValue, "1.84") | ||
t.pass() | ||
}) | ||
|
||
test('Does not show a11y tooltip on <svg> node', async t => { | ||
const {page} = t.context; | ||
await changeMode({page, tool: 'accessibility'}) | ||
|
||
const svgEl = await page.$('svg') | ||
const {x, y} = await svgEl.boundingBox() | ||
await page.mouse.click(x + 1, y + 1) // an empty space of the first svg element | ||
const targetNodeName = await page.$eval('visbug-label', el => el.$shadow.querySelector('a[node]') .textContent) | ||
t.is(targetNodeName, 'svg') | ||
t.pass() | ||
|
||
t.is(await page.$('visbug-ally'), null) | ||
t.pass() | ||
}) | ||
|
||
test('Gets fill or stroke value first if the target is one of svg elements', async t => { | ||
const {page} = t.context; | ||
await changeMode({page, tool: 'accessibility'}) | ||
|
||
await page.hover('svg') | ||
const pathContrastValue = await page.evaluate(contrastValueSelector) | ||
t.not(pathContrastValue, "10.44") | ||
t.pass() | ||
}) | ||
|
||
test.afterEach(teardownPptrTab) |