Skip to content

Commit

Permalink
Add a couple of tests for anchor buttons
Browse files Browse the repository at this point in the history
1. It should trigger with a space key
2. It shouldn’t trigger with a tab key
  • Loading branch information
Robin Whittleton committed Aug 19, 2016
1 parent 205b522 commit 711c4b9
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spec/manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var manifest = {
'../../node_modules/jquery/dist/jquery.js',
'../../javascripts/govuk/modules.js',
'../../javascripts/govuk/modules/auto-track-event.js',
'../../javascripts/govuk/anchor-buttons.js',
'../../javascripts/govuk/multivariate-test.js',
'../../javascripts/govuk/primary-links.js',
'../../javascripts/govuk/stick-at-top-when-scrolling.js',
Expand All @@ -19,6 +20,7 @@ var manifest = {
test : [
'../unit/modules.spec.js',
'../unit/Modules/auto-track-event.spec.js',
'../unit/anchor-button.spec.js',
'../unit/multivariate-test.spec.js',
'../unit/primary-links.spec.js',
'../unit/stick-at-top-when-scrolling.spec.js',
Expand Down
34 changes: 34 additions & 0 deletions spec/unit/anchor-button.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
describe("anchor-buttons", function () {
var $body;
var $anchorButton;
var keyupEvent;

beforeEach(function () {
$anchorButton = $('<a role="button">Button</a>');
$anchorButton.on('click',function(){
$anchorButton.addClass('clicked');
});
$(document.body).append($anchorButton);
keyupEvent = $.Event('keyup');
keyupEvent.target = $anchorButton.get(0);
GOVUK.anchorButtons.init();
});

afterEach(function () {
$anchorButton.remove();
$(document).off('keyup');
});

it('should trigger event on space', function(){
keyupEvent.which = 32; // Space character
$(document).trigger(keyupEvent);
expect($anchorButton.hasClass('clicked')).toBe(true);
});

it('should not trigger event on tab', function(){
keyupEvent.which = 9; // Tab character
$(document).trigger(keyupEvent);
expect($anchorButton.hasClass('clicked')).toBe(false);
});

});

0 comments on commit 711c4b9

Please sign in to comment.