Skip to content

Commit 7ec9c50

Browse files
author
Andrew A Lee
authored
Merge pull request #132 from drewlee/master
Fixes #124. Allows a11yAudit to account for axe include/exclude context param.
2 parents 0aaa36f + c179f1d commit 7ec9c50

File tree

7 files changed

+44
-8
lines changed

7 files changed

+44
-8
lines changed

addon-test-support/audit.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ function isPlainObj(obj) {
4444
return typeof obj == 'object' && obj.constructor == Object;
4545
}
4646

47+
/**
48+
* Determines whether supplied object contains `include` and `exclude` axe
49+
* context selector properties. This is necessary to distinguish an axe
50+
* config object from a context selector object, after a single argument
51+
* is supplied to `runA11yAudit`.
52+
* @param {Object} obj
53+
* @return {Boolean}
54+
*/
55+
function isNotSelectorObj(obj) {
56+
return !obj.hasOwnProperty('include') && !obj.hasOwnProperty('exclude');
57+
}
58+
4759
/**
4860
* Runs the axe a11y audit with the given context selector and options.
4961
* The context defaults to '#ember-testing-container' if not specified.
@@ -56,7 +68,7 @@ function runA11yAudit(contextSelector = '#ember-testing-container', axeOptions)
5668
mark('a11y_audit_start');
5769

5870
// Support passing axeOptions as a single argument
59-
if (arguments.length === 1 && isPlainObj(contextSelector)) {
71+
if (arguments.length === 1 && isPlainObj(contextSelector) && isNotSelectorObj(contextSelector)) {
6072
axeOptions = contextSelector;
6173
contextSelector = '#ember-testing-container';
6274
}

addon/utils/concurrent-axe.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export class ConcurrentAxe {
2020
* @return {Void}
2121
*/
2222
run(element, options, callback) {
23-
if (this._timer) {
23+
if (this._timer !== null) {
2424
this._queue.push(arguments);
2525
} else {
2626
this._timer = next(() => {

tests/acceptance/a11y-audit-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,30 @@ test('a11yAudit should properly scope to a specified html element context (not r
7171
});
7272
});
7373

74+
test('a11yAudit accounts for axe.run include and exclude context parameter', function(assert) {
75+
visit('/');
76+
77+
a11yAudit({
78+
include: [[SELECTORS.passingComponent]]
79+
});
80+
81+
a11yAudit({
82+
include: [['#ember-testing-container']],
83+
exclude: [
84+
[SELECTORS.failingComponent],
85+
['[data-test-selector="labeless-text-input"]'],
86+
['[data-test-selector="paragraph-with-blink-tag"]'],
87+
['[data-test-selector="ungrouped-radio-inputs"]'],
88+
['[data-test-selector="noise-level-selection"]'],
89+
['[data-test-selector="poor-text-contrast"]']
90+
]
91+
});
92+
93+
andThen(() => {
94+
assert.ok(true, 'no errors should have been found in a11yAudit');
95+
});
96+
});
97+
7498
test('a11yAudit can accept an options hash in addition to context', function(assert) {
7599
visit('/');
76100

tests/dummy/app/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html>
2+
<html lang="en-US">
33
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">

tests/dummy/app/templates/application.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="application o-content-box">
22

33
<header class="application__header">
4-
<h2 class="u-align-center">Ember A11y Testing</h2>
4+
<h1 class="u-align-center">Ember A11y Testing</h1>
55
</header>
66

77
<main class="application__main-content u-relative u-fill-width o-content-box--lg">

tests/dummy/app/templates/components/violations-grid-item.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<section class="c-violations-grid-item__header">
2-
<h4 class="c-violations-grid-item__title u-align-center">{{title}}</h4>
2+
<h3 class="c-violations-grid-item__title u-align-center">{{title}}</h3>
33
</section>
44

55
<section class="c-violations-grid-item__body u-relative">

tests/dummy/app/templates/violations.hbs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<span class="p-violations__header-hint">&#42;Open your developer console to view violation logging</span>
44
</header>
55

6-
<section class="p-violations__noise-selectors">
6+
<section class="p-violations__noise-selectors" data-test-selector="noise-level-selection">
77

88
<fieldset class="c-radio-track u-align-center u-relative">
99
<legend class="c-radio-track__heading">Visual Noise Level</legend>
@@ -93,7 +93,7 @@
9393
{{#violations-grid-item class="p-violations__grid-item" title="Poorly Contrasting Text Color" turnAuditOff=true}}
9494
{{#x-paragraph
9595
class="p-violations__grid-item-content--low-contrast-text"
96-
data-test-selector="labeless-text-input"
96+
data-test-selector="poor-text-contrast"
9797
id="violations__low-contrast-text"
9898
visualNoiseLevel=model.currentNoiseLevel}}
9999
Swoooosh
@@ -119,7 +119,7 @@
119119
💡 PRO TIP: In lieu of a <radiogroup>, a containing <fieldset>
120120
here would make these accessible.
121121
--}}
122-
<div class="p-violations__grid-item-content--radio-items">
122+
<div class="p-violations__grid-item-content--radio-items" data-test-selector="ungrouped-radio-inputs">
123123
<label class="u-fill-width u-align-center p-violations__grid-item-content--radio" for="violations__radio-group-items--strawberries">
124124
Strawberries
125125
{{radio-button-input name="fruits" groupValue=model.currentFruit value="Strawberries" id="violations__radio-group-items--strawberries" visualNoiseLevel=model.currentNoiseLevel}}

0 commit comments

Comments
 (0)