-
Notifications
You must be signed in to change notification settings - Fork 779
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dpub): upgrade to DPUB 1.1 and report deprecated roles (#3280)
* feat(dpub): upgrade to DPUB 1.1 and report deprecated roles * Apply suggestions from code review Co-authored-by: Steven Lambert <[email protected]> * Handle fallback roles Co-authored-by: Steven Lambert <[email protected]>
- Loading branch information
1 parent
ce4dfaf
commit 034a846
Showing
11 changed files
with
205 additions
and
75 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import standards from '../../standards'; | ||
import { getRole } from '../../commons/aria'; | ||
|
||
/** | ||
* Check that an elements semantic role is deprecated. | ||
* | ||
* Deprecated roles are taken from the `ariaRoles` standards object from the roles `deprecated` property. | ||
* | ||
* @memberof checks | ||
* @return {Boolean} True if the elements semantic role is deprecated. False otherwise. | ||
*/ | ||
export default function deprecatedroleEvaluate(node, options, virtualNode) { | ||
const role = getRole(virtualNode, { dpub: true, fallback: true }); | ||
const roleDefinition = standards.ariaRoles[role]; | ||
if (!roleDefinition?.deprecated) { | ||
return false; | ||
} | ||
|
||
this.data(role); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"id": "deprecatedrole", | ||
"evaluate": "deprecatedrole-evaluate", | ||
"metadata": { | ||
"impact": "minor", | ||
"messages": { | ||
"pass": "ARIA role is not deprecated", | ||
"fail": "The role used is deprecated: ${data.values}" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
describe('deprecatedrole', function() { | ||
'use strict'; | ||
|
||
var checkContext = axe.testUtils.MockCheckContext(); | ||
var checkSetup = axe.testUtils.checkSetup; | ||
var checkEvaluate = axe.testUtils.getCheckEvaluate('deprecatedrole'); | ||
afterEach(function () { | ||
checkContext.reset(); | ||
axe.reset(); | ||
}) | ||
|
||
it('returns true if applied to a deprecated role', function() { | ||
axe.configure({ | ||
standards: { | ||
ariaRoles: { | ||
melon: { | ||
type: 'widget', | ||
deprecated: true | ||
} | ||
} | ||
} | ||
}); | ||
var params = checkSetup('<div id="target" role="melon">Contents</div>'); | ||
assert.isTrue(checkEvaluate.apply(checkContext, params)); | ||
assert.deepEqual(checkContext._data, 'melon'); | ||
}); | ||
|
||
it('returns true if applied to a deprecated DPUB role', function() { | ||
axe.configure({ | ||
standards: { | ||
ariaRoles: { | ||
'doc-fizzbuzz': { | ||
type: 'widget', | ||
deprecated: true | ||
} | ||
} | ||
} | ||
}); | ||
var params = checkSetup('<div id="target" role="doc-fizzbuzz">Contents</div>'); | ||
assert.isTrue(checkEvaluate.apply(checkContext, params)); | ||
assert.deepEqual(checkContext._data, 'doc-fizzbuzz'); | ||
}); | ||
|
||
it('returns false if applied to a non-deprecated role', function() { | ||
var params = checkSetup('<div id="target" role="button">Contents</div>'); | ||
assert.isFalse(checkEvaluate.apply(checkContext, params)); | ||
assert.isNull(checkContext._data); | ||
|
||
var params = checkSetup('<button id="target">Contents</button>'); | ||
assert.isFalse(checkEvaluate.apply(checkContext, params)); | ||
assert.isNull(checkContext._data); | ||
}); | ||
|
||
it('returns false if applied to an invalid role', function() { | ||
var params = checkSetup('<input id="target" role="foo">'); | ||
assert.isFalse(checkEvaluate.apply(checkContext, params)); | ||
assert.isNull(checkContext._data); | ||
}); | ||
|
||
describe('with fallback roles', function () { | ||
it('returns true if the deprecated role is the first valid role', function () { | ||
axe.configure({ | ||
standards: { | ||
ariaRoles: { | ||
melon: { | ||
type: 'widget', | ||
deprecated: true | ||
} | ||
} | ||
} | ||
}); | ||
var params = checkSetup('<div id="target" role="foo widget melon button">Contents</div>'); | ||
assert.isTrue(checkEvaluate.apply(checkContext, params)); | ||
assert.deepEqual(checkContext._data, 'melon'); | ||
}) | ||
|
||
it('returns false if the deprecated role is not the first valid role', function () { | ||
axe.configure({ | ||
standards: { | ||
ariaRoles: { | ||
melon: { | ||
type: 'widget', | ||
deprecated: true | ||
} | ||
} | ||
} | ||
}); | ||
var params = checkSetup('<div id="target" role="button melon widget">Contents</div>'); | ||
assert.isFalse(checkEvaluate.apply(checkContext, params)); | ||
assert.isNull(checkContext._data); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters