Skip to content

Commit

Permalink
Create new warning gradient and begin setting up a tests for new beha…
Browse files Browse the repository at this point in the history
…vior
  • Loading branch information
BrianSipple authored and BrianSipple committed Jun 21, 2016
1 parent 45d0e55 commit e1e1bcb
Show file tree
Hide file tree
Showing 20 changed files with 211 additions and 37 deletions.
16 changes: 14 additions & 2 deletions app/instance-initializers/axe-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ export function initialize(application) {
*/
turnAuditOff: false,

/**
* An array of classNames to add to the component when a violation occurs.
* If unspecified, the `axe-violation` class is used to apply our default
* styling
*
* @public
* @type {Array}
*/
axeViolationClassNames: ['axe-violation'],


/**
* Runs an accessibility audit on any render of the component.
* @private
Expand All @@ -59,7 +70,8 @@ export function initialize(application) {
audit() {
if (this.get('tagName') !== '') {
axe.a11yCheck(this.$(), this.axeOptions, (results) => {
let violations = results.violations;
const violations = results.violations;
const violationClassNames = this.get('axeViolationClassNames');

for (let i = 0, l = violations.length; i < l; i++) {
let violation = violations[i];
Expand All @@ -72,7 +84,7 @@ export function initialize(application) {
let node = nodes[j];

if (node) {
Ember.$(node.target.join(','))[0].classList.add('axe-violation');
Ember.$(node.target.join(','))[0].classList.add(...violationClassNames);
}
}
}
Expand Down
16 changes: 15 additions & 1 deletion content-for/head-footer.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<style>
.axe-violation {
border: 2px solid red !important;
background-image: repeating-linear-gradient(
45deg,
transparent,
transparent 0.4em,
hsla(69, 84%, 83%, 1.00) 0.4em,
hsla(69, 84%, 83%, 1.00) 0.8em,
hsla(166, 44%, 65%, 1.00) 0.8em,
hsla(166, 44%, 65%, 1.00) 1.2em,
hsla(214, 96%, 45%, 1.00) 1.2em,
hsla(214, 96%, 45%, 1.00) 1.6em
) !important;
}

.axe-violation:hover {
background-image: none !important;
}
</style>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"testing"
],
"dependencies": {
"bower": "1.7.9",
"broccoli-funnel": "^1.0.1",
"ember-cli-babel": "^5.1.6",
"ember-cli-version-checker": "^1.1.6"
Expand Down
1 change: 1 addition & 0 deletions tests/.jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"wait",
"DS",
"andThen",
"axe",
"currentURL",
"currentPath",
"currentRouteName"
Expand Down
6 changes: 5 additions & 1 deletion tests/acceptance/auto-run-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import sinon from 'sinon';
let application;
let sandbox;

const SELECTORS = {
passingInput: '[data-test-selector="passing-input"]'
};

module('Acceptance | auto-run', {
beforeEach: function() {
application = startApp();
Expand Down Expand Up @@ -39,7 +43,7 @@ test('should run the function whenever a render occurs', function(assert) {
assert.equal(currentPath(), 'index');
});

click('label');
click(`${SELECTORS.passingInput} label`);

andThen(() => {
assert.ok(callbackStub.calledTwice);
Expand Down
38 changes: 38 additions & 0 deletions tests/acceptance/violations-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Ember from 'ember';
import { test } from 'qunit';
import moduleForAcceptance from '../../tests/helpers/module-for-acceptance';
import sinon from 'sinon';

let actual, expected, sandbox;

const IDs = {
emptyButton: '#empty-button',
sloppyInput: '#sloppy-input'
};

const findBy = (items, key, val) => items.find(item => item[key] === val);

moduleForAcceptance('Acceptance | violations', {
beforeEach() {
sandbox = sinon.sandbox.create();
},

afterEach() {
sandbox.restore();
}
});

test('marking DOM nodes with violations', function(assert) {

sandbox.stub(axe.ember, 'a11yCheckCallback', function (results) {
console.log('Results****', results.violations.find);
assert.equal(results.violations.length, 2);

const buttonNameViolation = findBy(results.violations, 'id', 'button-name');
assert.equal(buttonNameViolation.nodes[0].target[0], IDs.emptyButton);

});

visit('/violations');

});
7 changes: 7 additions & 0 deletions tests/dummy/app/components/_base-demo-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Ember from 'ember';

const { Component } = Ember;

export default Component.extend({
attributeBindings: ['data-test-selector']
});
6 changes: 6 additions & 0 deletions tests/dummy/app/components/empty-button.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import BaseDemoComponent from './_base-demo-component';

export default BaseDemoComponent.extend({
classNames: ['button'],
tagName: 'button'
});
4 changes: 2 additions & 2 deletions tests/dummy/app/components/passing-component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Ember from 'ember';
import BaseDemoComponent from './_base-demo-component';

export default Ember.Component.extend({
export default BaseDemoComponent.extend({
actions: {
toggle() {
this.set('isFailing', true);
Expand Down
5 changes: 5 additions & 0 deletions tests/dummy/app/components/sloppy-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import BaseDemoComponent from './_base-demo-component';

export default BaseDemoComponent.extend({
tagName: 'input',
});
1 change: 1 addition & 0 deletions tests/dummy/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const Router = Ember.Router.extend({
});

Router.map(function() {
this.route('violations');
});

export default Router;
4 changes: 4 additions & 0 deletions tests/dummy/app/routes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Ember from 'ember';

export default Ember.Route.extend({
});
4 changes: 4 additions & 0 deletions tests/dummy/app/routes/violations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Ember from 'ember';

export default Ember.Route.extend({
});
10 changes: 10 additions & 0 deletions tests/dummy/app/styles/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.button {
background-color: aqua;
border-radius: 0.25em;
border: none;
min-height: 1.5rem;
height: 1.5rem;

width: 2.2rem;
min-width: 2.2rem;
}
4 changes: 2 additions & 2 deletions tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<h2 id="title">Welcome to Ember.js</h2>
<h2 id="title">Welcome to Ember</h2>

{{passing-component}}
{{outlet}}
1 change: 1 addition & 0 deletions tests/dummy/app/templates/components/empty-button.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
1 change: 1 addition & 0 deletions tests/dummy/app/templates/components/sloppy-input.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield}}
2 changes: 2 additions & 0 deletions tests/dummy/app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{passing-component data-test-selector="passing-input"}}
{{outlet}}
3 changes: 3 additions & 0 deletions tests/dummy/app/templates/violations.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{empty-button id="empty-button" data-test-selector="empty-button"}}

{{sloppy-input id="sloppy-input" data-test-selector="sloppy-input"}}
Loading

0 comments on commit e1e1bcb

Please sign in to comment.