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

Add axe accessibility testing #33

Merged
merged 6 commits into from
Aug 25, 2017
Merged

Add axe accessibility testing #33

merged 6 commits into from
Aug 25, 2017

Conversation

NickColley
Copy link
Contributor

@NickColley NickColley commented Aug 17, 2017

These tests will look for '[data-module="test-a11y"]' and run axe against them,
it'll then throw an error to be caught in dev tools or better in an applications'
integration tests.

Adds Jasmine as a development dependency to test this behaviour, we add require jasmine to the dummy application
so that the default rake build will execute successfully.

government-frontend integration test failure:

screen shot 2017-08-17 at 14 08 22

Chrome DevTools example:

screen shot 2017-08-17 at 14 08 43

@NickColley NickColley changed the title Add axe accessibility testing WIP: Add axe accessibility testing Aug 17, 2017
@NickColley
Copy link
Contributor Author

WIP, need to figure out a good way to test this behaviour

@fofr
Copy link
Contributor

fofr commented Aug 17, 2017

I don't like that jQuery will get included twice. Once from component guide and once from static.

@NickColley
Copy link
Contributor Author

@fofr I was thinking of not including jQuery at all but was thinking of the cases where we're testing the guide against older browsers, that said might be able to just use the static dependency, will check.

@NickColley
Copy link
Contributor Author

Trying to add the jasmine tests to the default rake command results in

Don't know how to build task 'app:jasmine:ci' (see --tasks)

I'm not currently sure how to resolve this.

