Skip to content

Commit

Permalink
tests: add test for role-img-alt for serial nodes (#2402)
Browse files Browse the repository at this point in the history
  • Loading branch information
straker authored Jul 20, 2020
1 parent 1ef3066 commit 9f2d8db
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/integration/virtual-rules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<script src="aria-toggle-field-name.js"></script>
<script src="aria-input-field-name.js"></script>
<script src="area-alt.js"></script>
<script src="role-img-alt.js"></script>
<script src="/test/integration/adapter.js"></script>
</body>
</html>
104 changes: 104 additions & 0 deletions test/integration/virtual-rules/role-img-alt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
describe('role-img-alt', function() {
it('should pass for aria-label', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'div',
attributes: {
role: 'img',
'aria-label': 'foobar'
}
});

var results = axe.runVirtualRule('role-img-alt', 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: 'div',
attributes: {
role: 'img',
'aria-labelledby': 'foobar'
}
});

var results = axe.runVirtualRule('role-img-alt', node);

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

it('should pass for title', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'div',
attributes: {
role: 'img',
title: 'foobar'
}
});

// children are required since titleText comes after subtree text
// in accessible name calculation
node.children = [];

var results = axe.runVirtualRule('role-img-alt', node);

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

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

var results = axe.runVirtualRule('role-img-alt', 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: 'div',
attributes: {
role: 'img',
'aria-label': ''
}
});
node.children = [];

var results = axe.runVirtualRule('role-img-alt', node);

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

it('should fail when title is empty', function() {
var node = new axe.SerialVirtualNode({
nodeName: 'div',
attributes: {
role: 'img',
title: ''
}
});
node.children = [];

var results = axe.runVirtualRule('role-img-alt', node);

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

0 comments on commit 9f2d8db

Please sign in to comment.