idsk_frontend_toolkit 7.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (227) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.gitmodules +3 -0
  4. data/.ruby-version +1 -0
  5. data/.travis/govuk_frontend_toolkit_gem_push.enc +0 -0
  6. data/.travis/govuk_frontend_toolkit_gem_push.pub +1 -0
  7. data/.travis.yml +23 -0
  8. data/CONTRIBUTING.md +13 -0
  9. data/Gemfile +3 -0
  10. data/LICENCE +20 -0
  11. data/README.md +61 -0
  12. data/Rakefile +10 -0
  13. data/app/assets/.gitignore +5 -0
  14. data/app/assets/.ruby-version +1 -0
  15. data/app/assets/.travis/README.md +23 -0
  16. data/app/assets/.travis/govuk_frontend_toolkit_push.enc +0 -0
  17. data/app/assets/.travis/govuk_frontend_toolkit_push.pub +1 -0
  18. data/app/assets/.travis.yml +18 -0
  19. data/app/assets/CHANGELOG.md +381 -0
  20. data/app/assets/CONTRIBUTING.md +23 -0
  21. data/app/assets/Gemfile +4 -0
  22. data/app/assets/Gemfile.lock +48 -0
  23. data/app/assets/Gruntfile.js +68 -0
  24. data/app/assets/LICENCE +20 -0
  25. data/app/assets/README.md +170 -0
  26. data/app/assets/VERSION.txt +1 -0
  27. data/app/assets/create-release.sh +38 -0
  28. data/app/assets/docs/analytics.md +270 -0
  29. data/app/assets/docs/functions.md +62 -0
  30. data/app/assets/docs/javascript.md +337 -0
  31. data/app/assets/docs/mixins.md +617 -0
  32. data/app/assets/images/accordion-arrow-2x.png +0 -0
  33. data/app/assets/images/accordion-arrow.png +0 -0
  34. data/app/assets/images/arrow-sprite.png +0 -0
  35. data/app/assets/images/crests/bis_crest_13px.png +0 -0
  36. data/app/assets/images/crests/bis_crest_13px_x2.png +0 -0
  37. data/app/assets/images/crests/bis_crest_18px.png +0 -0
  38. data/app/assets/images/crests/bis_crest_18px_x2.png +0 -0
  39. data/app/assets/images/crests/bis_crest_27px.png +0 -0
  40. data/app/assets/images/crests/bis_crest_27px_x2.png +0 -0
  41. data/app/assets/images/crests/coastguard_13px.png +0 -0
  42. data/app/assets/images/crests/coastguard_13px_x2.png +0 -0
  43. data/app/assets/images/crests/coastguard_18px.png +0 -0
  44. data/app/assets/images/crests/coastguard_18px_x2.png +0 -0
  45. data/app/assets/images/crests/coastguard_27px.png +0 -0
  46. data/app/assets/images/crests/coastguard_27px_x2.png +0 -0
  47. data/app/assets/images/crests/dit_crest_13px.png +0 -0
  48. data/app/assets/images/crests/dit_crest_13px_x2.png +0 -0
  49. data/app/assets/images/crests/dit_crest_18px.png +0 -0
  50. data/app/assets/images/crests/dit_crest_18px_x2.png +0 -0
  51. data/app/assets/images/crests/dit_crest_27px.png +0 -0
  52. data/app/assets/images/crests/dit_crest_27px_x2.png +0 -0
  53. data/app/assets/images/crests/hmrc_crest_13px.png +0 -0
  54. data/app/assets/images/crests/hmrc_crest_13px_x2.png +0 -0
  55. data/app/assets/images/crests/hmrc_crest_18px.png +0 -0
  56. data/app/assets/images/crests/hmrc_crest_18px_x2.png +0 -0
  57. data/app/assets/images/crests/hmrc_crest_27px.png +0 -0
  58. data/app/assets/images/crests/hmrc_crest_27px_x2.png +0 -0
  59. data/app/assets/images/crests/ho_crest_13px.png +0 -0
  60. data/app/assets/images/crests/ho_crest_13px_x2.png +0 -0
  61. data/app/assets/images/crests/ho_crest_18px.png +0 -0
  62. data/app/assets/images/crests/ho_crest_18px_x2.png +0 -0
  63. data/app/assets/images/crests/ho_crest_27px.png +0 -0
  64. data/app/assets/images/crests/ho_crest_27px_x2.png +0 -0
  65. data/app/assets/images/crests/mod_crest_13px.png +0 -0
  66. data/app/assets/images/crests/mod_crest_13px_x2.png +0 -0
  67. data/app/assets/images/crests/mod_crest_18px.png +0 -0
  68. data/app/assets/images/crests/mod_crest_18px_x2.png +0 -0
  69. data/app/assets/images/crests/mod_crest_27px.png +0 -0
  70. data/app/assets/images/crests/mod_crest_27px_x2.png +0 -0
  71. data/app/assets/images/crests/org_crest_13px.png +0 -0
  72. data/app/assets/images/crests/org_crest_13px_x2.png +0 -0
  73. data/app/assets/images/crests/org_crest_18px.png +0 -0
  74. data/app/assets/images/crests/org_crest_18px_x2.png +0 -0
  75. data/app/assets/images/crests/org_crest_27px.png +0 -0
  76. data/app/assets/images/crests/org_crest_27px_x2.png +0 -0
  77. data/app/assets/images/crests/portcullis_13px.png +0 -0
  78. data/app/assets/images/crests/portcullis_13px_x2.png +0 -0
  79. data/app/assets/images/crests/portcullis_18px.png +0 -0
  80. data/app/assets/images/crests/portcullis_18px_x2.png +0 -0
  81. data/app/assets/images/crests/portcullis_27px.png +0 -0
  82. data/app/assets/images/crests/portcullis_27px_x2.png +0 -0
  83. data/app/assets/images/crests/so_crest_13px.png +0 -0
  84. data/app/assets/images/crests/so_crest_13px_x2.png +0 -0
  85. data/app/assets/images/crests/so_crest_18px.png +0 -0
  86. data/app/assets/images/crests/so_crest_18px_x2.png +0 -0
  87. data/app/assets/images/crests/so_crest_27px.png +0 -0
  88. data/app/assets/images/crests/so_crest_27px_x2.png +0 -0
  89. data/app/assets/images/crests/ukaea_crest_13px.png +0 -0
  90. data/app/assets/images/crests/ukaea_crest_13px_x2.png +0 -0
  91. data/app/assets/images/crests/ukaea_crest_18px.png +0 -0
  92. data/app/assets/images/crests/ukaea_crest_18px_x2.png +0 -0
  93. data/app/assets/images/crests/ukaea_crest_27px.png +0 -0
  94. data/app/assets/images/crests/ukaea_crest_27px_x2.png +0 -0
  95. data/app/assets/images/crests/ukho_13px.png +0 -0
  96. data/app/assets/images/crests/ukho_13px_x2.png +0 -0
  97. data/app/assets/images/crests/ukho_18px.png +0 -0
  98. data/app/assets/images/crests/ukho_18px_x2.png +0 -0
  99. data/app/assets/images/crests/ukho_27px.png +0 -0
  100. data/app/assets/images/crests/ukho_27px_x2.png +0 -0
  101. data/app/assets/images/crests/wales_crest_13px.png +0 -0
  102. data/app/assets/images/crests/wales_crest_13px_x2.png +0 -0
  103. data/app/assets/images/crests/wales_crest_18px.png +0 -0
  104. data/app/assets/images/crests/wales_crest_18px_x2.png +0 -0
  105. data/app/assets/images/crests/wales_crest_27px.png +0 -0
  106. data/app/assets/images/crests/wales_crest_27px_x2.png +0 -0
  107. data/app/assets/images/icon-arrow-left.png +0 -0
  108. data/app/assets/images/icon-calendar-2x.png +0 -0
  109. data/app/assets/images/icon-calendar.png +0 -0
  110. data/app/assets/images/icon-file-download-2x.png +0 -0
  111. data/app/assets/images/icon-file-download.png +0 -0
  112. data/app/assets/images/icon-important-2x.png +0 -0
  113. data/app/assets/images/icon-important.png +0 -0
  114. data/app/assets/images/icon-information-2x.png +0 -0
  115. data/app/assets/images/icon-information.png +0 -0
  116. data/app/assets/images/icon-locator-2x.png +0 -0
  117. data/app/assets/images/icon-locator.png +0 -0
  118. data/app/assets/images/icon-pointer-2x.png +0 -0
  119. data/app/assets/images/icon-pointer-black-2x.png +0 -0
  120. data/app/assets/images/icon-pointer-black.png +0 -0
  121. data/app/assets/images/icon-pointer-indexed.png +0 -0
  122. data/app/assets/images/icon-pointer.png +0 -0
  123. data/app/assets/images/icon-search-2x.png +0 -0
  124. data/app/assets/images/icon-search.png +0 -0
  125. data/app/assets/images/icon-steps/icon-step-1-2x.png +0 -0
  126. data/app/assets/images/icon-steps/icon-step-1.png +0 -0
  127. data/app/assets/images/icon-steps/icon-step-10-2x.png +0 -0
  128. data/app/assets/images/icon-steps/icon-step-10.png +0 -0
  129. data/app/assets/images/icon-steps/icon-step-11-2x.png +0 -0
  130. data/app/assets/images/icon-steps/icon-step-11.png +0 -0
  131. data/app/assets/images/icon-steps/icon-step-12-2x.png +0 -0
  132. data/app/assets/images/icon-steps/icon-step-12.png +0 -0
  133. data/app/assets/images/icon-steps/icon-step-13-2x.png +0 -0
  134. data/app/assets/images/icon-steps/icon-step-13.png +0 -0
  135. data/app/assets/images/icon-steps/icon-step-14-2x.png +0 -0
  136. data/app/assets/images/icon-steps/icon-step-14.png +0 -0
  137. data/app/assets/images/icon-steps/icon-step-2-2x.png +0 -0
  138. data/app/assets/images/icon-steps/icon-step-2.png +0 -0
  139. data/app/assets/images/icon-steps/icon-step-3-2x.png +0 -0
  140. data/app/assets/images/icon-steps/icon-step-3.png +0 -0
  141. data/app/assets/images/icon-steps/icon-step-4-2x.png +0 -0
  142. data/app/assets/images/icon-steps/icon-step-4.png +0 -0
  143. data/app/assets/images/icon-steps/icon-step-5-2x.png +0 -0
  144. data/app/assets/images/icon-steps/icon-step-5.png +0 -0
  145. data/app/assets/images/icon-steps/icon-step-6-2x.png +0 -0
  146. data/app/assets/images/icon-steps/icon-step-6.png +0 -0
  147. data/app/assets/images/icon-steps/icon-step-7-2x.png +0 -0
  148. data/app/assets/images/icon-steps/icon-step-7.png +0 -0
  149. data/app/assets/images/icon-steps/icon-step-8-2x.png +0 -0
  150. data/app/assets/images/icon-steps/icon-step-8.png +0 -0
  151. data/app/assets/images/icon-steps/icon-step-9-2x.png +0 -0
  152. data/app/assets/images/icon-steps/icon-step-9.png +0 -0
  153. data/app/assets/images/player-icon-forward.png +0 -0
  154. data/app/assets/images/player-icon-pause.png +0 -0
  155. data/app/assets/images/player-icon-play.png +0 -0
  156. data/app/assets/images/player-icon-rewind.png +0 -0
  157. data/app/assets/images/player-icon-volume.png +0 -0
  158. data/app/assets/images/separator-2x.png +0 -0
  159. data/app/assets/images/separator.png +0 -0
  160. data/app/assets/javascripts/govuk/analytics/analytics.js +143 -0
  161. data/app/assets/javascripts/govuk/analytics/download-link-tracker.js +41 -0
  162. data/app/assets/javascripts/govuk/analytics/error-tracking.js +51 -0
  163. data/app/assets/javascripts/govuk/analytics/external-link-tracker.js +56 -0
  164. data/app/assets/javascripts/govuk/analytics/google-analytics-universal-tracker.js +166 -0
  165. data/app/assets/javascripts/govuk/analytics/govuk-tracker.js +134 -0
  166. data/app/assets/javascripts/govuk/analytics/mailto-link-tracker.js +38 -0
  167. data/app/assets/javascripts/govuk/analytics/print-intent.js +39 -0
  168. data/app/assets/javascripts/govuk/details.polyfill.js +240 -0
  169. data/app/assets/javascripts/govuk/modules/auto-track-event.js +30 -0
  170. data/app/assets/javascripts/govuk/modules.js +61 -0
  171. data/app/assets/javascripts/govuk/primary-links.js +57 -0
  172. data/app/assets/javascripts/govuk/selection-buttons.js +116 -0
  173. data/app/assets/javascripts/govuk/shim-links-with-button-role.js +34 -0
  174. data/app/assets/javascripts/govuk/show-hide-content.js +172 -0
  175. data/app/assets/javascripts/govuk/stick-at-top-when-scrolling.js +128 -0
  176. data/app/assets/javascripts/govuk/stop-scrolling-at-footer.js +139 -0
  177. data/app/assets/javascripts/govuk_toolkit.js +1 -0
  178. data/app/assets/javascripts/stageprompt.js +69 -0
  179. data/app/assets/javascripts/vendor/jquery/jquery.player.min.js +25 -0
  180. data/app/assets/javascripts/vendor/polyfills/bind.js +40 -0
  181. data/app/assets/package.json +25 -0
  182. data/app/assets/spec/manifest.js +41 -0
  183. data/app/assets/spec/stylesheets/_colour_contrast_spec.scss +12 -0
  184. data/app/assets/spec/support/LocalTestRunner.html +21 -0
  185. data/app/assets/spec/support/console-runner.js +102 -0
  186. data/app/assets/spec/support/load.js +47 -0
  187. data/app/assets/spec/support/run_jasmine_test.js +62 -0
  188. data/app/assets/spec/unit/analytics/analytics.spec.js +315 -0
  189. data/app/assets/spec/unit/analytics/download-link-tracker.spec.js +72 -0
  190. data/app/assets/spec/unit/analytics/error-tracking.spec.js +65 -0
  191. data/app/assets/spec/unit/analytics/external-link-tracker.spec.js +109 -0
  192. data/app/assets/spec/unit/analytics/google-analytics-universal-tracker.spec.js +180 -0
  193. data/app/assets/spec/unit/analytics/govuk-tracker.spec.js +171 -0
  194. data/app/assets/spec/unit/analytics/mailto-link-tracker.spec.js +62 -0
  195. data/app/assets/spec/unit/details.polyfill.spec.js +91 -0
  196. data/app/assets/spec/unit/modules/auto-track-event.spec.js +54 -0
  197. data/app/assets/spec/unit/modules.spec.js +93 -0
  198. data/app/assets/spec/unit/primary-links.spec.js +55 -0
  199. data/app/assets/spec/unit/selection-button.spec.js +761 -0
  200. data/app/assets/spec/unit/shim-links-with-button-role.spec.js +41 -0
  201. data/app/assets/spec/unit/show-hide-content.spec.js +306 -0
  202. data/app/assets/spec/unit/stick-at-top-when-scrolling.spec.js +137 -0
  203. data/app/assets/stylesheets/.gitkeep +0 -0
  204. data/app/assets/stylesheets/_colours.scss +2 -0
  205. data/app/assets/stylesheets/_conditionals.scss +81 -0
  206. data/app/assets/stylesheets/_css3.scss +90 -0
  207. data/app/assets/stylesheets/_device-pixels.scss +10 -0
  208. data/app/assets/stylesheets/_font_stack.scss +25 -0
  209. data/app/assets/stylesheets/_grid_layout.scss +136 -0
  210. data/app/assets/stylesheets/_helpers.scss +16 -0
  211. data/app/assets/stylesheets/_measurements.scss +14 -0
  212. data/app/assets/stylesheets/_shims.scss +55 -0
  213. data/app/assets/stylesheets/_typography.scss +249 -0
  214. data/app/assets/stylesheets/_url-helpers.scss +16 -0
  215. data/app/assets/stylesheets/colours/_organisation.scss +104 -0
  216. data/app/assets/stylesheets/colours/_palette.scss +77 -0
  217. data/app/assets/stylesheets/design-patterns/_alpha-beta.scss +67 -0
  218. data/app/assets/stylesheets/design-patterns/_breadcrumbs.scss +53 -0
  219. data/app/assets/stylesheets/design-patterns/_buttons.scss +145 -0
  220. data/app/assets/stylesheets/design-patterns/_media-player.scss +264 -0
  221. data/app/assets/trigger.sh +24 -0
  222. data/idsk_frontend_toolkit.gemspec +49 -0
  223. data/lib/idsk_frontend_toolkit/engine.rb +4 -0
  224. data/lib/idsk_frontend_toolkit/version.rb +5 -0
  225. data/lib/idsk_frontend_toolkit.rb +4 -0
  226. data/publish.sh +30 -0
  227. metadata +314 -0
