Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(validate-attr,unsupported-attr): work with standards object #2374

Merged
merged 1 commit into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 4 additions & 18 deletions lib/checks/aria/aria-unsupported-attr-evaluate.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { lookupTable, getRole, validateAttr } from '../../commons/aria';
import { validateAttr } from '../../commons/aria';
import standards from '../../standards';
import matches from '../../commons/matches';
import { getNodeAttributes } from '../../core/utils';

function ariaUnsupportedAttrEvaluate(node) {
const nodeName = node.nodeName.toUpperCase();
const role = getRole(node);

const unsupportedAttrs = Array.from(getNodeAttributes(node))
.filter(({ name }) => {
const attribute = lookupTable.attributes[name];
const attribute = standards.ariaAttrs[name];

if (!validateAttr(name)) {
return false;
Expand All @@ -20,19 +18,7 @@ function ariaUnsupportedAttrEvaluate(node) {
return !!unsupported;
}

// validate attributes and conditions (if any) from allowedElement to given node
const isException = matches(node, unsupported.exceptions);

if (!Object.keys(lookupTable.evaluateRoleForElement).includes(nodeName)) {
return !isException;
}

// evaluate a given aria-role, execute the same
return !lookupTable.evaluateRoleForElement[nodeName]({
node,
role,
out: isException
});
return !matches(node, unsupported.exceptions);
})
.map(candidate => candidate.name.toString());

Expand Down
4 changes: 2 additions & 2 deletions lib/commons/aria/validate-attr.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import lookupTable from './lookup-table';
import standards from '../../standards';

/**
* Check if an aria- attribute name is valid
Expand All @@ -9,7 +9,7 @@ import lookupTable from './lookup-table';
* @return {Boolean}
*/
function validateAttr(att) {
const attrDefinition = lookupTable.attributes[att];
const attrDefinition = standards.ariaAttrs[att];
return !!attrDefinition;
}

Expand Down
108 changes: 73 additions & 35 deletions test/checks/aria/unsupportedattr.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,39 @@ describe('unsupportedattr', function() {

afterEach(function() {
checkContext.reset();
axe.reset();
});

it('should return true if applied to an unsupported attribute', function() {
axe.commons.aria.lookupTable.attributes['aria-mccheddarton'] = {
unsupported: true
};
axe.configure({
standards: {
ariaAttrs: {
'aria-mccheddarton': {
unsupported: true
}
}
}
});

var params = checkSetup(
'<div id="target" aria-mccheddarton="true">Contents</div>'
);
assert.isTrue(check.evaluate.apply(checkContext, params));
});

it('should return true with multiple unsupported and supported attributes', function() {
axe.commons.aria.lookupTable.attributes['aria-mccheddarton'] = {
unsupported: true
};
axe.commons.aria.lookupTable.attributes['aria-bagleypants'] = {
unsupported: true
};
axe.configure({
standards: {
ariaAttrs: {
'aria-mccheddarton': {
unsupported: true
},
'aria-bagleypants': {
unsupported: true
}
}
}
});
var params = checkSetup(
'<div id="target" aria-mccheddarton="true" aria-bagleypants="false" aria-label="Nope">Contents</div>'
);
Expand All @@ -51,61 +65,85 @@ describe('unsupportedattr', function() {
});

it('should return false if applied to an element that matches the unsupported "exceptions" list', function() {
axe.commons.aria.lookupTable.attributes['aria-mccheddarton'] = {
unsupported: {
exceptions: ['button']
axe.configure({
standards: {
ariaAttrs: {
'aria-mccheddarton': {
unsupported: {
exceptions: ['button']
}
}
}
}
};
});
var params = checkSetup(
'<button id="target" aria-mccheddarton="true">Contents</button>'
);
assert.isFalse(check.evaluate.apply(checkContext, params));
});

it('should return false if applied to an element that matches the unsupported "exceptions" list using complex conditions', function() {
axe.commons.aria.lookupTable.attributes['aria-mccheddarton'] = {
unsupported: {
exceptions: [
{
nodeName: 'input',
properties: {
type: 'checkbox'
axe.configure({
standards: {
ariaAttrs: {
'aria-mccheddarton': {
unsupported: {
exceptions: [
{
nodeName: 'input',
properties: {
type: 'checkbox'
}
}
]
}
}
]
}
}
};
});
var params = checkSetup(
'<input type="checkbox" id="target" aria-mccheddarton="true">'
);
assert.isFalse(check.evaluate.apply(checkContext, params));
});

it('should return true if applied to an element that does not match the unsupported "exceptions" list', function() {
axe.commons.aria.lookupTable.attributes['aria-mccheddarton'] = {
unsupported: {
exceptions: ['button']
axe.configure({
standards: {
ariaAttrs: {
'aria-mccheddarton': {
unsupported: {
exceptions: ['button']
}
}
}
}
};
});
var params = checkSetup(
'<div id="target" aria-mccheddarton="true">Contents</div>'
);
assert.isTrue(check.evaluate.apply(checkContext, params));
});

it('should return true if applied to an element that does not match the unsupported "exceptions" list using complex conditions', function() {
axe.commons.aria.lookupTable.attributes['aria-mccheddarton'] = {
unsupported: {
exceptions: [
{
nodeName: 'input',
properties: {
type: 'checkbox'
axe.configure({
standards: {
ariaAttrs: {
'aria-mccheddarton': {
unsupported: {
exceptions: [
{
nodeName: 'input',
properties: {
type: 'checkbox'
}
}
]
}
}
]
}
}
};
});
var params = checkSetup(
'<input type="radio" id="target" aria-mccheddarton="true">'
);
Expand Down
13 changes: 10 additions & 3 deletions test/checks/aria/valid-attr.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('aria-valid-attr', function() {
afterEach(function() {
fixture.innerHTML = '';
checkContext.reset();
axe.reset();
});

it('should return false if any invalid ARIA attributes are found', function() {
Expand Down Expand Up @@ -37,9 +38,15 @@ describe('aria-valid-attr', function() {
});

it('should return true for unsupported ARIA attributes', function() {
axe.commons.aria.lookupTable.attributes['aria-mccheddarton'] = {
unsupported: true
};
axe.configure({
standards: {
ariaAttrs: {
'aria-mccheddarton': {
unsupported: true
}
}
}
});

var node = document.createElement('div');
node.id = 'test';
Expand Down
27 changes: 0 additions & 27 deletions test/commons/aria/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,3 @@ describe('aria.requiredAttr', function() {
assert.deepEqual(result, []);
});
});

describe('aria.validateAttr', function() {
'use strict';

var orig;
beforeEach(function() {
orig = axe.commons.aria.lookupTable.attributes;
});

afterEach(function() {
axe.commons.aria.lookupTable.attributes = orig;
});

it('should return true if attribute is found in lut', function() {
axe.commons.aria.lookupTable.attributes = {
cats: {}
};

assert.isTrue(axe.commons.aria.validateAttr('cats'));
});

it('should return false if attribute is found in lut', function() {
axe.commons.aria.lookupTable.attributes = {};

assert.isFalse(axe.commons.aria.validateAttr('cats'));
});
});
23 changes: 23 additions & 0 deletions test/commons/aria/validate-attr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe('aria.validateAttr', function() {
'use strict';

afterEach(function() {
axe.reset();
});

it('should return true if attribute is found in lut', function() {
axe.configure({
standards: {
ariaAttrs: {
cats: {}
}
}
});

assert.isTrue(axe.commons.aria.validateAttr('cats'));
});

it('should return false if attribute is found in lut', function() {
assert.isFalse(axe.commons.aria.validateAttr('cats'));
});
});
3 changes: 0 additions & 3 deletions test/integration/rules/aria-allowed-attr/failures.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,3 @@
<div role="link" aria-selected="true" id="fail2">fail</div>
<div role="row" aria-colcount="value" id="fail3">fail</div>
<div role="row" aria-rowcount="value" id="fail4">fail</div>

<!-- unsupported attributes -->
<div aria-describedat="#fail4" id="fail5">fail</div>
2 changes: 1 addition & 1 deletion test/integration/rules/aria-allowed-attr/failures.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"description": "aria-allowed-attr failing tests",
"rule": "aria-allowed-attr",
"violations": [["#fail1"], ["#fail2"], ["#fail3"], ["#fail4"], ["#fail5"]]
"violations": [["#fail1"], ["#fail2"], ["#fail3"], ["#fail4"]]
}