govuk_frontend_toolkit 4.18.3 → 4.18.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,89 +1,93 @@
|
|
1
|
-
describe
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
1
|
+
/* global describe it expect beforeEach afterEach jasmine */
|
2
|
+
|
3
|
+
var $ = window.jQuery
|
4
|
+
|
5
|
+
describe('GOVUK Modules', function () {
|
6
|
+
'use strict'
|
7
|
+
var GOVUK = window.GOVUK
|
8
|
+
|
9
|
+
it('finds modules', function () {
|
10
|
+
var module = $('<div data-module="a-module"></div>')
|
11
|
+
$('body').append(module)
|
12
|
+
|
13
|
+
expect(GOVUK.modules.find().length).toBe(1)
|
14
|
+
expect(GOVUK.modules.find().eq(0).is('[data-module="a-module"]')).toBe(true)
|
15
|
+
module.remove()
|
16
|
+
})
|
17
|
+
|
18
|
+
it('finds modules in a container', function () {
|
19
|
+
var module = $('<div data-module="a-module"></div>')
|
20
|
+
var container = $('<div></div>').append(module)
|
21
|
+
|
22
|
+
expect(GOVUK.modules.find(container).length).toBe(1)
|
23
|
+
expect(GOVUK.modules.find(container).eq(0).data('module')).toBe('a-module')
|
24
|
+
})
|
25
|
+
|
26
|
+
it('finds modules that are a container', function () {
|
27
|
+
var module = $('<div data-module="a-module"></div>')
|
28
|
+
var container = $('<div data-module="container-module"></div>').append(module)
|
29
|
+
|
30
|
+
expect(GOVUK.modules.find(container).length).toBe(2)
|
31
|
+
expect(GOVUK.modules.find(container).eq(0).data('module')).toBe('container-module')
|
32
|
+
expect(GOVUK.modules.find(container).eq(1).data('module')).toBe('a-module')
|
33
|
+
})
|
34
|
+
|
35
|
+
describe('when a module exists', function () {
|
36
|
+
var callback
|
37
|
+
|
38
|
+
beforeEach(function () {
|
39
|
+
callback = jasmine.createSpy()
|
40
|
+
GOVUK.Modules.TestAlertModule = function () {
|
41
|
+
var that = this
|
42
|
+
that.start = function (element) {
|
43
|
+
callback(element)
|
40
44
|
}
|
41
|
-
}
|
42
|
-
})
|
45
|
+
}
|
46
|
+
})
|
43
47
|
|
44
|
-
afterEach(function() {
|
45
|
-
delete GOVUK.Modules.TestAlertModule
|
46
|
-
})
|
48
|
+
afterEach(function () {
|
49
|
+
delete GOVUK.Modules.TestAlertModule
|
50
|
+
})
|
47
51
|
|
48
|
-
it('starts modules within a container', function() {
|
49
|
-
var module = $('<div data-module="test-alert-module"></div>')
|
50
|
-
|
52
|
+
it('starts modules within a container', function () {
|
53
|
+
var module = $('<div data-module="test-alert-module"></div>')
|
54
|
+
var container = $('<div></div>').append(module)
|
51
55
|
|
52
|
-
GOVUK.modules.start(container)
|
53
|
-
expect(callback).toHaveBeenCalled()
|
54
|
-
})
|
56
|
+
GOVUK.modules.start(container)
|
57
|
+
expect(callback).toHaveBeenCalled()
|
58
|
+
})
|
55
59
|
|
56
|
-
it('does not start modules that are already started', function() {
|
57
|
-
var module = $('<div data-module="test-alert-module"></div>')
|
58
|
-
|
60
|
+
it('does not start modules that are already started', function () {
|
61
|
+
var module = $('<div data-module="test-alert-module"></div>')
|
62
|
+
$('<div></div>').append(module)
|
59
63
|
|
60
|
-
GOVUK.modules.start(module)
|
61
|
-
GOVUK.modules.start(module)
|
62
|
-
expect(callback.calls.count()).toBe(1)
|
63
|
-
})
|
64
|
+
GOVUK.modules.start(module)
|
65
|
+
GOVUK.modules.start(module)
|
66
|
+
expect(callback.calls.count()).toBe(1)
|
67
|
+
})
|
64
68
|
|
65
|
-
it('passes the HTML element to the module\'s start method', function() {
|
66
|
-
var module = $('<div data-module="test-alert-module"></div>')
|
67
|
-
|
69
|
+
it('passes the HTML element to the module\'s start method', function () {
|
70
|
+
var module = $('<div data-module="test-alert-module"></div>')
|
71
|
+
var container = $('<h1></h1>').append(module)
|
68
72
|
|
69
|
-
GOVUK.modules.start(container)
|
73
|
+
GOVUK.modules.start(container)
|
70
74
|
|
71
|
-
var args = callback.calls.argsFor(0)
|
72
|
-
expect(args[0].is('div[data-module="test-alert-module"]')).toBe(true)
|
73
|
-
})
|
75
|
+
var args = callback.calls.argsFor(0)
|
76
|
+
expect(args[0].is('div[data-module="test-alert-module"]')).toBe(true)
|
77
|
+
})
|
74
78
|
|
75
|
-
it('starts all modules that are on the page', function() {
|
79
|
+
it('starts all modules that are on the page', function () {
|
76
80
|
var modules = $(
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
$('body').append(modules)
|
83
|
-
GOVUK.modules.start()
|
84
|
-
expect(callback.calls.count()).toBe(3)
|
85
|
-
|
86
|
-
modules.remove()
|
87
|
-
})
|
88
|
-
})
|
89
|
-
})
|
81
|
+
'<div data-module="test-alert-module"></div>' +
|
82
|
+
'<strong data-module="test-alert-module"></strong>' +
|
83
|
+
'<span data-module="test-alert-module"></span>'
|
84
|
+
)
|
85
|
+
|
86
|
+
$('body').append(modules)
|
87
|
+
GOVUK.modules.start()
|
88
|
+
expect(callback.calls.count()).toBe(3)
|
89
|
+
|
90
|
+
modules.remove()
|
91
|
+
})
|
92
|
+
})
|
93
|
+
})
|
@@ -1,49 +1,54 @@
|
|
1
|
-
describe
|
2
|
-
|
1
|
+
/* global describe it expect beforeEach afterEach spyOn */
|
2
|
+
|
3
|
+
var $ = window.jQuery
|
4
|
+
|
5
|
+
describe('An auto event tracker', function () {
|
6
|
+
'use strict'
|
7
|
+
var GOVUK = window.GOVUK
|
3
8
|
|
4
9
|
var tracker,
|
5
|
-
|
10
|
+
element
|
6
11
|
|
7
|
-
beforeEach(function() {
|
8
|
-
GOVUK.analytics = {trackEvent: function() {}}
|
9
|
-
tracker = new GOVUK.Modules.AutoTrackEvent()
|
10
|
-
})
|
12
|
+
beforeEach(function () {
|
13
|
+
GOVUK.analytics = {trackEvent: function () {}}
|
14
|
+
tracker = new GOVUK.Modules.AutoTrackEvent()
|
15
|
+
})
|
11
16
|
|
12
|
-
afterEach(function() {
|
13
|
-
delete GOVUK.analytics
|
14
|
-
})
|
17
|
+
afterEach(function () {
|
18
|
+
delete GOVUK.analytics
|
19
|
+
})
|
15
20
|
|
16
|
-
it('tracks non-interactive events on start', function() {
|
17
|
-
spyOn(GOVUK.analytics, 'trackEvent')
|
21
|
+
it('tracks non-interactive events on start', function () {
|
22
|
+
spyOn(GOVUK.analytics, 'trackEvent')
|
18
23
|
|
19
|
-
element = $(
|
20
|
-
<div
|
21
|
-
data-track-category="category"
|
22
|
-
data-track-action="action"
|
23
|
-
Some content
|
24
|
-
</div
|
25
|
-
|
24
|
+
element = $(
|
25
|
+
'<div ' +
|
26
|
+
'data-track-category="category"' +
|
27
|
+
'data-track-action="action">' +
|
28
|
+
'Some content' +
|
29
|
+
'</div>'
|
30
|
+
)
|
26
31
|
|
27
|
-
tracker.start(element)
|
32
|
+
tracker.start(element)
|
28
33
|
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
29
|
-
'category', 'action', {nonInteraction: 1})
|
30
|
-
})
|
31
|
-
|
32
|
-
it('can track non-interactive events with optional label and value', function() {
|
33
|
-
spyOn(GOVUK.analytics, 'trackEvent')
|
34
|
-
|
35
|
-
element = $(
|
36
|
-
<div
|
37
|
-
data-track-category="category"
|
38
|
-
data-track-action="action"
|
39
|
-
data-track-label="label"
|
40
|
-
data-track-value="10"
|
41
|
-
Some content
|
42
|
-
</div
|
43
|
-
|
44
|
-
|
45
|
-
tracker.start(element)
|
34
|
+
'category', 'action', {nonInteraction: 1})
|
35
|
+
})
|
36
|
+
|
37
|
+
it('can track non-interactive events with optional label and value', function () {
|
38
|
+
spyOn(GOVUK.analytics, 'trackEvent')
|
39
|
+
|
40
|
+
element = $(
|
41
|
+
'<div ' +
|
42
|
+
'data-track-category="category"' +
|
43
|
+
'data-track-action="action"' +
|
44
|
+
'data-track-label="label"' +
|
45
|
+
'data-track-value="10">' +
|
46
|
+
'Some content' +
|
47
|
+
'</div>'
|
48
|
+
)
|
49
|
+
|
50
|
+
tracker.start(element)
|
46
51
|
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
47
|
-
'category', 'action', {label: 'label', value: 10, nonInteraction: 1})
|
48
|
-
})
|
49
|
-
})
|
52
|
+
'category', 'action', {label: 'label', value: 10, nonInteraction: 1})
|
53
|
+
})
|
54
|
+
})
|
@@ -1,136 +1,142 @@
|
|
1
|
-
describe
|
2
|
-
beforeEach(function() {
|
3
|
-
GOVUK.cookie = jasmine.createSpy('GOVUK.cookie');
|
4
|
-
GOVUK.analytics = {setDimension:function(){}, trackEvent:function(){}};
|
5
|
-
spyOn(GOVUK.analytics, "setDimension");
|
6
|
-
spyOn(GOVUK.analytics, "trackEvent");
|
7
|
-
});
|
1
|
+
/* global describe it expect beforeEach afterEach jasmine spyOn */
|
8
2
|
|
9
|
-
|
10
|
-
delete GOVUK.analytics;
|
11
|
-
});
|
3
|
+
var $ = window.jQuery
|
12
4
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
5
|
+
describe('MultivariateTest', function () {
|
6
|
+
'use strict'
|
7
|
+
var GOVUK = window.GOVUK
|
8
|
+
|
9
|
+
beforeEach(function () {
|
10
|
+
GOVUK.cookie = jasmine.createSpy('GOVUK.cookie')
|
11
|
+
GOVUK.analytics = {setDimension: function () {}, trackEvent: function () {}}
|
12
|
+
spyOn(GOVUK.analytics, 'setDimension')
|
13
|
+
spyOn(GOVUK.analytics, 'trackEvent')
|
14
|
+
})
|
15
|
+
|
16
|
+
afterEach(function () {
|
17
|
+
delete GOVUK.analytics
|
18
|
+
})
|
19
|
+
|
20
|
+
describe('#run', function () {
|
21
|
+
it('should pick a random cohort on first run', function () {
|
22
|
+
GOVUK.cookie.and.returnValue(null)
|
23
|
+
var fooSpy = jasmine.createSpy('fooSpy')
|
24
|
+
var barSpy = jasmine.createSpy('barSpy')
|
25
|
+
new GOVUK.MultivariateTest({ // eslint-disable-line no-new
|
19
26
|
name: 'stuff',
|
20
27
|
cohorts: {
|
21
28
|
foo: {callback: fooSpy},
|
22
29
|
bar: {callback: barSpy}
|
23
30
|
}
|
24
|
-
})
|
31
|
+
})
|
25
32
|
|
26
|
-
expect(GOVUK.cookie.calls.count()).toEqual(2)
|
27
|
-
expect(GOVUK.cookie.calls.argsFor(1)[0]).toEqual('multivariatetest_cohort_stuff')
|
28
|
-
if (GOVUK.cookie.calls.argsFor(1)[1]
|
29
|
-
expect(fooSpy).toHaveBeenCalled()
|
30
|
-
}
|
31
|
-
|
32
|
-
expect(barSpy).toHaveBeenCalled();
|
33
|
+
expect(GOVUK.cookie.calls.count()).toEqual(2)
|
34
|
+
expect(GOVUK.cookie.calls.argsFor(1)[0]).toEqual('multivariatetest_cohort_stuff')
|
35
|
+
if (GOVUK.cookie.calls.argsFor(1)[1] === 'foo') {
|
36
|
+
expect(fooSpy).toHaveBeenCalled()
|
37
|
+
} else {
|
38
|
+
expect(barSpy).toHaveBeenCalled()
|
33
39
|
}
|
34
|
-
})
|
40
|
+
})
|
35
41
|
|
36
|
-
it(
|
37
|
-
GOVUK.cookie.and.returnValue('foo')
|
38
|
-
var fooSpy = jasmine.createSpy('fooSpy')
|
39
|
-
var barSpy = jasmine.createSpy('barSpy')
|
40
|
-
|
42
|
+
it('should use an existing cohort choice on subsequent runs', function () {
|
43
|
+
GOVUK.cookie.and.returnValue('foo')
|
44
|
+
var fooSpy = jasmine.createSpy('fooSpy')
|
45
|
+
var barSpy = jasmine.createSpy('barSpy')
|
46
|
+
new GOVUK.MultivariateTest({ // eslint-disable-line no-new
|
41
47
|
name: 'stuff',
|
42
48
|
cohorts: {
|
43
49
|
foo: {callback: fooSpy},
|
44
50
|
bar: {callback: barSpy}
|
45
51
|
}
|
46
|
-
})
|
47
|
-
expect(fooSpy).toHaveBeenCalled()
|
48
|
-
})
|
52
|
+
})
|
53
|
+
expect(fooSpy).toHaveBeenCalled()
|
54
|
+
})
|
49
55
|
|
50
|
-
it(
|
51
|
-
GOVUK.cookie.and.returnValue('foo')
|
52
|
-
|
56
|
+
it('should set a custom var with the name and cohort if one is defined', function () {
|
57
|
+
GOVUK.cookie.and.returnValue('foo')
|
58
|
+
new GOVUK.MultivariateTest({ // eslint-disable-line no-new
|
53
59
|
name: 'stuff',
|
54
60
|
cohorts: {
|
55
61
|
foo: {},
|
56
62
|
bar: {}
|
57
63
|
},
|
58
64
|
customDimensionIndex: 2
|
59
|
-
})
|
65
|
+
})
|
60
66
|
expect(GOVUK.analytics.setDimension).toHaveBeenCalledWith(
|
61
67
|
2,
|
62
68
|
'multivariatetest_cohort_stuff__foo'
|
63
|
-
)
|
64
|
-
})
|
69
|
+
)
|
70
|
+
})
|
65
71
|
|
66
|
-
it(
|
67
|
-
GOVUK.cookie.and.returnValue('foo')
|
68
|
-
|
72
|
+
it('should be able to set multiple custom vars with the name and cohort if one is defined as an array', function () {
|
73
|
+
GOVUK.cookie.and.returnValue('foo')
|
74
|
+
new GOVUK.MultivariateTest({ // eslint-disable-line no-new
|
69
75
|
name: 'stuff',
|
70
76
|
cohorts: {
|
71
77
|
foo: {},
|
72
78
|
bar: {}
|
73
79
|
},
|
74
|
-
customDimensionIndex: [2,3]
|
75
|
-
})
|
80
|
+
customDimensionIndex: [2, 3]
|
81
|
+
})
|
76
82
|
expect(GOVUK.analytics.setDimension).toHaveBeenCalledWith(
|
77
83
|
2,
|
78
84
|
'multivariatetest_cohort_stuff__foo'
|
79
|
-
)
|
85
|
+
)
|
80
86
|
expect(GOVUK.analytics.setDimension).toHaveBeenCalledWith(
|
81
87
|
3,
|
82
88
|
'multivariatetest_cohort_stuff__foo'
|
83
|
-
)
|
84
|
-
})
|
89
|
+
)
|
90
|
+
})
|
85
91
|
|
86
|
-
it(
|
87
|
-
GOVUK.cookie.and.returnValue('foo')
|
88
|
-
|
92
|
+
it('should trigger an event to track that the test has been run', function () {
|
93
|
+
GOVUK.cookie.and.returnValue('foo')
|
94
|
+
new GOVUK.MultivariateTest({ // eslint-disable-line no-new
|
89
95
|
name: 'stuff',
|
90
96
|
cohorts: {
|
91
97
|
foo: {},
|
92
98
|
bar: {}
|
93
|
-
}
|
94
|
-
})
|
99
|
+
}
|
100
|
+
})
|
95
101
|
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
96
102
|
'multivariatetest_cohort_stuff',
|
97
103
|
'run',
|
98
|
-
{nonInteraction:true}
|
99
|
-
)
|
100
|
-
})
|
104
|
+
{nonInteraction: true}
|
105
|
+
)
|
106
|
+
})
|
101
107
|
|
102
|
-
it(
|
103
|
-
GOVUK.cookie.and.returnValue('foo')
|
104
|
-
var $el = $('<div>')
|
105
|
-
|
108
|
+
it('should set html for a cohort', function () {
|
109
|
+
GOVUK.cookie.and.returnValue('foo')
|
110
|
+
var $el = $('<div>')
|
111
|
+
new GOVUK.MultivariateTest({ // eslint-disable-line no-new
|
106
112
|
name: 'stuff',
|
107
113
|
el: $el,
|
108
114
|
cohorts: {
|
109
|
-
foo: {html:
|
110
|
-
bar: {html:
|
115
|
+
foo: {html: 'foo'},
|
116
|
+
bar: {html: 'bar'}
|
111
117
|
}
|
112
|
-
})
|
113
|
-
expect($el.html()).toEqual('foo')
|
114
|
-
})
|
118
|
+
})
|
119
|
+
expect($el.html()).toEqual('foo')
|
120
|
+
})
|
115
121
|
|
116
|
-
it(
|
117
|
-
var fooSpy = jasmine.createSpy('fooSpy')
|
118
|
-
var barSpy = jasmine.createSpy('barSpy')
|
119
|
-
GOVUK.cookie.and.returnValue('bar')
|
120
|
-
var $el = $('<div>')
|
121
|
-
|
122
|
+
it('should call the callback for a cohort', function () {
|
123
|
+
var fooSpy = jasmine.createSpy('fooSpy')
|
124
|
+
var barSpy = jasmine.createSpy('barSpy')
|
125
|
+
GOVUK.cookie.and.returnValue('bar')
|
126
|
+
var $el = $('<div>')
|
127
|
+
new GOVUK.MultivariateTest({ // eslint-disable-line no-new
|
122
128
|
name: 'stuff',
|
123
129
|
el: $el,
|
124
130
|
cohorts: {
|
125
131
|
foo: {callback: fooSpy},
|
126
132
|
bar: {callback: barSpy}
|
127
133
|
}
|
128
|
-
})
|
129
|
-
expect(barSpy).toHaveBeenCalled()
|
130
|
-
})
|
134
|
+
})
|
135
|
+
expect(barSpy).toHaveBeenCalled()
|
136
|
+
})
|
131
137
|
|
132
|
-
it(
|
133
|
-
GOVUK.cookie.and.returnValue('foo')
|
138
|
+
it('should call the callback for a cohort if it is a string', function () {
|
139
|
+
GOVUK.cookie.and.returnValue('foo')
|
134
140
|
var test = new GOVUK.MultivariateTest({
|
135
141
|
name: 'stuff',
|
136
142
|
cohorts: {
|
@@ -138,120 +144,119 @@ describe("MultivariateTest", function() {
|
|
138
144
|
bar: {}
|
139
145
|
},
|
140
146
|
runImmediately: false
|
141
|
-
})
|
142
|
-
test.fooCallback = jasmine.createSpy('fooCallback')
|
143
|
-
test.run()
|
144
|
-
expect(test.fooCallback).toHaveBeenCalled()
|
145
|
-
})
|
147
|
+
})
|
148
|
+
test.fooCallback = jasmine.createSpy('fooCallback')
|
149
|
+
test.run()
|
150
|
+
expect(test.fooCallback).toHaveBeenCalled()
|
151
|
+
})
|
146
152
|
|
147
|
-
it("should assign 30 if cookieDuration isn't defined", function() {
|
148
|
-
GOVUK.cookie.and.returnValue('foo')
|
153
|
+
it("should assign 30 if cookieDuration isn't defined", function () {
|
154
|
+
GOVUK.cookie.and.returnValue('foo')
|
149
155
|
var test = new GOVUK.MultivariateTest({
|
150
156
|
name: 'cookie_duration_test',
|
151
157
|
cohorts: {
|
152
|
-
foo: {callback: function(){}}
|
158
|
+
foo: {callback: function () {}}
|
153
159
|
}
|
154
|
-
})
|
155
|
-
expect(test.cookieDuration).toEqual(30)
|
156
|
-
})
|
160
|
+
})
|
161
|
+
expect(test.cookieDuration).toEqual(30)
|
162
|
+
})
|
157
163
|
|
158
|
-
it("should assign the user's cookie duration, when cookieDuration is defined", function() {
|
159
|
-
GOVUK.cookie.and.returnValue('foo')
|
164
|
+
it("should assign the user's cookie duration, when cookieDuration is defined", function () {
|
165
|
+
GOVUK.cookie.and.returnValue('foo')
|
160
166
|
var test = new GOVUK.MultivariateTest({
|
161
167
|
name: 'cookie_duration_test',
|
162
168
|
cookieDuration: 14,
|
163
169
|
cohorts: {
|
164
|
-
foo: {callback: function(){}}
|
170
|
+
foo: {callback: function () {}}
|
165
171
|
}
|
166
|
-
})
|
167
|
-
expect(test.cookieDuration).toEqual(14)
|
168
|
-
})
|
172
|
+
})
|
173
|
+
expect(test.cookieDuration).toEqual(14)
|
174
|
+
})
|
169
175
|
|
170
|
-
it(
|
171
|
-
var fooSpy = jasmine.createSpy('fooSpy')
|
172
|
-
var barSpy = jasmine.createSpy('barSpy')
|
173
|
-
GOVUK.cookie.and.returnValue('baz')
|
174
|
-
|
176
|
+
it('should assign a new random cohort if the assigned cohort does not exist', function () {
|
177
|
+
var fooSpy = jasmine.createSpy('fooSpy')
|
178
|
+
var barSpy = jasmine.createSpy('barSpy')
|
179
|
+
GOVUK.cookie.and.returnValue('baz')
|
180
|
+
new GOVUK.MultivariateTest({ // eslint-disable-line no-new
|
175
181
|
name: 'stuff',
|
176
182
|
cohorts: {
|
177
183
|
foo: {callback: fooSpy},
|
178
184
|
bar: {callback: barSpy}
|
179
185
|
}
|
180
|
-
})
|
181
|
-
if (GOVUK.cookie.calls.argsFor(1)[1]
|
182
|
-
expect(fooSpy).toHaveBeenCalled()
|
183
|
-
}
|
184
|
-
|
185
|
-
expect(barSpy).toHaveBeenCalled();
|
186
|
+
})
|
187
|
+
if (GOVUK.cookie.calls.argsFor(1)[1] === 'foo') {
|
188
|
+
expect(fooSpy).toHaveBeenCalled()
|
189
|
+
} else {
|
190
|
+
expect(barSpy).toHaveBeenCalled()
|
186
191
|
}
|
187
|
-
})
|
188
|
-
})
|
192
|
+
})
|
193
|
+
})
|
189
194
|
|
190
|
-
describe(
|
191
|
-
it(
|
195
|
+
describe('#weightedCohortNames', function () {
|
196
|
+
it('should return the weighted names of the cohorts when no weights are defined', function () {
|
192
197
|
var test = new GOVUK.MultivariateTest({
|
193
198
|
name: 'stuff',
|
194
199
|
cohorts: {foo: {}, bar: {}, baz: {}}
|
195
|
-
})
|
196
|
-
expect(test.weightedCohortNames()).toEqual(['foo', 'bar', 'baz'])
|
197
|
-
})
|
200
|
+
})
|
201
|
+
expect(test.weightedCohortNames()).toEqual(['foo', 'bar', 'baz'])
|
202
|
+
})
|
198
203
|
|
199
|
-
it(
|
204
|
+
it('should return the weighted names of the cohorts when weights are defined', function () {
|
200
205
|
var test = new GOVUK.MultivariateTest({
|
201
206
|
name: 'stuff',
|
202
207
|
cohorts: {foo: { weight: 2 }, bar: { weight: 1 }, baz: { weight: 3 }}
|
203
|
-
})
|
204
|
-
expect(test.weightedCohortNames()).toEqual(['foo', 'foo', 'bar', 'baz', 'baz', 'baz'])
|
205
|
-
})
|
208
|
+
})
|
209
|
+
expect(test.weightedCohortNames()).toEqual(['foo', 'foo', 'bar', 'baz', 'baz', 'baz'])
|
210
|
+
})
|
206
211
|
|
207
|
-
it(
|
212
|
+
it('should return the weighted names of the cohorts using default weighting', function () {
|
208
213
|
var test = new GOVUK.MultivariateTest({
|
209
214
|
name: 'stuff',
|
210
215
|
defaultWeight: 2,
|
211
216
|
cohorts: {foo: {}, bar: {}, baz: {}}
|
212
|
-
})
|
213
|
-
expect(test.weightedCohortNames()).toEqual(['foo', 'foo', 'bar', 'bar', 'baz', 'baz'])
|
214
|
-
})
|
217
|
+
})
|
218
|
+
expect(test.weightedCohortNames()).toEqual(['foo', 'foo', 'bar', 'bar', 'baz', 'baz'])
|
219
|
+
})
|
215
220
|
|
216
|
-
it(
|
221
|
+
it('should return the weighted names of the cohorts using default weighting or defined weighting', function () {
|
217
222
|
var test = new GOVUK.MultivariateTest({
|
218
223
|
name: 'stuff',
|
219
224
|
defaultWeight: 2,
|
220
225
|
cohorts: {foo: {}, bar: { weight: 1 }, baz: {}}
|
221
|
-
})
|
222
|
-
expect(test.weightedCohortNames()).toEqual(['foo', 'foo', 'bar', 'baz', 'baz'])
|
223
|
-
})
|
224
|
-
})
|
226
|
+
})
|
227
|
+
expect(test.weightedCohortNames()).toEqual(['foo', 'foo', 'bar', 'baz', 'baz'])
|
228
|
+
})
|
229
|
+
})
|
225
230
|
|
226
|
-
describe(
|
227
|
-
it(
|
231
|
+
describe('#chooseRandomCohort', function () {
|
232
|
+
it('should choose a random cohort', function () {
|
228
233
|
var test = new GOVUK.MultivariateTest({
|
229
234
|
name: 'stuff',
|
230
235
|
cohorts: {foo: {}, bar: {}}
|
231
|
-
})
|
232
|
-
expect(['foo', 'bar']).toContain(test.chooseRandomCohort())
|
236
|
+
})
|
237
|
+
expect(['foo', 'bar']).toContain(test.chooseRandomCohort())
|
233
238
|
})
|
234
|
-
})
|
239
|
+
})
|
235
240
|
|
236
|
-
describe(
|
237
|
-
beforeEach(function() {
|
238
|
-
window.ga = function() {}
|
239
|
-
spyOn(window, 'ga')
|
240
|
-
})
|
241
|
+
describe('Google Content Experiment Integration', function () {
|
242
|
+
beforeEach(function () {
|
243
|
+
window.ga = function () {}
|
244
|
+
spyOn(window, 'ga')
|
245
|
+
})
|
241
246
|
|
242
|
-
it(
|
243
|
-
|
247
|
+
it('should report the experiment data to Google', function () {
|
248
|
+
new GOVUK.MultivariateTest({ // eslint-disable-line no-new
|
244
249
|
name: 'stuff',
|
245
|
-
contentExperimentId:
|
246
|
-
cohorts: {foo: {variantId: 0, weight: 1},
|
247
|
-
})
|
248
|
-
expect(window.ga.calls.first().args).toEqual(['set', 'expId', 'asdfsadasdfa'])
|
249
|
-
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'expVar', 0])
|
250
|
+
contentExperimentId: 'asdfsadasdfa',
|
251
|
+
cohorts: {foo: {variantId: 0, weight: 1}, bar: {variantId: 1, weight: 0}}
|
252
|
+
})
|
253
|
+
expect(window.ga.calls.first().args).toEqual(['set', 'expId', 'asdfsadasdfa'])
|
254
|
+
expect(window.ga.calls.mostRecent().args).toEqual(['set', 'expVar', 0])
|
250
255
|
expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
|
251
256
|
'multivariatetest_cohort_stuff',
|
252
257
|
'run',
|
253
|
-
{nonInteraction:true}
|
254
|
-
)
|
255
|
-
})
|
256
|
-
})
|
257
|
-
})
|
258
|
+
{nonInteraction: true}
|
259
|
+
)
|
260
|
+
})
|
261
|
+
})
|
262
|
+
})
|