Skip to content

Commit

Permalink
Update details component
Browse files Browse the repository at this point in the history
- it used the track click code to do some tracking
- this involved making a dummy object for it in the test (because the code is in static and unreachable here in the gem) which broke the new track click code testing here
- updating this to use the track click code in the gem, and updating the test accordingly
  • Loading branch information
andysellick committed Oct 24, 2020
1 parent f434f72 commit e1b2bb0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ window.GOVUK.Modules = window.GOVUK.Modules || {};

// If a custom label has been provided, we can simply call the tracking module
if (customTrackLabel) {
var trackDetails = new window.GOVUK.Modules.TrackClick()
var trackDetails = new window.GOVUK.Modules.GemTrackClick()
trackDetails.start(element)
} else {
// If no custom label is set, we use the open/close status as the label
Expand Down
12 changes: 3 additions & 9 deletions spec/javascripts/components/details-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ describe('Details component', function () {
GOVUK.analytics = { trackEvent: function () {} }
}

var callback = jasmine.createSpy()
GOVUK.Modules.TrackClick = function () {
this.start = function () {
callback()
}
}

function loadDetailsComponent () {
var details = new GOVUK.Modules.GovukDetails()
details.start($('.gem-c-details'))
Expand All @@ -38,12 +31,13 @@ describe('Details component', function () {
})

it('uses built in tracking module when provided with a track-label', function () {
spyOn(GOVUK.Modules, 'GemTrackClick').and.callThrough()
loadDetailsComponent()

$('.govuk-details__summary').click()

expect(GOVUK.analytics.trackEvent.calls.count()).toEqual(0)
expect(callback).toHaveBeenCalled()
expect(GOVUK.Modules.GemTrackClick).toHaveBeenCalled()
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith('track-category', 'track-action', { transport: 'beacon', label: 'track-label' })
})

it('does not fire an event if track category and track action are not present', function () {
Expand Down

0 comments on commit e1b2bb0

Please sign in to comment.