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

fix: link-name to be deciphered from children #1134

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions lib/commons/text/accessible-text-virtual.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,11 @@ text.accessibleTextVirtual = function accessibleTextVirtual(
return element.actualNode.getAttribute('title');
}

//handle children with role presentation
if (role === 'presentation') {
return getInnerText(element, false, false);
}

return '';
};

Expand Down
77 changes: 77 additions & 0 deletions test/checks/shared/has-visible-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,81 @@ describe('has-visible-text', function() {
checks['has-visible-text'].evaluate.apply(checkContext, params)
);
});

it('should return true if there is children with role presentation and text content', function() {
var params = checkSetup(
'<a id="target" href="link"><span role="presentation">Link text</span></a>'
);
var actual = checks['has-visible-text'].evaluate.apply(
checkContext,
params
);
assert.isTrue(actual);
});

it('should return false if there is children with role presentation and empty text content', function() {
var params = checkSetup(
'<a id="target" href="link"><span role="presentation"></span></a>'
);
var actual = checks['has-visible-text'].evaluate.apply(
checkContext,
params
);
assert.isFalse(actual);
});

it('should return true if any of the nested children with role presentation has text content', function() {
var params = checkSetup(
'<a id="target" href="link"><div><span role="presentation">Link text</span></div></a>'
);
var actual = checks['has-visible-text'].evaluate.apply(
checkContext,
params
);
assert.isTrue(actual);
});

it('should return true if any of the nested children has text content', function() {
var params = checkSetup(
'<a id="target" href="link"><div>Some content<span role="presentation"></span></div></a>'
);
var actual = checks['has-visible-text'].evaluate.apply(
checkContext,
params
);
assert.isTrue(actual);
});

it('should return true if any of the siblings has text content', function() {
var params = checkSetup(
'<a id="target" href="link"><div>Some content</div><span role="presentation"></span></a>'
);
var actual = checks['has-visible-text'].evaluate.apply(
checkContext,
params
);
assert.isTrue(actual);
});

it('should return false if none of the siblings has text content', function() {
var params = checkSetup(
'<a id="target" href="link"><div></div><span></span><i></i></a>'
);
var actual = checks['has-visible-text'].evaluate.apply(
checkContext,
params
);
assert.isFalse(actual);
});

it('should return false if there is children with role presentation and empty text content', function() {
var params = checkSetup(
'<a id="target" href="link"><div><span role="presentation"></span></div></a>'
);
var actual = checks['has-visible-text'].evaluate.apply(
checkContext,
params
);
assert.isFalse(actual);
});
});
10 changes: 10 additions & 0 deletions test/integration/rules/link-name/link-name.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
<span role="link" href="#" tabindex="0" id="violation6" aria-labelledby="nonexistent"></span>

<a href="#" role="button">Does not apply</a>

<a id="pass8" href="link"><span role="presentation">Link text</span></a>
<a id="pass9" href="link"><div><span role="presentation">Link text</span></div></a>
<a id="pass10" href="link"><div>Some content<span role="presentation"></span></div></a>
<a id="pass11" href="link"><div>Some content</div><span role="presentation"></span></a>


<a id="fail1" href="link"><span role="presentation"></span></a>
<a id="fail2" href="link"><div></div><span></span><i></i></a>
<a id="fail3" href="link"><div><span role="presentation"></span></div></a>
24 changes: 22 additions & 2 deletions test/integration/rules/link-name/link-name.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
{
"description": "link-name tests",
"rule": "link-name",
"violations": [["#violation1"], ["#violation2"], ["#violation3"], ["#violation4"], ["#violation5"], ["#violation6"]],
"passes": [["#pass1"], ["#pass3"], ["#pass4"], ["#pass6"], ["#pass7"]]
"violations": [
["#violation1"],
["#violation2"],
["#violation3"],
["#violation4"],
["#violation5"],
["#violation6"],
["#fail1"],
["#fail2"],
["#fail3"]
],
"passes": [
["#pass1"],
["#pass3"],
["#pass4"],
["#pass6"],
["#pass7"],
["#pass8"],
["#pass9"],
["#pass10"],
["#pass11"]
]
}