govuk_frontend_toolkit 1.7.0 → 2.0.0

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.
@@ -2,7 +2,8 @@ describe("selection-buttons", function () {
2
2
  var $radioButtons,
3
3
  $radioLabels,
4
4
  $checkboxButtons,
5
- $checkboxLabels;
5
+ $checkboxLabels,
6
+ buttonsInstance;
6
7
 
7
8
  beforeEach(function () {
8
9
  $radioLabels = $(
@@ -35,309 +36,730 @@ describe("selection-buttons", function () {
35
36
  );
36
37
  $radioButtons = $radioLabels.find('input');
37
38
  $checkboxButtons = $checkboxLabels.find('input');
38
- $(document.body).append($radioLabels);
39
- $(document.body).append($checkboxLabels);
39
+ $radioForm = $('<form action="" method="post" />');
40
+ $checkboxForm = $('<form action="" method="post" />');
41
+ $content = $('<div id="content" />');
42
+ $radioForm.append($radioLabels);
43
+ $checkboxForm.append($checkboxLabels);
44
+ $content.append($radioForm);
45
+ $content.append($checkboxForm);
46
+ $(document.body).append($content);
40
47
  });
41
48
 
42
49
  afterEach(function () {
43
- $radioLabels.remove();
44
- $checkboxLabels.remove();
50
+ $content.remove();
45
51
  });
46
52
 
47
- describe("RadioButtons", function () {
48
- it("Should create a new instance with the correct interface", function () {
49
- var buttons = new GOVUK.RadioButtons($radioButtons);
53
+ describe("When buttonsInstance = new GOVUK.SelectionButtons is called with a jQuery object", function () {
54
+ describe("When that object contains only radio inputs", function () {
55
+ describe("At the point it is called", function () {
56
+ it("Should do nothing if no radios are checked", function () {
57
+ buttonsInstance = new GOVUK.SelectionButtons($radioButtons);
58
+ expect($radioLabels.eq(0).hasClass('selected')).toBe(false);
59
+ expect($radioLabels.eq(1).hasClass('selected')).toBe(false);
60
+ expect($radioLabels.eq(2).hasClass('selected')).toBe(false);
61
+ });
50
62
 
51
- expect(buttons.getSelections).toBeDefined();
52
- expect(buttons.bindEvents).toBeDefined();
53
- expect(buttons.markSelected).toBeDefined();
54
- expect(buttons.markFocused).toBeDefined();
55
- });
63
+ it("Should mark checked radios with the selected class", function () {
64
+ $radioButtons.eq(0).attr('checked', true);
65
+ buttonsInstance = new GOVUK.SelectionButtons($radioButtons);
66
+ expect($radioLabels.eq(0).hasClass('selected')).toBe(true);
67
+ });
56
68
 
57
- it("Should set the selectedClass property if sent in as an option", function () {
58
- var buttons = new GOVUK.RadioButtons($radioButtons, { 'selectedClass' : 'selectable-selected' });
69
+ it("Should mark checked radios with the custom selected class if given", function () {
70
+ $radioButtons.eq(0).attr('checked', true);
71
+ buttonsInstance = new GOVUK.SelectionButtons($radioButtons, { 'selectedClass' : 'selectable-selected' });
72
+ expect($radioLabels.eq(0).hasClass('selectable-selected')).toBe(true);
73
+ });
74
+ });
59
75
 
60
- expect(buttons.selectedClass).toEqual('selectable-selected');
61
- });
76
+ describe("If one of those radios receives focus", function () {
77
+ it("Should add the focused class to that radio", function () {
78
+ buttonsInstance = new GOVUK.SelectionButtons($radioButtons);
79
+ $radioButtons.eq(0).focus();
80
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(true);
81
+ });
62
82
 
63
- it("Should set the focusedClass property if sent in as an option", function () {
64
- var buttons = new GOVUK.RadioButtons($radioButtons, { 'focusedClass' : 'selectable-focused' });
83
+ it("Should add a custom focused class to that radio if specified as an option", function () {
84
+ buttonsInstance = new GOVUK.SelectionButtons($radioButtons, { 'focusedClass' : 'selectable-focused' });
85
+ $radioButtons.eq(0).focus();
86
+ expect($radioLabels.eq(0).hasClass('selectable-focused')).toBe(true);
87
+ });
88
+ });
65
89
 
66
- expect(buttons.focusedClass).toEqual('selectable-focused');
67
- });
90
+ describe("If one of those radios loses focus", function () {
91
+ it("Should remove the focused class from that radio", function () {
92
+ buttonsInstance = new GOVUK.SelectionButtons($radioButtons);
93
+ $radioButtons.eq(0).focus();
94
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(true);
95
+ $radioButtons.eq(0).blur();
96
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(false);
97
+ });
68
98
 
69
- describe("getSelections method", function () {
70
- it("Should mark the label of any checked radios as selected", function () {
71
- var radioButtonsMock = {
72
- 'markSelected' : GOVUK.RadioButtons.prototype.markSelected,
73
- '$elms' : $radioButtons,
74
- 'selectedClass' : 'selected'
75
- };
99
+ it("Should add a custom focused class to that radio if specified as an option", function () {
100
+ buttonsInstance = new GOVUK.SelectionButtons($radioButtons, { 'focusedClass' : 'selectable-focused' });
101
+ $radioButtons.eq(0).focus();
102
+ expect($radioLabels.eq(0).hasClass('selectable-focused')).toBe(true);
103
+ $radioButtons.eq(0).blur();
104
+ expect($radioLabels.eq(0).hasClass('selectable-focused')).toBe(false);
105
+ });
106
+ });
107
+
108
+ describe("If one of those radios is clicked", function () {
109
+ it("Should mark that radio with the selected class", function () {
110
+ buttonsInstance = new GOVUK.SelectionButtons($radioButtons);
111
+ $radioButtons.eq(0)
112
+ .attr('checked', true)
113
+ .trigger('click');
114
+ expect($radioLabels.eq(0).hasClass('selected')).toBe(true);
115
+ });
76
116
 
77
- $radioButtons.eq(0).attr('checked', true);
78
- spyOn(radioButtonsMock, 'markSelected').andCallThrough();
79
- GOVUK.RadioButtons.prototype.getSelections.call(radioButtonsMock);
80
- expect(radioButtonsMock.markSelected).toHaveBeenCalled();
81
- expect($radioButtons.eq(0).parent('label').hasClass('selected')).toBe(true);
117
+ it("Should remove the selected class from all other radios", function () {
118
+ buttonsInstance = new GOVUK.SelectionButtons($radioButtons);
119
+ $radioLabels.eq(1).addClass('selected');
120
+ $radioButtons.eq(0)
121
+ .attr('checked', true)
122
+ .trigger('click');
123
+ expect($radioLabels.eq(2).hasClass('selected')).toBe(false);
124
+ });
82
125
  });
83
126
  });
84
127
 
85
- describe("setEventNames method", function () {
86
- it("Should set the selectionEvents and focusEvents properties on the instance", function () {
87
- var radioButtonsMock = {};
128
+ describe("When that object contains only checkbox inputs", function () {
129
+ describe("At the point it is called", function () {
130
+ it("Should do nothing if no checkboxes are checked", function () {
131
+ buttonsInstance = new GOVUK.SelectionButtons($checkboxButtons);
132
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(false);
133
+ expect($checkboxLabels.eq(1).hasClass('selected')).toBe(false);
134
+ expect($checkboxLabels.eq(2).hasClass('selected')).toBe(false);
135
+ });
88
136
 
89
- GOVUK.RadioButtons.prototype.setEventNames.call(radioButtonsMock);
90
- expect(typeof radioButtonsMock.focusEvents !== 'undefined').toBe(true);
91
- expect(typeof radioButtonsMock.selectionEvents !== 'undefined').toBe(true);
137
+ it("Should mark checked checkboxes with the selected class", function () {
138
+ $checkboxButtons.eq(0).attr('checked', true);
139
+ buttonsInstance = new GOVUK.SelectionButtons($checkboxButtons);
140
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(true);
141
+ });
142
+
143
+ it("Should mark all checked checkboxes with the selected class if there are more than one", function () {
144
+ $checkboxButtons.eq(0).attr('checked', true);
145
+ $checkboxButtons.eq(1).attr('checked', true);
146
+ buttonsInstance = new GOVUK.SelectionButtons($checkboxButtons);
147
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(true);
148
+ expect($checkboxLabels.eq(1).hasClass('selected')).toBe(true);
149
+ });
150
+
151
+ it("Should mark checked checkboxes with the custom selected class if given", function () {
152
+ $checkboxButtons.eq(0).attr('checked', true);
153
+ buttonsInstance = new GOVUK.SelectionButtons($checkboxButtons, { 'selectedClass' : 'selectable-selected' });
154
+ expect($checkboxLabels.eq(0).hasClass('selectable-selected')).toBe(true);
155
+ });
92
156
  });
93
- });
94
157
 
95
- describe("bindEvents method", function () {
96
- it("Should bind click and change events to each radio", function () {
97
- var radioButtonsMock = {
98
- '$elms' : $radioButtons,
99
- 'selectionEvents' : 'click change',
100
- 'focusEvents' : 'focus blur',
101
- 'markSelected' : function () {},
102
- 'markFocused' : function () {}
103
- },
104
- eventsBound = false;
105
-
106
- spyOn($.fn, 'on').andCallFake(function (evt, func) {
107
- if (evt === 'click change') {
108
- eventsBound = true;
109
- }
110
- return $.fn;
111
- });
112
- expect($.fn.on.calls.length).toEqual(0);
113
- GOVUK.RadioButtons.prototype.bindEvents.call(radioButtonsMock);
114
- expect($.fn.on).toHaveBeenCalled();
115
- expect(eventsBound).toEqual(true);
116
- });
117
-
118
- it("Should call the markSelected method on any checked radio that's the target of an event", function () {
119
- var radioButtonsMock = {
120
- '$elms' : $radioButtons,
121
- 'selectionEvents' : 'click change',
122
- 'focusEvents' : 'focus blur',
123
- 'markSelected' : function () {},
124
- 'markFocused' : function () {}
125
- },
126
- eventsBound = false;
127
-
128
- spyOn($.fn, 'on').andCallFake(function (evt, func) {
129
- if (evt === 'click change') {
130
- callback = func;
131
- }
132
- return $.fn;
158
+ describe("If one of those checkboxes receives focus", function () {
159
+ it("Should add the focused class to that checkbox", function () {
160
+ buttonsInstance = new GOVUK.SelectionButtons($checkboxButtons);
161
+ $checkboxButtons.eq(0).focus();
162
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(true);
163
+ });
164
+
165
+ it("Should add a custom focused class to that checkbox if specified as an option", function () {
166
+ buttonsInstance = new GOVUK.SelectionButtons($checkboxButtons, { 'focusedClass' : 'selectable-focused' });
167
+ $checkboxButtons.eq(0).focus();
168
+ expect($checkboxLabels.eq(0).hasClass('selectable-focused')).toBe(true);
169
+ });
170
+ });
171
+
172
+ describe("If one of those checkboxes loses focus", function () {
173
+ it("Should add the focused class to that checkbox", function () {
174
+ buttonsInstance = new GOVUK.SelectionButtons($checkboxButtons);
175
+ $checkboxButtons.eq(0).focus();
176
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(true);
177
+ $checkboxButtons.eq(0).blur();
178
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(false);
179
+ });
180
+
181
+ it("Should add a custom focused class to that checkbox if specified as an option", function () {
182
+ buttonsInstance = new GOVUK.SelectionButtons($checkboxButtons, { 'focusedClass' : 'selectable-focused' });
183
+ $checkboxButtons.eq(0).focus();
184
+ expect($checkboxLabels.eq(0).hasClass('selectable-focused')).toBe(true);
185
+ $checkboxButtons.eq(0).blur();
186
+ expect($checkboxLabels.eq(0).hasClass('selectable-focused')).toBe(false);
187
+ });
188
+ });
189
+
190
+ describe("If one of those checkboxes is clicked", function () {
191
+ it("Should add the selected class to that checkbox", function () {
192
+ buttonsInstance = new GOVUK.SelectionButtons($checkboxButtons);
193
+ $checkboxButtons.eq(0)
194
+ .attr('checked', true)
195
+ .trigger('click');
196
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(true);
197
+ });
198
+
199
+ it("Should add the selected class to that checkbox", function () {
200
+ buttonsInstance = new GOVUK.SelectionButtons($checkboxButtons, { 'selectedClass' : 'selectable-selected' });
201
+ $checkboxButtons.eq(0)
202
+ .attr('checked', true)
203
+ .trigger('click');
204
+ expect($checkboxLabels.eq(0).hasClass('selectable-selected')).toBe(true);
133
205
  });
134
- spyOn(radioButtonsMock, 'markSelected');
135
- radioButtonsMock.$elms.eq(0).attr('checked', true);
136
- GOVUK.RadioButtons.prototype.bindEvents.call(radioButtonsMock);
137
- callback({ 'target' : radioButtonsMock.$elms[0] });
138
- expect(radioButtonsMock.markSelected).toHaveBeenCalled();
139
206
  });
140
207
  });
141
208
 
142
- describe("markSelected method", function () {
143
- it("Should add the selectedClass class to the label of the sent in radio", function () {
144
- var radioButtonsMock = {
145
- 'selections' : {
146
- 'size' : false
147
- },
148
- 'selectedClass' : 'selected'
149
- },
150
- $clickedRadio = $radioButtons.eq(0);
209
+ describe("When that object contains a mixture of checkbox and radio inputs", function () {
210
+ var $mixedButtons;
211
+
212
+ beforeEach(function () {
213
+ $mixedButtons = $checkboxButtons.add($radioButtons);
214
+ });
215
+
216
+ describe("At the point it is called", function () {
217
+ it("Should do nothing if no checkboxes or radios are checked", function () {
218
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons);
219
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(false);
220
+ expect($checkboxLabels.eq(1).hasClass('selected')).toBe(false);
221
+ expect($checkboxLabels.eq(2).hasClass('selected')).toBe(false);
222
+ expect($radioLabels.eq(0).hasClass('selected')).toBe(false);
223
+ expect($radioLabels.eq(1).hasClass('selected')).toBe(false);
224
+ expect($radioLabels.eq(2).hasClass('selected')).toBe(false);
225
+ });
226
+
227
+ it("Should mark checked checkboxes or radios with the selected class", function () {
228
+ $mixedButtons.eq(0).attr('checked', true);
229
+ $mixedButtons.eq(3).attr('checked', true);
230
+
231
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons);
232
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(true);
233
+ expect($radioLabels.eq(0).hasClass('selected')).toBe(true);
234
+ });
235
+
236
+ it("Should mark checked checkboxes or radios with the custom selected class if given", function () {
237
+ $mixedButtons.eq(0).attr('checked', true);
238
+ $mixedButtons.eq(3).attr('checked', true);
151
239
 
152
- GOVUK.RadioButtons.prototype.markSelected.call(radioButtonsMock, $clickedRadio);
153
- expect($clickedRadio.parent('label').hasClass('selected')).toEqual(true);
240
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons, { 'selectedClass' : 'selectable-selected' });
241
+ expect($checkboxLabels.eq(0).hasClass('selectable-selected')).toBe(true);
242
+ expect($radioLabels.eq(0).hasClass('selectable-selected')).toBe(true);
243
+ });
154
244
  });
155
245
 
156
- it("Should remove the selectedClass class from the label of the previously selected radio", function () {
157
- var radioButtonsMock = {
158
- 'selections' : {
159
- 'size' : $radioButtons.eq(1)
160
- },
161
- 'selectedClass' : 'selected'
162
- },
163
- $clickedRadio = $radioButtons.eq(0);
246
+ describe("If a checkbox in the set receives focus", function () {
247
+ it("Should add the focused class to that checkbox", function () {
248
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons);
249
+ $checkboxButtons.eq(0).focus();
250
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(true);
251
+ });
252
+
253
+ it("Should add a custom focused class to that checkbox if specified as an option", function () {
254
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons, { 'focusedClass' : 'selectable-focused' });
255
+ $checkboxButtons.eq(0).focus();
256
+ expect($checkboxLabels.eq(0).hasClass('selectable-focused')).toBe(true);
257
+ });
258
+ });
164
259
 
165
- $radioLabels.eq(1).addClass('selected');
166
- GOVUK.RadioButtons.prototype.markSelected.call(radioButtonsMock, $clickedRadio);
167
- expect($('#medium').parent('label').hasClass('selected')).toEqual(false);
260
+ describe("If a checkbox in the set loses focus", function () {
261
+ it("Should add the focused class to that checkbox", function () {
262
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons);
263
+ $checkboxButtons.eq(0).focus();
264
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(true);
265
+ $checkboxButtons.eq(0).blur();
266
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(false);
267
+ });
168
268
 
269
+ it("Should add a custom focused class to that checkbox if specified as an option", function () {
270
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons, { 'focusedClass' : 'selectable-focused' });
271
+ $checkboxButtons.eq(0).focus();
272
+ expect($checkboxLabels.eq(0).hasClass('selectable-focused')).toBe(true);
273
+ $checkboxButtons.eq(0).blur();
274
+ expect($checkboxLabels.eq(0).hasClass('selectable-focused')).toBe(false);
275
+ });
169
276
  });
170
- });
171
277
 
172
- describe("markFocused method", function () {
173
- var radioButtonsMock = {
174
- 'focused' : false,
175
- 'focusedClass' : 'focused'
176
- };
278
+ describe("If one of those checkboxes is clicked", function () {
279
+ it("Should add the selected class to that checkbox", function () {
280
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons);
281
+ $checkboxButtons.eq(0)
282
+ .attr('checked', true)
283
+ .trigger('click');
284
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(true);
285
+ });
177
286
 
178
- it("Should add the focusedClass class to the sent radio if it is focused", function () {
179
- GOVUK.RadioButtons.prototype.markFocused.apply(radioButtonsMock, [$radioButtons.eq(0), 'focused']);
287
+ it("Should add the selected class to that checkbox", function () {
288
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons, { 'selectedClass' : 'selectable-selected' });
289
+ $checkboxButtons.eq(0)
290
+ .attr('checked', true)
291
+ .trigger('click');
292
+ expect($checkboxLabels.eq(0).hasClass('selectable-selected')).toBe(true);
293
+ });
294
+ });
295
+
296
+ describe("If a radio in the set receives focus", function () {
297
+ it("Should add the focused class to that radio", function () {
298
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons);
299
+ $radioButtons.eq(0).focus();
300
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(true);
301
+ });
180
302
 
181
- expect($radioLabels.eq(0).hasClass(radioButtonsMock.focusedClass)).toBe(true);
303
+ it("Should add a custom focused class to that radio if specified as an option", function () {
304
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons, { 'focusedClass' : 'selectable-focused' });
305
+ $radioButtons.eq(0).focus();
306
+ expect($radioLabels.eq(0).hasClass('selectable-focused')).toBe(true);
307
+ });
308
+ });
309
+
310
+ describe("If a radio in the set loses focus", function () {
311
+ it("Should remove the focused class from that radio", function () {
312
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons);
313
+ $radioButtons.eq(0).focus();
314
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(true);
315
+ $radioButtons.eq(0).blur();
316
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(false);
317
+ });
318
+
319
+ it("Should add a custom focused class to that radio if specified as an option", function () {
320
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons, { 'focusedClass' : 'selectable-focused' });
321
+ $radioButtons.eq(0).focus();
322
+ expect($radioLabels.eq(0).hasClass('selectable-focused')).toBe(true);
323
+ $radioButtons.eq(0).blur();
324
+ expect($radioLabels.eq(0).hasClass('selectable-focused')).toBe(false);
325
+ });
182
326
  });
183
327
 
184
- it("Should remove the focusedClass class from the sent radio if it is blurred", function () {
185
- $radioLabels.eq(0).addClass(radioButtonsMock.focusedClass);
186
- GOVUK.RadioButtons.prototype.markFocused.apply(radioButtonsMock, [$radioButtons.eq(0), 'blurred']);
328
+ describe("If a radio in the set is clicked", function () {
329
+ it("Should mark that radio with the selected class", function () {
330
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons);
331
+ $radioButtons.eq(0)
332
+ .attr('checked', true)
333
+ .trigger('click');
334
+ expect($radioLabels.eq(0).hasClass('selected')).toBe(true);
335
+ });
187
336
 
188
- expect($radioLabels.eq(0).hasClass(radioButtonsMock.focusedClass)).toBe(false);
337
+ it("Should remove the selected class from all other radios", function () {
338
+ buttonsInstance = new GOVUK.SelectionButtons($mixedButtons);
339
+ $radioLabels.eq(1).addClass('selected');
340
+ $radioButtons.eq(0)
341
+ .attr('checked', true)
342
+ .trigger('click');
343
+ expect($radioLabels.eq(2).hasClass('selected')).toBe(false);
344
+ });
189
345
  });
190
346
  });
191
347
  });
192
348
 
193
- describe("CheckboxButtons", function () {
194
- it("Should create a new instance with the correct interface", function () {
195
- var buttons = new GOVUK.CheckboxButtons($checkboxButtons);
349
+ describe("When new GOVUK.SelectionButtons is called with a selector", function () {
350
+ describe("When that selector matches radio inputs", function () {
351
+ afterEach(function () {
352
+ buttonsInstance.destroy();
353
+ });
196
354
 
197
- expect(buttons.getSelections).toBeDefined();
198
- expect(buttons.bindEvents).toBeDefined();
199
- expect(buttons.markSelected).toBeDefined();
200
- expect(buttons.markFocused).toBeDefined();
201
- });
355
+ describe("At the point it is called", function () {
356
+ it("Should do nothing if no radios are checked", function () {
357
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']");
358
+ expect($radioLabels.eq(0).hasClass('selected')).toBe(false);
359
+ expect($radioLabels.eq(1).hasClass('selected')).toBe(false);
360
+ expect($radioLabels.eq(2).hasClass('selected')).toBe(false);
361
+ });
202
362
 
203
- describe("getSelections method", function () {
204
- it("Should add the selectedClass class to the label of a checkbox that is checked", function () {
205
- var checkboxButtonsMock = {
206
- '$elms' : $checkboxButtons,
207
- 'markSelected' : function () {}
208
- };
363
+ it("Should mark checked radios with the selected class", function () {
364
+ $radioButtons.eq(0).attr('checked', true);
365
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']");
366
+ expect($radioLabels.eq(0).hasClass('selected')).toBe(true);
367
+ });
209
368
 
210
- checkboxButtonsMock.$elms.eq(0).attr('checked', true);
211
- spyOn(checkboxButtonsMock, 'markSelected');
212
- GOVUK.CheckboxButtons.prototype.getSelections.call(checkboxButtonsMock);
213
- expect(checkboxButtonsMock.markSelected).toHaveBeenCalled();
369
+ it("Should mark checked radios with the custom selected class if given", function () {
370
+ $radioButtons.eq(0).attr('checked', true);
371
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']", { 'selectedClass' : 'selectable-selected' });
372
+ expect($radioLabels.eq(0).hasClass('selectable-selected')).toBe(true);
373
+ });
374
+ });
375
+
376
+ describe("If one of those radios receives focus", function () {
377
+ it("Should add the focused class to that radio", function () {
378
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']");
379
+ $radioButtons.eq(0).focus();
380
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(true);
381
+ });
382
+
383
+ it("Should add a custom focused class to that radio if specified as an option", function () {
384
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']", { 'focusedClass' : 'selectable-focused' });
385
+ $radioButtons.eq(0).focus();
386
+ expect($radioLabels.eq(0).hasClass('selectable-focused')).toBe(true);
387
+ });
214
388
  });
215
- });
216
389
 
217
- describe("setEventNames method", function () {
218
- it("Should set the selectionEvents and focusEvents properties on the instance", function () {
219
- var checkboxButtonsMock = {};
390
+ describe("If one of those radios loses focus", function () {
391
+ it("Should remove the focused class from that radio", function () {
392
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']");
393
+ $radioButtons.eq(0).focus();
394
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(true);
395
+ $radioButtons.eq(0).blur();
396
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(false);
397
+ });
398
+
399
+ it("Should add a custom focused class to that radio if specified as an option", function () {
400
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']", { 'focusedClass' : 'selectable-focused' });
401
+ $radioButtons.eq(0).focus();
402
+ expect($radioLabels.eq(0).hasClass('selectable-focused')).toBe(true);
403
+ $radioButtons.eq(0).blur();
404
+ expect($radioLabels.eq(0).hasClass('selectable-focused')).toBe(false);
405
+ });
406
+ });
407
+
408
+ describe("If one of those radios is clicked", function () {
409
+ it("Should mark that radio with the selected class", function () {
410
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']");
411
+ $radioButtons.eq(0)
412
+ .attr('checked', true)
413
+ .trigger('click');
414
+ expect($radioLabels.eq(0).hasClass('selected')).toBe(true);
415
+ });
220
416
 
221
- GOVUK.CheckboxButtons.prototype.setEventNames.call(checkboxButtonsMock);
222
- expect(typeof checkboxButtonsMock.focusEvents !== 'undefined').toBe(true);
223
- expect(typeof checkboxButtonsMock.selectionEvents !== 'undefined').toBe(true);
417
+ it("Should remove the selected class from all other radios", function () {
418
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']");
419
+ $radioLabels.eq(1).addClass('selected');
420
+ $radioButtons.eq(0)
421
+ .attr('checked', true)
422
+ .trigger('click');
423
+ expect($radioLabels.eq(2).hasClass('selected')).toBe(false);
424
+ });
224
425
  });
225
426
  });
226
427
 
227
- describe("bindEvents method", function () {
228
- var checkboxButtonsMock;
428
+ describe("When that selector matches checkbox inputs", function () {
429
+ afterEach(function () {
430
+ buttonsInstance.destroy();
431
+ });
229
432
 
230
- beforeEach(function () {
231
- checkboxButtonsMock = {
232
- '$elms' : $checkboxButtons
233
- };
234
- });
235
-
236
- it("Should add a click event to each checkbox that fires the markSelected method", function () {
237
- var eventCalled = false;
238
-
239
- checkboxButtonsMock.markSelected = function () {};
240
- checkboxButtonsMock.markFocused = function () {};
241
- checkboxButtonsMock.selectionEvents = 'click';
242
- checkboxButtonsMock.focusEvents = 'focus blur';
243
- spyOn(checkboxButtonsMock, 'markSelected');
244
- spyOn($.fn, 'on').andCallFake(function (evt, func) {
245
- if (evt === 'click') {
246
- eventCalled = true;
247
- callback = func;
248
- }
249
- return $.fn;
250
- });
251
- $checkboxButtons.eq(0).attr('checked', true);
252
- GOVUK.CheckboxButtons.prototype.bindEvents.call(checkboxButtonsMock);
253
- expect(eventCalled).toBe(true);
254
- callback({ 'target' : $checkboxButtons.eq(0) });
255
- expect(checkboxButtonsMock.markSelected).toHaveBeenCalled();
256
- });
257
-
258
- it("Should add focus and blur events to each checkbox that fires the markFocused method", function () {
259
- var eventCalled = false;
260
-
261
- checkboxButtonsMock.markFocused = function () {};
262
- checkboxButtonsMock.markSelected = function () {};
263
- checkboxButtonsMock.selectionEvents = 'click';
264
- checkboxButtonsMock.focusEvents = 'focus blur';
265
- spyOn(checkboxButtonsMock, 'markFocused');
266
- spyOn($.fn, 'on').andCallFake(function (evt, func) {
267
- if (evt === 'focus blur') {
268
- eventCalled = true;
269
- callback = func;
270
- }
271
- return $.fn;
433
+ describe("At the point it is called", function () {
434
+ it("Should do nothing if no checkboxes are checked", function () {
435
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']");
436
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(false);
437
+ expect($checkboxLabels.eq(1).hasClass('selected')).toBe(false);
438
+ expect($checkboxLabels.eq(2).hasClass('selected')).toBe(false);
439
+ });
440
+
441
+ it("Should mark checked checkboxes with the selected class", function () {
442
+ $checkboxButtons.eq(0).attr('checked', true);
443
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']");
444
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(true);
445
+ });
446
+
447
+ it("Should mark all checked checkboxes with the selected class if there are more than one", function () {
448
+ $checkboxButtons.eq(0).attr('checked', true);
449
+ $checkboxButtons.eq(1).attr('checked', true);
450
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']");
451
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(true);
452
+ expect($checkboxLabels.eq(1).hasClass('selected')).toBe(true);
272
453
  });
273
- GOVUK.CheckboxButtons.prototype.bindEvents.call(checkboxButtonsMock);
274
- expect(eventCalled).toBe(true);
275
- callback({
276
- 'target' : $checkboxButtons.eq(0),
277
- 'type' : 'focus'
454
+
455
+ it("Should mark checked checkboxes with the custom selected class if given", function () {
456
+ $checkboxButtons.eq(0).attr('checked', true);
457
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']", { 'selectedClass' : 'selectable-selected' });
458
+ expect($checkboxLabels.eq(0).hasClass('selectable-selected')).toBe(true);
459
+ });
460
+ });
461
+
462
+ describe("If one of those checkboxes receives focus", function () {
463
+ it("Should add the focused class to that checkbox", function () {
464
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']");
465
+ $checkboxButtons.eq(0).focus();
466
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(true);
467
+ });
468
+
469
+ it("Should add a custom focused class to that checkbox if specified as an option", function () {
470
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']", { 'focusedClass' : 'selectable-focused' });
471
+ $checkboxButtons.eq(0).focus();
472
+ expect($checkboxLabels.eq(0).hasClass('selectable-focused')).toBe(true);
473
+ });
474
+ });
475
+
476
+ describe("If one of those checkboxes loses focus", function () {
477
+ it("Should add the focused class to that checkbox", function () {
478
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']");
479
+ $checkboxButtons.eq(0).focus();
480
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(true);
481
+ $checkboxButtons.eq(0).blur();
482
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(false);
483
+ });
484
+
485
+ it("Should add a custom focused class to that checkbox if specified as an option", function () {
486
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']", { 'focusedClass' : 'selectable-focused' });
487
+ $checkboxButtons.eq(0).focus();
488
+ expect($checkboxLabels.eq(0).hasClass('selectable-focused')).toBe(true);
489
+ $checkboxButtons.eq(0).blur();
490
+ expect($checkboxLabels.eq(0).hasClass('selectable-focused')).toBe(false);
278
491
  });
279
- expect(checkboxButtonsMock.markFocused).toHaveBeenCalled();
280
492
  });
281
493
  });
282
494
 
283
- describe("markSelected method", function () {
284
- var checkboxButtonsMock = {
285
- 'selectedClass' : 'selected'
286
- };
495
+ describe("When that selector matches a mixture of checkbox and radio inputs", function () {
496
+ var $mixedButtons;
287
497
 
288
- it("Should add the selectedClass class to a checked checkbox", function () {
289
- $checkboxButtons.eq(0).attr('checked', true);
290
- GOVUK.CheckboxButtons.prototype.markSelected.call(checkboxButtonsMock, $checkboxButtons.eq(0));
291
- expect($checkboxLabels.eq(0).hasClass(checkboxButtonsMock.selectedClass)).toBe(true);
498
+ beforeEach(function () {
499
+ $mixedButtons = $checkboxButtons.add($radioButtons);
292
500
  });
293
501
 
294
- it("Should remove the selectedClass class from an unchecked checkbox", function () {
295
- $checkboxButtons.eq(0).addClass(checkboxButtonsMock.selectedClass);
296
- GOVUK.CheckboxButtons.prototype.markSelected.call(checkboxButtonsMock, $checkboxButtons.eq(0));
297
- expect($checkboxLabels.eq(0).hasClass(checkboxButtonsMock.selectedClass)).toBe(false);
502
+ afterEach(function () {
503
+ buttonsInstance.destroy();
504
+ });
505
+
506
+ it("Should do nothing if no checkboxes or radios are checked", function () {
507
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input");
508
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(false);
509
+ expect($checkboxLabels.eq(1).hasClass('selected')).toBe(false);
510
+ expect($checkboxLabels.eq(2).hasClass('selected')).toBe(false);
511
+ expect($radioLabels.eq(0).hasClass('selected')).toBe(false);
512
+ expect($radioLabels.eq(1).hasClass('selected')).toBe(false);
513
+ expect($radioLabels.eq(2).hasClass('selected')).toBe(false);
514
+ });
515
+
516
+ it("Should mark checked checkboxes or radios with the selected class", function () {
517
+ $mixedButtons.eq(0).attr('checked', true);
518
+ $mixedButtons.eq(3).attr('checked', true);
519
+
520
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input");
521
+ expect($checkboxLabels.eq(0).hasClass('selected')).toBe(true);
522
+ expect($radioLabels.eq(0).hasClass('selected')).toBe(true);
523
+ });
524
+
525
+ it("Should mark checked checkboxes or radios with the custom selected class if given", function () {
526
+ $mixedButtons.eq(0).attr('checked', true);
527
+ $mixedButtons.eq(3).attr('checked', true);
528
+
529
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input", { 'selectedClass' : 'selectable-selected' });
530
+ expect($checkboxLabels.eq(0).hasClass('selectable-selected')).toBe(true);
531
+ expect($radioLabels.eq(0).hasClass('selectable-selected')).toBe(true);
298
532
  });
299
533
  });
534
+ });
535
+
536
+ describe("When GOVUK.SelectionButtons is called with a selector and then the page content is replaced", function () {
537
+ describe("When that selector matches radio inputs", function () {
538
+ describe("If one of those radios is clicked", function () {
539
+ afterEach(function () {
540
+ buttonsInstance.destroy();
541
+ });
542
+
543
+ it("Should mark that radio with the selected class", function () {
544
+ var contentCache;
545
+
546
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']");
547
+ contentCache = $('#content').html();
548
+ $('#content').html('');
549
+ $('#content').html(contentCache);
550
+ $("label.selectable input[type='radio']").eq(0)
551
+ .attr('checked', true)
552
+ .trigger('click');
553
+ expect($("label.selectable input[type='radio']").eq(0).parent('label').hasClass('selected')).toBe(true);
554
+ });
555
+
556
+ it("Should remove the selected class from all other radios", function () {
557
+ var contentCache;
558
+
559
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']");
560
+ contentCache = $('#content').html();
561
+ $('#content').html('');
562
+ $('#content').html(contentCache);
563
+ $radioButtons = $("label.selectable input[type='radio']");
564
+ $radioLabels = $radioButtons.parent('label');
565
+ $radioLabels.eq(1).addClass('selected');
566
+ $radioButtons.eq(0)
567
+ .attr('checked', true)
568
+ .trigger('click');
569
+ expect($radioLabels.eq(2).hasClass('selected')).toBe(false);
570
+ });
571
+ });
572
+
573
+ describe("If one of those radios is focused", function () {
574
+ afterEach(function () {
575
+ buttonsInstance.destroy();
576
+ });
300
577
 
301
- describe("markFocused method", function () {
302
- var checkboxButtonsMock = {
303
- 'focused' : false,
304
- 'focusedClass' : 'focused'
305
- };
578
+ it("Should add the focused class to the radio", function () {
579
+ var contentCache;
580
+
581
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']");
582
+ contentCache = $('#content').html();
583
+ $('#content').html('');
584
+ $('#content').html(contentCache);
585
+ $radioButtons = $("label.selectable input[type='radio']");
586
+ $radioLabels = $radioButtons.parent('label');
587
+ $radioButtons.eq(0).focus();
588
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(true)
589
+ });
306
590
 
307
- it("Should add the focusedClass class to the sent radio if it is focused", function () {
308
- GOVUK.CheckboxButtons.prototype.markFocused.apply(checkboxButtonsMock, [$checkboxButtons.eq(0), 'focused']);
591
+ it("Should add a custom focused class to the radio if sent in as an option", function () {
592
+ var contentCache;
593
+
594
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']", { 'focusedClass' : 'selectable-focused' });
595
+ contentCache = $('#content').html();
596
+ $('#content').html('');
597
+ $('#content').html(contentCache);
598
+ $radioButtons = $("label.selectable input[type='radio']");
599
+ $radioLabels = $radioButtons.parent('label');
600
+ $radioButtons.eq(0).focus();
601
+ expect($radioLabels.eq(0).hasClass('selectable-focused')).toBe(true)
602
+ });
309
603
 
310
- expect($checkboxLabels.eq(0).hasClass(checkboxButtonsMock.focusedClass)).toBe(true);
604
+ it("Should remove the focused class from a radio when it loses focus", function () {
605
+ var contentCache;
606
+
607
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='radio']");
608
+ contentCache = $('#content').html();
609
+ $('#content').html('');
610
+ $('#content').html(contentCache);
611
+ $radioButtons = $("label.selectable input[type='radio']");
612
+ $radioLabels = $radioButtons.parent('label');
613
+ $radioButtons.eq(0).focus();
614
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(true)
615
+ $radioButtons.eq(0).blur();
616
+ expect($radioLabels.eq(0).hasClass('focused')).toBe(false)
617
+ });
311
618
  });
619
+ });
312
620
 
313
- it("Should remove the focusedClass class from the sent radio if it is blurred", function () {
314
- $checkboxLabels.eq(0).addClass(checkboxButtonsMock.focusedClass);
315
- GOVUK.CheckboxButtons.prototype.markFocused.apply(checkboxButtonsMock, [$checkboxButtons.eq(0), 'blurred']);
621
+ describe("When that selector matches checkbox inputs", function () {
622
+ describe("If one of those checkboxes is clicked", function () {
623
+ afterEach(function () {
624
+ buttonsInstance.destroy();
625
+ });
316
626
 
317
- expect($checkboxLabels.eq(0).hasClass(checkboxButtonsMock.focusedClass)).toBe(false);
627
+ it("Should add the selected class to the checkbox", function () {
628
+ var contentCache;
629
+
630
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']");
631
+ contentCache = $('#content').html();
632
+ $('#content').html('');
633
+ $('#content').html(contentCache);
634
+ $("label.selectable input[type='checkbox']").eq(0)
635
+ .attr('checked', true)
636
+ .trigger('click');
637
+ expect($("label.selectable input[type='checkbox']").eq(0).parent('label').hasClass('selected')).toBe(true);
638
+ });
639
+ });
640
+
641
+ describe("If one of those checkboxes is focused", function () {
642
+ afterEach(function () {
643
+ buttonsInstance.destroy();
644
+ });
645
+
646
+ it("Should add the focused class to the checkbox", function () {
647
+ var contentCache;
648
+
649
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']");
650
+ contentCache = $('#content').html();
651
+ $('#content').html('');
652
+ $('#content').html(contentCache);
653
+ $checkboxButtons = $("label.selectable input[type='checkbox']");
654
+ $checkboxLabels = $checkboxButtons.parent('label');
655
+ $checkboxButtons.eq(0).focus();
656
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(true);
657
+ });
658
+
659
+ it("Should add a custom focused class to the checkbox if sent in as an option", function () {
660
+ var contentCache;
661
+
662
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']", { 'focusedClass' : 'selectable-focused' });
663
+ contentCache = $('#content').html();
664
+ $('#content').html('');
665
+ $('#content').html(contentCache);
666
+ $checkboxButtons = $("label.selectable input[type='checkbox']");
667
+ $checkboxLabels = $checkboxButtons.parent('label');
668
+ $checkboxButtons.eq(0).focus();
669
+ expect($checkboxLabels.eq(0).hasClass('selectable-focused')).toBe(true);
670
+ });
671
+
672
+ it("Should remove the focused class from the checkbox when it loses focus", function () {
673
+ var contentCache;
674
+
675
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']");
676
+ contentCache = $('#content').html();
677
+ $('#content').html('');
678
+ $('#content').html(contentCache);
679
+ $checkboxButtons = $("label.selectable input[type='checkbox']");
680
+ $checkboxLabels = $checkboxButtons.parent('label');
681
+ $checkboxButtons.eq(0).focus();
682
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(true);
683
+ $checkboxButtons.eq(0).blur();
684
+ expect($checkboxLabels.eq(0).hasClass('focused')).toBe(false);
685
+ });
318
686
  });
319
687
  });
320
688
  });
321
689
 
322
- describe("selectionButtons", function () {
323
- it("Should create an instance of RadioButtons for a set of radios", function () {
324
- spyOn(GOVUK, 'RadioButtons');
325
- GOVUK.selectionButtons($radioButtons);
326
- expect(GOVUK.RadioButtons).toHaveBeenCalled();
327
- });
328
-
329
- it("Should create an instance of CheckboxButtons for a set of checkboxes", function () {
330
- spyOn(GOVUK, 'CheckboxButtons');
331
- GOVUK.selectionButtons($checkboxButtons);
332
- expect(GOVUK.CheckboxButtons).toHaveBeenCalled();
333
- });
334
-
335
- it("Should create instances of RadioButtons and CheckboxButtons for a set containing radios and checkboxes", function () {
336
- spyOn(GOVUK, 'RadioButtons');
337
- spyOn(GOVUK, 'CheckboxButtons');
338
- GOVUK.selectionButtons($checkboxButtons.add($radioButtons));
339
- expect(GOVUK.RadioButtons).toHaveBeenCalled();
340
- expect(GOVUK.CheckboxButtons).toHaveBeenCalled();
341
- });
690
+ describe("GOVUK.SelectionButtons.prototype.destroy", function () {
691
+ it("Should remove the events bound to the jQuery-wrapped elements sent into GOVUK.SelectionButtons", function () {
692
+ var clickCallbackBound = false,
693
+ focusBlurCallbackBound = false,
694
+ clickCallbackCancelled = false,
695
+ focusBlurCallbackCancelled = false;
696
+
697
+ spyOn($.fn, "on").andCallFake(function (evt, callback) {
698
+ if (this === $radioButtons) {
699
+ if (evt === "click") {
700
+ clickCallbackBound = callback;
701
+ }
702
+ if (evt === "focus blur") {
703
+ focusBlurCallbackBound = callback;
704
+ }
705
+ }
706
+ return this;
707
+ });
708
+
709
+ spyOn($.fn, "off").andCallFake(function (evt, callback) {
710
+ if (this === $radioButtons) {
711
+ if (evt === "click") {
712
+ clickCallbackCancelled = callback;
713
+ }
714
+ if (evt === "focus blur") {
715
+ focusBlurCallbackCancelled = callback;
716
+ }
717
+ }
718
+ return this;
719
+ });
720
+ buttonsInstance = new GOVUK.SelectionButtons($radioButtons);
721
+ expect(clickCallbackBound).not.toBe(false);
722
+ expect(focusBlurCallbackBound).not.toBe(false);
723
+ buttonsInstance.destroy();
724
+ expect(clickCallbackCancelled).toEqual(clickCallbackBound);
725
+ expect(focusBlurCallbackCancelled).toEqual(focusBlurCallbackBound);
726
+ });
727
+
728
+ it("Should remove the events bound to the document for the selector was sent into GOVUK.SelectionButtons", function () {
729
+ var clickCallbackBound = false,
730
+ focusBlurCallbackBound = false,
731
+ clickCallbackCancelled = false,
732
+ focusBlurCallbackCancelled = false;
733
+
734
+ spyOn($.fn, "on").andCallFake(function (evt, selector, callback) {
735
+ if ((this[0] === document) && (selector === "label.selectable input[type='checkbox']")) {
736
+ if (evt === "click") {
737
+ clickCallbackBound = callback;
738
+ }
739
+ if (evt === "focus blur") {
740
+ focusBlurCallbackBound = callback;
741
+ }
742
+ }
743
+ return this;
744
+ });
745
+
746
+ spyOn($.fn, "off").andCallFake(function (evt, selector, callback) {
747
+ if ((this[0] === document) && (selector === "label.selectable input[type='checkbox']")) {
748
+ if (evt === "click") {
749
+ clickCallbackCancelled = callback;
750
+ }
751
+ if (evt === "focus blur") {
752
+ focusBlurCallbackCancelled = callback;
753
+ }
754
+ }
755
+ return this;
756
+ });
757
+ buttonsInstance = new GOVUK.SelectionButtons("label.selectable input[type='checkbox']");
758
+ expect(clickCallbackBound).not.toBe(false);
759
+ expect(focusBlurCallbackBound).not.toBe(false);
760
+ buttonsInstance.destroy();
761
+ expect(clickCallbackCancelled).toEqual(clickCallbackBound);
762
+ expect(focusBlurCallbackCancelled).toEqual(focusBlurCallbackBound);
763
+ });
342
764
  });
343
765
  });