Skip to content

Commit

Permalink
fix(aria/get-role-type): work with standards object (#2361)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker authored Jul 13, 2020
1 parent 40397f5 commit a61e314
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
11 changes: 8 additions & 3 deletions lib/commons/aria/get-role-type.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lookupTable from './lookup-table';
import standards from '../../standards';

/**
* Get the "type" of role; either widget, composite, abstract, landmark or `null`
Expand All @@ -9,8 +9,13 @@ import lookupTable from './lookup-table';
* @return {Mixed} String if a matching role and its type are found, otherwise `null`
*/
function getRoleType(role) {
var r = lookupTable.role[role];
return (r && r.type) || null;
const roleDef = standards.ariaRoles[role];

if (!roleDef) {
return null;
}

return roleDef.type;
}

export default getRoleType;
28 changes: 28 additions & 0 deletions test/commons/aria/get-role-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
describe('aria.getRoleType', function() {
'use strict';

before(function() {
axe._load({});
});

afterEach(function() {
axe.reset();
});

it('should return true if role is found in the lookup table', function() {
axe.configure({
standards: {
ariaRoles: {
cats: {
type: 'stuff'
}
}
}
});
assert.equal(axe.commons.aria.getRoleType('cats'), 'stuff');
});

it('should return null if role is not found in the lookup table', function() {
assert.isNull(axe.commons.aria.getRoleType('cats'));
});
});
19 changes: 0 additions & 19 deletions test/commons/aria/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,6 @@ describe('aria.getRolesByType', function() {
});
});

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

it('should return true if role is found in the lookup table', function() {
var orig = axe.commons.aria.lookupTable.role;
axe.commons.aria.lookupTable.role = {
cats: {
type: 'stuff'
}
};
assert.equal(axe.commons.aria.getRoleType('cats'), 'stuff');
axe.commons.aria.lookupTable.role = orig;
});

it('should return null if role is not found in the lookup table', function() {
assert.isNull(axe.commons.aria.getRoleType('cats'));
});
});

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

Expand Down

0 comments on commit a61e314

Please sign in to comment.