Sha256: a98ef32d51e403a63869c1af3c81ddeeb30bfcfeeaae31ac765026a3546f7f2a

Contents?: true

Size: 1.3 KB

Versions: 33

Compression:

Stored size: 1.3 KB

Contents

/* global describe it expect beforeEach afterEach spyOn */

var $ = window.jQuery

describe('An auto event tracker', function () {
  'use strict'
  var GOVUK = window.GOVUK

  var tracker,
    element

  beforeEach(function () {
    GOVUK.analytics = {trackEvent: function () {}}
    tracker = new GOVUK.Modules.AutoTrackEvent()
  })

  afterEach(function () {
    delete GOVUK.analytics
  })

  it('tracks non-interactive events on start', function () {
    spyOn(GOVUK.analytics, 'trackEvent')

    element = $(
      '<div ' +
        'data-track-category="category"' +
        'data-track-action="action">' +
        'Some content' +
      '</div>'
    )

    tracker.start(element)
    expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
      'category', 'action', {nonInteraction: 1})
  })

  it('can track non-interactive events with optional label and value', function () {
    spyOn(GOVUK.analytics, 'trackEvent')

    element = $(
      '<div ' +
        'data-track-category="category"' +
        'data-track-action="action"' +
        'data-track-label="label"' +
        'data-track-value="10">' +
        'Some content' +
      '</div>'
    )

    tracker.start(element)
    expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
      'category', 'action', {label: 'label', value: 10, nonInteraction: 1})
  })
})

Version data entries

33 entries across 33 versions & 2 rubygems

Version Path
govuk_frontend_toolkit-9.0.1 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-9.0.0 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-8.2.0 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-8.1.0 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-8.0.0 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-7.6.0 app/assets/spec/unit/modules/auto-track-event.spec.js
idsk_frontend_toolkit-8.4.4 app/assets/spec/unit/modules/auto-track-event.spec.js
idsk_frontend_toolkit-7.4.3 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-7.5.0 app/assets/spec/unit/modules/auto-track-event.spec.js
idsk_frontend_toolkit-7.4.2 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-7.4.2 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-7.4.1 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-7.4.0 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-7.3.0 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-7.2.0 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-7.1.0 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-7.0.1 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-7.0.0 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-6.0.4 app/assets/spec/unit/modules/auto-track-event.spec.js
govuk_frontend_toolkit-6.0.3 app/assets/spec/unit/modules/auto-track-event.spec.js