From 3b519a6a70ef98573cf13b9b89fc032ed73df4cc Mon Sep 17 00:00:00 2001 From: Jey Nandakumar Date: Thu, 20 Feb 2020 17:32:49 +0000 Subject: [PATCH] fix(label-content-name-mismatch): ignore non `widget` aria role(s) & do not use deprecated `lookupTable.rolesOfType` (#2022) * fix: ignore non-widget roles for rule label-content-name-mismatch * update helper fn for getting role type * update aria-query * rollback using aria-query * updates * update --- lib/commons/aria/index.js | 14 ++++---------- lib/rules/label-content-name-mismatch-matches.js | 5 ++++- .../label-content-name-mismatch.html | 5 ++++- .../label-content-name-mismatch-matches.js | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/commons/aria/index.js b/lib/commons/aria/index.js index cc1a836f67..7ccd18fcf9 100644 --- a/lib/commons/aria/index.js +++ b/lib/commons/aria/index.js @@ -1995,7 +1995,7 @@ lookupTable.role = { allowedElements: ['ol', 'ul'] }, tooltip: { - type: 'widget', + type: 'structure', attributes: { allowed: ['aria-expanded', 'aria-errormessage'] }, @@ -2387,15 +2387,9 @@ lookupTable.evaluateRoleForElement = { }; /** - * Reference -> https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/ARIA_Techniques#Widget_roles - * The current lookupTable.role['widget'] widget, yeilds - * -> - * [ - * "alert", "alertdialog", "button", "checkbox", "dialog", "gridcell", "link", "log", "marquee", "menuitem", "menuitemcheckbox", - * "menuitemradio", "option", "progressbar", "radio", "scrollbar", "searchbox", "slider", "spinbutton", "status", "switch", "tab", "tabpanel", - * "textbox", "timer", "tooltip", "treeitem" - * ] - * There are some differences against specs, hence the below listing was made + * Note: + * Usage of `rolesOfType` is deprecated within the source code. + * Leaving this here for now, to keep support for custom rules. */ lookupTable.rolesOfType = { widget: [ diff --git a/lib/rules/label-content-name-mismatch-matches.js b/lib/rules/label-content-name-mismatch-matches.js index 9aab2449cd..5d68e8c05d 100644 --- a/lib/rules/label-content-name-mismatch-matches.js +++ b/lib/rules/label-content-name-mismatch-matches.js @@ -12,7 +12,10 @@ if (!role) { return false; } -const isWidgetType = aria.lookupTable.rolesOfType.widget.includes(role); +const widgetRoles = Object.keys(aria.lookupTable.role).filter( + key => aria.lookupTable.role[key].type === `widget` +); +const isWidgetType = widgetRoles.includes(role); if (!isWidgetType) { return false; } diff --git a/test/integration/rules/label-content-name-mismatch/label-content-name-mismatch.html b/test/integration/rules/label-content-name-mismatch/label-content-name-mismatch.html index 7805d4e896..bb74165b29 100644 --- a/test/integration/rules/label-content-name-mismatch/label-content-name-mismatch.html +++ b/test/integration/rules/label-content-name-mismatch/label-content-name-mismatch.html @@ -14,6 +14,7 @@ +
Next
@@ -38,4 +39,6 @@ Next - + +
RSS Feed
+
Foo Restaurant
diff --git a/test/rule-matches/label-content-name-mismatch-matches.js b/test/rule-matches/label-content-name-mismatch-matches.js index c0e884447f..dae58661bf 100644 --- a/test/rule-matches/label-content-name-mismatch-matches.js +++ b/test/rule-matches/label-content-name-mismatch-matches.js @@ -107,12 +107,12 @@ describe('label-content-name-mismatch-matches tests', function() { assert.isFalse(actual); }); - it('returns true for widget role that does support name from content', function() { + it('returns false for non-widget role that does support name from content', function() { var vNode = queryFixture( '' ); var actual = rule.matches(vNode.actualNode, vNode); - assert.isTrue(actual); + assert.isFalse(actual); }); it('returns false for empty text content', function() {