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

feat(has-text-content): add generic check has-text-content #2234

Merged
merged 3 commits into from
Jun 5, 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
7 changes: 7 additions & 0 deletions lib/checks/generic/has-text-content-evaluate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { sanitize, subtreeText } from '../../commons/text';

function hasTextContentEvaluate(node, options, virtualNode) {
return sanitize(subtreeText(virtualNode)) !== '';
}

export default hasTextContentEvaluate;
18 changes: 0 additions & 18 deletions lib/checks/shared/button-has-visible-text-evaluate.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/checks/shared/button-has-visible-text.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "button-has-visible-text",
"evaluate": "button-has-visible-text-evaluate",
"evaluate": "has-text-content-evaluate",
"metadata": {
"impact": "critical",
"messages": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { accessibleTextVirtual } from '../../commons/text';

function hasVisibleTextEvaluate(node, options, virtualNode) {
function hasAccessibleTextEvaluate(node, options, virtualNode) {
return accessibleTextVirtual(virtualNode).length > 0;
}

export default hasVisibleTextEvaluate;
export default hasAccessibleTextEvaluate;
11 changes: 11 additions & 0 deletions lib/checks/shared/has-accessible-text.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "has-accessible-text",
"evaluate": "has-accessible-text-evaluate",
"metadata": {
"impact": "minor",
"messages": {
"pass": "Element has text that is visible to screen readers",
"fail": "Element does not have text that is visible to screen readers"
}
}
}
2 changes: 1 addition & 1 deletion lib/checks/shared/has-visible-text.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "has-visible-text",
"evaluate": "has-visible-text-evaluate",
"evaluate": "has-text-content-evaluate",
"metadata": {
"impact": "minor",
"messages": {
Expand Down
8 changes: 4 additions & 4 deletions lib/core/base/metadata-function-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import autocompleteValidEvaluate from '../../checks/forms/autocomplete-valid-eva
import attrNonSpaceContentEvaluate from '../../checks/generic/attr-non-space-content-evaluate';
import hasDescendantAfter from '../../checks/generic/has-descendant-after';
import hasDescendantEvaluate from '../../checks/generic/has-descendant-evaluate';
import hasTextContentEvaluate from '../../checks/generic/has-text-content-evaluate';
import matchesDefinitionEvaluate from '../../checks/generic/matches-definition-evaluate';
import pageNoDuplicateAfter from '../../checks/generic/page-no-duplicate-after';
import pageNoDuplicateEvaluate from '../../checks/generic/page-no-duplicate-evaluate';
Expand All @@ -63,11 +64,10 @@ import uniqueFrameTitleEvaluate from '../../checks/navigation/unique-frame-title
import ariaLabelEvaluate from '../../checks/shared/aria-label-evaluate';
import ariaLabelledbyEvaluate from '../../checks/shared/aria-labelledby-evaluate';
import avoidInlineSpacingEvaluate from '../../checks/shared/avoid-inline-spacing-evaluate';
import buttonHasVisibleTextEvaluate from '../../checks/shared/button-has-visible-text-evaluate';
import docHasTitleEvaluate from '../../checks/shared/doc-has-title-evaluate';
import existsEvaluate from '../../checks/shared/exists-evaluate';
import hasAccessibleTextEvaluate from '../../checks/shared/has-accessible-text-evaluate';
import hasAltEvaluate from '../../checks/shared/has-alt-evaluate';
import hasVisibleTextEvaluate from '../../checks/shared/has-visible-text-evaluate';
import isOnScreenEvaluate from '../../checks/shared/is-on-screen-evaluate';
import nonEmptyIfPresentEvaluate from '../../checks/shared/non-empty-if-present-evaluate';
import svgNonEmptyTitleEvaluate from '../../checks/shared/svg-non-empty-title-evaluate';
Expand Down Expand Up @@ -204,6 +204,7 @@ const metadataFunctionMap = {
'attr-non-space-content-evaluate': attrNonSpaceContentEvaluate,
'has-descendant-after': hasDescendantAfter,
'has-descendant-evaluate': hasDescendantEvaluate,
'has-text-content-evaluate': hasTextContentEvaluate,
'matches-definition-evaluate': matchesDefinitionEvaluate,
'page-no-duplicate-after': pageNoDuplicateAfter,
'page-no-duplicate-evaluate': pageNoDuplicateEvaluate,
Expand All @@ -225,11 +226,10 @@ const metadataFunctionMap = {
'aria-label-evaluate': ariaLabelEvaluate,
'aria-labelledby-evaluate': ariaLabelledbyEvaluate,
'avoid-inline-spacing-evaluate': avoidInlineSpacingEvaluate,
'button-has-visible-text-evaluate': buttonHasVisibleTextEvaluate,
'doc-has-title-evaluate': docHasTitleEvaluate,
'exists-evaluate': existsEvaluate,
'has-accessible-text-evaluate': hasAccessibleTextEvaluate,
'has-alt-evaluate': hasAltEvaluate,
'has-visible-text-evaluate': hasVisibleTextEvaluate,
'is-on-screen-evaluate': isOnScreenEvaluate,
'non-empty-if-present-evaluate': nonEmptyIfPresentEvaluate,
'svg-non-empty-title-evaluate': svgNonEmptyTitleEvaluate,
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/empty-heading.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"help": "Headings must not be empty"
},
"all": [],
"any": ["has-visible-text"],
straker marked this conversation as resolved.
Show resolved Hide resolved
"any": ["has-accessible-text"],
"none": []
}
2 changes: 0 additions & 2 deletions test/checks/shared/button-has-visible-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ describe('button-has-visible-text', function() {
.getCheckEvaluate('button-has-visible-text')
.apply(checkContext, checkArgs)
);
assert.deepEqual(checkContext._data, 'Name');
});

it('should return true if ARIA button has text', function() {
Expand All @@ -42,7 +41,6 @@ describe('button-has-visible-text', function() {
.getCheckEvaluate('button-has-visible-text')
.apply(checkContext, checkArgs)
);
assert.deepEqual(checkContext._data, 'Text');
});

it('should return false if ARIA button has no text', function() {
Expand Down