-
Notifications
You must be signed in to change notification settings - Fork 791
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: migrate aria-errormessage to its own check
Integration tests are failing, but I couldn't figure out why. The union of the two checks seems to be causing problems
- Loading branch information
Marcy Sutton
committed
Oct 12, 2017
1 parent
cb8e39c
commit ae6d887
Showing
7 changed files
with
95 additions
and
39 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,25 @@ | ||
options = Array.isArray(options) ? options : []; | ||
|
||
var attr = node.getAttribute('aria-errormessage'), | ||
hasAttr = node.hasAttribute('aria-errormessage'); | ||
|
||
var doc = axe.commons.dom.getRootNode(node); | ||
|
||
function validateAttrValue() { | ||
var idref = attr && doc.getElementById(attr); | ||
if (idref) { | ||
return idref.getAttribute('role') === 'alert' || | ||
idref.getAttribute('aria-live') === 'assertive' || | ||
axe.utils.tokenList(node.getAttribute('aria-describedby') || '').indexOf(attr) > -1; | ||
} | ||
} | ||
|
||
// limit results to elements that actually have this attribute | ||
if (options.indexOf(attr) === -1 && hasAttr) { | ||
if (!validateAttrValue()) { | ||
this.data(attr); | ||
return false; | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"id": "aria-errormessage", | ||
"evaluate": "errormessage.js", | ||
"metadata": { | ||
"impact": "critical", | ||
"messages": { | ||
"pass": "Uses a supported aria-errormessage technique", | ||
"fail": "aria-errormessage value{{=it.data && it.data.length > 1 ? 's' : ''}} {{~it.data:value}} `{{=value}}{{~}}` must use a technique to announce the message (e.g., aria-live, aria-describedby, role=alert, etc.)" | ||
} | ||
} | ||
} |
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
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,49 @@ | ||
describe('aria-errormessage', function () { | ||
'use strict'; | ||
|
||
var fixture = document.getElementById('fixture'); | ||
|
||
var checkContext = axe.testUtils.MockCheckContext(); | ||
|
||
afterEach(function () { | ||
fixture.innerHTML = ''; | ||
checkContext._data = null; | ||
}); | ||
|
||
it('should return false if aria-errormessage value is invalid', function () { | ||
var testHTML = '<div></div>'; | ||
testHTML += '<div id="plain"></div>'; | ||
fixture.innerHTML = testHTML; | ||
var target = fixture.children[0]; | ||
target.setAttribute('aria-errormessage', 'plain'); | ||
assert.isFalse(checks['aria-errormessage'].evaluate.call(checkContext, target)); | ||
}); | ||
|
||
it('should return true if aria-errormessage id is alert', function () { | ||
var testHTML = '<div></div>'; | ||
testHTML += '<div id="alert" role="alert"></div>'; | ||
fixture.innerHTML = testHTML; | ||
var target = fixture.children[0]; | ||
target.setAttribute('aria-errormessage', 'alert'); | ||
assert.isTrue(checks['aria-errormessage'].evaluate.call(checkContext, target)); | ||
}); | ||
|
||
it('should return true if aria-errormessage id is aria-live=assertive', function () { | ||
var testHTML = '<div></div>'; | ||
testHTML += '<div id="live" aria-live="assertive"></div>'; | ||
fixture.innerHTML = testHTML; | ||
var target = fixture.children[0]; | ||
target.setAttribute('aria-errormessage', 'live'); | ||
assert.isTrue(checks['aria-errormessage'].evaluate.call(checkContext, target)); | ||
}); | ||
|
||
it('should return true if aria-errormessage id is aria-describedby', function () { | ||
var testHTML = '<div></div>'; | ||
testHTML += '<div id="plain"></div>'; | ||
fixture.innerHTML = testHTML; | ||
var target = fixture.children[0]; | ||
target.setAttribute('aria-errormessage', 'plain'); | ||
target.setAttribute('aria-describedby', 'plain'); | ||
assert.isTrue(checks['aria-errormessage'].evaluate.call(checkContext, target)); | ||
}); | ||
}); |
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
move both of these to the
all
array. Currently, one of them can short-circuit the testing logic and it will mess up the integration tests.