From 493fc391fce3e7010c0015d0d109389b0d837a0a Mon Sep 17 00:00:00 2001 From: Dan Tripp Date: Sat, 9 Oct 2021 09:29:38 -0400 Subject: [PATCH] refactor(check): undo recent split of checks Recombine checks "no-focusable-content-for-aria-text" and "no-focusable-content-for-nested-interactive" back into "no-focusable-content". --- ...te.js => no-focusable-content-evaluate.js} | 4 +- ...ocusable-content-for-aria-text-evaluate.js | 35 ---------------- ...usable-content-for-nested-interactive.json | 12 ------ ...ia-text.json => no-focusable-content.json} | 4 +- lib/core/base/metadata-function-map.js | 6 +-- lib/rules/aria-text.json | 2 +- lib/rules/nested-interactive.json | 2 +- ...ocusable-content-for-nested-interactive.js | 41 ------------------- ...r-aria-text.js => no-focusable-content.js} | 16 ++++---- 9 files changed, 16 insertions(+), 106 deletions(-) rename lib/checks/keyboard/{no-focusable-content-for-nested-interactive-evaluate.js => no-focusable-content-evaluate.js} (91%) delete mode 100644 lib/checks/keyboard/no-focusable-content-for-aria-text-evaluate.js delete mode 100644 lib/checks/keyboard/no-focusable-content-for-nested-interactive.json rename lib/checks/keyboard/{no-focusable-content-for-aria-text.json => no-focusable-content.json} (70%) delete mode 100644 test/checks/keyboard/no-focusable-content-for-nested-interactive.js rename test/checks/keyboard/{no-focusable-content-for-aria-text.js => no-focusable-content.js} (65%) diff --git a/lib/checks/keyboard/no-focusable-content-for-nested-interactive-evaluate.js b/lib/checks/keyboard/no-focusable-content-evaluate.js similarity index 91% rename from lib/checks/keyboard/no-focusable-content-for-nested-interactive-evaluate.js rename to lib/checks/keyboard/no-focusable-content-evaluate.js index 4cc5c7a2fa..0d7eeb6b65 100644 --- a/lib/checks/keyboard/no-focusable-content-for-nested-interactive-evaluate.js +++ b/lib/checks/keyboard/no-focusable-content-evaluate.js @@ -25,7 +25,7 @@ function usesUnreliableHidingStrategy(vNode) { return !isNaN(tabIndex) && tabIndex < 0 && vNode.attr('aria-hidden') === 'true'; } -function noFocusableContentForNestedInteractiveEvaluate(node, options, virtualNode) { +function noFocusableContentEvaluate(node, options, virtualNode) { if (!virtualNode.children) { return undefined; } @@ -47,4 +47,4 @@ function noFocusableContentForNestedInteractiveEvaluate(node, options, virtualNo } } -export default noFocusableContentForNestedInteractiveEvaluate; +export default noFocusableContentEvaluate; diff --git a/lib/checks/keyboard/no-focusable-content-for-aria-text-evaluate.js b/lib/checks/keyboard/no-focusable-content-for-aria-text-evaluate.js deleted file mode 100644 index fc2ef483bd..0000000000 --- a/lib/checks/keyboard/no-focusable-content-for-aria-text-evaluate.js +++ /dev/null @@ -1,35 +0,0 @@ -import isFocusable from '../../commons/dom/is-focusable'; - -function focusableDescendants(vNode) { - if (isFocusable(vNode)) { - return true; - } - - if (!vNode.children) { - if (vNode.props.nodeType === 1) { - throw new Error('Cannot determine children'); - } - - return false; - } - - return vNode.children.some(child => { - return focusableDescendants(child); - }); -} - -function noFocusableContentForAriaTextEvaluate(node, options, virtualNode) { - if (!virtualNode.children) { - return undefined; - } - - try { - return !virtualNode.children.some(child => { - return focusableDescendants(child); - }); - } catch (e) { - return undefined; - } -} - -export default noFocusableContentForAriaTextEvaluate; diff --git a/lib/checks/keyboard/no-focusable-content-for-nested-interactive.json b/lib/checks/keyboard/no-focusable-content-for-nested-interactive.json deleted file mode 100644 index bbd0d74506..0000000000 --- a/lib/checks/keyboard/no-focusable-content-for-nested-interactive.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "id": "no-focusable-content-for-nested-interactive", - "evaluate": "no-focusable-content-for-nested-interactive-evaluate", - "metadata": { - "impact": "serious", - "messages": { - "pass": "Element does not have focusable descendants", - "fail": "Element has focusable descendants", - "incomplete": "Could not determine if element has descendants" - } - } -} diff --git a/lib/checks/keyboard/no-focusable-content-for-aria-text.json b/lib/checks/keyboard/no-focusable-content.json similarity index 70% rename from lib/checks/keyboard/no-focusable-content-for-aria-text.json rename to lib/checks/keyboard/no-focusable-content.json index 4d89a75a63..a67554e6a8 100644 --- a/lib/checks/keyboard/no-focusable-content-for-aria-text.json +++ b/lib/checks/keyboard/no-focusable-content.json @@ -1,6 +1,6 @@ { - "id": "no-focusable-content-for-aria-text", - "evaluate": "no-focusable-content-for-aria-text-evaluate", + "id": "no-focusable-content", + "evaluate": "no-focusable-content-evaluate", "metadata": { "impact": "serious", "messages": { diff --git a/lib/core/base/metadata-function-map.js b/lib/core/base/metadata-function-map.js index fcabf06a73..9728debe69 100644 --- a/lib/core/base/metadata-function-map.js +++ b/lib/core/base/metadata-function-map.js @@ -97,8 +97,7 @@ import focusableNoNameEvaluate from '../../checks/keyboard/focusable-no-name-eva import focusableNotTabbableEvaluate from '../../checks/keyboard/focusable-not-tabbable-evaluate'; import landmarkIsTopLevelEvaluate from '../../checks/keyboard/landmark-is-top-level-evaluate'; import noFocusableContentForFrameEvaluate from '../../checks/keyboard/frame-focusable-content-evaluate'; -import noFocusableContentForAriaTextEvaluate from '../../checks/keyboard/no-focusable-content-for-aria-text-evaluate'; -import noFocusableContentForNestedInteractiveEvaluate from '../../checks/keyboard/no-focusable-content-for-nested-interactive-evaluate'; +import noFocusableContentEvaluate from '../../checks/keyboard/no-focusable-content-evaluate'; import tabindexEvaluate from '../../checks/keyboard/tabindex-evaluate'; // label @@ -276,8 +275,7 @@ const metadataFunctionMap = { 'focusable-not-tabbable-evaluate': focusableNotTabbableEvaluate, 'landmark-is-top-level-evaluate': landmarkIsTopLevelEvaluate, 'no-focusable-content-for-frame-evaluate': noFocusableContentForFrameEvaluate, - 'no-focusable-content-for-aria-text-evaluate': noFocusableContentForAriaTextEvaluate, - 'no-focusable-content-for-nested-interactive-evaluate': noFocusableContentForNestedInteractiveEvaluate, + 'no-focusable-content-evaluate': noFocusableContentEvaluate, 'tabindex-evaluate': tabindexEvaluate, // label diff --git a/lib/rules/aria-text.json b/lib/rules/aria-text.json index aa93b2fa9c..aa284a5867 100644 --- a/lib/rules/aria-text.json +++ b/lib/rules/aria-text.json @@ -7,6 +7,6 @@ "help": "\"role=text\" should have no focusable descendants" }, "all": [], - "any": ["no-focusable-content-for-aria-text"], + "any": ["no-focusable-content"], "none": [] } diff --git a/lib/rules/nested-interactive.json b/lib/rules/nested-interactive.json index 6c2a4d20f7..ad6b5b0770 100644 --- a/lib/rules/nested-interactive.json +++ b/lib/rules/nested-interactive.json @@ -8,6 +8,6 @@ "help": "Ensure interactive controls are not nested" }, "all": [], - "any": ["no-focusable-content-for-nested-interactive"], + "any": ["no-focusable-content"], "none": [] } diff --git a/test/checks/keyboard/no-focusable-content-for-nested-interactive.js b/test/checks/keyboard/no-focusable-content-for-nested-interactive.js deleted file mode 100644 index 4c4553e9bf..0000000000 --- a/test/checks/keyboard/no-focusable-content-for-nested-interactive.js +++ /dev/null @@ -1,41 +0,0 @@ -describe('no-focusable-content-for-nested-interactive tests', function() { - var fixture = document.querySelector('#fixture'); - var queryFixture = axe.testUtils.queryFixture; - var noFocusableContentForNestedInteractive = axe.testUtils.getCheckEvaluate( - 'no-focusable-content-for-nested-interactive' - ); - - afterEach(function() { - fixture.innerHTML = ''; - }); - - it('should return true if element has no focusable content', function() { - var vNode = queryFixture(''); - assert.isTrue(noFocusableContentForNestedInteractive(null, null, vNode)); - }); - - it('should return true if element is empty', function() { - var vNode = queryFixture(''); - assert.isTrue(noFocusableContentForNestedInteractive(null, null, vNode)); - }); - - it('should return true if element only has text content', function() { - var vNode = queryFixture(''); - assert.isTrue(noFocusableContentForNestedInteractive(null, null, vNode)); - }); - - it('should return false if element has focusable content', function() { - var vNode = queryFixture( - '' - ); - assert.isFalse(noFocusableContentForNestedInteractive(null, null, vNode)); - }); - - it('should return false if element has natively focusable content', function() { - var vNode = queryFixture( - '' - ); - assert.isFalse(noFocusableContentForNestedInteractive(null, null, vNode)); - }); - -}); diff --git a/test/checks/keyboard/no-focusable-content-for-aria-text.js b/test/checks/keyboard/no-focusable-content.js similarity index 65% rename from test/checks/keyboard/no-focusable-content-for-aria-text.js rename to test/checks/keyboard/no-focusable-content.js index 48c9395729..761bbb547d 100644 --- a/test/checks/keyboard/no-focusable-content-for-aria-text.js +++ b/test/checks/keyboard/no-focusable-content.js @@ -1,8 +1,8 @@ -describe('no-focusable-content-for-aria-text tests', function() { +describe('no-focusable-content tests', function() { var fixture = document.querySelector('#fixture'); var queryFixture = axe.testUtils.queryFixture; - var noFocusableContentForAriaText = axe.testUtils.getCheckEvaluate( - 'no-focusable-content-for-aria-text' + var noFocusableContent = axe.testUtils.getCheckEvaluate( + 'no-focusable-content' ); afterEach(function() { @@ -11,31 +11,31 @@ describe('no-focusable-content-for-aria-text tests', function() { it('should return true if element has no focusable content', function() { var vNode = queryFixture(''); - assert.isTrue(noFocusableContentForAriaText(null, null, vNode)); + assert.isTrue(noFocusableContent(null, null, vNode)); }); it('should return true if element is empty', function() { var vNode = queryFixture(''); - assert.isTrue(noFocusableContentForAriaText(null, null, vNode)); + assert.isTrue(noFocusableContent(null, null, vNode)); }); it('should return true if element only has text content', function() { var vNode = queryFixture(''); - assert.isTrue(noFocusableContentForAriaText(null, null, vNode)); + assert.isTrue(noFocusableContent(null, null, vNode)); }); it('should return false if element has focusable content', function() { var vNode = queryFixture( '' ); - assert.isFalse(noFocusableContentForAriaText(null, null, vNode)); + assert.isFalse(noFocusableContent(null, null, vNode)); }); it('should return false if element has natively focusable content', function() { var vNode = queryFixture( '' ); - assert.isFalse(noFocusableContentForAriaText(null, null, vNode)); + assert.isFalse(noFocusableContent(null, null, vNode)); }); });