Skip to content

Commit

Permalink
tests: add test for link-name for serial nodes (#2404)
Browse files Browse the repository at this point in the history
* tests: add test for link-name for serial nodes

* finish tests
  • Loading branch information
straker authored Jul 20, 2020
1 parent bda2cd5 commit 9ca5dde
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 7 deletions.
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);
});
});

0 comments on commit 9ca5dde

Please sign in to comment.