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(aria/get-role-type): work with standards object #2361

Merged
merged 1 commit into from
Jul 13, 2020
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
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;
Copy link
Member

@stephenmathieson stephenmathieson Jul 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this would return null if there wasn't a truthy .type. Do we need to maintain consistently, or is the possibility of returning undefined here ok?

Copy link
Contributor Author

@straker straker Jul 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every role should have a type so it shouldn't be possible to return undefined or null. A role without a type should be treated as a bug.

}

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 @@ -67,25 +67,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