@ons/design-system 50.0.1 → 53.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/README.md +35 -15
  2. package/components/access-code/_macro.njk +1 -1
  3. package/components/access-code/_macro.spec.js +162 -0
  4. package/components/access-code/uac.spec.js +26 -0
  5. package/components/accordion/_macro.spec.js +224 -0
  6. package/components/accordion/accordion.spec.js +134 -0
  7. package/components/address-input/_macro.njk +1 -1
  8. package/components/address-input/_macro.spec.js +465 -0
  9. package/components/address-input/autosuggest.address.js +5 -4
  10. package/components/address-input/autosuggest.address.setter.js +9 -3
  11. package/components/address-input/autosuggest.address.spec.js +733 -0
  12. package/components/address-output/_macro.njk +6 -6
  13. package/components/address-output/_macro.spec.js +122 -0
  14. package/components/autosuggest/_macro.njk +1 -1
  15. package/components/autosuggest/_macro.spec.js +229 -0
  16. package/components/autosuggest/autosuggest.helpers.js +2 -3
  17. package/components/autosuggest/autosuggest.helpers.spec.js +85 -0
  18. package/components/autosuggest/autosuggest.js +4 -2
  19. package/components/autosuggest/autosuggest.spec.js +625 -0
  20. package/components/autosuggest/autosuggest.ui.js +6 -2
  21. package/components/breadcrumbs/_macro.spec.js +129 -0
  22. package/components/button/_button.scss +75 -33
  23. package/components/button/_macro.njk +6 -6
  24. package/components/button/_macro.spec.js +446 -0
  25. package/components/button/button.spec.js +290 -0
  26. package/components/call-to-action/_macro.njk +3 -1
  27. package/components/call-to-action/_macro.spec.js +52 -0
  28. package/components/card/_macro.njk +26 -19
  29. package/components/card/_macro.spec.js +261 -0
  30. package/components/char-check-limit/_macro.spec.js +73 -0
  31. package/components/char-check-limit/character-check.spec.js +196 -0
  32. package/components/char-check-limit/character-limit.js +1 -1
  33. package/components/checkboxes/_checkbox-macro.spec.js +419 -0
  34. package/components/checkboxes/_macro.njk +1 -3
  35. package/components/checkboxes/_macro.spec.js +306 -0
  36. package/components/checkboxes/checkbox-with-autoselect.js +2 -1
  37. package/components/checkboxes/checkboxes.spec.js +208 -0
  38. package/components/code-highlight/_macro.spec.js +56 -0
  39. package/components/code-highlight/code-highlight.spec.js +18 -0
  40. package/components/collapsible/_macro.spec.js +204 -0
  41. package/components/collapsible/collapsible.js +2 -1
  42. package/components/collapsible/collapsible.spec.js +236 -0
  43. package/components/content-pagination/_macro.spec.js +199 -0
  44. package/components/cookies-banner/_macro.njk +1 -1
  45. package/components/cookies-banner/_macro.spec.js +171 -0
  46. package/components/cookies-banner/cookies-banner.spec.js +90 -0
  47. package/components/date-input/_macro.njk +6 -3
  48. package/components/date-input/_macro.spec.js +286 -0
  49. package/components/document-list/_macro.njk +3 -5
  50. package/components/document-list/_macro.spec.js +491 -0
  51. package/components/download-resources/download-resources.spec.js +540 -0
  52. package/components/duration/_macro.njk +7 -6
  53. package/components/duration/_macro.spec.js +251 -0
  54. package/components/error/_macro.spec.js +97 -0
  55. package/components/external-link/_macro.njk +5 -2
  56. package/components/external-link/_macro.spec.js +77 -0
  57. package/components/feedback/_macro.njk +5 -3
  58. package/components/feedback/_macro.spec.js +122 -0
  59. package/components/field/_macro.njk +2 -2
  60. package/components/field/_macro.spec.js +97 -0
  61. package/components/fieldset/_macro.njk +3 -3
  62. package/components/fieldset/_macro.spec.js +173 -0
  63. package/components/footer/_footer.scss +19 -4
  64. package/components/footer/_macro.njk +106 -137
  65. package/components/footer/_macro.spec.js +678 -0
  66. package/components/header/_header.scss +65 -46
  67. package/components/header/_macro.njk +173 -121
  68. package/components/header/_macro.spec.js +618 -0
  69. package/components/hero/_hero.scss +30 -143
  70. package/components/hero/_macro.njk +12 -23
  71. package/components/hero/_macro.spec.js +218 -0
  72. package/components/icons/_macro.njk +258 -30
  73. package/components/icons/_macro.spec.js +140 -0
  74. package/components/images/_macro.njk +1 -1
  75. package/components/images/_macro.spec.js +121 -0
  76. package/components/input/_input-type.scss +12 -5
  77. package/components/input/_input.scss +8 -0
  78. package/components/input/_macro.njk +4 -5
  79. package/components/input/_macro.spec.js +658 -0
  80. package/components/label/_macro.spec.js +189 -0
  81. package/components/language-selector/_macro.njk +1 -1
  82. package/components/language-selector/_macro.spec.js +137 -0
  83. package/components/lists/_list.scss +4 -0
  84. package/components/lists/_macro.njk +4 -7
  85. package/components/lists/_macro.spec.js +618 -0
  86. package/components/message/_macro.spec.js +137 -0
  87. package/components/message-list/_macro.njk +7 -7
  88. package/components/message-list/_macro.spec.js +159 -0
  89. package/components/metadata/_macro.spec.js +167 -0
  90. package/components/modal/_macro.njk +6 -6
  91. package/components/modal/_macro.spec.js +87 -0
  92. package/components/modal/modal.spec.js +59 -0
  93. package/components/mutually-exclusive/_macro.njk +2 -2
  94. package/components/mutually-exclusive/_macro.spec.js +184 -0
  95. package/components/mutually-exclusive/mutually-exclusive.checkboxes.spec.js +203 -0
  96. package/components/mutually-exclusive/mutually-exclusive.date.spec.js +142 -0
  97. package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +141 -0
  98. package/components/mutually-exclusive/mutually-exclusive.email.spec.js +117 -0
  99. package/components/mutually-exclusive/mutually-exclusive.multiple-options.checkboxes.spec.js +213 -0
  100. package/components/mutually-exclusive/mutually-exclusive.number.spec.js +125 -0
  101. package/components/mutually-exclusive/mutually-exclusive.textarea.spec.js +131 -0
  102. package/components/navigation/_macro.njk +45 -38
  103. package/components/navigation/_macro.spec.js +329 -0
  104. package/components/navigation/_navigation.scss +20 -4
  105. package/components/navigation/navigation.dom.js +1 -1
  106. package/components/navigation/navigation.spec.js +232 -0
  107. package/components/pagination/_macro.njk +1 -1
  108. package/components/pagination/_macro.spec.js +411 -0
  109. package/components/panel/_macro.njk +6 -6
  110. package/components/panel/_macro.spec.js +423 -0
  111. package/components/password/_macro.spec.js +137 -0
  112. package/components/password/password.spec.js +40 -0
  113. package/components/phase-banner/_macro.spec.js +73 -0
  114. package/components/promotional-banner/_macro.spec.js +97 -0
  115. package/components/question/_macro.njk +16 -22
  116. package/components/question/_macro.spec.js +309 -0
  117. package/components/quote/_macro.spec.js +81 -0
  118. package/components/radios/_macro.njk +3 -6
  119. package/components/radios/_macro.spec.js +575 -0
  120. package/components/radios/radios.spec.js +180 -0
  121. package/components/related-content/_macro.njk +14 -21
  122. package/components/related-content/_macro.spec.js +133 -0
  123. package/components/related-content/_section-macro.njk +10 -0
  124. package/components/related-content/_section-macro.spec.js +43 -0
  125. package/components/relationships/_macro.spec.js +108 -0
  126. package/components/relationships/relationships.spec.js +84 -0
  127. package/components/reply/_macro.njk +2 -2
  128. package/components/reply/_macro.spec.js +69 -0
  129. package/components/reply/reply.spec.js +78 -0
  130. package/components/search/_macro.njk +14 -12
  131. package/components/search/_macro.spec.js +44 -0
  132. package/components/search/_search.scss +7 -7
  133. package/components/section-navigation/_macro.njk +7 -2
  134. package/components/section-navigation/_macro.spec.js +206 -0
  135. package/components/select/_macro.njk +3 -3
  136. package/components/select/_macro.spec.js +203 -0
  137. package/components/select/select.spec.js +56 -0
  138. package/components/share-page/_macro.njk +6 -4
  139. package/components/share-page/_macro.spec.js +110 -0
  140. package/components/skip-to-content/_macro.spec.js +57 -0
  141. package/components/skip-to-content/skip-to-content.spec.js +44 -0
  142. package/components/status/_macro.spec.js +77 -0
  143. package/components/summary/_macro.njk +5 -5
  144. package/components/summary/_macro.spec.js +472 -0
  145. package/components/table/_macro.njk +2 -2
  146. package/components/table/_macro.spec.js +557 -0
  147. package/components/table/table.spec.js +155 -0
  148. package/components/table-of-contents/_macro.njk +35 -35
  149. package/components/table-of-contents/_macro.spec.js +178 -0
  150. package/components/table-of-contents/toc.js +29 -25
  151. package/components/table-of-contents/toc.spec.js +61 -0
  152. package/components/tabs/_macro.njk +1 -1
  153. package/components/tabs/_macro.spec.js +79 -0
  154. package/components/tabs/tabs.spec.js +162 -0
  155. package/components/text-indent/_macro.spec.js +52 -0
  156. package/components/textarea/_macro.njk +5 -3
  157. package/components/textarea/_macro.spec.js +300 -0
  158. package/components/textarea/textarea.spec.js +98 -0
  159. package/components/timeline/_macro.njk +3 -3
  160. package/components/timeline/_macro.spec.js +81 -0
  161. package/components/timeout-modal/_macro.spec.js +68 -0
  162. package/components/timeout-modal/timeout-modal.spec.js +226 -0
  163. package/components/timeout-panel/_macro.njk +0 -1
  164. package/components/timeout-panel/_macro.spec.js +54 -0
  165. package/components/timeout-panel/timeout-panel.dom.js +1 -2
  166. package/components/timeout-panel/timeout-panel.spec.js +161 -0
  167. package/components/upload/_macro.spec.js +75 -0
  168. package/components/video/_macro.spec.js +34 -0
  169. package/css/census.css +3 -1
  170. package/css/ids.css +2 -0
  171. package/css/main.css +1 -1
  172. package/img/dummy-brand-logo.svg +1 -0
  173. package/js/cookies-settings.spec.js +154 -0
  174. package/layout/_template.njk +7 -4
  175. package/package.json +10 -23
  176. package/scripts/main.es5.js +2 -2
  177. package/scripts/main.js +1 -1
  178. package/scss/ids.scss +2 -0
  179. package/scss/settings/_census.scss +141 -0
  180. package/scss/settings/_ids.scss +48 -0
  181. package/scss/utilities/_margin.scss +1 -0
  182. package/scss/vars/_colors.scss +5 -2
