Skip to content

Commit

Permalink
fix(checks/unsupportedrole): support unsupported dpub and fallback ro…
Browse files Browse the repository at this point in the history
…les, add role to message (#3395)

* refactor(checks/navigation): improve `internal-link-present-evaluate`

Make `internal-link-present-evaluate` work with virtualNode rather than actualNode.

Closes issue #2466

* test commit 1

* test commit 2

* test commit 3

* Revert "Merge branch 'dan-test-branch-1' into develop"

This reverts commit 428e015, reversing
changes made to 9f996bc.

* Revert "test commit 1"

This reverts commit 9f996bc.

* fix(rule): allow "tabindex=-1" for rules "aria-text" and "nested-interactive"

Closes issue #2934

* work in progress

* work in progress

* test commit 1

* Revert "test commit 1"

This reverts commit 9f996bc.

* fix(rule): allow "tabindex=-1" for rules "aria-text" and "nested-interactive"

Closes issue #2934

* work in progress

* work in progress

* fix whitespace

* add new case to test test/checks/keyboard/no-focusable-content.js

* change "disabled" test case in test/checks/keyboard/no-focusable-content.js

* fix merge problem

* fix(rules): unsupportedrole check bugs

Closes issue #3282

* lint fix

* add assertion on checkContext._data to unit tests

* refactor(checks/unsupportedrole): change this.data from using array to single string

to match lib/checks/aria/deprecatedrole-evaluate.js

* Revert "refactor(checks/unsupportedrole): change this.data from using array to single string"

This reverts commit e7c757f9330b635b1ed16385b3526f2e71786488.

* refactor(checks/unsupportedrole): change this.data from using array to single string
  • Loading branch information
dan-tripp committed Feb 28, 2022
1 parent 0edc02d commit 3c0f10f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 11 deletions.
8 changes: 7 additions & 1 deletion lib/checks/aria/unsupportedrole-evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ import { isUnsupportedRole, getRole } from '../../commons/aria';
* @return {Boolean} True if the elements semantic role is unsupported. False otherwise.
*/
function unsupportedroleEvaluate(node, options, virtualNode) {
return isUnsupportedRole(getRole(virtualNode));
const role = getRole(virtualNode, { dpub: true, fallback: true });
const isUnsupported = isUnsupportedRole(role);
if (isUnsupported) {
this.data(role);
}
return isUnsupported;

}

export default unsupportedroleEvaluate;
2 changes: 1 addition & 1 deletion lib/checks/aria/unsupportedrole.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"impact": "critical",
"messages": {
"pass": "ARIA role is supported",
"fail": "The role used is not widely supported in screen readers and assistive technologies: ${data.values}"
"fail": "The role used is not widely supported in screen readers and assistive technologies: ${data}"
}
}
}
67 changes: 58 additions & 9 deletions test/checks/aria/unsupportedrole.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
describe('unsupportedrole', function() {
'use strict';

var queryFixture = axe.testUtils.queryFixture;
var checkContext = axe.testUtils.MockCheckContext();
var checkSetup = axe.testUtils.checkSetup;
var check = checks.unsupportedrole;
afterEach(function() {
checkContext.reset();
axe.reset();
});

it('should return true if applied to an unsupported role', function() {
axe.configure({
Expand All @@ -15,22 +21,65 @@ describe('unsupportedrole', function() {
}
});

var vNode = queryFixture(
var params = checkSetup(
'<div id="target" role="mccheddarton">Contents</div>'
);
assert.isTrue(checks.unsupportedrole.evaluate(null, null, vNode));
assert.isTrue(check.evaluate.apply(checkContext, params));
assert.deepEqual(checkContext._data, "mccheddarton");
});

it('should return false if applied to a supported role', function() {
var vNode = queryFixture('<div id="target" role="alert">Contents</div>');
assert.isFalse(checks.unsupportedrole.evaluate(null, null, vNode));
var params = checkSetup('<div id="target" role="alert">Contents</div>');
assert.isFalse(check.evaluate.apply(checkContext, params));
assert.isNull(checkContext._data);

var vNode = queryFixture('<button id="target">Contents</button>');
assert.isFalse(checks.unsupportedrole.evaluate(null, null, vNode));
var params = checkSetup('<button id="target">Contents</button>');
assert.isFalse(check.evaluate.apply(checkContext, params));
assert.isNull(checkContext._data);
});

it('should return false if applied to an invalid role', function() {
var vNode = queryFixture('<input id="target" role="foo">');
assert.isFalse(checks.unsupportedrole.evaluate(null, null, vNode));
var params = checkSetup('<input id="target" role="foo">');
assert.isFalse(check.evaluate.apply(checkContext, params));
assert.isNull(checkContext._data);
});

it('should return true if applied to an unsupported dpub role', function() {
axe.configure({
standards: {
ariaRoles: {
'doc-abstract': {
type: 'section',
unsupported: true
}
}
}
});

var params = checkSetup(
'<div id="target" role="doc-abstract">Contents</div>'
);
assert.isTrue(check.evaluate.apply(checkContext, params));
assert.deepEqual(checkContext._data, "doc-abstract");
});

it('should return true if applied to an unsupported fallback role', function() {
axe.configure({
standards: {
ariaRoles: {
alert: {
type: 'widget',
unsupported: true
}
}
}
});

var params = checkSetup(
'<div id="target" role="unsupported alert">Contents</div>'
);
assert.isTrue(check.evaluate.apply(checkContext, params));
assert.deepEqual(checkContext._data, "alert");
});

});

0 comments on commit 3c0f10f

Please sign in to comment.