From a470b9a043e09b783774167acfde124ef164ca32 Mon Sep 17 00:00:00 2001 From: Steven Lambert Date: Mon, 20 Jul 2020 09:07:17 -0600 Subject: [PATCH] tests: add test for role-img-alt for serial nodes --- test/integration/virtual-rules/index.html | 1 + .../integration/virtual-rules/role-img-alt.js | 104 ++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 test/integration/virtual-rules/role-img-alt.js 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); + }); +});