From a61e3142ba5976bde09a9cd82cc944eab5ee284b Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Mon, 13 Jul 2020 08:49:58 -0600 Subject: [PATCH] fix(aria/get-role-type): work with standards object (#2361) --- lib/commons/aria/get-role-type.js | 11 ++++++++--- test/commons/aria/get-role-type.js | 28 ++++++++++++++++++++++++++++ test/commons/aria/roles.js | 19 ------------------- 3 files changed, 36 insertions(+), 22 deletions(-) create mode 100644 test/commons/aria/get-role-type.js diff --git a/lib/commons/aria/get-role-type.js b/lib/commons/aria/get-role-type.js index ed089b944e..58af45bac4 100644 --- a/lib/commons/aria/get-role-type.js +++ b/lib/commons/aria/get-role-type.js @@ -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` @@ -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; diff --git a/test/commons/aria/get-role-type.js b/test/commons/aria/get-role-type.js new file mode 100644 index 0000000000..1d17fb5a0a --- /dev/null +++ b/test/commons/aria/get-role-type.js @@ -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')); + }); +}); diff --git a/test/commons/aria/roles.js b/test/commons/aria/roles.js index 78860b381c..69c44795c7 100644 --- a/test/commons/aria/roles.js +++ b/test/commons/aria/roles.js @@ -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';