Skip to content
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

fix: don't flag invalid roles in unsupportedrole #1328

Merged
merged 6 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/checks/aria/unsupportedrole.js
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
return !axe.commons.aria.isValidRole(node.getAttribute('role'), {
flagUnsupported: true
});
return axe.commons.aria.isUnsupportedRole(axe.commons.aria.getRole(node));
14 changes: 14 additions & 0 deletions lib/commons/aria/is-unsupported-role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* global aria, axe */

/**
* Check if a given role is unsupported
* @method isUnsupportedRole
* @memberof axe.commons.aria
* @instance
* @param {String} role The role to check
* @return {Boolean}
*/
aria.isUnsupportedRole = function(role) {
const roleDefinition = aria.lookupTable.role[role];
return roleDefinition ? roleDefinition.unsupported : false;
};
12 changes: 11 additions & 1 deletion test/checks/aria/unsupportedrole.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('unsupportedrole', function() {
});

it('should return true if applied to an unsupported role', function() {
axe.commons.aria.lookupTable.role.mcheddarton = {
axe.commons.aria.lookupTable.role.mccheddarton = {
type: 'widget',
unsupported: true
};
Expand All @@ -21,5 +21,15 @@ describe('unsupportedrole', function() {
fixture.innerHTML = '<div id="target" role="alert">Contents</div>';
var node = fixture.querySelector('#target');
assert.isFalse(checks.unsupportedrole.evaluate(node));

fixture.innerHTML = '<button id="target">Contents</button>';
var node = fixture.querySelector('#target');
assert.isFalse(checks.unsupportedrole.evaluate(node));
});

it('should return false if applied to an invalid role', function() {
fixture.innerHTML = '<input id="target" role="foo">';
var node = fixture.querySelector('#target');
assert.isFalse(checks.unsupportedrole.evaluate(node));
});
});
32 changes: 32 additions & 0 deletions test/commons/aria/is-unsupported-role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
describe('aria.isUnsupportedRole', function() {
'use strict';

it('should return true if the role is unsupported', function() {
var orig = axe.commons.aria.lookupTable.role;
axe.commons.aria.lookupTable.role = {
cats: {
unsupported: true
}
};
assert.isTrue(axe.commons.aria.isUnsupportedRole('cats'));
axe.commons.aria.lookupTable.role = orig;
});

it('should return false if the role is supported', function() {
var orig = axe.commons.aria.lookupTable.role;
axe.commons.aria.lookupTable.role = {
cats: {
unsupported: false
}
};
assert.isFalse(axe.commons.aria.isUnsupportedRole('cats'));
axe.commons.aria.lookupTable.role = orig;
});

it('should return false if the role is invalid', function() {
var orig = axe.commons.aria.lookupTable.role;
axe.commons.aria.lookupTable.role = {};
assert.isFalse(axe.commons.aria.isUnsupportedRole('cats'));
axe.commons.aria.lookupTable.role = orig;
});
});