-
Notifications
You must be signed in to change notification settings - Fork 776
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add test for link-name for serial nodes (#2404)
* tests: add test for link-name for serial nodes * finish tests
- Loading branch information
Showing
5 changed files
with
181 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |