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 1 commit
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(node.getAttribute('role'));
straker marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions lib/commons/aria/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ aria.isValidRole = function(
return allowAbstract ? true : roleDefinition.type !== 'abstract';
};

/**
* 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) {
straker marked this conversation as resolved.
Show resolved Hide resolved
const roleDefinition = aria.lookupTable.role[role];
return roleDefinition ? roleDefinition.unsupported : false;
};

/**
* Get the roles that get name from the element's contents
* @method getRolesWithNameFromContents
Expand Down
8 changes: 7 additions & 1 deletion test/checks/aria/unsupportedrole.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('unsupportedrole', function() {
type: 'widget',
unsupported: true
};
fixture.innerHTML = '<div id="target" role="mccheddarton">Contents</div>';
fixture.innerHTML = '<div id="target" role="mcheddarton">Contents</div>';
straker marked this conversation as resolved.
Show resolved Hide resolved
var node = fixture.querySelector('#target');
assert.isTrue(checks.unsupportedrole.evaluate(node));
});
Expand All @@ -22,4 +22,10 @@ describe('unsupportedrole', function() {
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));
});
});
33 changes: 33 additions & 0 deletions test/commons/aria/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,39 @@ describe('aria.isValidRole', function() {
});
});

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

describe('aria.getRolesWithNameFromContents', function() {
'use strict';

Expand Down