@NickColley NickColley force-pushed the add-axe-accessibility-testing branch from 470d52a to 8ab3503 Compare August 22, 2017 16:10
@NickColley NickColley changed the title WIP: Add axe accessibility testing Add axe accessibility testing Aug 22, 2017
@NickColley NickColley force-pushed the add-axe-accessibility-testing branch 3 times, most recently from 64d429b to 575a364 Compare August 22, 2017 17:13
locals: {
component_doc: @component_doc,
fixture: fixture,
flush: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "flush" mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in 'flush fit'. It's not so obvious, maybe there's an alternative.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be a way to change this so the borders wrap the internal component, will try something.

@fofr
Copy link
Contributor

fofr commented Aug 23, 2017

@NickColley I get the error locally too:

vagrant@development:/var/govuk/govuk_publishing_components$ bundle exec rake
rake aborted!
Don't know how to build task 'app:jasmine:ci' (see --tasks)
/usr/lib/rbenv/versions/2.3.1/bin/bundle:23:in `load'
/usr/lib/rbenv/versions/2.3.1/bin/bundle:23:in `<main>'

@NickColley NickColley force-pushed the add-axe-accessibility-testing branch from 70bfd7d to 807a738 Compare August 23, 2017 17:29
@NickColley
Copy link
Contributor Author

I'm going to redo this PR to tidy up the commits.

@NickColley NickColley closed this Aug 24, 2017
@NickColley NickColley reopened this Aug 24, 2017
@NickColley
Copy link
Contributor Author

Actually just gonna squash this one together 👍

@NickColley NickColley force-pushed the add-axe-accessibility-testing branch 4 times, most recently from 3d454df to 36d8a7a Compare August 24, 2017 10:31
// http://responsivenews.co.uk/post/18948466399/cutting-the-mustard
if (document.addEventListener) {
document.addEventListener('DOMContentLoaded', function () {
AccessibilityTest('.js-test-a11y', function (err, results) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use data-module="test-a11y" pattern?

var axeOptions = {
restoreScroll: true,
include: [selector]
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace here: run through standardjs linter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some space 👍

restoreScroll: true,
include: [selector]
}
axe.run(axeOptions, function (err, results, blah, boo) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blah, boo 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

@NickColley NickColley force-pushed the add-axe-accessibility-testing branch from 36d8a7a to 68b3f78 Compare August 24, 2017 10:48
})

it('should throw if there\'s a contrast issue', function (done) {
addToDom('<a href="#">Low contrast</a>', 'a { background: white; color: #ddd }')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@@ -7,6 +7,7 @@
require 'action_cable/engine'
require 'rails/test_unit/railtie'
require 'sprockets/railtie'
require 'jasmine'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the pain caused by this – is it worth adding a comment or more of a length description in commit?

@fofr
Copy link
Contributor

fofr commented Aug 24, 2017

Are the screenshots in the PR still accurate?

@NickColley NickColley force-pushed the add-axe-accessibility-testing branch from 68b3f78 to cbb8b95 Compare August 24, 2017 11:30
@NickColley
Copy link
Contributor Author

@fofr screenshots are accurate yes

These tests will look for '[data-module="test-a11y"]' and run axe against them,
it'll then throw an error to be caught in dev tools or better in an applications'
integration tests.

Adds Jasmine as a development dependency to test this behaviour, we add require jasmine to the dummy application
so that the default rake build will execute successfully.
@NickColley NickColley force-pushed the add-axe-accessibility-testing branch from cbb8b95 to 3bd7524 Compare August 24, 2017 11:33
@@ -0,0 +1,136 @@
/* global describe, afterEach, it, expect */

var TEST_SELECTOR = '.js-test-a11y'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need updating too?

Copy link
Contributor Author

@NickColley NickColley Aug 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some troubles with using a consistent data attribute, I don't think axe likes it as much when outputting the targeting.

Since this spec test the behaviour rather than how it works in the guide, this is fine.


WebMock.disable_net_connect!(allow_localhost: true)

# Allow us to test Javascript for example thrown errors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"for errors thrown by examples"?

@@ -83,12 +84,18 @@
end
end

it 'guide throws errors if component has a11y issues' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"accessibility"

@NickColley NickColley force-pushed the add-axe-accessibility-testing branch from 57e95c1 to 885783f Compare August 24, 2017 13:02
@@ -3,6 +3,12 @@
require 'webmock/rspec'
require 'slimmer/rspec'
require 'capybara/rails'
require 'capybara/poltergeist'

WebMock.disable_net_connect!(allow_localhost: true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this stop external scripts from loading?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NickColley NickColley force-pushed the add-axe-accessibility-testing branch from 885783f to efc7237 Compare August 24, 2017 13:03
Makes sure a JavaScript error is thrown on pages where there is an
accessibility issue.
@NickColley NickColley force-pushed the add-axe-accessibility-testing branch from efc7237 to 2ecfaac Compare August 24, 2017 13:10
Since we're using the alpha release, the help urls generated are not live yet.
This commit fixes that by pointing at the 2.3.x release, and adds a message
that'll be noticed if someone updated axe in the future.
@NickColley NickColley force-pushed the add-axe-accessibility-testing branch from 0f7d1fe to 50453e5 Compare August 24, 2017 14:22
@fofr
Copy link
Contributor

fofr commented Aug 25, 2017

Regarding 46c86e3, I'm not sure why CI was running the tests with Ruby 2.4 when 2.3.1 is specified in the .ruby-version file.

Edit: We test against 2.2, 2.3 and 2.4:
https://github.com/alphagov/govuk-puppet/blob/master/modules/govuk_jenkins/files/var/lib/jenkins/groovy_scripts/govuk_jenkinslib.groovy#L513-L528

@fofr
Copy link
Contributor

fofr commented Aug 25, 2017

This branch fails locally on 2.3.1 and 2.4:

Failures:

  1) Component guide guide throws errors if component has an accessibility issue
     Failure/Error:
       expect { visit '/component-guide/test-component-with-a11y-issue' }
         .to raise_error(Capybara::Poltergeist::JavascriptError)
     
       expected Capybara::Poltergeist::JavascriptError but nothing was raised
     # ./spec/component_guide/component_guide_spec.rb:88:in `block (2 levels) in <top (required)>'

fofr added 2 commits August 25, 2017 11:56
Tests were running without running `assets:precompile` and this led
javascript to be unavailable in the test app.

They passed on CI because we run the assets:precompile task as part of
the standard CI suite.

They only failed locally.
We want to know if there are any errors in our dummy app.
@fofr
Copy link
Contributor

fofr commented Aug 25, 2017

Fixed local tests in 5636164

Copy link
Contributor

@fofr fofr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have fixed the issue with local tests.

Top work 👍 💯

@fofr fofr merged commit 588faf0 into master Aug 25, 2017
@fofr fofr deleted the add-axe-accessibility-testing branch August 25, 2017 11:04
fofr added a commit that referenced this pull request Aug 25, 2017
* Add aXe accessibility testing javascript to component guide pages (PR
#33)
fofr added a commit that referenced this pull request Aug 25, 2017
* Add aXe accessibility testing javascript (PR #33)
* Mark strings in YAML fixtures as HTML safe (PR #36)
* Refactor internal structs to use classes (PR #34)
@fofr fofr mentioned this pull request Aug 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants