-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new-rule): check that meter role has an accessible name (#2607)
- Loading branch information
1 parent
0af0551
commit 3ca2f04
Showing
5 changed files
with
135 additions
and
0 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,13 @@ | ||
{ | ||
"id": "aria-meter-name", | ||
"selector": "[role=\"meter\"]", | ||
"matches": "no-naming-method-matches", | ||
"tags": ["cat.aria", "wcag2a", "wcag111"], | ||
"metadata": { | ||
"description": "Ensures every ARIA meter node has an accessible name", | ||
"help": "ARIA meter nodes must have an accessible name" | ||
}, | ||
"all": [], | ||
"any": ["aria-label", "aria-labelledby", "non-empty-title"], | ||
"none": [] | ||
} |
26 changes: 26 additions & 0 deletions
26
test/integration/rules/aria-meter-name/aria-meter-name.html
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,26 @@ | ||
<!-- PASS --> | ||
<div id="pass1" role="meter" title="CPU usage"></div> | ||
<div id="pass2" role="meter" aria-label="CPU usage"></div> | ||
<div id="pass3" role="meter" aria-labelledby="usage"></div> | ||
|
||
<div id="usage">CPU usage</div> | ||
|
||
<!-- FAIL --> | ||
<div id="fail1" role="meter">CPU usage</div> | ||
<div id="fail2" role="meter"></div> | ||
<div id="fail3" role="meter" aria-labelledby="usage-non-existant"></div> | ||
<div id="fail4" role="meter" aria-labelledby="usage-empty"></div> | ||
|
||
<div id="usage-empty"></div> | ||
|
||
<!-- INAPPLICABLE --> | ||
<img role="meter" alt="Label" id="inapplicable1" /> | ||
<input role="meter" title="Label" id="inapplicable2" /> | ||
<button role="meter" title="Label" id="inapplicable3"></button> | ||
<a href="#" role="meter" title="Label" id="inapplicable4"></a> | ||
<select role="meter" title="Label" id="inapplicable5"> | ||
<option value="volvo">Volvo</option> | ||
<option value="saab">Saab</option> | ||
<option value="opel">Opel</option> | ||
</select> | ||
<textarea role="meter" id="inapplicable6" title="Label"></textarea> |
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,6 @@ | ||
{ | ||
"description": "aria-meter-name test", | ||
"rule": "aria-meter-name", | ||
"passes": [["#pass1"], ["#pass2"], ["#pass3"]], | ||
"violations": [["#fail1"], ["#fail2"], ["#fail3"], ["#fail4"]] | ||
} |
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,89 @@ | ||
describe('aria-meter-name', function() { | ||
it('should pass for aria-label', function() { | ||
var node = new axe.SerialVirtualNode({ | ||
nodeName: 'div', | ||
attributes: { | ||
role: 'meter', | ||
'aria-label': 'foobar' | ||
} | ||
}); | ||
node.parent = null; | ||
|
||
var results = axe.runVirtualRule('aria-meter-name', node); | ||
|
||
assert.lengthOf(results.passes, 1); | ||
assert.lengthOf(results.violations, 0); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
|
||
it('should incomplete for aria-labelledby', function() { | ||
var node = new axe.SerialVirtualNode({ | ||
nodeName: 'div', | ||
attributes: { | ||
role: 'meter', | ||
'aria-labelledby': 'foobar' | ||
} | ||
}); | ||
node.parent = null; | ||
|
||
var results = axe.runVirtualRule('aria-meter-name', node); | ||
|
||
assert.lengthOf(results.passes, 0); | ||
assert.lengthOf(results.violations, 0); | ||
assert.lengthOf(results.incomplete, 1); | ||
}); | ||
|
||
it('should pass for title', function() { | ||
var node = new axe.SerialVirtualNode({ | ||
nodeName: 'div', | ||
attributes: { | ||
role: 'meter', | ||
title: 'foobar' | ||
} | ||
}); | ||
// children are required since titleText comes after subtree text | ||
// in accessible name calculation | ||
node.children = []; | ||
node.parent = null; | ||
|
||
var results = axe.runVirtualRule('aria-meter-name', node); | ||
|
||
assert.lengthOf(results.passes, 1); | ||
assert.lengthOf(results.violations, 0); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
|
||
it('should fail when aria-label contains only whitespace', function() { | ||
var node = new axe.SerialVirtualNode({ | ||
nodeName: 'div', | ||
attributes: { | ||
role: 'meter', | ||
'aria-label': ' \t \n ' | ||
} | ||
}); | ||
node.children = []; | ||
|
||
var results = axe.runVirtualRule('aria-meter-name', node); | ||
|
||
assert.lengthOf(results.passes, 0); | ||
assert.lengthOf(results.violations, 1); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
|
||
it('should fail when title is empty', function() { | ||
var node = new axe.SerialVirtualNode({ | ||
nodeName: 'div', | ||
attributes: { | ||
role: 'meter', | ||
title: '' | ||
} | ||
}); | ||
node.children = []; | ||
|
||
var results = axe.runVirtualRule('aria-meter-name', node); | ||
|
||
assert.lengthOf(results.passes, 0); | ||
assert.lengthOf(results.violations, 1); | ||
assert.lengthOf(results.incomplete, 0); | ||
}); | ||
}); |