Skip to content

Commit

Permalink
feat: add required-attr options, integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcy Sutton committed Jan 6, 2018
1 parent e30a372 commit 4f266c7
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/checks/aria/required-attr.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
options = Array.isArray(options) ? options : [];

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];
Expand Down
8 changes: 8 additions & 0 deletions test/checks/aria/required-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>';
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']);
});
});
});
25 changes: 25 additions & 0 deletions test/integration/full/configure-options/configure-options.html
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>
50 changes: 50 additions & 0 deletions test/integration/full/configure-options/configure-options.js
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');

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();
});
});
});
});

0 comments on commit 4f266c7

Please sign in to comment.