diff --git a/spec/manifest.js b/spec/manifest.js index 0b7e7822..6521202d 100644 --- a/spec/manifest.js +++ b/spec/manifest.js @@ -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', @@ -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', diff --git a/spec/unit/anchor-button.spec.js b/spec/unit/anchor-button.spec.js new file mode 100644 index 00000000..3a7d34b8 --- /dev/null +++ b/spec/unit/anchor-button.spec.js @@ -0,0 +1,34 @@ +describe("anchor-buttons", function () { + var $body; + var $anchorButton; + var keyupEvent; + + beforeEach(function () { + $anchorButton = $('Button'); + $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); + }); + +});