govuk_frontend_toolkit 4.18.3 → 4.18.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/.gitignore +1 -0
- data/app/assets/CHANGELOG.md +5 -0
- data/app/assets/Gruntfile.js +21 -22
- data/app/assets/README.md +4 -0
- data/app/assets/VERSION.txt +1 -1
- data/app/assets/docs/javascript.md +29 -28
- data/app/assets/javascripts/govuk/analytics/analytics.js +37 -37
- data/app/assets/javascripts/govuk/analytics/download-link-tracker.js +21 -21
- data/app/assets/javascripts/govuk/analytics/error-tracking.js +19 -19
- data/app/assets/javascripts/govuk/analytics/external-link-tracker.js +23 -24
- data/app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js +71 -70
- data/app/assets/javascripts/govuk/analytics/mailto-link-tracker.js +20 -21
- data/app/assets/javascripts/govuk/analytics/print-intent.js +19 -20
- data/app/assets/javascripts/govuk/modules.js +33 -32
- data/app/assets/javascripts/govuk/modules/auto-track-event.js +18 -18
- data/app/assets/javascripts/govuk/multivariate-test.js +83 -85
- data/app/assets/javascripts/govuk/primary-links.js +39 -38
- data/app/assets/javascripts/govuk/selection-buttons.js +57 -58
- data/app/assets/javascripts/govuk/shim-links-with-button-role.js +14 -15
- data/app/assets/javascripts/govuk/stick-at-top-when-scrolling.js +70 -70
- data/app/assets/javascripts/govuk/stop-scrolling-at-footer.js +74 -75
- data/app/assets/javascripts/govuk_toolkit.js +1 -1
- data/app/assets/javascripts/stageprompt.js +24 -25
- data/app/assets/javascripts/vendor/jquery/jquery.player.min.js +1 -1
- data/app/assets/package.json +10 -3
- data/app/assets/spec/manifest.js +2 -0
- data/app/assets/spec/support/console-runner.js +0 -1
- data/app/assets/spec/unit/analytics/analytics.spec.js +51 -47
- data/app/assets/spec/unit/analytics/download-link-tracker.spec.js +59 -51
- data/app/assets/spec/unit/analytics/error-tracking.spec.js +35 -30
- data/app/assets/spec/unit/analytics/external-link-tracker.spec.js +69 -61
- data/app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js +129 -122
- data/app/assets/spec/unit/analytics/mailto-link-tracker.spec.js +55 -47
- data/app/assets/spec/unit/modules.spec.js +82 -78
- data/app/assets/spec/unit/modules/auto-track-event.spec.js +45 -40
- data/app/assets/spec/unit/multivariate-test.spec.js +150 -145
- data/app/assets/spec/unit/primary-links.spec.js +53 -47
- data/app/assets/spec/unit/selection-button.spec.js +701 -693
- data/app/assets/spec/unit/shim-links-with-button-role.spec.js +33 -28
- data/app/assets/spec/unit/show-hide-content.spec.js +5 -1
- data/app/assets/spec/unit/stick-at-top-when-scrolling.spec.js +104 -107
- metadata +2 -2
@@ -1,69 +1,77 @@
|
|
1
|
-
describe
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
<a href="http://
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
$('
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
$('
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
1
|
+
/* global describe it expect beforeEach afterEach spyOn */
|
2
|
+
|
3
|
+
var $ = window.jQuery
|
4
|
+
|
5
|
+
describe('GOVUK.analyticsPlugins.externalLinkTracker', function () {
|
6
|
+
'use strict'
|
7
|
+
var GOVUK = window.GOVUK
|
8
|
+
|
9
|
+
var $links
|
10
|
+
|
11
|
+
beforeEach(function () {
|
12
|
+
$links = $(
|
13
|
+
'<div class="external-links">' +
|
14
|
+
'<a href="http://www.nationalarchives.gov.uk"> National Archives </a>' +
|
15
|
+
'<a href="https://www.nationalarchives.gov.uk"></a>' +
|
16
|
+
'<a href="https://www.nationalarchives.gov.uk/one.pdf">National Archives PDF</a>' +
|
17
|
+
'<a href="https://www.nationalarchives.gov.uk/an/image/link.png"><img src="/img" /></a>' +
|
18
|
+
'</div>' +
|
19
|
+
'<div class="internal-links">' +
|
20
|
+
'<a href="/some-path">Local link</a>' +
|
21
|
+
'<a href="http://fake-hostname.com/some-path">Another local link</a>' +
|
22
|
+
'</div>'
|
23
|
+
)
|
24
|
+
|
25
|
+
$('html').on('click', function (evt) { evt.preventDefault() })
|
26
|
+
$('body').append($links)
|
27
|
+
GOVUK.analytics = {trackEvent: function () {}}
|
28
|
+
|
29
|
+
spyOn(GOVUK.analyticsPlugins.externalLinkTracker, 'getHostname').and.returnValue('fake-hostname.com')
|
30
|
+
GOVUK.analyticsPlugins.externalLinkTracker()
|
31
|
+
})
|
32
|
+
|
33
|
+
afterEach(function () {
|
34
|
+
$('html').off()
|
35
|
+
$('body').off()
|
36
|
+
$links.remove()
|
37
|
+
delete GOVUK.analytics
|
38
|
+
})
|
39
|
+
|
40
|
+
it('listens to click events on only external links', function () {
|
41
|
+
spyOn(GOVUK.analytics, 'trackEvent')
|
42
|
+
|
43
|
+
$('.external-links a').each(function () {
|
44
|
+
$(this).trigger('click')
|
45
|
+
expect(GOVUK.analytics.trackEvent).toHaveBeenCalled()
|
46
|
+
GOVUK.analytics.trackEvent.calls.reset()
|
47
|
+
})
|
48
|
+
|
49
|
+
$('.internal-links a').each(function () {
|
50
|
+
$(this).trigger('click')
|
51
|
+
expect(GOVUK.analytics.trackEvent).not.toHaveBeenCalled()
|
52
|
+
GOVUK.analytics.trackEvent.calls.reset()
|
53
|
+
})
|
54
|
+
})
|
55
|
+
|
56
|
+
it('listens to click events on elements within external links', function () {
|
57
|
+
spyOn(GOVUK.analytics, 'trackEvent')
|
58
|
+
|
59
|
+
$('.external-links a img').trigger('click')
|
52
60
|
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
53
|
-
'External Link Clicked', 'https://www.nationalarchives.gov.uk/an/image/link.png', {transport: 'beacon'})
|
54
|
-
})
|
61
|
+
'External Link Clicked', 'https://www.nationalarchives.gov.uk/an/image/link.png', {transport: 'beacon'})
|
62
|
+
})
|
55
63
|
|
56
|
-
it('tracks an external link\'s href and link text', function() {
|
57
|
-
spyOn(GOVUK.analytics, 'trackEvent')
|
58
|
-
$('.external-links a').trigger('click')
|
64
|
+
it('tracks an external link\'s href and link text', function () {
|
65
|
+
spyOn(GOVUK.analytics, 'trackEvent')
|
66
|
+
$('.external-links a').trigger('click')
|
59
67
|
|
60
68
|
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
61
|
-
'External Link Clicked', 'http://www.nationalarchives.gov.uk', {transport: 'beacon', label: 'National Archives'})
|
69
|
+
'External Link Clicked', 'http://www.nationalarchives.gov.uk', {transport: 'beacon', label: 'National Archives'})
|
62
70
|
|
63
71
|
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
64
|
-
'External Link Clicked', 'https://www.nationalarchives.gov.uk', {transport: 'beacon'})
|
72
|
+
'External Link Clicked', 'https://www.nationalarchives.gov.uk', {transport: 'beacon'})
|
65
73
|
|
66
74
|
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
67
|
-
'External Link Clicked', 'https://www.nationalarchives.gov.uk/one.pdf', {transport: 'beacon', label: 'National Archives PDF'})
|
68
|
-
})
|
69
|
-
})
|
75
|
+
'External Link Clicked', 'https://www.nationalarchives.gov.uk/one.pdf', {transport: 'beacon', label: 'National Archives PDF'})
|
76
|
+
})
|
77
|
+
})
|
@@ -1,113 +1,120 @@
|
|
1
|
-
describe
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
/* global describe it expect beforeEach spyOn jasmine */
|
2
|
+
|
3
|
+
var $ = window.jQuery
|
4
|
+
|
5
|
+
describe('GOVUK.GoogleAnalyticsUniversalTracker', function () {
|
6
|
+
'use strict'
|
7
|
+
var GOVUK = window.GOVUK
|
8
|
+
|
9
|
+
function addGoogleAnalyticsSpy () {
|
10
|
+
window.ga = function () {}
|
11
|
+
spyOn(window, 'ga')
|
5
12
|
}
|
6
13
|
|
7
|
-
var universal
|
8
|
-
var setupArguments
|
14
|
+
var universal
|
15
|
+
var setupArguments
|
9
16
|
|
10
|
-
beforeEach(function() {
|
11
|
-
addGoogleAnalyticsSpy()
|
17
|
+
beforeEach(function () {
|
18
|
+
addGoogleAnalyticsSpy()
|
12
19
|
|
13
20
|
universal = new GOVUK.GoogleAnalyticsUniversalTracker('id', {
|
14
21
|
cookieDomain: 'cookie-domain.com',
|
15
22
|
siteSpeedSampleRate: 100
|
16
|
-
})
|
17
|
-
})
|
18
|
-
|
19
|
-
it('can load the libraries needed to run universal Google Analytics', function() {
|
20
|
-
delete window.ga
|
21
|
-
$('[src="https://www.google-analytics.com/analytics.js"]').remove()
|
22
|
-
GOVUK.GoogleAnalyticsUniversalTracker.load()
|
23
|
-
expect($('script[async][src="https://www.google-analytics.com/analytics.js"]').length).toBe(1)
|
24
|
-
expect(typeof window.ga).toBe('function')
|
25
|
-
|
26
|
-
window.ga('send message')
|
27
|
-
expect(window.ga.q[0]).toEqual(jasmine.any(Object))
|
28
|
-
})
|
29
|
-
|
30
|
-
describe('when created', function() {
|
31
|
-
beforeEach(function() {
|
32
|
-
setupArguments = window.ga.calls.allArgs()
|
33
|
-
})
|
34
|
-
|
35
|
-
it('configures a Google tracker using the provided profile ID and config', function() {
|
36
|
-
expect(setupArguments[0]).toEqual(['create', 'id', {cookieDomain: 'cookie-domain.com', siteSpeedSampleRate: 100}])
|
37
|
-
})
|
38
|
-
|
39
|
-
it('anonymises the IP', function() {
|
40
|
-
expect(setupArguments[1]).toEqual(['set', 'anonymizeIp', true])
|
41
|
-
})
|
42
|
-
})
|
43
|
-
|
44
|
-
describe('when created (with legacy non-object syntax)', function() {
|
45
|
-
beforeEach(function() {
|
46
|
-
addGoogleAnalyticsSpy()
|
47
|
-
|
48
|
-
universal = new GOVUK.GoogleAnalyticsUniversalTracker('id', 'cookie-domain.com')
|
49
|
-
setupArguments = window.ga.calls.allArgs()
|
50
|
-
})
|
51
|
-
|
52
|
-
it('configures a Google tracker using the provided profile ID and cookie domain', function() {
|
53
|
-
expect(setupArguments[0]).toEqual(['create', 'id', {cookieDomain: 'cookie-domain.com'}])
|
54
|
-
})
|
55
|
-
})
|
56
|
-
|
57
|
-
describe('when pageviews are tracked', function() {
|
58
|
-
it('sends them to Google Analytics', function() {
|
59
|
-
universal.trackPageview()
|
60
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview'])
|
61
|
-
})
|
62
|
-
|
63
|
-
it('can track a virtual pageview', function() {
|
64
|
-
universal.trackPageview('/nicholas-page')
|
65
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', {page: '/nicholas-page'}])
|
66
|
-
})
|
67
|
-
|
68
|
-
it('can track a virtual pageview with a custom title', function() {
|
69
|
-
universal.trackPageview('/nicholas-page', 'Nicholas Page')
|
70
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', {page: '/nicholas-page', title: 'Nicholas Page'}])
|
71
|
-
})
|
72
|
-
|
73
|
-
it('can set the transport method on a pageview', function() {
|
74
|
-
universal.trackPageview('/t', 'T', {transport: 'beacon'})
|
75
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', {page: '/t', title: 'T', transport: 'beacon'}])
|
76
|
-
})
|
77
|
-
})
|
78
|
-
|
79
|
-
describe('when events are tracked', function() {
|
80
|
-
function eventObjectFromSpy() {
|
81
|
-
return window.ga.calls.mostRecent().args[1]
|
23
|
+
})
|
24
|
+
})
|
25
|
+
|
26
|
+
it('can load the libraries needed to run universal Google Analytics', function () {
|
27
|
+
delete window.ga
|
28
|
+
$('[src="https://www.google-analytics.com/analytics.js"]').remove()
|
29
|
+
GOVUK.GoogleAnalyticsUniversalTracker.load()
|
30
|
+
expect($('script[async][src="https://www.google-analytics.com/analytics.js"]').length).toBe(1)
|
31
|
+
expect(typeof window.ga).toBe('function')
|
32
|
+
|
33
|
+
window.ga('send message')
|
34
|
+
expect(window.ga.q[0]).toEqual(jasmine.any(Object))
|
35
|
+
})
|
36
|
+
|
37
|
+
describe('when created', function () {
|
38
|
+
beforeEach(function () {
|
39
|
+
setupArguments = window.ga.calls.allArgs()
|
40
|
+
})
|
41
|
+
|
42
|
+
it('configures a Google tracker using the provided profile ID and config', function () {
|
43
|
+
expect(setupArguments[0]).toEqual(['create', 'id', {cookieDomain: 'cookie-domain.com', siteSpeedSampleRate: 100}])
|
44
|
+
})
|
45
|
+
|
46
|
+
it('anonymises the IP', function () {
|
47
|
+
expect(setupArguments[1]).toEqual(['set', 'anonymizeIp', true])
|
48
|
+
})
|
49
|
+
})
|
50
|
+
|
51
|
+
describe('when created (with legacy non-object syntax)', function () {
|
52
|
+
beforeEach(function () {
|
53
|
+
addGoogleAnalyticsSpy()
|
54
|
+
|
55
|
+
universal = new GOVUK.GoogleAnalyticsUniversalTracker('id', 'cookie-domain.com')
|
56
|
+
setupArguments = window.ga.calls.allArgs()
|
57
|
+
})
|
58
|
+
|
59
|
+
it('configures a Google tracker using the provided profile ID and cookie domain', function () {
|
60
|
+
expect(setupArguments[0]).toEqual(['create', 'id', {cookieDomain: 'cookie-domain.com'}])
|
61
|
+
})
|
62
|
+
})
|
63
|
+
|
64
|
+
describe('when pageviews are tracked', function () {
|
65
|
+
it('sends them to Google Analytics', function () {
|
66
|
+
universal.trackPageview()
|
67
|
+
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview'])
|
68
|
+
})
|
69
|
+
|
70
|
+
it('can track a virtual pageview', function () {
|
71
|
+
universal.trackPageview('/nicholas-page')
|
72
|
+
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', {page: '/nicholas-page'}])
|
73
|
+
})
|
74
|
+
|
75
|
+
it('can track a virtual pageview with a custom title', function () {
|
76
|
+
universal.trackPageview('/nicholas-page', 'Nicholas Page')
|
77
|
+
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', {page: '/nicholas-page', title: 'Nicholas Page'}])
|
78
|
+
})
|
79
|
+
|
80
|
+
it('can set the transport method on a pageview', function () {
|
81
|
+
universal.trackPageview('/t', 'T', {transport: 'beacon'})
|
82
|
+
expect(window.ga.calls.mostRecent().args).toEqual(['send', 'pageview', {page: '/t', title: 'T', transport: 'beacon'}])
|
83
|
+
})
|
84
|
+
})
|
85
|
+
|
86
|
+
describe('when events are tracked', function () {
|
87
|
+
function eventObjectFromSpy () {
|
88
|
+
return window.ga.calls.mostRecent().args[1]
|
82
89
|
}
|
83
90
|
|
84
|
-
it('sends them to Google Analytics', function() {
|
85
|
-
universal.trackEvent('category', 'action', {label: 'label'})
|
91
|
+
it('sends them to Google Analytics', function () {
|
92
|
+
universal.trackEvent('category', 'action', {label: 'label'})
|
86
93
|
expect(window.ga.calls.mostRecent().args).toEqual(
|
87
94
|
['send', {hitType: 'event', eventCategory: 'category', eventAction: 'action', eventLabel: 'label'}]
|
88
|
-
)
|
89
|
-
})
|
95
|
+
)
|
96
|
+
})
|
90
97
|
|
91
|
-
it('the label is optional', function() {
|
92
|
-
universal.trackEvent('category', 'action')
|
98
|
+
it('the label is optional', function () {
|
99
|
+
universal.trackEvent('category', 'action')
|
93
100
|
expect(window.ga.calls.mostRecent().args).toEqual(
|
94
101
|
['send', {hitType: 'event', eventCategory: 'category', eventAction: 'action'}]
|
95
|
-
)
|
96
|
-
})
|
102
|
+
)
|
103
|
+
})
|
97
104
|
|
98
|
-
it('only sends values if they are parseable as numbers', function() {
|
99
|
-
universal.trackEvent('category', 'action', {label: 'label', value: '10'})
|
100
|
-
expect(eventObjectFromSpy()['eventValue']).toEqual(10)
|
105
|
+
it('only sends values if they are parseable as numbers', function () {
|
106
|
+
universal.trackEvent('category', 'action', {label: 'label', value: '10'})
|
107
|
+
expect(eventObjectFromSpy()['eventValue']).toEqual(10)
|
101
108
|
|
102
|
-
universal.trackEvent('category', 'action', {label: 'label', value: 10})
|
103
|
-
expect(eventObjectFromSpy()['eventValue']).toEqual(10)
|
109
|
+
universal.trackEvent('category', 'action', {label: 'label', value: 10})
|
110
|
+
expect(eventObjectFromSpy()['eventValue']).toEqual(10)
|
104
111
|
|
105
|
-
universal.trackEvent('category', 'action', {label: 'label', value: 'not a number'})
|
106
|
-
expect(eventObjectFromSpy()['eventValue']).toEqual(undefined)
|
107
|
-
})
|
112
|
+
universal.trackEvent('category', 'action', {label: 'label', value: 'not a number'})
|
113
|
+
expect(eventObjectFromSpy()['eventValue']).toEqual(undefined)
|
114
|
+
})
|
108
115
|
|
109
|
-
it('can mark an event as non interactive', function() {
|
110
|
-
universal.trackEvent('category', 'action', {label: 'label', value: 0, nonInteraction: true})
|
116
|
+
it('can mark an event as non interactive', function () {
|
117
|
+
universal.trackEvent('category', 'action', {label: 'label', value: 0, nonInteraction: true})
|
111
118
|
expect(window.ga.calls.mostRecent().args).toEqual(
|
112
119
|
['send', {
|
113
120
|
hitType: 'event',
|
@@ -117,45 +124,45 @@ describe("GOVUK.GoogleAnalyticsUniversalTracker", function() {
|
|
117
124
|
eventValue: 0,
|
118
125
|
nonInteraction: 1
|
119
126
|
}]
|
120
|
-
)
|
121
|
-
})
|
127
|
+
)
|
128
|
+
})
|
122
129
|
|
123
|
-
it('sends the page if supplied', function() {
|
124
|
-
universal.trackEvent('category', 'action', {page: '/path/to/page'})
|
130
|
+
it('sends the page if supplied', function () {
|
131
|
+
universal.trackEvent('category', 'action', {page: '/path/to/page'})
|
125
132
|
expect(window.ga.calls.mostRecent().args).toEqual(
|
126
133
|
['send', {hitType: 'event', eventCategory: 'category', eventAction: 'action', page: '/path/to/page'}]
|
127
|
-
)
|
128
|
-
})
|
134
|
+
)
|
135
|
+
})
|
129
136
|
|
130
|
-
it('can set the transport method on an event', function() {
|
131
|
-
universal.trackEvent('category', 'action', {transport: 'beacon'})
|
137
|
+
it('can set the transport method on an event', function () {
|
138
|
+
universal.trackEvent('category', 'action', {transport: 'beacon'})
|
132
139
|
expect(window.ga.calls.mostRecent().args).toEqual(
|
133
140
|
['send', {hitType: 'event', eventCategory: 'category', eventAction: 'action', transport: 'beacon'}]
|
134
|
-
)
|
135
|
-
})
|
136
|
-
})
|
141
|
+
)
|
142
|
+
})
|
143
|
+
})
|
137
144
|
|
138
|
-
describe('when social events are tracked', function() {
|
139
|
-
it('sends them to Google Analytics', function() {
|
140
|
-
universal.trackSocial('network', 'action', 'target')
|
145
|
+
describe('when social events are tracked', function () {
|
146
|
+
it('sends them to Google Analytics', function () {
|
147
|
+
universal.trackSocial('network', 'action', 'target')
|
141
148
|
expect(window.ga.calls.mostRecent().args).toEqual(['send', {
|
142
149
|
'hitType': 'social',
|
143
150
|
'socialNetwork': 'network',
|
144
151
|
'socialAction': 'action',
|
145
152
|
'socialTarget': 'target'
|
146
|
-
}])
|
147
|
-
})
|
148
|
-
})
|
149
|
-
|
150
|
-
describe('when setting a custom dimension', function() {
|
151
|
-
it('sends the dimension to Google Analytics with the specified index and value', function() {
|
152
|
-
universal.setDimension(1, 'value')
|
153
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', 'value'])
|
154
|
-
})
|
155
|
-
|
156
|
-
it('coerces the value to a string', function() {
|
157
|
-
universal.setDimension(1, 10)
|
158
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', '10'])
|
159
|
-
})
|
160
|
-
})
|
161
|
-
})
|
153
|
+
}])
|
154
|
+
})
|
155
|
+
})
|
156
|
+
|
157
|
+
describe('when setting a custom dimension', function () {
|
158
|
+
it('sends the dimension to Google Analytics with the specified index and value', function () {
|
159
|
+
universal.setDimension(1, 'value')
|
160
|
+
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', 'value'])
|
161
|
+
})
|
162
|
+
|
163
|
+
it('coerces the value to a string', function () {
|
164
|
+
universal.setDimension(1, 10)
|
165
|
+
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'dimension1', '10'])
|
166
|
+
})
|
167
|
+
})
|
168
|
+
})
|
@@ -1,54 +1,62 @@
|
|
1
|
-
describe
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
$
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
$('html').
|
21
|
-
$('body').
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
$('
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
1
|
+
/* global describe it expect afterEach beforeEach spyOn */
|
2
|
+
|
3
|
+
var $ = window.jQuery
|
4
|
+
|
5
|
+
describe('GOVUK.analyticsPlugins.mailtoLinkTracker', function () {
|
6
|
+
'use strict'
|
7
|
+
var GOVUK = window.GOVUK
|
8
|
+
|
9
|
+
var $links
|
10
|
+
|
11
|
+
beforeEach(function () {
|
12
|
+
$links = $(
|
13
|
+
'<div class="mailto-links">' +
|
14
|
+
'<a href="mailto:name1@email.com"></a>' +
|
15
|
+
'<a href="mailto:name2@email.com">The link for a mailto</a>' +
|
16
|
+
'<a href="mailto:name3@email.com"><img src="/img" /></a>' +
|
17
|
+
'</div>'
|
18
|
+
)
|
19
|
+
|
20
|
+
$('html').on('click', function (evt) { evt.preventDefault() })
|
21
|
+
$('body').append($links)
|
22
|
+
GOVUK.analytics = {trackEvent: function () {}}
|
23
|
+
|
24
|
+
GOVUK.analyticsPlugins.mailtoLinkTracker()
|
25
|
+
})
|
26
|
+
|
27
|
+
afterEach(function () {
|
28
|
+
$('html').off()
|
29
|
+
$('body').off()
|
30
|
+
$links.remove()
|
31
|
+
delete GOVUK.analytics
|
32
|
+
})
|
33
|
+
|
34
|
+
it('listens to click events on mailto links', function () {
|
35
|
+
spyOn(GOVUK.analytics, 'trackEvent')
|
36
|
+
|
37
|
+
$('.mailto-links a').each(function () {
|
38
|
+
$(this).trigger('click')
|
39
|
+
expect(GOVUK.analytics.trackEvent).toHaveBeenCalled()
|
40
|
+
GOVUK.analytics.trackEvent.calls.reset()
|
41
|
+
})
|
42
|
+
})
|
43
|
+
|
44
|
+
it('tracks mailto addresses and link text', function () {
|
45
|
+
spyOn(GOVUK.analytics, 'trackEvent')
|
46
|
+
$('.mailto-links a').trigger('click')
|
39
47
|
|
40
48
|
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
41
|
-
'Mailto Link Clicked', 'mailto:name1@email.com', {transport: 'beacon'})
|
49
|
+
'Mailto Link Clicked', 'mailto:name1@email.com', {transport: 'beacon'})
|
42
50
|
|
43
51
|
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
44
|
-
'Mailto Link Clicked', 'mailto:name2@email.com', {transport: 'beacon', label: 'The link for a mailto'})
|
45
|
-
})
|
52
|
+
'Mailto Link Clicked', 'mailto:name2@email.com', {transport: 'beacon', label: 'The link for a mailto'})
|
53
|
+
})
|
46
54
|
|
47
|
-
it('listens to click events on elements within mailto links', function() {
|
48
|
-
spyOn(GOVUK.analytics, 'trackEvent')
|
55
|
+
it('listens to click events on elements within mailto links', function () {
|
56
|
+
spyOn(GOVUK.analytics, 'trackEvent')
|
49
57
|
|
50
|
-
$('.mailto-links a img').trigger('click')
|
58
|
+
$('.mailto-links a img').trigger('click')
|
51
59
|
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
52
|
-
'Mailto Link Clicked', 'mailto:name3@email.com', {transport: 'beacon'})
|
53
|
-
})
|
54
|
-
})
|
60
|
+
'Mailto Link Clicked', 'mailto:name3@email.com', {transport: 'beacon'})
|
61
|
+
})
|
62
|
+
})
|