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

tests: add test for link-name for serial nodes #2404

Merged
merged 3 commits into from
Jul 20, 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
11 changes: 6 additions & 5 deletions lib/checks/keyboard/focusable-no-name-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { isFocusable } from '../../commons/dom';
import { accessibleTextVirtual } from '../../commons/text';

function focusableNoNameEvaluate(node, options, virtualNode) {
const tabIndex = virtualNode.attr('tabindex');
const inFocusOrder = isFocusable(virtualNode) && tabIndex > -1;
if (!inFocusOrder) {
return false;
}

try {
const tabIndex = virtualNode.attr('tabindex');
const inFocusOrder = isFocusable(virtualNode) && tabIndex > -1;
if (!inFocusOrder) {
return false;
}
return !accessibleTextVirtual(virtualNode);
} catch (e) {
return undefined;
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/aria/get-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function resolveImplicitRole(vNode, explicitRoleOptions) {
// See also: https://github.com/w3c/aria/issues/1270
function hasConflictResolution(vNode) {
const hasGlobalAria = getGlobalAriaAttrs().some(attr => vNode.hasAttr(attr));
return hasGlobalAria || isFocusable(vNode.actualNode);
return hasGlobalAria || isFocusable(vNode);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/commons/standards/implicit-html-roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const implicitHtmlRoles = {
vNode.hasAttr(attr)
);

return emptyAlt && !hasGlobalAria && !isFocusable(vNode.actualNode)
return emptyAlt && !hasGlobalAria && !isFocusable(vNode)
? 'presentation'
: 'img';
},
Expand Down
1 change: 1 addition & 0 deletions test/integration/virtual-rules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<script src="area-alt.js"></script>
<script src="svg-img-alt.js"></script>
<script src="role-img-alt.js"></script>
<script src="link-name.js"></script>
<script src="/test/integration/adapter.js"></script>
</body>
</html>
172 changes: 172 additions & 0 deletions test/integration/virtual-rules/link-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
describe('link-name', function() {
it('should pass for aria-label', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'a',
attributes: {
href: '/foo.html',
'aria-label': 'foobar'
}
});

var results = axe.runVirtualRule('link-name', node);

assert.lengthOf(results.passes, 1);
assert.lengthOf(results.violations, 0);
assert.lengthOf(results.incomplete, 0);
});

it('should incomplete for aria-labelledby', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'a',
attributes: {
href: '/foo.html',
'aria-labelledby': 'foobar'
}
});

var results = axe.runVirtualRule('link-name', node);

assert.lengthOf(results.passes, 0);
assert.lengthOf(results.violations, 0);
assert.lengthOf(results.incomplete, 1);
});

it('should pass for role=presentation', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'a',
attributes: {
href: '/foo.html',
tabindex: '-1',
role: 'presentation'
}
});
node.children = [];

var results = axe.runVirtualRule('link-name', node);

assert.lengthOf(results.passes, 1);
assert.lengthOf(results.violations, 0);
assert.lengthOf(results.incomplete, 0);
});

it('should pass for role=none', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'a',
attributes: {
href: '/foo.html',
tabindex: '-1',
role: 'none'
}
});
node.children = [];

var results = axe.runVirtualRule('link-name', node);

assert.lengthOf(results.passes, 1);
assert.lengthOf(results.violations, 0);
assert.lengthOf(results.incomplete, 0);
});

it('should pass for visible text content', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'span',
attributes: {
role: 'link'
}
});
var child = new axe.SerialVirtualNode({
nodeName: '#text',
nodeType: 3,
nodeValue: 'foobar'
});
node.children = [child];

var results = axe.runVirtualRule('link-name', node);

assert.lengthOf(results.passes, 1);
assert.lengthOf(results.violations, 0);
assert.lengthOf(results.incomplete, 0);
});

it('should incomplete when aria-label and children are missing', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'a',
attributes: {
href: '/foo.html'
}
});

var results = axe.runVirtualRule('link-name', node);

assert.lengthOf(results.passes, 0);
assert.lengthOf(results.violations, 0);
assert.lengthOf(results.incomplete, 1);
});

it('should fail when aria-label contains only whitespace', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'a',
attributes: {
href: '/foo.html',
'aria-label': ' \t \n '
}
});
node.children = [];

var results = axe.runVirtualRule('link-name', node);

assert.lengthOf(results.passes, 0);
assert.lengthOf(results.violations, 1);
assert.lengthOf(results.incomplete, 0);
});

it('should fail when aria-label is empty', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'a',
attributes: {
href: '/foo.html',
'aria-label': ''
}
});
node.children = [];

var results = axe.runVirtualRule('link-name', node);

assert.lengthOf(results.passes, 0);
assert.lengthOf(results.violations, 1);
assert.lengthOf(results.incomplete, 0);
});

it('should incomplete if anchor is still focusable and missing children', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'a',
attributes: {
href: '/foo.html',
role: 'presentation'
}
});

var results = axe.runVirtualRule('link-name', node);

assert.lengthOf(results.passes, 0);
assert.lengthOf(results.violations, 0);
assert.lengthOf(results.incomplete, 1);
});

it('should fail if anchor is still focusable and no children', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'a',
attributes: {
href: '/foo.html',
role: 'presentation'
}
});
node.children = [];

var results = axe.runVirtualRule('link-name', node);

assert.lengthOf(results.passes, 0);
assert.lengthOf(results.violations, 1);
assert.lengthOf(results.incomplete, 0);
});
});