Skip to content

Commit

Permalink
tests: prepare tests for commons.matches change (#1989)
Browse files Browse the repository at this point in the history
* tests: prepare tests for commons.matches change

* remove dups

* refactor

* changes

* fix typo
  • Loading branch information
straker authored Jan 20, 2020
1 parent 759d88d commit 937a99f
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 7 deletions.
8 changes: 6 additions & 2 deletions lib/commons/aria/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2169,8 +2169,12 @@ lookupTable.elementsAllowedNoRole = [
},
{
nodeName: 'select',
condition: node => {
return Number(node.getAttribute('size')) > 1;
condition: vNode => {
if (!(vNode instanceof axe.AbstractVirtualNode)) {
vNode = axe.utils.getNodeFromTree(vNode);
}

return Number(vNode.attr('size')) > 1;
},
properties: {
multiple: true
Expand Down
29 changes: 29 additions & 0 deletions test/checks/aria/aria-allowed-role.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ describe('aria-allowed-role', function() {

var fixture = document.getElementById('fixture');
var checkContext = axe.testUtils.MockCheckContext();
var flatTreeSetup = axe.testUtils.flatTreeSetup;

afterEach(function() {
fixture.innerHTML = '';
Expand All @@ -13,6 +14,7 @@ describe('aria-allowed-role', function() {
var node = document.createElement('article');
node.setAttribute('role', 'presentation');
fixture.appendChild(node);
flatTreeSetup(fixture);
var options = {
ignoredTags: ['article']
};
Expand All @@ -30,6 +32,7 @@ describe('aria-allowed-role', function() {
fixture.innerHTML =
'<table role="grid"><tr id="target" role="row"></tr></table>';
var target = fixture.querySelector('#target');
flatTreeSetup(fixture);
var options = {
allowImplicit: false
};
Expand All @@ -46,6 +49,7 @@ describe('aria-allowed-role', function() {
it('returns true when A has namespace as svg', function() {
var node = document.createElementNS('http://www.w3.org/2000/svg', 'a');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -56,6 +60,7 @@ describe('aria-allowed-role', function() {
'<button id="target" type="button" aria-hidden="true"' +
'role="presentation"></button>';
var target = fixture.querySelector('#target');
flatTreeSetup(fixture);
var actual = checks['aria-allowed-role'].evaluate.call(
checkContext,
target
Expand All @@ -70,6 +75,7 @@ describe('aria-allowed-role', function() {
'role="presentation"></button>' +
'</div>';
var target = fixture.querySelector('#target');
flatTreeSetup(fixture);
var actual = checks['aria-allowed-role'].evaluate.call(
checkContext,
target
Expand All @@ -82,6 +88,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('type', 'menu');
node.setAttribute('role', 'menuitem');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -91,6 +98,7 @@ describe('aria-allowed-role', function() {
var node = document.createElement('img');
node.setAttribute('role', 'presentation');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -107,6 +115,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('alt', '');
node.setAttribute('role', 'presentation');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -123,6 +132,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('alt', 'not empty');
node.setAttribute('role', 'presentation');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isFalse(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -138,6 +148,7 @@ describe('aria-allowed-role', function() {
var node = document.createElement('img');
node.setAttribute('type', 'image');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -149,6 +160,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('type', 'checkbox');
node.setAttribute('aria-pressed', '');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -159,6 +171,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('type', 'text');
node.setAttribute('role', 'combobox');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -169,6 +182,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('type', 'tel');
node.setAttribute('role', 'combobox');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -179,6 +193,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('type', 'url');
node.setAttribute('role', 'combobox');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -189,6 +204,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('type', 'search');
node.setAttribute('role', 'combobox');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -199,6 +215,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('type', 'email');
node.setAttribute('role', 'combobox');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -209,6 +226,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('type', 'text');
node.setAttribute('role', 'spinbutton');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -219,6 +237,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('type', 'text');
node.setAttribute('role', 'searchbox');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -228,6 +247,7 @@ describe('aria-allowed-role', function() {
var node = document.createElement('dd');
node.setAttribute('role', 'link');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isFalse(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -238,6 +258,7 @@ describe('aria-allowed-role', function() {
var node = document.createElement('div');
node.setAttribute('role', 'link');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -247,6 +268,7 @@ describe('aria-allowed-role', function() {
var node = document.createElement('a');
node.setAttribute('role', 'presentation');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -257,6 +279,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('role', 'link');
node.href = '';
fixture.appendChild(node);
flatTreeSetup(fixture);
var actual = checks['aria-allowed-role'].evaluate.call(checkContext, node);
assert.isTrue(actual);
});
Expand All @@ -266,6 +289,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('role', 'banner');
node.alt = 'some text';
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -276,6 +300,7 @@ describe('aria-allowed-role', function() {
node.setAttribute('role', 'presentation');
node.alt = 'some text';
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isFalse(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -285,6 +310,7 @@ describe('aria-allowed-role', function() {
var node = document.createElement('select');
node.setAttribute('role', 'menu');
fixture.appendChild(node);
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, node)
);
Expand All @@ -295,6 +321,7 @@ describe('aria-allowed-role', function() {
var node = document.createElement('my-navbar');
node.setAttribute('role', 'navigation');
fixture.appendChild(node);
flatTreeSetup(fixture);
var actual = checks['aria-allowed-role'].evaluate.call(checkContext, node);
assert.isTrue(actual);
assert.isNull(checkContext._data, null);
Expand All @@ -303,6 +330,7 @@ describe('aria-allowed-role', function() {
it('returns false if a dpub role’s type is not the element’s implicit role', function() {
fixture.innerHTML = '<article role="doc-biblioref" id="target"></article>';
var target = fixture.children[0];
flatTreeSetup(fixture);
assert.isFalse(
checks['aria-allowed-role'].evaluate.call(checkContext, target)
);
Expand All @@ -311,6 +339,7 @@ describe('aria-allowed-role', function() {
it('returns true if a dpub role’s type is the element’s implicit role', function() {
fixture.innerHTML = '<a href="foo" role="doc-biblioref" id="target"></a>';
var target = fixture.children[0];
flatTreeSetup(fixture);
assert.isTrue(
checks['aria-allowed-role'].evaluate.call(checkContext, target)
);
Expand Down
5 changes: 5 additions & 0 deletions test/checks/shared/non-empty-title.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ describe('non-empty-title', function() {
'use strict';

var fixture = document.getElementById('fixture');
var flatTreeSetup = axe.testUtils.flatTreeSetup;

afterEach(function() {
fixture.innerHTML = '';
Expand All @@ -11,13 +12,15 @@ describe('non-empty-title', function() {
var node = document.createElement('img');
node.setAttribute('title', 'woohoo');
fixture.appendChild(node);
flatTreeSetup(fixture);

assert.isTrue(checks['non-empty-title'].evaluate(node));
});

it('should return false if a title is not present', function() {
var node = document.createElement('img');
fixture.appendChild(node);
flatTreeSetup(fixture);

assert.isFalse(checks['non-empty-title'].evaluate(node));
});
Expand All @@ -26,6 +29,7 @@ describe('non-empty-title', function() {
var node = document.createElement('img');
node.setAttribute('title', ' ');
fixture.appendChild(node);
flatTreeSetup(fixture);

assert.isFalse(checks['non-empty-title'].evaluate(node));
});
Expand All @@ -34,6 +38,7 @@ describe('non-empty-title', function() {
var node = document.createElement('div');
node.setAttribute('title', ' \t \n \r \t \t\r\n ');
fixture.appendChild(node);
flatTreeSetup(fixture);

assert.isFalse(checks['non-empty-title'].evaluate(node));
});
Expand Down
18 changes: 13 additions & 5 deletions test/commons/aria/get-element-unallowed-roles.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
describe('aria.getElementUnallowedRoles', function() {
var flatTreeSetup = axe.testUtils.flatTreeSetup;

it('returns false for INPUT with role application', function() {
var node = document.createElement('input');
var role = 'application';
node.setAttribute('type', '');
node.setAttribute('aria-pressed', '');
node.setAttribute('role', role);
flatTreeSetup(node);
var actual = axe.commons.aria.getElementUnallowedRoles(node);
assert.isNotEmpty(actual);
assert.include(actual, role);
Expand All @@ -14,6 +17,7 @@ describe('aria.getElementUnallowedRoles', function() {
var node = document.createElement('input');
node.setAttribute('type', 'checkbox');
node.setAttribute('aria-pressed', '');
flatTreeSetup(node);
var actual = axe.commons.aria.getElementUnallowedRoles(node);
assert.isEmpty(actual);
});
Expand All @@ -22,6 +26,7 @@ describe('aria.getElementUnallowedRoles', function() {
var node = document.createElement('li');
var role = 'menubar';
node.setAttribute('role', role);
flatTreeSetup(node);
var actual = axe.commons.aria.getElementUnallowedRoles(node);
assert.isEmpty(actual);
});
Expand All @@ -31,6 +36,7 @@ describe('aria.getElementUnallowedRoles', function() {
var role = 'menuitemcheckbox';
node.setAttribute('role', role);
node.setAttribute('type', 'button');
flatTreeSetup(node);
var actual = axe.commons.aria.getElementUnallowedRoles(node);
assert.isEmpty(actual);
});
Expand All @@ -39,6 +45,7 @@ describe('aria.getElementUnallowedRoles', function() {
var node = document.createElement('section');
var role = 'option';
node.setAttribute('role', role);
flatTreeSetup(node);
var actual = axe.commons.aria.getElementUnallowedRoles(node);
assert.isNotEmpty(actual);
assert.include(actual, role);
Expand All @@ -49,6 +56,7 @@ describe('aria.getElementUnallowedRoles', function() {
var role = 'menuitemradio';
node.setAttribute('role', role);
node.setAttribute('type', 'radio');
flatTreeSetup(node);
var actual = axe.commons.aria.getElementUnallowedRoles(node);
assert.isEmpty(actual);
});
Expand All @@ -57,16 +65,16 @@ describe('aria.getElementUnallowedRoles', function() {
var node = document.createElement('input');
var role = 'textbox';
node.setAttribute('role', role);
flatTreeSetup(node);
var actual = axe.commons.aria.getElementUnallowedRoles(node, true);
assert.isEmpty(actual);
});

it('returns false with implicit role of row for TR when allowImplicit is set to false via options', function() {
var node = document.createElement('table');
node.setAttribute('role', 'grid');
var row = document.createElement('tr');
row.setAttribute('role', 'row');
var actual = axe.commons.aria.getElementUnallowedRoles(row, false);
var node = document.createElement('tr');
node.setAttribute('role', 'row');
flatTreeSetup(node);
var actual = axe.commons.aria.getElementUnallowedRoles(node, false);
assert.isNotEmpty(actual);
assert.include(actual, 'row');
});
Expand Down
Loading

0 comments on commit 937a99f

Please sign in to comment.