Skip to content

Commit

Permalink
fix: dont flag invalid roles in unsupportedrole (#1328)
Browse files Browse the repository at this point in the history
fix: don't flag invalid roles in unsupportedrole
  • Loading branch information
straker authored and WilcoFiers committed Jan 22, 2019
1 parent 2660efc commit 2dfcbaa
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 4 deletions.
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;
});
});

0 comments on commit 2dfcbaa

Please sign in to comment.