Skip to content

Commit

Permalink
feat(aria/get-roles-by-type): deprecate in favor of standards/get-ari…
Browse files Browse the repository at this point in the history
…a-roles-by-type (#2362)

* feat(aria/get-roles-by-type): deprecate in favor of standards/get-aria-roles-by-type

* replace functions
  • Loading branch information
straker authored Jul 13, 2020
1 parent a61e314 commit c0c37ea
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 31 deletions.
5 changes: 3 additions & 2 deletions lib/checks/keyboard/landmark-is-top-level-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getRolesByType, implicitRole } from '../../commons/aria';
import { implicitRole } from '../../commons/aria';
import { getAriaRolesByType } from '../../commons/standards';
import { getComposedParent } from '../../commons/dom';

function landmarkIsTopLevelEvaluate(node) {
var landmarks = getRolesByType('landmark');
var landmarks = getAriaRolesByType('landmark');
var parent = getComposedParent(node);

this.data({
Expand Down
3 changes: 2 additions & 1 deletion lib/checks/navigation/region-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import * as dom from '../../commons/dom';
import * as aria from '../../commons/aria';
import * as standards from '../../commons/standards';
import * as text from '../../commons/text';
import matches from '../../commons/matches';
import { matchesSelector } from '../../core/utils';
import cache from '../../core/base/cache';

const landmarkRoles = aria.getRolesByType('landmark');
const landmarkRoles = standards.getAriaRolesByType('landmark');
const implicitAriaLiveRoles = ['alert', 'log', 'status'];

// Create a list of nodeNames that have a landmark as an implicit role
Expand Down
7 changes: 3 additions & 4 deletions lib/commons/aria/get-roles-by-type.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import lookupTable from './lookup-table';
import getAriaRolesByType from '../standards/get-aria-roles-by-type';

/**
* Get the roles that have a certain "type"
* @method getRolesByType
* @memberof axe.commons.aria
* @deprecated use standards/get-aria-roles-by-type
* @instance
* @param {String} roleType The roletype to check
* @return {Array} Array of roles that match the type
*/
function getRolesByType(roleType) {
return Object.keys(lookupTable.role).filter(function(r) {
return lookupTable.role[r].type === roleType;
});
return getAriaRolesByType(roleType);
}

export default getRolesByType;
5 changes: 3 additions & 2 deletions lib/rules/landmark-unique-matches.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { findUpVirtual, isVisible } from '../commons/dom';
import { getRolesByType, getRole } from '../commons/aria';
import { getRole } from '../commons/aria';
import { getAriaRolesByType } from '../commons/standards';
import { accessibleTextVirtual } from '../commons/text';

function landmarkUniqueMatches(node, virtualNode) {
Expand All @@ -24,7 +25,7 @@ function landmarkUniqueMatches(node, virtualNode) {

function isLandmarkVirtual(virtualNode) {
var { actualNode } = virtualNode;
var landmarkRoles = getRolesByType('landmark');
var landmarkRoles = getAriaRolesByType('landmark');
var role = getRole(actualNode);
if (!role) {
return false;
Expand Down
31 changes: 31 additions & 0 deletions test/commons/aria/get-roles-by-type.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
describe('aria.getRolesByType', function() {
'use strict';

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

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

it('should return array if roletype is found in the lookup table', function() {
axe.configure({
standards: {
ariaRoles: {
dogs: {
type: 'things'
},
cats: {
type: 'stuff'
}
}
}
});
assert.deepEqual(axe.commons.aria.getRolesByType('stuff'), ['cats']);
});

it('should return empty array if role is not found in the lookup table', function() {
assert.deepEqual(axe.commons.aria.getRolesByType('blahblahblah'), []);
});
});
22 changes: 0 additions & 22 deletions test/commons/aria/roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,6 @@ describe('aria.isValidRole', function() {
});
});

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

it('should return array if roletype is found in the lookup table', function() {
var orig = axe.commons.aria.lookupTable.role;
axe.commons.aria.lookupTable.role = {
dogs: {
type: 'things'
},
cats: {
type: 'stuff'
}
};
assert.deepEqual(axe.commons.aria.getRolesByType('stuff'), ['cats']);
axe.commons.aria.lookupTable.role = orig;
});

it('should return empty array if role is not found in the lookup table', function() {
assert.deepEqual(axe.commons.aria.getRolesByType('blahblahblah'), []);
});
});

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

Expand Down

0 comments on commit c0c37ea

Please sign in to comment.