diff --git a/test/integration/virtual-rules/index.html b/test/integration/virtual-rules/index.html index ac4bb7216d..da78676812 100644 --- a/test/integration/virtual-rules/index.html +++ b/test/integration/virtual-rules/index.html @@ -32,6 +32,7 @@ + diff --git a/test/integration/virtual-rules/role-img-alt.js b/test/integration/virtual-rules/role-img-alt.js new file mode 100644 index 0000000000..7bee710e81 --- /dev/null +++ b/test/integration/virtual-rules/role-img-alt.js @@ -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); + }); +});