-
Notifications
You must be signed in to change notification settings - Fork 784
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support options in aria-allowed-attr and aria-required-attr #673
Changes from 5 commits
66646a8
cf9af49
e30a372
4f266c7
69fba9d
fd6d671
86fd5bf
a51514d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
options = Array.isArray(options) ? options : []; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as my comment above. This is a generic "required everywhere". That seems a bit useless. You wouldn't require a particular attribute on every element. You'd need to set certain things to be required for certain roles. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, thanks for the tip! |
||
|
||
var uniqueArray = (arrArg) => { | ||
return arrArg.filter((elem, pos, arr) => { | ||
return arr.indexOf(elem) === pos; | ||
}); | ||
}; | ||
|
||
var missing = []; | ||
|
||
if (node.hasAttributes()) { | ||
var attr, | ||
role = node.getAttribute('role'), | ||
required = axe.commons.aria.requiredAttr(role); | ||
|
||
if (options.length) { | ||
required = uniqueArray(required.concat(options)); | ||
} | ||
if (role && required) { | ||
for (var i = 0, l = required.length; i < l; i++) { | ||
attr = required[i]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,4 +119,11 @@ describe('aria-allowed-attr', function () { | |
assert.isNull(checkContext._data); | ||
}); | ||
|
||
describe('options', function () { | ||
it('should allow provided attribute names', function () { | ||
fixture.innerHTML = '<div role="separator" id="target" aria-valuenow="0" aria-valuemin="-2" aria-valuemax="4"></div>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You may want to use fake aria properties instead. Otherwise, once we've added those values, this test becomes invalid. |
||
var target = fixture.children[0]; | ||
assert.isTrue(checks['aria-allowed-attr'].evaluate.call(checkContext, target, ['aria-valuenow', 'aria-valuemin', 'aria-valuemax'])); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,4 +57,12 @@ describe('aria-required-attr', function () { | |
axe.commons.aria.requiredAttr = orig; | ||
}); | ||
|
||
describe('options', function () { | ||
it('should require provided attribute names', function () { | ||
fixture.innerHTML = '<div role="slider" id="target"></div>'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here, you should use a made up role. May I suggest There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Love it! will do. |
||
var target = fixture.children[0]; | ||
assert.isFalse(checks['aria-required-attr'].evaluate.call(checkContext, target, ['aria-valuemax', 'aria-bats'])); | ||
assert.deepEqual(checkContext._data, ['aria-valuenow', 'aria-valuemax', 'aria-valuemin', 'aria-bats']); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!doctype html> | ||
<html lang="en" id="main"> | ||
<head> | ||
<title></title> | ||
<meta charset="utf8"> | ||
<link rel="stylesheet" type="text/css" href="/node_modules/mocha/mocha.css" /> | ||
<script src="/node_modules/mocha/mocha.js"></script> | ||
<script src="/node_modules/chai/chai.js"></script> | ||
<script src="/axe.js"></script> | ||
<script> | ||
mocha.setup({ | ||
timeout: 50000, | ||
ui: 'bdd' | ||
}); | ||
var assert = chai.assert; | ||
</script> | ||
</head> | ||
<body> | ||
<div id="target"></div> | ||
|
||
<div id="mocha"></div> | ||
<script src="configure-options.js"></script> | ||
<script src="/test/integration/adapter.js"></script> | ||
</body> | ||
</html> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
describe('Check Configure Options', function() { | ||
'use strict'; | ||
|
||
var target = document.querySelector('#target'); | ||
|
||
describe('aria-allowed-attr', function() { | ||
it('should allow an attribute supplied in options', function(done) { | ||
target.setAttribute('role', 'separator'); | ||
target.setAttribute('aria-valuenow', '0'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the event that 'aria-valuenow' becomes an allowed attribute in our lookup table, this test won't be testing anything anymore. Just to make the test more future-proof, I suggest using a random value like 'peanutbutter' instead of a real attribute so we can guarantee the test will always be testing the override functionality with a truly unexpected value. |
||
|
||
axe.configure({ | ||
checks: [{ | ||
id: 'aria-allowed-attr', | ||
options: ['aria-valuenow'] | ||
}] | ||
}); | ||
axe.run(target, { | ||
runOnly: { | ||
type: 'rule', | ||
values: [ 'aria-allowed-attr' ] | ||
} | ||
}, function(error, results) { | ||
assert.lengthOf(results.violations, 0, 'violations'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('aria-required-attr', function() { | ||
it('should report unique attributes when supplied from options', function(done) { | ||
target.setAttribute('role', 'slider'); | ||
axe.configure({ | ||
checks: [{ | ||
id: 'aria-required-attr', | ||
options: ['aria-checked'] | ||
}] | ||
}); | ||
axe.run('#target', { | ||
runOnly: { | ||
type: 'rule', | ||
values: [ 'aria-required-attr' ] | ||
} | ||
}, function(error, results) { | ||
assert.lengthOf(results.violations, 1, 'violations'); | ||
assert.sameMembers(results.violations[0].nodes[0].any[0].data, ['aria-valuemax', 'aria-valuemin', 'aria-checked']); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wondering if this should allow per role specification, instead of (or in addition to) a generic "allowed everywhere". So you could do:
{ separator: ['aria-valuenow', 'aria-valuemin', 'aria-valuemax'] }
. You could still allow the array, and you could add a wildcard option for the "generic" case you've got now:{ '*': ['always-allowed'] }
.