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-6.0.2 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-6.0.1 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-6.0.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-5.2.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-5.1.3 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-5.1.2 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-5.1.1 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-5.1.0 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-5.0.3 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-5.0.2 app/assets/spec/unit/shim-links-with-button-role.spec.js
govuk_frontend_toolkit-5.0.1 app/assets/spec/unit/shim-links-with-button-role.spec.js