@ons/design-system 72.0.1 → 72.1.1

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 (55) hide show
  1. package/README.md +1 -1
  2. package/components/accordion/_macro.spec.js +2 -2
  3. package/components/address-input/_macro.spec.js +245 -322
  4. package/components/address-input/autosuggest.address.spec.js +16 -14
  5. package/components/address-output/_macro.spec.js +121 -74
  6. package/components/address-output/_test_examples.js +8 -0
  7. package/components/autosuggest/_macro.njk +1 -0
  8. package/components/autosuggest/_macro.spec.js +373 -178
  9. package/components/autosuggest/autosuggest.spec.js +3 -1
  10. package/components/autosuggest/autosuggest.ui.js +39 -10
  11. package/components/autosuggest/example-autosuggest-country.njk +2 -1
  12. package/components/autosuggest/fuse-config.js +7 -2
  13. package/components/back-to-top/back-to-top.dom.js +4 -4
  14. package/components/back-to-top/back-to-top.js +1 -1
  15. package/components/browser-banner/_macro.spec.js +11 -11
  16. package/components/button/_macro.njk +1 -1
  17. package/components/button/_macro.spec.js +405 -351
  18. package/components/button/example-button-group.njk +1 -0
  19. package/components/checkboxes/_checkbox-macro.njk +20 -0
  20. package/components/checkboxes/_checkbox.scss +3 -3
  21. package/components/checkboxes/_macro.njk +5 -0
  22. package/components/checkboxes/_macro.spec.js +35 -0
  23. package/components/checkboxes/example-checkboxes-with-revealed-text-area-expanded.njk +68 -0
  24. package/components/checkboxes/example-checkboxes-with-revealed-text-area.njk +67 -0
  25. package/components/details/_details.scss +1 -2
  26. package/components/details/example-details-open.njk +10 -0
  27. package/components/external-link/_macro.spec.js +66 -69
  28. package/components/external-link/_test_examples.js +4 -0
  29. package/components/feedback/_macro.spec.js +109 -80
  30. package/components/feedback/_test_examples.js +17 -0
  31. package/components/field/_macro.spec.js +106 -69
  32. package/components/section-navigation/_macro.njk +9 -6
  33. package/components/summary/_macro.njk +73 -78
  34. package/components/summary/_macro.spec.js +5 -15
  35. package/components/summary/_summary.scss +16 -11
  36. package/components/table-of-contents/_macro.njk +3 -3
  37. package/components/table-of-contents/_macro.spec.js +3 -3
  38. package/components/table-of-contents/{_toc.scss → _table-of-contents.scss} +1 -1
  39. package/components/table-of-contents/table-of-contents.dom.js +13 -0
  40. package/components/table-of-contents/{toc.js → table-of-contents.js} +4 -4
  41. package/components/table-of-contents/{toc.spec.js → table-of-contents.spec.js} +2 -2
  42. package/components/tabs/_tabs.scss +10 -11
  43. package/components/tabs/tabs.js +3 -3
  44. package/components/timeout-modal/timeout-modal.spec.js +1 -1
  45. package/css/main.css +1 -1
  46. package/js/analytics.js +1 -1
  47. package/js/main.js +1 -1
  48. package/package.json +2 -2
  49. package/scripts/main.es5.js +1 -1
  50. package/scripts/main.js +1 -1
  51. package/scss/main.scss +1 -1
  52. package/scss/objects/_page.scss +1 -1
  53. package/scss/utilities/_margin.scss +4 -0
  54. package/scss/utilities/_padding.scss +4 -0
  55. package/components/table-of-contents/toc.dom.js +0 -13
@@ -4,69 +4,22 @@ import * as cheerio from 'cheerio';
4
4
 
5
5
  import axe from '../../tests/helpers/axe';
6
6
  import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
