Sha256: 0f6c00a5d4ad781542c4eb255ad9bb7f27d6b41182d8397165f4231ff0894eef

Contents?: true

Size: 1.16 KB

Versions: 31

Compression:

Stored size: 1.16 KB

Contents

/* global describe it expect beforeEach afterEach */

var $ = window.jQuery

describe('shim-links-with-button-role', function () {
  'use strict'
  var GOVUK = window.GOVUK

  var $buttonLink
  var keyDownEvent

  beforeEach(function () {
    $buttonLink = $('<a role="button">Button</a>')
    $buttonLink.on('click', function () {
      $buttonLink.addClass('clicked')
    })
    $(document.body).append($buttonLink)
    keyDownEvent = $.Event('keydown')
    keyDownEvent.target = $buttonLink.get(0)
    GOVUK.shimLinksWithButtonRole.init()
  })

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

  it('should trigger event on space', function () {
    // Ideally we’d test the page loading functionality but that seems hard to
    // do within a Jasmine context. Settle for checking a bound event trigger.
    keyDownEvent.which = 32 // Space character
    $(document).trigger(keyDownEvent)
    expect($buttonLink.hasClass('clicked')).toBe(true)
  })

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

Version data entries

31 entries across 31 versions & 2 rubygems

Version Path
govuk_frontend_toolkit-9.0.1 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-9.0.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-8.2.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-8.1.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-8.0.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-7.6.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
idsk_frontend_toolkit-8.4.4 app/assets/spec/unit/shim-links-with-button-role.spec.js
idsk_frontend_toolkit-7.4.3 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-7.5.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
idsk_frontend_toolkit-7.4.2 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-7.4.2 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-7.4.1 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-7.4.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-7.3.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-7.2.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-7.1.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-7.0.1 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-7.0.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-6.0.4 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-6.0.3 app/assets/spec/unit/shim-links-with-button-role.spec.js