@@ -0,0 +1,761 @@
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
15
+
16
+ beforeEach(function () {
17
+ $radioLabels = $(
18
+ '<label class="selectable">' +
19
+ 'Small' +
20
+ '<input type="radio" name="size" id="small" value="small" />' +
21
+ '</label>' +
22
+ '<label class="selectable">' +
23
+ 'Medium' +
24
+ '<input type="radio" name="size" id="medium" value="medium" />' +
25
+ '</label>' +
26
+ '<label class="selectable">' +
27
+ 'Large' +
28
+ '<input type="radio" name="size" id="large" value="large" />' +
29
+ '</label>'
30
+ )
31
+ $checkboxLabels = $(
32
+ '<label class="selectable">' +
33
+ 'Eggs' +
34
+ '<input id="eggs" name="food" value="eggs" type="checkbox" />' +
35
+ '</label>' +
36
+ '<label class="selectable">' +
37
+ 'Bread' +
38
+ '<input id="bread" name="food" value="bread" type="checkbox" />' +
39
+ '</label>' +
40
+ '<label class="selectable">' +
41
+ 'Fruit' +
42
+ '<input id="fruit" name="food" value="fruit" type="checkbox" />' +
43
+ '</label>'
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
+ })
56
+
57
+ afterEach(function () {
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
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).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 () {
343
+ afterEach(function () {
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 () {
424
+ afterEach(function () {
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
499
+
500
+ beforeEach(function () {
501
+ $mixedButtons = $checkboxButtons.add($radioButtons)
502
+ })
503
+
504
+ afterEach(function () {
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 () {
541
+ afterEach(function () {
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 () {
572
+ afterEach(function () {
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 () {
621
+ afterEach(function () {
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 () {
638
+ afterEach(function () {
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) {
694
+ if (this === $radioButtons) {
695
+ if (evt === 'click') {
696
+ clickCallbackBound = callback
697
+ }
698
+ if (evt === 'focus blur') {
699
+ focusBlurCallbackBound = callback
700
+ }
701
+ }
702
+ return this
703
+ })
704
+
705
+ spyOn($.fn, 'off').and.callFake(function (evt, callback) {
706
+ if (this === $radioButtons) {
707
+ if (evt === 'click') {
708
+ clickCallbackCancelled = callback
709
+ }
710
+ if (evt === 'focus blur') {
711
+ focusBlurCallbackCancelled = callback
712
+ }
713
+ }
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) {
731
+ if ((this[0] === document) && (selector === "label.selectable input[type='checkbox']")) {
732
+ if (evt === 'click') {
733
+ clickCallbackBound = callback
734
+ }
735
+ if (evt === 'focus blur') {
736
+ focusBlurCallbackBound = callback
737
+ }
738
+ }
739
+ return this
740
+ })
741
+
742
+ spyOn($.fn, 'off').and.callFake(function (evt, selector, callback) {
743
+ if ((this[0] === document) && (selector === "label.selectable input[type='checkbox']")) {
744
+ if (evt === 'click') {
745
+ clickCallbackCancelled = callback
746
+ }
747
+ if (evt === 'focus blur') {
748
+ focusBlurCallbackCancelled = callback
749
+ }
750
+ }
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
+ })