7
+ import { EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL, EXAMPLE_MANUAL_INPUT_FIELDS } from './_test-examples';
7
8
 
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();
9
+ describe('FOR: Macro: Address-input', () => {
10
+ describe('GIVEN: Params: required', () => {
11
+ describe('WHEN: required params are provided', () => {
12
+ const $ = cheerio.load(renderComponent('address-input', EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL));
13
+
14
+ test('THEN: jest-axe tests pass', async () => {
15
+ const results = await axe($.html());
16
+ expect(results).toHaveNoViolations();
17
+ });
18
+ });
66
19
  });
67
20
 
68
- describe('manual entry of address', () => {
69
- it('has class to hide input fields when automatic search is enabled', () => {
21
+ describe('GIVEN: Params: manualEntry', () => {
22
+ describe('WHEN: manualEntry is set to false', () => {
70
23
  const $ = cheerio.load(
71
24
  renderComponent('address-input', {
72
25
  ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
@@ -75,10 +28,15 @@ describe('macro: address-input', () => {
75
28
  }),
76
29
  );
77
30
 
78
- expect($('.ons-js-address-input__manual').hasClass('ons-u-db-no-js_enabled')).toBe(true);
31
+ test('THEN: it renders with class to hide manual input fields', () => {
32
+ expect($('.ons-js-address-input__manual').hasClass('ons-u-db-no-js_enabled')).toBe(true);
33
+ });
79
34
  });
80
35
 
81
- it('does not have class to hide input fields when automatic search is disabled', () => {
36
+ describe('WHEN: manualEntry is set to true', () => {
37
+ const faker = templateFaker();
38
+ const autosuggestSpy = faker.spy('autosuggest', { suppressOutput: true });
39
+
82
40
  const $ = cheerio.load(
83
41
  renderComponent('address-input', {
84
42
  ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
@@ -87,126 +45,209 @@ describe('macro: address-input', () => {
87
45
  }),
88
46
  );
89
47
 
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,
48
+ test('THEN: it renders with class to show manual input fields', () => {
49
+ expect($('.ons-js-address-input__manual').hasClass('ons-u-db-no-js_enabled')).toBe(false);
101
50
  });
102
51
 
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' },
52
+ test('THEN: autosuggest search field is not shown', () => {
53
+ expect(autosuggestSpy.occurrences.length).toBe(0);
113
54
  });
114
55
  });
115
56
 
116
- it('renders "address line 1" input field with expected parameters', () => {
57
+ describe('WHEN: manualEntry is not set', () => {
117
58
  const faker = templateFaker();
118
- const inputSpy = faker.spy('input', { suppressOutput: true });
59
+ const autosuggestSpy = faker.spy('autosuggest', { suppressOutput: true });
119
60
 
61
+ // Since autosuggestSpy suppresses output the values being tested below do not
62
+ // need to represent real values. This test is only interested in verifying that
63
+ // the provided values are being passed through to the autosuggest component.
120
64
  faker.renderComponent('address-input', {
121
65
  ...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
66
  label: {
131
- text: 'Address line 1',
67
+ text: '[params.label.text]',
68
+ id: '[params.label.id]',
132
69
  },
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,
70
+ value: '[params.value]',
71
+ attributes: '[params.attributes]',
72
+ error: '[params.error]',
73
+ name: '[params.name]',
74
+ mutuallyExclusive: '[params.mutuallyExclusive]',
75
+ apiDomain: '[params.apiDomain]',
76
+ apiDomainBearerToken: '[params.apiDomainBearerToken]',
77
+ apiManualQueryParams: '[params.apiManualQueryParams]',
78
+ allowMultiple: '[params.allowMultiple]',
79
+ mandatory: '[params.mandatory]',
80
+ instructions: '[params.instructions]',
81
+ autocomplete: '[params.autocomplete]',
82
+ isEditable: '[params.isEditable]',
83
+ ariaYouHaveSelected: '[params.ariaYouHaveSelected]',
84
+ ariaMinChars: '[params.ariaMinChars]',
85
+ minChars: '[params.minChars]',
86
+ ariaResultsLabel: '[params.ariaResultsLabel]',
87
+ ariaOneResult: '[params.ariaOneResult]',
88
+ ariaNResults: '[params.ariaNResults]',
89
+ ariaLimitedResults: '[params.ariaLimitedResults]',
90
+ ariaGroupedResults: '[params.ariaGroupedResults]',
91
+ groupCount: '[params.groupCount]',
92
+ moreResults: '[params.moreResults]',
93
+ tooManyResults: '[params.tooManyResults]',
94
+ resultsTitle: '[params.resultsTitle]',
95
+ resultsTitleId: '[params.resultsTitleId]',
96
+ noResults: '[params.noResults]',
97
+ typeMore: '[params.typeMore]',
98
+ errorTitle: '[params.errorTitle]',
99
+ errorMessageEnter: '[params.errorMessageEnter]',
100
+ errorMessageSelect: '[params.errorMessageSelect]',
101
+ errorMessageApi: '[params.errorMessageApi]',
102
+ errorMessageApiLinkText: '[params.errorMessageApiLinkText]',
103
+ options: '[params.options]',
104
+ manualLinkUrl: '[params.manualLinkUrl]',
105
+ manualLinkText: '[params.manualLinkText]',
147
106
  });
148
107
 
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' },
108
+ test('THEN: the provided attributes are passed through to the autosuggest component', () => {
109
+ expect(autosuggestSpy.occurrences[0]).toEqual({
110
+ id: 'address-input-example-id-autosuggest',
111
+ classes: 'ons-address-input__autosuggest ons-u-mb-no',
112
+ input: {
113
+ width: '50',
114
+ label: {
115
+ text: '[params.label.text]',
116
+ id: '[params.label.id]',
117
+ classes: 'ons-js-autosuggest-label',
118
+ },
119
+ value: '[params.value]',
120
+ attributes: '[params.attributes]',
121
+ error: '[params.error]',
122
+ name: '[params.name]',
123
+ mutuallyExclusive: '[params.mutuallyExclusive]',
124
+ },
125
+ externalInitialiser: true,
126
+ apiDomain: '[params.apiDomain]',
127
+ apiDomainBearerToken: '[params.apiDomainBearerToken]',
128
+ apiManualQueryParams: '[params.apiManualQueryParams]',
129
+ allowMultiple: '[params.allowMultiple]',
130
+ mandatory: '[params.mandatory]',
131
+ instructions: '[params.instructions]',
132
+ autocomplete: '[params.autocomplete]',
133
+ isEditable: '[params.isEditable]',
134
+ ariaYouHaveSelected: '[params.ariaYouHaveSelected]',
135
+ ariaMinChars: '[params.ariaMinChars]',
136
+ minChars: '[params.minChars]',
137
+ ariaOneResult: '[params.ariaOneResult]',
138
+ ariaNResults: '[params.ariaNResults]',
139
+ ariaLimitedResults: '[params.ariaLimitedResults]',
140
+ ariaGroupedResults: '[params.ariaGroupedResults]',
141
+ groupCount: '[params.groupCount]',
142
+ moreResults: '[params.moreResults]',
143
+ tooManyResults: '[params.tooManyResults]',
144
+ resultsTitle: '[params.resultsTitle]',
145
+ resultsTitleId: '[params.resultsTitleId]',
146
+ noResults: '[params.noResults]',
147
+ typeMore: '[params.typeMore]',
148
+ errorTitle: '[params.errorTitle]',
149
+ errorMessageEnter: '[params.errorMessageEnter]',
150
+ errorMessageSelect: '[params.errorMessageSelect]',
151
+ errorMessageApi: '[params.errorMessageApi]',
152
+ errorMessageApiLinkText: '[params.errorMessageApiLinkText]',
153
+ options: '[params.options]',
154
+ manualLinkUrl: '[params.manualLinkUrl]',
155
+ manualLinkText: '[params.manualLinkText]',
156
+ });
159
157
  });
160
158
  });
159
+ });
161
160
 
162
- it('renders "town or city" input field with expected parameters', () => {
163
- const faker = templateFaker();
164
- const inputSpy = faker.spy('input', { suppressOutput: true });
161
+ describe('GIVEN: Params: AddressField object', () => {
162
+ const faker = templateFaker();
163
+ const inputSpy = faker.spy('input', { suppressOutput: true });
165
164
 
166
- faker.renderComponent('address-input', {
167
- ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
168
- ...EXAMPLE_MANUAL_INPUT_FIELDS,
169
- isEditable: true,
165
+ faker.renderComponent('address-input', {
166
+ ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
167
+ ...EXAMPLE_MANUAL_INPUT_FIELDS,
168
+ isEditable: true,
169
+ });
170
+ describe('WHEN: organisation is provided', () => {
171
+ test('THEN: it renders "organisation" input field with expected parameters', () => {
172
+ expect(inputSpy.occurrences).toContainEqual({
173
+ id: 'address-input-example-id-organisation',
174
+ name: 'address-input-example-id-organisation',
175
+ classes: 'ons-js-address-organisation',
176
+ label: {
177
+ text: 'Organisation name',
178
+ },
179
+ value: 'Example Organisation',
180
+ width: '20@m',
181
+ error: { text: 'Server error: organisation name' },
182
+ });
170
183
  });
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' },
184
+ });
185
+ describe('WHEN: line1 is provided', () => {
186
+ test('THEN: it renders "address line 1" input field with expected parameters', () => {
187
+ expect(inputSpy.occurrences).toContainEqual({
188
+ id: 'address-input-example-id-line1',
189
+ name: 'address-input-example-id-line1',
190
+ classes: 'ons-js-address-line1',
191
+ label: {
192
+ text: 'Address line 1',
193
+ },
194
+ value: 'Flat 12345',
195
+ width: '20@m',
196
+ error: { text: 'Server error: address line 1' },
197
+ });
181
198
  });
182
199
  });
183
200
 
184
- it('renders "postcode" input field with expected parameters', () => {
185
- const faker = templateFaker();
186
- const inputSpy = faker.spy('input', { suppressOutput: true });
201
+ describe('WHEN: line2 is provided', () => {
202
+ test('THEN: it renders "address line 2" input field with expected parameters', () => {
203
+ expect(inputSpy.occurrences).toContainEqual({
204
+ id: 'address-input-example-id-line2',
205
+ name: 'address-input-example-id-line2',
206
+ classes: 'ons-js-address-line2',
207
+ label: {
208
+ text: 'Address line 2',
209
+ },
210
+ value: '12345 The Road',
211
+ width: '20@m',
212
+ error: { text: 'Server error: address line 2' },
213
+ });
214
+ });
215
+ });
187
216
 
188
- faker.renderComponent('address-input', {
189
- ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
190
- ...EXAMPLE_MANUAL_INPUT_FIELDS,
191
- isEditable: true,
217
+ describe('WHEN: town is provided', () => {
218
+ test('THEN: it renders "town or city" input field with expected parameters', () => {
219
+ expect(inputSpy.occurrences).toContainEqual({
220
+ id: 'address-input-example-id-town',
221
+ name: 'address-input-example-id-town',
222
+ classes: 'ons-js-address-town',
223
+ label: {
224
+ text: 'Town or city',
225
+ },
226
+ value: 'The Town',
227
+ error: { text: 'Server error: town or city' },
228
+ });
192
229
  });
230
+ });
193
231
 
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' },
232
+ describe('WHEN: postcode is provided', () => {
233
+ test('THEN: it renders "postcode" input field with expected parameters', () => {
234
+ expect(inputSpy.occurrences).toContainEqual({
235
+ id: 'address-input-example-id-postcode',
236
+ name: 'address-input-example-id-postcode',
237
+ classes: 'ons-js-address-postcode',
238
+ label: {
239
+ text: 'Postcode',
240
+ },
241
+ value: 'PO57 6ODE',
242
+ width: '7',
243
+ error: { text: 'Server error: postcode' },
244
+ });
204
245
  });
205
246
  });
206
247
  });
207
248
 
208
- describe('search button for no-js', () => {
209
- it('is not rendered when automatic search is disabled', () => {
249
+ describe('GIVEN: Params: searchButton for no-js', () => {
250
+ describe('WHEN: manualEntry parameter is set to true', () => {
210
251
  const $ = cheerio.load(
211
252
  renderComponent('address-input', {
212
253
  ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
@@ -215,11 +256,12 @@ describe('macro: address-input', () => {
215
256
  searchButton: 'Search for address',
216
257
  }),
217
258
  );
218
-
219
- expect($('.ons-js-address-search-btn').length).toBe(0);
259
+ test('THEN: search button does not render', () => {
260
+ expect($('.ons-js-address-search-btn').length).toBe(0);
261
+ });
220
262
  });
221
263
 
222
- it('marks field so that it is displayed only when there is no javascript', () => {
264
+ describe('WHEN: manualEntry parameter is not set', () => {
223
265
  const $ = cheerio.load(
224
266
  renderComponent('address-input', {
225
267
  ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
@@ -228,39 +270,35 @@ describe('macro: address-input', () => {
228
270
  }),
229
271
  );
230
272
 
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
- );
273
+ test('THEN: search button is displayed', () => {
274
+ expect($('.ons-js-address-search-btn').hasClass('ons-u-db-no-js_disabled')).toBe(true);
275
+ });
242
276
 
243
- expect($('.ons-js-address-search-btn').text().trim()).toBe('Search for address');
277
+ test('THEN: it renders search button with provided text', () => {
278
+ expect($('.ons-js-address-search-btn').text().trim()).toBe('Search for address');
279
+ });
244
280
  });
245
281
  });
246
282
 
247
- describe('hidden field for uprn', () => {
248
- it('renders hidden `input` component with expected parameters when `uprn.value` is not provided', () => {
283
+ describe('GIVEN: Params: uprn', () => {
284
+ describe('WHEN: uprn.value is not provided', () => {
249
285
  const faker = templateFaker();
250
286
  const inputSpy = faker.spy('input', { suppressOutput: true });
251
287
 
252
288
  faker.renderComponent('address-input', EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL);
253
289
 
254
- expect(inputSpy.occurrences).toContainEqual({
255
- id: 'address-input-example-id-uprn',
256
- classes: 'ons-js-hidden-uprn ons-u-d-no',
257
- type: 'hidden',
258
- name: 'address-input-example-id-uprn',
259
- value: '',
290
+ test('THEN: it renders hidden input component with expected parameters', () => {
291
+ expect(inputSpy.occurrences).toContainEqual({
292
+ id: 'address-input-example-id-uprn',
293
+ classes: 'ons-js-hidden-uprn ons-u-d-no',
294
+ type: 'hidden',
295
+ name: 'address-input-example-id-uprn',
296
+ value: '',
297
+ });
260
298
  });
261
299
  });
262
300
 
263
- it('renders hidden `input` component with expected parameters when `uprn.value` is provided', () => {
301
+ describe('WHEN: uprn.value is provided', () => {
264
302
  const faker = templateFaker();
265
303
  const inputSpy = faker.spy('input', { suppressOutput: true });
266
304
 
@@ -271,131 +309,20 @@ describe('macro: address-input', () => {
271
309
  },
272
310
  });
273
311
 
274
- expect(inputSpy.occurrences).toContainEqual({
275
- id: 'address-input-example-id-uprn',
276
- classes: 'ons-js-hidden-uprn ons-u-d-no',
277
- type: 'hidden',
278
- name: 'address-input-example-id-uprn',
279
- value: '[params.uprn.value]',
312
+ test('THEN: it renders hidden input component with expected parameters', () => {
313
+ expect(inputSpy.occurrences).toContainEqual({
314
+ id: 'address-input-example-id-uprn',
315
+ classes: 'ons-js-hidden-uprn ons-u-d-no',
316
+ type: 'hidden',
317
+ name: 'address-input-example-id-uprn',
318
+ value: '[params.uprn.value]',
319
+ });
280
320
  });
281
321
  });
282
322
  });
283
323
 
284
- describe('autosuggest search field', () => {
285
- it('is not shown when `manualEntry` is `true`', () => {
286
- const faker = templateFaker();
287
- const autosuggestSpy = faker.spy('autosuggest', { suppressOutput: true });
288
-
289
- faker.renderComponent('address-input', {
290
- ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
291
- manualEntry: true,
292
- });
293
-
294
- expect(autosuggestSpy.occurrences.length).toBe(0);
295
- });
296
-
297
- it('renders `autosuggest` component with expected parameters', () => {
298
- const faker = templateFaker();
299
- const autosuggestSpy = faker.spy('autosuggest', { suppressOutput: true });
300
-
301
- // Since `autosuggestSpy` suppresses output the values being tested below do not
302
- // need to represent real values. This test is only interested in verifying that
303
- // the provided values are being passed through to the `autosuggest` component.
304
- faker.renderComponent('address-input', {
305
- ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
306
- label: {
307
- text: '[params.label.text]',
308
- id: '[params.label.id]',
309
- },
310
- value: '[params.value]',
311
- attributes: '[params.attributes]',
312
- error: '[params.error]',
313
- name: '[params.name]',
314
- mutuallyExclusive: '[params.mutuallyExclusive]',
315
- apiDomain: '[params.apiDomain]',
316
- apiDomainBearerToken: '[params.apiDomainBearerToken]',
317
- apiManualQueryParams: '[params.apiManualQueryParams]',
318
- allowMultiple: '[params.allowMultiple]',
319
- mandatory: '[params.mandatory]',
320
- instructions: '[params.instructions]',
321
- autocomplete: '[params.autocomplete]',
322
- isEditable: '[params.isEditable]',
323
- ariaYouHaveSelected: '[params.ariaYouHaveSelected]',
324
- ariaMinChars: '[params.ariaMinChars]',
325
- minChars: '[params.minChars]',
326
- ariaResultsLabel: '[params.ariaResultsLabel]',
327
- ariaOneResult: '[params.ariaOneResult]',
328
- ariaNResults: '[params.ariaNResults]',
329
- ariaLimitedResults: '[params.ariaLimitedResults]',
330
- ariaGroupedResults: '[params.ariaGroupedResults]',
331
- groupCount: '[params.groupCount]',
332
- moreResults: '[params.moreResults]',
333
- tooManyResults: '[params.tooManyResults]',
334
- resultsTitle: '[params.resultsTitle]',
335
- resultsTitleId: '[params.resultsTitleId]',
336
- noResults: '[params.noResults]',
337
- typeMore: '[params.typeMore]',
338
- errorTitle: '[params.errorTitle]',
339
- errorMessageEnter: '[params.errorMessageEnter]',
340
- errorMessageSelect: '[params.errorMessageSelect]',
341
- errorMessageApi: '[params.errorMessageApi]',
342
- errorMessageApiLinkText: '[params.errorMessageApiLinkText]',
343
- options: '[params.options]',
344
- manualLinkUrl: '[params.manualLinkUrl]',
345
- manualLinkText: '[params.manualLinkText]',
346
- });
347
-
348
- expect(autosuggestSpy.occurrences[0]).toEqual({
349
- id: 'address-input-example-id-autosuggest',
350
- classes: 'ons-address-input__autosuggest ons-u-mb-no',
351
- input: {
352
- width: '50',
353
- label: {
354
- text: '[params.label.text]',
355
- id: '[params.label.id]',
356
- classes: 'ons-js-autosuggest-label',
357
- },
358
- value: '[params.value]',
359
- attributes: '[params.attributes]',
360
- error: '[params.error]',
361
- name: '[params.name]',
362
- mutuallyExclusive: '[params.mutuallyExclusive]',
363
- },
364
- externalInitialiser: true,
365
- apiDomain: '[params.apiDomain]',
366
- apiDomainBearerToken: '[params.apiDomainBearerToken]',
367
- apiManualQueryParams: '[params.apiManualQueryParams]',
368
- allowMultiple: '[params.allowMultiple]',
369
- mandatory: '[params.mandatory]',
370
- instructions: '[params.instructions]',
371
- autocomplete: '[params.autocomplete]',
372
- isEditable: '[params.isEditable]',
373
- ariaYouHaveSelected: '[params.ariaYouHaveSelected]',
374
- ariaMinChars: '[params.ariaMinChars]',
375
- minChars: '[params.minChars]',
376
- ariaOneResult: '[params.ariaOneResult]',
377
- ariaNResults: '[params.ariaNResults]',
378
- ariaLimitedResults: '[params.ariaLimitedResults]',
379
- ariaGroupedResults: '[params.ariaGroupedResults]',
380
- groupCount: '[params.groupCount]',
381
- moreResults: '[params.moreResults]',
382
- tooManyResults: '[params.tooManyResults]',
383
- resultsTitle: '[params.resultsTitle]',
384
- resultsTitleId: '[params.resultsTitleId]',
385
- noResults: '[params.noResults]',
386
- typeMore: '[params.typeMore]',
387
- errorTitle: '[params.errorTitle]',
388
- errorMessageEnter: '[params.errorMessageEnter]',
389
- errorMessageSelect: '[params.errorMessageSelect]',
390
- errorMessageApi: '[params.errorMessageApi]',
391
- errorMessageApiLinkText: '[params.errorMessageApiLinkText]',
392
- options: '[params.options]',
393
- manualLinkUrl: '[params.manualLinkUrl]',
394
- manualLinkText: '[params.manualLinkText]',
395
- });
396
- });
397
-
398
- it('renders manualLinkText` when provided with a default value for `manualLinkUrl`', () => {
324
+ describe('GIVEN: Params: manualLink', () => {
325
+ describe('WHEN: provided with a default value for manualLink', () => {
399
326
  const $ = cheerio.load(
400
327
  renderComponent('address-input', {
401
328
  ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
@@ -404,26 +331,18 @@ describe('macro: address-input', () => {
404
331
  }),
405
332
  );
406
333
 
407
- expect($('.ons-js-address-manual-btn').attr('href')).toBe('#0');
408
- expect($('.ons-js-address-manual-btn').text().trim()).toBe('Manually enter address');
409
- });
410
-
411
- it('renders `manualLinkText` with `manualLinkUrl` when provided', () => {
412
- const $ = cheerio.load(
413
- renderComponent('address-input', {
414
- ...EXAMPLE_AUTOSUGGEST_ADDRESS_MINIMAL,
415
- manualLinkUrl: 'https://example.com/edit-address',
416
- manualLinkText: 'Manually enter address',
417
- }),
418
- );
334
+ test('THEN: it renders the manual link with the provided url', () => {
335
+ expect($('.ons-js-address-manual-btn').attr('href')).toBe('#0');
336
+ });
419
337
 
420
- expect($('.ons-js-address-manual-btn').attr('href')).toBe('https://example.com/edit-address');
421
- expect($('.ons-js-address-manual-btn').text().trim()).toBe('Manually enter address');
338
+ test('THEN: it renders the manual link with the provided text', () => {
339
+ expect($('.ons-js-address-manual-btn').text().trim()).toBe('Manually enter address');
340
+ });
422
341
  });
423
342
  });
424
343
 
425
- describe('fieldset', () => {
426
- it('does not render `fieldset` component when `dontWrap` is `true`', () => {
344
+ describe('GIVEN: Params: dontWrap', () => {
345
+ describe('WHEN: dontWrap is true', () => {
427
346
  const faker = templateFaker();
428
347
  const fieldsetSpy = faker.spy('fieldset', { suppressOutput: true });
429
348
 
@@ -432,10 +351,12 @@ describe('macro: address-input', () => {
432
351
  dontWrap: true,
433
352
  });
434
353
 
435
- expect(fieldsetSpy.occurrences.length).toBe(0);
354
+ test('THEN: it does not render fieldset component', () => {
355
+ expect(fieldsetSpy.occurrences.length).toBe(0);
356
+ });
436
357
  });
437
358
 
438
- it('renders `fieldset` component with expected parameters', () => {
359
+ describe('WHEN: dontWrap is not set', () => {
439
360
  const faker = templateFaker();
440
361
  const fieldsetSpy = faker.spy('fieldset', { suppressOutput: true });
441
362
 
@@ -445,11 +366,13 @@ describe('macro: address-input', () => {
445
366
  legendClasses: 'extra-legend-class',
446
367
  });
447
368
 
448
- expect(fieldsetSpy.occurrences[0]).toEqual({
449
- id: 'address-input-example-id',
450
- classes: 'extra-field-class',
451
- legend: 'What is the address?',
452
- legendClasses: 'extra-legend-class',
369
+ test('THEN: it renders the fieldset component with expected parameters', () => {
370
+ expect(fieldsetSpy.occurrences[0]).toEqual({
371
+ id: 'address-input-example-id',
372
+ classes: 'extra-field-class',
373
+ legend: 'What is the address?',
374
+ legendClasses: 'extra-legend-class',
375
+ });
453
376
  });
454
377
  });
455
378
  });