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