govuk_frontend_toolkit 6.0.4 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e19506a0003566927e5f74fa4c81760684f2dff3
4
- data.tar.gz: 49aef344e0394145b25b71ba11c8d85bebe3fa76
3
+ metadata.gz: 78b452b51c6d7bdb928111cdaf554ca4f2e7a084
4
+ data.tar.gz: dfcdc53acdf0f0757b8536dd0eb992c0f95a7bb3
5
5
  SHA512:
6
- metadata.gz: ccaff34c71508cdbd93962af75d84485a615ac218778ddf5e9f31d5ce7a8277732c83df329ca693126f5c5c0f5d859071c4679faed7a07a63f5a9f32567048c8
7
- data.tar.gz: a14b005f41b7db9011c86b153a37d37bc8203f7848c577493a6e46c180191648c1335ceba68d09a948383a0f884854898c7d211f766a21bbe363b721c21ed71e
6
+ metadata.gz: 044d0927e1a0938a22583981cb17007d4b228d170e966423621a0a0804643a99348464c2addcd1b86e39da80241f9523e8a7119f9299a02aa932c966f79247bd
7
+ data.tar.gz: 133d696715ec1c3e18509eff81eb85fcaa24542dff408833a489018a656d410dd87be04bdac593736cdff3cda0db6e66cf7ccc7d3bddeff9c1455f9420b27691
@@ -1,3 +1,7 @@
1
+ # 7.0.0
2
+
3
+ - Remove multivariate test library ([PR #420](https://github.com/alphagov/govuk_frontend_toolkit/pull/420)). If you need to continue using this library please copy the JavaScript and documentation from version 6.0.4 into your repository.
4
+
1
5
  # 6.0.4
2
6
 
3
7
  - Version bumping related to [govuk_frontend_toolkit_gem PR #15](https://github.com/alphagov/govuk_frontend_toolkit_gem/pull/15)
data/app/assets/README.md CHANGED
@@ -63,9 +63,9 @@ For example, if you are using [bower](http://bower.io), you can add the toolkit
63
63
 
64
64
  #### Using git submodules
65
65
 
66
- You can include the toolkit as a [git submodule][https://git-scm.com/book/en/v2/Git-Tools-Submodules].
66
+ You can include the toolkit as a [git submodule][git submodule].
67
67
 
68
- [git submodule]: https://www.kernel.org/pub/software/scm/git/docs/git-submodule.html
68
+ [git submodule]: https://git-scm.com/book/en/v2/Git-Tools-Submodules
69
69
 
70
70
  To add the submodule to your project run the following command substituting the path to a subdirectory in your project's assets directory:
71
71
 
@@ -141,7 +141,6 @@ In production:
141
141
  * [JavaScript](/docs/javascript.md)
142
142
  * [Modules](/docs/javascript.md#modules)
143
143
  * [Media player](/docs/javascript.md#media-player)
144
- * [Multivariate test framework](/docs/javascript.md#multivariate-test-framework)
145
144
  * [Primary links](/docs/javascript.md#primary-links)
146
145
  * [Stick at top when scrolling](/docs/javascript.md#stick-at-top-when-scrolling)
147
146
  * [Selection buttons](/docs/javascript.md#selection-buttons)
@@ -1 +1 @@
1
- 6.0.4
1
+ 7.0.0
@@ -134,155 +134,6 @@ Accesible Media Player][nomensa] repository.
134
134
 
135
135
  [nomensa]: https://github.com/nomensa/Accessible-Media-Player/tree/master/example
136
136
 
137
- ## Multivariate test framework
138
-
139
- `GOVUK.MultiVariateTest` runs split tests to display different content, layouts etc to users.
140
-
141
- It randomly assigns a user a cohort on first execution by setting a cookie, and on every execution sets a session level custom variable on Google Analytics to mark which cohort a user is in. This can be used to segment users in GA.
142
-
143
- A simple content replacement test can be done by defining a set of cohorts with content. E.g.:
144
-
145
- ```javascript
146
- var test = new GOVUK.MultivariateTest({
147
- el: '.car-tax-button',
148
- name: 'car_tax_button_text',
149
- cohorts: {
150
- pay_your_car_tax: {html: "Pay Your Car Tax"},
151
- give_us_money: {html: "Give Us Money Or We Will Crush Your Car"}
152
- }
153
- });
154
- ```
155
-
156
- A more complex test can be done by defining callbacks for what to do
157
- when a user is in each cohort:
158
-
159
- ```javascript
160
- var test = new GOVUK.MultivariateTest({
161
- name: 'car_tax_button_text',
162
- cohorts: {
163
- pay_your_car_tax: {callback: function() { ... }},
164
- give_us_money: {callback: function() { ... }}
165
- }
166
- });
167
- ```
168
-
169
- If you want one cohort to appear 25% of the time then you can optionally weight
170
- that cohort:
171
-
172
- ```javascript
173
- var test = new GOVUK.MultivariateTest({
174
- name: 'car_tax_button_text',
175
- cohorts: {
176
- pay_your_car_tax: {weight: 25, callback: function() { ... }}, // 25%
177
- give_us_money: {weight: 75, callback: function() { ... }} // 75%
178
- }
179
- });
180
- ```
181
-
182
- If you want to set the cookie expiration then you can optionally set cookieDuration as follows:
183
-
184
- ```javascript
185
- var test = new GOVUK.MultivariateTest({
186
- name: 'car_tax_button_text',
187
- cookieDuration: 14,
188
- cohorts: {
189
- pay_your_car_tax: {weight: 25, callback: function() { ... }}, // 25%
190
- give_us_money: {weight: 75, callback: function() { ... }} // 75%
191
- }
192
- });
193
- ```
194
- Here, it is set to expire in 14 days time. if this option is not set the default cookie expiration (30 days) take effect.
195
-
196
- If you have a complex test, it may be worth extending MultivariateTest with
197
- your own. Callbacks can be strings which will call a method of that name
198
- on the current object.
199
-
200
- Takes these options:
201
- - `el`: Element to run this test on (optional)
202
- - `name`: The name of the text (alphanumeric and underscores), which will be part of the cookie.
203
- - `defaultWeight`: Number of times each cohorts should appear in an array the random cohort is picked from, to be used in conjunction with weights on individual cohorts.
204
- - `cohorts`: An object that maps cohort name to an object that defines the cohort. Name must be same format as test name. Object contains keys (all optional):
205
- - `html`: HTML to fill element with when this cohort is picked.
206
- - `callback`: Function to call when this cohort is chosen. If it is a string, that method on the test object is called.
207
- - `weight`: Number of times this cohort should appear in an array the random cohort is picked from, defaults to the `defaultWeight` of the test.
208
-
209
- Full documentation on how to design multivariate tests, use the data in GA and construct hypothesis tests is on its way soon.
210
-
211
- ### Reporting to Google Content Experiments
212
- The toolkit includes a library for multivariate testing that is capable of reporting data into [Google Content Experiments](https://developers.google.com/analytics/devguides/platform/experiments-overview).
213
-
214
- #### To create a new experiment
215
-
216
- 1. Log in to Google Universal Analytics, select "UA - 1. GOV.UK(Entire Site - Filtered)".
217
-
218
- 2. In the left column, click on Behaviour, then Experiments and follow [these instructions](https://support.google.com/analytics/answer/1745152?hl=en-GB) to set up your experiment; you will need to have edit permissions on the Universal Analytics profile. If you cannot see a "Create experiment" button, this means you don't have these permissions; you can ask someone from the Performance Analyst team to set the experiment up for you.
219
-
220
- 3. In step number 2, in our case the address of the web pages will purely be used as descriptions in reports, so we recommend you pick the addresses accordingly, ie: "www.gov.uk" and "www.gov.uk/?=variation1".
221
-
222
- 4. In step number 3, "Setting up your experiment code", select "Manually insert the code" and make a note of the Experiment ID number located under the script window.
223
-
224
- 5. Add the below code to the page you want to test.
225
- - the contentExperimentId is the Experiment ID you retrieved in step 3.
226
- - the variantId is 0 for the original variant, 1 for the first modified variant, 2 for the second modified variant, etc.
227
- - see section above for other elements.
228
- This code requires analytics to be loaded in order to run; static is the app that would load the analytics by default, which automatically happens before experiments are run.
229
-
230
- 6. Check that it works: launch the app, open the page of your app, and check that there is a cookie with the name you had picked in your experiment. You can delete the cookie and refresh the page to check whether you can be assigned to another cohort. Then in your browser console, go to the Networks tab and search for xid and xvar. The values should correspond to your contentExperimentId and the cohort your cookie indicates you were assigned to.
231
-
232
- 7. If it works, in Google Universal Analytics, click on "Next Step" and then "Start Experiment". You can ignore the error messages relative to Experiment Code Validation as they don't concern us in our setup.
233
-
234
- ```js
235
- var test = new GOVUK.MultivariateTest({
236
- name: 'car_tax_button_text',
237
- contentExperimentId: "Your_Experiment_ID",
238
- cohorts: {
239
- pay_your_car_tax: {weight: 25, variantId: 0},
240
- give_us_money: {weight: 25, variantId: 1}
241
- }
242
- });
243
-
244
- ```
245
-
246
- ### Using Google custom dimensions with your own statistical model
247
-
248
- It is possible to use Google custom dimensions for determining the results of
249
- the multivariate test (as an alternative to Google Content Experiments). This
250
- may be appropriate if you wish to build the statistical model yourself or you
251
- aren't able to use Content Experiments for some reason.
252
-
253
- This requires setting the optional `customDimensionIndex` variable:
254
-
255
- ```js
256
- var test = new GOVUK.MultivariateTest({
257
- name: 'car_tax_button_text',
258
- customDimensionIndex: 555,
259
- cohorts: {
260
- pay_your_car_tax: {weight: 25},
261
- give_us_money: {weight: 50}
262
- }
263
- });
264
- ```
265
-
266
- `customDimensionIndex` is the index of the custom variable in Google Analytics. GA only gives 50 integer slots to each account, and it is important that a unique integer is assigned to each test. Current contact for assigning a custom var slot for GOV.UK is: Tim Leighton-Boyce <tim.leighton-boyce@digital.cabinet-office.gov.uk>
267
-
268
- For certain types of tests where the custom dimensions in Google Analytics can only have one of three scopes (hit, session, or user). Measuring performance of A/B tests, and want to compare test results for session-scoped custom dimensions (eg: index 222) against hit-scoped ones (eg: index 223) may become important.
269
-
270
- Instead of supplying an integer (like the above example), `customDimensionIndex` can also accept an array of dimension indexes ([222, 223]), see below for more.
271
-
272
- Make sure to check GA debugger that these values are being sent before deploying.
273
-
274
- ```js
275
- var test = new GOVUK.MultivariateTest({
276
- name: 'car_tax_button_text',
277
- customDimensionIndex: [222, 223],
278
- cohorts: {
279
- pay_your_car_tax: {weight: 25},
280
- give_us_money: {weight: 50}
281
- }
282
- });
283
- ```
284
-
285
-
286
137
  ## Primary Links
287
138
 
288
139
  `GOVUK.PrimaryList` hides elements in a list which don't have a supplied
@@ -4,7 +4,6 @@ var manifest = {
4
4
  '../../node_modules/jquery/dist/jquery.js',
5
5
  '../../javascripts/govuk/modules.js',
6
6
  '../../javascripts/govuk/modules/auto-track-event.js',
7
- '../../javascripts/govuk/multivariate-test.js',
8
7
  '../../javascripts/govuk/primary-links.js',
9
8
  '../../javascripts/govuk/shim-links-with-button-role.js',
10
9
  '../../javascripts/govuk/show-hide-content.js',
@@ -22,7 +21,6 @@ var manifest = {
22
21
  test: [
23
22
  '../unit/modules.spec.js',
24
23
  '../unit/Modules/auto-track-event.spec.js',
25
- '../unit/multivariate-test.spec.js',
26
24
  '../unit/primary-links.spec.js',
27
25
  '../unit/shim-links-with-button-role.spec.js',
28
26
  '../unit/show-hide-content.spec.js',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_frontend_toolkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.4
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Government Digital Service
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-14 00:00:00.000000000 Z
11
+ date: 2017-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -227,7 +227,6 @@ files:
227
227
  - app/assets/javascripts/govuk/analytics/print-intent.js
228
228
  - app/assets/javascripts/govuk/modules.js
229
229
  - app/assets/javascripts/govuk/modules/auto-track-event.js
230
- - app/assets/javascripts/govuk/multivariate-test.js
231
230
  - app/assets/javascripts/govuk/primary-links.js
232
231
  - app/assets/javascripts/govuk/selection-buttons.js
233
232
  - app/assets/javascripts/govuk/shim-links-with-button-role.js
@@ -254,7 +253,6 @@ files:
254
253
  - app/assets/spec/unit/analytics/mailto-link-tracker.spec.js
255
254
  - app/assets/spec/unit/modules.spec.js
256
255
  - app/assets/spec/unit/modules/auto-track-event.spec.js
257
- - app/assets/spec/unit/multivariate-test.spec.js
258
256
  - app/assets/spec/unit/primary-links.spec.js
259
257
  - app/assets/spec/unit/selection-button.spec.js
260
258
  - app/assets/spec/unit/shim-links-with-button-role.spec.js
@@ -1,145 +0,0 @@
1
- ;(function (global) {
2
- 'use strict'
3
-
4
- var $ = global.jQuery
5
- var GOVUK = global.GOVUK || {}
6
-
7
- // A multivariate test framework
8
- //
9
- // Based loosely on https://github.com/jamesyu/cohorts
10
- //
11
- // Full documentation is in README.md.
12
- //
13
- function MultivariateTest (options) {
14
- this.$el = $(options.el)
15
- this._loadOption(options, 'name')
16
- this._loadOption(options, 'customDimensionIndex', null)
17
- this._loadOption(options, 'cohorts')
18
- this._loadOption(options, 'runImmediately', true)
19
- this._loadOption(options, 'defaultWeight', 1)
20
- this._loadOption(options, 'contentExperimentId', null)
21
- this._loadOption(options, 'cookieDuration', 30)
22
-
23
- if (this.runImmediately) {
24
- this.run()
25
- }
26
- }
27
-
28
- MultivariateTest.prototype._loadOption = function (options, key, defaultValue) {
29
- if (options[key] !== undefined) {
30
- this[key] = options[key]
31
- }
32
- if (this[key] === undefined) {
33
- if (defaultValue === undefined) {
34
- throw new Error(key + ' option is required for a multivariate test')
35
- } else {
36
- this[key] = defaultValue
37
- }
38
- }
39
- }
40
-
41
- MultivariateTest.prototype.run = function () {
42
- var cohort = this.getCohort()
43
- if (cohort) {
44
- this.setUpContentExperiment(cohort)
45
- this.setCustomVar(cohort)
46
- this.executeCohort(cohort)
47
- this.createDummyEvent(cohort)
48
- }
49
- }
50
-
51
- MultivariateTest.prototype.executeCohort = function (cohort) {
52
- var cohortObj = this.cohorts[cohort]
53
- if (cohortObj.callback) {
54
- if (typeof cohortObj.callback === 'string') {
55
- this[cohortObj.callback]()
56
- } else {
57
- cohortObj.callback()
58
- }
59
- }
60
- if (cohortObj.html) {
61
- this.$el.html(cohortObj.html)
62
- this.$el.show()
63
- }
64
- }
65
-
66
- // Get the current cohort or assign one if it has not been already
67
- MultivariateTest.prototype.getCohort = function () {
68
- var cohort = GOVUK.cookie(this.cookieName())
69
- if (!cohort || !this.cohorts[cohort]) {
70
- cohort = this.chooseRandomCohort()
71
- GOVUK.cookie(this.cookieName(), cohort, {days: this.cookieDuration})
72
- }
73
- return cohort
74
- }
75
-
76
- MultivariateTest.prototype.setCustomVar = function (cohort) {
77
- if (this.customDimensionIndex &&
78
- this.customDimensionIndex.constructor === Array) {
79
- for (var index = 0; index < this.customDimensionIndex.length; index++) {
80
- this.setDimension(cohort, this.customDimensionIndex[index])
81
- }
82
- } else if (this.customDimensionIndex) {
83
- this.setDimension(cohort, this.customDimensionIndex)
84
- }
85
- }
86
-
87
- MultivariateTest.prototype.setDimension = function (cohort, dimension) {
88
- GOVUK.analytics.setDimension(
89
- dimension,
90
- this.cookieName() + '__' + cohort
91
- )
92
- }
93
-
94
- MultivariateTest.prototype.setUpContentExperiment = function (cohort) {
95
- var contentExperimentId = this.contentExperimentId
96
- var cohortVariantId = this.cohorts[cohort]['variantId']
97
- if (typeof contentExperimentId !== 'undefined' &&
98
- typeof cohortVariantId !== 'undefined' &&
99
- typeof window.ga === 'function') {
100
- window.ga('set', 'expId', contentExperimentId)
101
- window.ga('set', 'expVar', cohortVariantId)
102
- };
103
- }
104
-
105
- MultivariateTest.prototype.createDummyEvent = function (cohort) {
106
- // Fire off a dummy event to set the custom var and the content experiment on the page.
107
- // Ideally we'd be able to call setCustomVar before trackPageview,
108
- // but would need reordering the existing GA code.
109
- GOVUK.analytics.trackEvent(this.cookieName(), 'run', {nonInteraction: true})
110
- }
111
-
112
- MultivariateTest.prototype.weightedCohortNames = function () {
113
- var names = []
114
- var defaultWeight = this.defaultWeight
115
-
116
- $.each(this.cohorts, function (key, cohortSettings) {
117
- var numberForCohort, i
118
-
119
- if (typeof cohortSettings.weight === 'undefined') {
120
- numberForCohort = defaultWeight
121
- } else {
122
- numberForCohort = cohortSettings.weight
123
- }
124
-
125
- for (i = 0; i < numberForCohort; i++) {
126
- names.push(key)
127
- }
128
- })
129
-
130
- return names
131
- }
132
-
133
- MultivariateTest.prototype.chooseRandomCohort = function () {
134
- var names = this.weightedCohortNames()
135
- return names[Math.floor(Math.random() * names.length)]
136
- }
137
-
138
- MultivariateTest.prototype.cookieName = function () {
139
- return 'multivariatetest_cohort_' + this.name
140
- }
141
-
142
- GOVUK.MultivariateTest = MultivariateTest
143
-
144
- global.GOVUK = GOVUK
145
- })(window)
@@ -1,262 +0,0 @@
1
- /* global describe it expect beforeEach afterEach jasmine spyOn */
2
-
3
- var $ = window.jQuery
4
-
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
26
- name: 'stuff',
27
- cohorts: {
28
- foo: {callback: fooSpy},
29
- bar: {callback: barSpy}
30
- }
31
- })
32
-
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()
39
- }
40
- })
41
-
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
47
- name: 'stuff',
48
- cohorts: {
49
- foo: {callback: fooSpy},
50
- bar: {callback: barSpy}
51
- }
52
- })
53
- expect(fooSpy).toHaveBeenCalled()
54
- })
55
-
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
59
- name: 'stuff',
60
- cohorts: {
61
- foo: {},
62
- bar: {}
63
- },
64
- customDimensionIndex: 2
65
- })
66
- expect(GOVUK.analytics.setDimension).toHaveBeenCalledWith(
67
- 2,
68
- 'multivariatetest_cohort_stuff__foo'
69
- )
70
- })
71
-
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
75
- name: 'stuff',
76
- cohorts: {
77
- foo: {},
78
- bar: {}
79
- },
80
- customDimensionIndex: [2, 3]
81
- })
82
- expect(GOVUK.analytics.setDimension).toHaveBeenCalledWith(
83
- 2,
84
- 'multivariatetest_cohort_stuff__foo'
85
- )
86
- expect(GOVUK.analytics.setDimension).toHaveBeenCalledWith(
87
- 3,
88
- 'multivariatetest_cohort_stuff__foo'
89
- )
90
- })
91
-
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
95
- name: 'stuff',
96
- cohorts: {
97
- foo: {},
98
- bar: {}
99
- }
100
- })
101
- expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
102
- 'multivariatetest_cohort_stuff',
103
- 'run',
104
- {nonInteraction: true}
105
- )
106
- })
107
-
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
112
- name: 'stuff',
113
- el: $el,
114
- cohorts: {
115
- foo: {html: 'foo'},
116
- bar: {html: 'bar'}
117
- }
118
- })
119
- expect($el.html()).toEqual('foo')
120
- })
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
128
- name: 'stuff',
129
- el: $el,
130
- cohorts: {
131
- foo: {callback: fooSpy},
132
- bar: {callback: barSpy}
133
- }
134
- })
135
- expect(barSpy).toHaveBeenCalled()
136
- })
137
-
138
- it('should call the callback for a cohort if it is a string', function () {
139
- GOVUK.cookie.and.returnValue('foo')
140
- var test = new GOVUK.MultivariateTest({
141
- name: 'stuff',
142
- cohorts: {
143
- foo: {callback: 'fooCallback'},
144
- bar: {}
145
- },
146
- runImmediately: false
147
- })
148
- test.fooCallback = jasmine.createSpy('fooCallback')
149
- test.run()
150
- expect(test.fooCallback).toHaveBeenCalled()
151
- })
152
-
153
- it("should assign 30 if cookieDuration isn't defined", function () {
154
- GOVUK.cookie.and.returnValue('foo')
155
- var test = new GOVUK.MultivariateTest({
156
- name: 'cookie_duration_test',
157
- cohorts: {
158
- foo: {callback: function () {}}
159
- }
160
- })
161
- expect(test.cookieDuration).toEqual(30)
162
- })
163
-
164
- it("should assign the user's cookie duration, when cookieDuration is defined", function () {
165
- GOVUK.cookie.and.returnValue('foo')
166
- var test = new GOVUK.MultivariateTest({
167
- name: 'cookie_duration_test',
168
- cookieDuration: 14,
169
- cohorts: {
170
- foo: {callback: function () {}}
171
- }
172
- })
173
- expect(test.cookieDuration).toEqual(14)
174
- })
175
-
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
181
- name: 'stuff',
182
- cohorts: {
183
- foo: {callback: fooSpy},
184
- bar: {callback: barSpy}
185
- }
186
- })
187
- if (GOVUK.cookie.calls.argsFor(1)[1] === 'foo') {
188
- expect(fooSpy).toHaveBeenCalled()
189
- } else {
190
- expect(barSpy).toHaveBeenCalled()
191
- }
192
- })
193
- })
194
-
195
- describe('#weightedCohortNames', function () {
196
- it('should return the weighted names of the cohorts when no weights are defined', function () {
197
- var test = new GOVUK.MultivariateTest({
198
- name: 'stuff',
199
- cohorts: {foo: {}, bar: {}, baz: {}}
200
- })
201
- expect(test.weightedCohortNames()).toEqual(['foo', 'bar', 'baz'])
202
- })
203
-
204
- it('should return the weighted names of the cohorts when weights are defined', function () {
205
- var test = new GOVUK.MultivariateTest({
206
- name: 'stuff',
207
- cohorts: {foo: { weight: 2 }, bar: { weight: 1 }, baz: { weight: 3 }}
208
- })
209
- expect(test.weightedCohortNames()).toEqual(['foo', 'foo', 'bar', 'baz', 'baz', 'baz'])
210
- })
211
-
212
- it('should return the weighted names of the cohorts using default weighting', function () {
213
- var test = new GOVUK.MultivariateTest({
214
- name: 'stuff',
215
- defaultWeight: 2,
216
- cohorts: {foo: {}, bar: {}, baz: {}}
217
- })
218
- expect(test.weightedCohortNames()).toEqual(['foo', 'foo', 'bar', 'bar', 'baz', 'baz'])
219
- })
220
-
221
- it('should return the weighted names of the cohorts using default weighting or defined weighting', function () {
222
- var test = new GOVUK.MultivariateTest({
223
- name: 'stuff',
224
- defaultWeight: 2,
225
- cohorts: {foo: {}, bar: { weight: 1 }, baz: {}}
226
- })
227
- expect(test.weightedCohortNames()).toEqual(['foo', 'foo', 'bar', 'baz', 'baz'])
228
- })
229
- })
230
-
231
- describe('#chooseRandomCohort', function () {
232
- it('should choose a random cohort', function () {
233
- var test = new GOVUK.MultivariateTest({
234
- name: 'stuff',
235
- cohorts: {foo: {}, bar: {}}
236
- })
237
- expect(['foo', 'bar']).toContain(test.chooseRandomCohort())
238
- })
239
- })
240
-
241
- describe('Google Content Experiment Integration', function () {
242
- beforeEach(function () {
243
- window.ga = function () {}
244
- spyOn(window, 'ga')
245
- })
246
-
247
- it('should report the experiment data to Google', function () {
248
- new GOVUK.MultivariateTest({ // eslint-disable-line no-new
249
- name: 'stuff',
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])
255
- expect(GOVUK.analytics.trackEvent).toHaveBeenCalledWith(
256
- 'multivariatetest_cohort_stuff',
257
- 'run',
258
- {nonInteraction: true}
259
- )
260
- })
261
- })
262
- })