@@ -0,0 +1,465 @@
1
+ /** @jest-environment jsdom */
2
+
3
+ import * as cheerio from 'cheerio';
4
+
5
+ import axe from '../../tests/helpers/axe';
6
+ import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
7
+
8
+ const EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL = {
9
+ id: 'address-input-example-id',
10
+ legend: 'What is the address?',
11
+ label: {
12
+ text: 'Enter address or postcode and select from results',
13
+ id: 'address-input-example-label-id',
14
+ },
15
+ isEditable: false,
16
+ instructions: 'Use up and down keys to navigate suggestions.',
17
+ ariaYouHaveSelected: 'You have selected',
18
+ ariaMinChars: 'Enter 3 or more characters for suggestions.',
19
+ ariaOneResult: 'There is one suggestion available.',
20
+ ariaNResults: 'There are {n} suggestions available.',
21
+ ariaLimitedResults: 'Results have been limited to 10 suggestions. Type more characters to improve your search',
22
+ ariaGroupedResults: 'There are {n} for {x}',
23
+ groupCount: '{n} addresses',
24
+ moreResults: 'Enter more of the address to improve results',
25
+ noResults: 'No results found. Try entering a different part of the address',
26
+ tooManyResults: '{n} results found. Enter more of the address to improve results',
27
+ typeMore: 'Enter more of the address to get results',
28
+ resultsTitle: 'Select an address',
29
+ resultsTitleId: 'address-suggestions',
30
+ };
31
+
32
+ const EXAMPLE_MANUAL_INPUT_FIELDS = {
33
+ organisation: {
34
+ label: 'Organisation name',
35
+ value: 'Example Organisation',
36
+ error: { text: 'Server error: organisation name' },
37
+ },
38
+ line1: {
39
+ label: 'Address line 1',
40
+ value: 'Flat 12345',
41
+ error: { text: 'Server error: address line 1' },
42
+ },
43
+ line2: {
44
+ label: 'Address line 2',
45
+ value: '12345 The Road',
46
+ error: { text: 'Server error: address line 2' },
47
+ },
48
+ town: {
49
+ label: 'Town or city',
50
+ value: 'The Town',
51
+ error: { text: 'Server error: town or city' },
52
+ },
53
+ postcode: {
54
+ label: 'Postcode',
55
+ value: 'PO57 6ODE',
56
+ error: { text: 'Server error: postcode' },
57
+ },
58
+ };
59
+
60
+ describe('macro: address-input', () => {
61
+ it('passes jest-axe checks', async () => {
62
+ const $ = cheerio.load(renderComponent('address-input', EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL));
63
+
64
+ const results = await axe($.html());
65
+ expect(results).toHaveNoViolations();
66
+ });
67
+
68
+ describe('manual entry of address', () => {
69
+ it('has class to hide input fields when automatic search is enabled', () => {
70
+ const $ = cheerio.load(
71
+ renderComponent('address-input', {
72
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
73
+ isEditable: true,
74
+ manualEntry: false,
75
+ }),
76
+ );
77
+
78
+ expect($('.ons-js-address-input__manual').hasClass('ons-u-db-no-js_enabled')).toBe(true);
79
+ });
80
+
81
+ it('does not have class to hide input fields when automatic search is disabled', () => {
82
+ const $ = cheerio.load(
83
+ renderComponent('address-input', {
84
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
85
+ isEditable: true,
86
+ manualEntry: true,
87
+ }),
88
+ );
89
+
90
+ expect($('.ons-js-address-input__manual').hasClass('ons-u-db-no-js_enabled')).toBe(false);
91
+ });
92
+
93
+ it('renders "organisation" input field with expected parameters', () => {
94
+ const faker = templateFaker();
95
+ const inputSpy = faker.spy('input', { suppressOutput: true });
96
+
97
+ faker.renderComponent('address-input', {
98
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
99
+ ...EXAMPLE_MANUAL_INPUT_FIELDS,
100
+ isEditable: true,
101
+ });
102
+
103
+ expect(inputSpy.occurrences).toContainEqual({
104
+ id: 'address-input-example-id-organisation',
105
+ name: 'address-input-example-id-organisation',
106
+ classes: 'ons-js-address-organisation',
107
+ label: {
108
+ text: 'Organisation name',
109
+ },
110
+ value: 'Example Organisation',
111
+ width: '20@m',
112
+ error: { text: 'Server error: organisation name' },
113
+ });
114
+ });
115
+
116
+ it('renders "address line 1" input field with expected parameters', () => {
117
+ const faker = templateFaker();
118
+ const inputSpy = faker.spy('input', { suppressOutput: true });
119
+
120
+ faker.renderComponent('address-input', {
121
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
122
+ ...EXAMPLE_MANUAL_INPUT_FIELDS,
123
+ isEditable: true,
124
+ });
125
+
126
+ expect(inputSpy.occurrences).toContainEqual({
127
+ id: 'address-input-example-id-line1',
128
+ name: 'address-input-example-id-line1',
129
+ classes: 'ons-js-address-line1',
130
+ label: {
131
+ text: 'Address line 1',
132
+ },
133
+ value: 'Flat 12345',
134
+ width: '20@m',
135
+ error: { text: 'Server error: address line 1' },
136
+ });
137
+ });
138
+
139
+ it('renders "address line 2" input field with expected parameters', () => {
140
+ const faker = templateFaker();
141
+ const inputSpy = faker.spy('input', { suppressOutput: true });
142
+
143
+ faker.renderComponent('address-input', {
144
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
145
+ ...EXAMPLE_MANUAL_INPUT_FIELDS,
146
+ isEditable: true,
147
+ });
148
+
149
+ expect(inputSpy.occurrences).toContainEqual({
150
+ id: 'address-input-example-id-line2',
151
+ name: 'address-input-example-id-line2',
152
+ classes: 'ons-js-address-line2',
153
+ label: {
154
+ text: 'Address line 2',
155
+ },
156
+ value: '12345 The Road',
157
+ width: '20@m',
158
+ error: { text: 'Server error: address line 2' },
159
+ });
160
+ });
161
+
162
+ it('renders "town or city" input field with expected parameters', () => {
163
+ const faker = templateFaker();
164
+ const inputSpy = faker.spy('input', { suppressOutput: true });
165
+
166
+ faker.renderComponent('address-input', {
167
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
168
+ ...EXAMPLE_MANUAL_INPUT_FIELDS,
169
+ isEditable: true,
170
+ });
171
+
172
+ expect(inputSpy.occurrences).toContainEqual({
173
+ id: 'address-input-example-id-town',
174
+ name: 'address-input-example-id-town',
175
+ classes: 'ons-js-address-town',
176
+ label: {
177
+ text: 'Town or city',
178
+ },
179
+ value: 'The Town',
180
+ error: { text: 'Server error: town or city' },
181
+ });
182
+ });
183
+
184
+ it('renders "postcode" input field with expected parameters', () => {
185
+ const faker = templateFaker();
186
+ const inputSpy = faker.spy('input', { suppressOutput: true });
187
+
188
+ faker.renderComponent('address-input', {
189
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
190
+ ...EXAMPLE_MANUAL_INPUT_FIELDS,
191
+ isEditable: true,
192
+ });
193
+
194
+ expect(inputSpy.occurrences).toContainEqual({
195
+ id: 'address-input-example-id-postcode',
196
+ name: 'address-input-example-id-postcode',
197
+ classes: 'ons-js-address-postcode',
198
+ label: {
199
+ text: 'Postcode',
200
+ },
201
+ value: 'PO57 6ODE',
202
+ width: '7',
203
+ error: { text: 'Server error: postcode' },
204
+ });
205
+ });
206
+ });
207
+
208
+ describe('search button for no-js', () => {
209
+ it('is not rendered when automatic search is disabled', () => {
210
+ const $ = cheerio.load(
211
+ renderComponent('address-input', {
212
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
213
+ isEditable: true,
214
+ manualEntry: true,
215
+ searchButton: 'Search for address',
216
+ }),
217
+ );
218
+
219
+ expect($('.ons-js-address-search-btn').length).toBe(0);
220
+ });
221
+
222
+ it('marks field so that it is displayed only when there is no javascript', () => {
223
+ const $ = cheerio.load(
224
+ renderComponent('address-input', {
225
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
226
+ isEditable: true,
227
+ searchButton: 'Search for address',
228
+ }),
229
+ );
230
+
231
+ expect($('.ons-js-address-search-btn').hasClass('ons-u-db-no-js_disabled')).toBe(true);
232
+ });
233
+
234
+ it('renders provided text for search button', () => {
235
+ const $ = cheerio.load(
236
+ renderComponent('address-input', {
237
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
238
+ isEditable: true,
239
+ searchButton: 'Search for address',
240
+ }),
241
+ );
242
+
243
+ expect(
244
+ $('.ons-js-address-search-btn')
245
+ .text()
246
+ .trim(),
247
+ ).toBe('Search for address');
248
+ });
249
+ });
250
+
251
+ describe('hidden field for uprn', () => {
252
+ it('renders hidden `input` component with expected parameters when `uprn.value` is not provided', () => {
253
+ const faker = templateFaker();
254
+ const inputSpy = faker.spy('input', { suppressOutput: true });
255
+
256
+ faker.renderComponent('address-input', EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL);
257
+
258
+ expect(inputSpy.occurrences).toContainEqual({
259
+ id: 'address-input-example-id-uprn',
260
+ classes: 'ons-js-hidden-uprn ons-u-d-no',
261
+ type: 'hidden',
262
+ name: 'address-input-example-id-uprn',
263
+ value: '',
264
+ });
265
+ });
266
+
267
+ it('renders hidden `input` component with expected parameters when `uprn.value` is provided', () => {
268
+ const faker = templateFaker();
269
+ const inputSpy = faker.spy('input', { suppressOutput: true });
270
+
271
+ faker.renderComponent('address-input', {
272
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
273
+ uprn: {
274
+ value: '[params.uprn.value]',
275
+ },
276
+ });
277
+
278
+ expect(inputSpy.occurrences).toContainEqual({
279
+ id: 'address-input-example-id-uprn',
280
+ classes: 'ons-js-hidden-uprn ons-u-d-no',
281
+ type: 'hidden',
282
+ name: 'address-input-example-id-uprn',
283
+ value: '[params.uprn.value]',
284
+ });
285
+ });
286
+ });
287
+
288
+ describe('autosuggest search field', () => {
289
+ it('is not shown when `manualEntry` is `true`', () => {
290
+ const faker = templateFaker();
291
+ const autosuggestSpy = faker.spy('autosuggest', { suppressOutput: true });
292
+
293
+ faker.renderComponent('address-input', {
294
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
295
+ manualEntry: true,
296
+ });
297
+
298
+ expect(autosuggestSpy.occurrences.length).toBe(0);
299
+ });
300
+
301
+ it('renders `autosuggest` component with expected parameters', () => {
302
+ const faker = templateFaker();
303
+ const autosuggestSpy = faker.spy('autosuggest', { suppressOutput: true });
304
+
305
+ // Since `autosuggestSpy` suppresses output the values being tested below do not
306
+ // need to represent real values. This test is only interested in verifying that
307
+ // the provided values are being passed through to the `autosuggest` component.
308
+ faker.renderComponent('address-input', {
309
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
310
+ label: {
311
+ text: '[params.label.text]',
312
+ id: '[params.label.id]',
313
+ },
314
+ value: '[params.value]',
315
+ attributes: '[params.attributes]',
316
+ error: '[params.error]',
317
+ name: '[params.name]',
318
+ mutuallyExclusive: '[params.mutuallyExclusive]',
319
+ APIDomain: '[params.APIDomain]',
320
+ APIDomainBearerToken: '[params.APIDomainBearerToken]',
321
+ APIManualQueryParams: '[params.APIManualQueryParams]',
322
+ allowMultiple: '[params.allowMultiple]',
323
+ mandatory: '[params.mandatory]',
324
+ instructions: '[params.instructions]',
325
+ autocomplete: '[params.autocomplete]',
326
+ isEditable: '[params.isEditable]',
327
+ ariaYouHaveSelected: '[params.ariaYouHaveSelected]',
328
+ ariaMinChars: '[params.ariaMinChars]',
329
+ minChars: '[params.minChars]',
330
+ ariaResultsLabel: '[params.ariaResultsLabel]',
331
+ ariaOneResult: '[params.ariaOneResult]',
332
+ ariaNResults: '[params.ariaNResults]',
333
+ ariaLimitedResults: '[params.ariaLimitedResults]',
334
+ ariaGroupedResults: '[params.ariaGroupedResults]',
335
+ groupCount: '[params.groupCount]',
336
+ moreResults: '[params.moreResults]',
337
+ tooManyResults: '[params.tooManyResults]',
338
+ resultsTitle: '[params.resultsTitle]',
339
+ resultsTitleId: '[params.resultsTitleId]',
340
+ noResults: '[params.noResults]',
341
+ typeMore: '[params.typeMore]',
342
+ errorTitle: '[params.errorTitle]',
343
+ errorMessageEnter: '[params.errorMessageEnter]',
344
+ errorMessageSelect: '[params.errorMessageSelect]',
345
+ errorMessageAPI: '[params.errorMessageAPI]',
346
+ errorMessageAPILinkText: '[params.errorMessageAPILinkText]',
347
+ options: '[params.options]',
348
+ manualLink: '[params.manualLink]',
349
+ manualLinkText: '[params.manualLinkText]',
350
+ });
351
+
352
+ expect(autosuggestSpy.occurrences[0]).toEqual({
353
+ id: 'address-input-example-id-autosuggest',
354
+ classes: 'ons-address-input__autosuggest ons-u-mb-no',
355
+ width: '50',
356
+ label: {
357
+ text: '[params.label.text]',
358
+ id: '[params.label.id]',
359
+ classes: 'ons-js-autosuggest-label',
360
+ },
361
+ value: '[params.value]',
362
+ attributes: '[params.attributes]',
363
+ error: '[params.error]',
364
+ name: '[params.name]',
365
+ mutuallyExclusive: '[params.mutuallyExclusive]',
366
+ externalInitialiser: true,
367
+ APIDomain: '[params.APIDomain]',
368
+ APIDomainBearerToken: '[params.APIDomainBearerToken]',
369
+ APIManualQueryParams: '[params.APIManualQueryParams]',
370
+ allowMultiple: '[params.allowMultiple]',
371
+ mandatory: '[params.mandatory]',
372
+ instructions: '[params.instructions]',
373
+ autocomplete: '[params.autocomplete]',
374
+ isEditable: '[params.isEditable]',
375
+ ariaYouHaveSelected: '[params.ariaYouHaveSelected]',
376
+ ariaMinChars: '[params.ariaMinChars]',
377
+ minChars: '[params.minChars]',
378
+ ariaOneResult: '[params.ariaOneResult]',
379
+ ariaNResults: '[params.ariaNResults]',
380
+ ariaLimitedResults: '[params.ariaLimitedResults]',
381
+ ariaGroupedResults: '[params.ariaGroupedResults]',
382
+ groupCount: '[params.groupCount]',
383
+ moreResults: '[params.moreResults]',
384
+ tooManyResults: '[params.tooManyResults]',
385
+ resultsTitle: '[params.resultsTitle]',
386
+ resultsTitleId: '[params.resultsTitleId]',
387
+ noResults: '[params.noResults]',
388
+ typeMore: '[params.typeMore]',
389
+ errorTitle: '[params.errorTitle]',
390
+ errorMessageEnter: '[params.errorMessageEnter]',
391
+ errorMessageSelect: '[params.errorMessageSelect]',
392
+ errorMessageAPI: '[params.errorMessageAPI]',
393
+ errorMessageAPILinkText: '[params.errorMessageAPILinkText]',
394
+ options: '[params.options]',
395
+ manualLink: '[params.manualLink]',
396
+ manualLinkText: '[params.manualLinkText]',
397
+ });
398
+ });
399
+
400
+ it('renders manualLinkText` when provided with a default value for `manualLink`', () => {
401
+ const $ = cheerio.load(
402
+ renderComponent('address-input', {
403
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
404
+ manualLinkText: 'Manually enter address',
405
+ }),
406
+ );
407
+
408
+ expect($('.ons-js-address-manual-btn').attr('href')).toBe('#0');
409
+ expect(
410
+ $('.ons-js-address-manual-btn')
411
+ .text()
412
+ .trim(),
413
+ ).toBe('Manually enter address');
414
+ });
415
+
416
+ it('renders `manualLinkText` with `manualLink` when provided', () => {
417
+ const $ = cheerio.load(
418
+ renderComponent('address-input', {
419
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
420
+ manualLink: 'https://example.com/edit-address',
421
+ manualLinkText: 'Manually enter address',
422
+ }),
423
+ );
424
+
425
+ expect($('.ons-js-address-manual-btn').attr('href')).toBe('https://example.com/edit-address');
426
+ expect(
427
+ $('.ons-js-address-manual-btn')
428
+ .text()
429
+ .trim(),
430
+ ).toBe('Manually enter address');
431
+ });
432
+ });
433
+
434
+ describe('fieldset', () => {
435
+ it('does not render `fieldset` component when `dontWrap` is `true`', () => {
436
+ const faker = templateFaker();
437
+ const fieldsetSpy = faker.spy('fieldset', { suppressOutput: true });
438
+
439
+ faker.renderComponent('address-input', {
440
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
441
+ dontWrap: true,
442
+ });
443
+
444
+ expect(fieldsetSpy.occurrences.length).toBe(0);
445
+ });
446
+
447
+ it('renders `fieldset` component with expected parameters', () => {
448
+ const faker = templateFaker();
449
+ const fieldsetSpy = faker.spy('fieldset', { suppressOutput: true });
450
+
451
+ faker.renderComponent('address-input', {
452
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
453
+ classes: 'extra-field-class',
454
+ legendClasses: 'extra-legend-class',
455
+ });
456
+
457
+ expect(fieldsetSpy.occurrences[0]).toEqual({
458
+ id: 'address-input-example-id',
459
+ classes: 'extra-field-class',
460
+ legend: 'What is the address?',
461
+ legendClasses: 'extra-legend-class',
462
+ });
463
+ });
464
+ });
465
+ });
@@ -16,7 +16,6 @@ export default class AutosuggestAddress {
16
16
  this.context = context;
17
17
  this.input = context.querySelector(`.${classInput}`);
18
18
  this.search = context.querySelector(`.${classSearch}`);
19
- this.lang = document.documentElement.getAttribute('lang').toLowerCase();
20
19
  this.addressReplaceChars = [','];
21
20
  this.sanitisedQuerySplitNumsChars = true;
22
21
  this.form = context.closest('form');
@@ -74,8 +73,12 @@ export default class AutosuggestAddress {
74
73
  this.checkAPIStatus();
75
74
  }
76
75
 
76
+ get lang() {
77
+ return document.documentElement.getAttribute('lang').toLowerCase();
78
+ }
79
+
77
80
  async checkAPIStatus() {
78
- this.fetch = abortableFetch(this.lookupURL + 'CF142&limit=10', {
81
+ this.fetch = abortableFetch(this.lookupURL + 'cf142&limit=10', {
79
82
  method: 'GET',
80
83
  headers: this.setAuthorization(this.authorizationToken),
81
84
  });
@@ -90,7 +93,6 @@ export default class AutosuggestAddress {
90
93
  }
91
94
  }
92
95
  } catch (error) {
93
- console.log(error);
94
96
  if (this.isEditable) {
95
97
  this.handleAPIError();
96
98
  } else {
@@ -282,7 +284,6 @@ export default class AutosuggestAddress {
282
284
  this.addressSelected = true;
283
285
  }
284
286
  } catch (error) {
285
- console.log(error);
286
287
  if (this.isEditable) {
287
288
  this.handleAPIError();
288
289
  } else {
@@ -1,6 +1,7 @@
1
1
  import AddressError from './autosuggest.address.error';
2
2
 
3
3
  export const classAutosuggestInput = 'ons-js-autosuggest-input';
4
+ export const classOrganisation = 'ons-js-address-organisation';
4
5
  export const classLine1 = 'ons-js-address-line1';
5
6
  export const classLine2 = 'ons-js-address-line2';
6
7
  export const classTown = 'ons-js-address-town';
@@ -17,12 +18,13 @@ export default class AddressSetter {
17
18
  constructor(context) {
18
19
  this.context = context;
19
20
  this.input = context.querySelector(`.${classAutosuggestInput}`);
21
+ this.organisation = context.querySelector(`.${classOrganisation}`);
20
22
  this.line1 = context.querySelector(`.${classLine1}`);
21
23
  this.line2 = context.querySelector(`.${classLine2}`);
22
24
  this.town = context.querySelector(`.${classTown}`);
23
25
  this.postcode = context.querySelector(`.${classPostcode}`);
24
26
  this.uprn = context.querySelector(`.${classInputUPRN}`);
25
- this.manualInputs = [this.line1, this.line2, this.town, this.postcode, this.uprn];
27
+ this.manualInputs = [this.organisation, this.line1, this.line2, this.town, this.postcode, this.uprn];
26
28
  this.search = context.querySelector(`.${classSearch}`);
27
29
  this.manual = context.querySelector(`.${classManual}`);
28
30
  this.searchButton = context.querySelector(`.${classSearchButton}`);
@@ -102,14 +104,18 @@ export default class AddressSetter {
102
104
 
103
105
  clearManualInputs() {
104
106
  this.manualInputs.forEach(input => {
105
- input.value = '';
107
+ if (input) {
108
+ input.value = '';
109
+ }
106
110
  });
107
111
  }
108
112
 
109
113
  checkManualInputsValues(onLoad) {
110
114
  if (onLoad) {
111
115
  this.originalValues = this.manualInputs.map(input => {
112
- return input.value;
116
+ if (input) {
117
+ return input.value;
118
+ }
113
119
  });
114
120
  } else if (this.uprn.value !== '' && this.originalValues.length) {
115
121
  this.newValues = this.manualInputs.map(input => {