@ons/design-system 72.1.0 → 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 (40) 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.spec.js +373 -184
  8. package/components/back-to-top/back-to-top.dom.js +4 -4
  9. package/components/back-to-top/back-to-top.js +1 -1
  10. package/components/browser-banner/_macro.spec.js +11 -11
  11. package/components/button/_macro.njk +1 -1
  12. package/components/button/_macro.spec.js +405 -351
  13. package/components/button/example-button-group.njk +1 -0
  14. package/components/checkboxes/_checkbox.scss +3 -3
  15. package/components/details/_details.scss +1 -2
  16. package/components/details/example-details-open.njk +10 -0
  17. package/components/external-link/_macro.spec.js +66 -69
  18. package/components/external-link/_test_examples.js +4 -0
  19. package/components/feedback/_macro.spec.js +109 -80
  20. package/components/feedback/_test_examples.js +17 -0
  21. package/components/field/_macro.spec.js +106 -69
  22. package/components/section-navigation/_macro.njk +9 -6
  23. package/components/table-of-contents/_macro.njk +3 -3
  24. package/components/table-of-contents/_macro.spec.js +3 -3
  25. package/components/table-of-contents/{_toc.scss → _table-of-contents.scss} +1 -1
  26. package/components/table-of-contents/table-of-contents.dom.js +13 -0
  27. package/components/table-of-contents/{toc.js → table-of-contents.js} +4 -4
  28. package/components/table-of-contents/{toc.spec.js → table-of-contents.spec.js} +2 -2
  29. package/components/tabs/_tabs.scss +10 -11
  30. package/components/tabs/tabs.js +3 -3
  31. package/components/timeout-modal/timeout-modal.spec.js +1 -1
  32. package/css/main.css +1 -1
  33. package/js/main.js +1 -1
  34. package/package.json +1 -1
  35. package/scripts/main.es5.js +1 -1
  36. package/scripts/main.js +1 -1
  37. package/scss/main.scss +1 -1
  38. package/scss/utilities/_margin.scss +4 -0
  39. package/scss/utilities/_padding.scss +4 -0
  40. package/components/table-of-contents/toc.dom.js +0 -13
@@ -5,136 +5,292 @@ import * as cheerio from 'cheerio';
5
5
  import axe from '../../tests/helpers/axe';
6
6
  import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
7
7
 
8
- const EXAMPLE_AUTOSUGGEST = {
9
- id: 'country-of-birth',
10
- input: {
11
- label: {
12
- text: 'Current name of country',
13
- description: 'Enter your own answer or select from suggestions',
14
- id: 'country-of-birth-label',
15
- classes: 'extra-label-class',
16
- },
17
- autocomplete: 'off',
18
- },
19
- instructions: 'Use up and down keys to navigate.',
20
- ariaYouHaveSelected: 'You have selected',
21
- ariaMinChars: 'Enter 3 or more characters for suggestions.',
22
- minChars: 2,
23
- ariaResultsLabel: 'Country suggestions',
24
- ariaOneResult: 'There is one suggestion available.',
25
- ariaNResults: 'There are {n} suggestions available.',
26
- ariaLimitedResults: 'Type more characters to improve your search',
27
- moreResults: 'Continue entering to improve suggestions',
28
- resultsTitle: 'Suggestions',
29
- resultsTitleId: 'country-of-birth-suggestions',
30
- autosuggestData: '/examples/data/country-of-birth.json',
31
- noResults: 'No suggestions found. You can enter your own answer',
32
- typeMore: 'Continue entering to get suggestions',
33
- };
34
-
35
- const EXAMPLE_AUTOSUGGEST_WITH_RESULTS_THRESHOLD = {
36
- ...EXAMPLE_AUTOSUGGEST,
37
- resultsThreshold: 0.5,
38
- };
39
-
40
- describe('macro: autosuggest', () => {
41
- it('passes jest-axe checks', async () => {
42
- const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
43
-
44
- const results = await axe($.html());
45
- expect(results).toHaveNoViolations();
8
+ import { EXAMPLE_AUTOSUGGEST } from './_test-examples';
9
+
10
+ describe('FOR: Macro: Autosuggest', () => {
11
+ describe('GIVEN: Params: Required', () => {
12
+ describe('WHEN: required params are provided', () => {
13
+ const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
14
+
15
+ test('THEN: it passes jest-axe checks', async () => {
16
+ const results = await axe($.html());
17
+ expect(results).toHaveNoViolations();
18
+ });
19
+
20
+ test('THEN: it has a special class that indicates the component should initialise itself', () => {
21
+ expect($('.ons-autosuggest').hasClass('ons-js-autosuggest')).toBe(true);
22
+ });
23
+
24
+ test('THEN: it has expected id on container element', () => {
25
+ expect($('.ons-autosuggest').attr('id')).toBe('country-of-birth-container');
26
+ });
27
+
28
+ test('THEN: it has data-aria-limited-results with expected message', () => {
29
+ expect($('.ons-autosuggest').attr('data-aria-limited-results')).toBe('Type more characters to improve your search');
30
+ });
31
+
32
+ test('THEN: it has data-aria-min-chars with expected message', () => {
33
+ expect($('.ons-autosuggest').attr('data-aria-min-chars')).toBe('Enter 3 or more characters for suggestions.');
34
+ });
35
+
36
+ test('THEN: it has data-aria-n-results with expected message', () => {
37
+ expect($('.ons-autosuggest').attr('data-aria-n-results')).toBe('There are {n} suggestions available.');
38
+ });
39
+
40
+ test('THEN: it has data-aria-one-result with expected message', () => {
41
+ expect($('.ons-autosuggest').attr('data-aria-one-result')).toBe('There is one suggestion available.');
42
+ });
43
+
44
+ test('THEN: it has data-aria-you-have-selected with expected message', () => {
45
+ expect($('.ons-autosuggest').attr('data-aria-you-have-selected')).toBe('You have selected');
46
+ });
47
+
48
+ test('THEN: it has data-autosuggest-data pointing to correct URL', () => {
49
+ expect($('.ons-autosuggest').attr('data-autosuggest-data')).toBe('/examples/data/country-of-birth.json');
50
+ });
51
+
52
+ test('THEN: it has data-instructions with expected instructions', () => {
53
+ expect($('.ons-autosuggest').attr('data-instructions')).toBe('Use up and down keys to navigate.');
54
+ });
55
+
56
+ test('THEN: it has data-more-results with expected message', () => {
57
+ expect($('.ons-autosuggest').attr('data-more-results')).toBe('Continue entering to improve suggestions');
58
+ });
59
+
60
+ test('THEN: it has data-no-results with expected message', () => {
61
+ expect($('.ons-autosuggest').attr('data-no-results')).toBe('No suggestions found. You can enter your own answer');
62
+ });
63
+
64
+ test('THEN: it has data-results-title with expected title', () => {
65
+ expect($('.ons-autosuggest').attr('data-results-title')).toBe('Suggestions');
66
+ });
67
+
68
+ test('THEN: it has data-type-more with expected message', () => {
69
+ expect($('.ons-autosuggest').attr('data-type-more')).toBe('Continue entering to get suggestions');
70
+ });
71
+
72
+ test('THEN: it has the expected id on the results title element', () => {
73
+ expect($('.ons-autosuggest__results-title').attr('id')).toBe('country-of-birth-suggestions');
74
+ });
75
+
76
+ test('THEN: it renders the results title div with the provided title text', () => {
77
+ expect($('.ons-autosuggest__results-title').text().trim()).toBe('Suggestions');
78
+ });
79
+
80
+ test('THEN: it has the expected id on the results list element', () => {
81
+ expect($('.ons-autosuggest__listbox').attr('id')).toBe('country-of-birth-listbox');
82
+ });
83
+
84
+ test('THEN: it renders the results list element with the title attribute set to the provided title text', () => {
85
+ expect($('.ons-autosuggest__listbox').attr('title')).toBe('Suggestions');
86
+ });
87
+
88
+ test('THEN: it renders instructions with the expected id', () => {
89
+ expect($('.ons-autosuggest__instructions').attr('id')).toBe('country-of-birth-instructions');
90
+ });
91
+
92
+ test('THEN: it renders the instructions with the provided instructions text', () => {
93
+ expect($('.ons-autosuggest__instructions').text().trim()).toBe('Use up and down keys to navigate.');
94
+ });
95
+
96
+ test('THEN: the aria-atomic attribute is set to true on the status container', () => {
97
+ expect($('.ons-autosuggest__status').attr('aria-atomic')).toBe('true');
98
+ });
99
+
100
+ test('THEN: it has no value set for data-min-chars', () => {
101
+ expect($('.ons-autosuggest').attr('data-min-chars')).toBe('');
102
+ });
103
+
104
+ test('THEN: it has no value set for data-result-threshold"', () => {
105
+ expect($('.ons-autosuggest').attr('data-result-threshold')).toBeUndefined();
106
+ });
107
+ });
46
108
  });
47
109
 
48
- it('has expected id on container element', () => {
49
- const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
110
+ describe('GIVEN: Params: minChars', () => {
111
+ describe('WHEN: minChars is provided', () => {
112
+ const $ = cheerio.load(
113
+ renderComponent('autosuggest', {
114
+ ...EXAMPLE_AUTOSUGGEST,
115
+ minChars: 2,
116
+ }),
117
+ );
50
118
 
51
- expect($('.ons-autosuggest').attr('id')).toBe('country-of-birth-container');
119
+ test('THEN: it has data-min-chars set to "2"', () => {
120
+ expect($('.ons-autosuggest').attr('data-min-chars')).toBe('2');
121
+ });
122
+ });
52
123
  });
53
124
 
54
- it('has the provided data attributes', () => {
55
- const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST_WITH_RESULTS_THRESHOLD));
56
-
57
- const $element = $('.ons-autosuggest');
58
- expect($element.attr('data-allow-multiple')).toBeUndefined();
59
- expect($element.attr('data-min-chars')).toBe('2');
60
- expect($element.attr('data-aria-limited-results')).toBe('Type more characters to improve your search');
61
- expect($element.attr('data-aria-min-chars')).toBe('Enter 3 or more characters for suggestions.');
62
- expect($element.attr('data-aria-n-results')).toBe('There are {n} suggestions available.');
63
- expect($element.attr('data-aria-one-result')).toBe('There is one suggestion available.');
64
- expect($element.attr('data-aria-you-have-selected')).toBe('You have selected');
65
- expect($element.attr('data-autosuggest-data')).toBe('/examples/data/country-of-birth.json');
66
- expect($element.attr('data-instructions')).toBe('Use up and down keys to navigate.');
67
- expect($element.attr('data-more-results')).toBe('Continue entering to improve suggestions');
68
- expect($element.attr('data-no-results')).toBe('No suggestions found. You can enter your own answer');
69
- expect($element.attr('data-results-title')).toBe('Suggestions');
70
- expect($element.attr('data-type-more')).toBe('Continue entering to get suggestions');
71
- expect($element.attr('data-result-threshold')).toBe('0.5');
125
+ describe('GIVEN: Params: allowMultiple', () => {
126
+ describe('WHEN: allowMultiple is true', () => {
127
+ const $ = cheerio.load(
128
+ renderComponent('autosuggest', {
129
+ ...EXAMPLE_AUTOSUGGEST,
130
+ allowMultiple: true,
131
+ }),
132
+ );
133
+ test('THEN: it has the data-allow-multiple attribute set to true on the container element', () => {
134
+ expect($('.ons-autosuggest').attr('data-allow-multiple')).toBe('true');
135
+ });
136
+ });
137
+
138
+ describe('WHEN: allowMultiple is false', () => {
139
+ const $ = cheerio.load(
140
+ renderComponent('autosuggest', {
141
+ ...EXAMPLE_AUTOSUGGEST,
142
+ allowMultiple: false,
143
+ }),
144
+ );
145
+ test('THEN: it does not have the data-allow-multiple attribute on the container element', () => {
146
+ expect($('.ons-autosuggest').attr('data-allow-multiple')).toBeUndefined();
147
+ });
148
+ });
149
+
150
+ describe('WHEN: allowMultiple is not set', () => {
151
+ const $ = cheerio.load(
152
+ renderComponent('autosuggest', {
153
+ ...EXAMPLE_AUTOSUGGEST,
154
+ }),
155
+ );
156
+ test('THEN: it does not have the data-allow-multiple attribute', () => {
157
+ expect($('.ons-autosuggest').attr('data-allow-multiple')).toBeUndefined();
158
+ });
159
+ });
72
160
  });
73
161
 
74
- it('has the `data-allow-multiple` attribute when `allowMultiple` is `true`', () => {
75
- const $ = cheerio.load(
76
- renderComponent('autosuggest', {
77
- ...EXAMPLE_AUTOSUGGEST,
78
- allowMultiple: true,
79
- }),
80
- );
162
+ describe('GIVEN: Params: externalInitialiser', () => {
163
+ describe('WHEN: externalInitialiser is true', () => {
164
+ const $ = cheerio.load(
165
+ renderComponent('autosuggest', {
166
+ ...EXAMPLE_AUTOSUGGEST,
167
+ externalInitialiser: true,
168
+ }),
169
+ );
170
+
171
+ test('THEN: it does not have the ons-js-autosuggest class that indicates the component should initialise itself', () => {
172
+ expect($('.ons-autosuggest').hasClass('ons-js-autosuggest')).toBe(false);
173
+ });
174
+ });
81
175
 
82
- expect($('.ons-autosuggest').attr('data-allow-multiple')).toBe('true');
176
+ describe('WHEN: externalInitialiser is false', () => {
177
+ const $ = cheerio.load(
178
+ renderComponent('autosuggest', {
179
+ ...EXAMPLE_AUTOSUGGEST,
180
+ externalInitialiser: false,
181
+ }),
182
+ );
183
+
184
+ test('THEN: it has the ons-js-autosuggest class that indicates the component should initialise itself', () => {
185
+ expect($('.ons-autosuggest').hasClass('ons-js-autosuggest')).toBe(true);
186
+ });
187
+ });
83
188
  });
84
189
 
85
- it('has a special class that indicates the component should initialise itself', () => {
86
- const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
190
+ describe('GIVEN: Params: isEditable', () => {
191
+ describe('WHEN: isEditable is false', () => {
192
+ const $ = cheerio.load(
193
+ renderComponent('autosuggest', {
194
+ ...EXAMPLE_AUTOSUGGEST,
195
+ isEditable: false,
196
+ }),
197
+ );
198
+
199
+ test('THEN: it has the ons-js-address-not-editable class to indicate that component is not editable', () => {
200
+ expect($('.ons-autosuggest').hasClass('ons-js-address-not-editable')).toBe(true);
201
+ });
202
+ });
203
+
204
+ describe('WHEN: isEditable is true', () => {
205
+ const $ = cheerio.load(
206
+ renderComponent('autosuggest', {
207
+ ...EXAMPLE_AUTOSUGGEST,
208
+ isEditable: true,
209
+ }),
210
+ );
87
211
 
88
- expect($('.ons-autosuggest').hasClass('ons-js-autosuggest')).toBe(true);
212
+ test('THEN: it has the ons-js-address-not-editable class to indicate that component is not editable', () => {
213
+ expect($('.ons-autosuggest').hasClass('ons-js-address-not-editable')).toBe(false);
214
+ });
215
+ });
89
216
  });
90
217
 
91
- it('does not have a special class when the component has an external initialiser', () => {
92
- const $ = cheerio.load(
93
- renderComponent('autosuggest', {
94
- ...EXAMPLE_AUTOSUGGEST,
95
- externalInitialiser: true,
96
- }),
97
- );
218
+ describe('GIVEN: Params: mandatory', () => {
219
+ describe('WHEN: mandatory is true', () => {
220
+ const $ = cheerio.load(
221
+ renderComponent('autosuggest', {
222
+ ...EXAMPLE_AUTOSUGGEST,
223
+ mandatory: true,
224
+ }),
225
+ );
98
226
 
99
- expect($('.ons-autosuggest').hasClass('ons-js-autosuggest')).toBe(false);
227
+ test('THEN: it has the ons-js-address-mandatory class to indicate that component input is mandatory', () => {
228
+ expect($('.ons-autosuggest').hasClass('ons-js-address-mandatory')).toBe(true);
229
+ });
230
+ });
231
+
232
+ describe('WHEN: mandatory is false', () => {
233
+ const $ = cheerio.load(
234
+ renderComponent('autosuggest', {
235
+ ...EXAMPLE_AUTOSUGGEST,
236
+ mandatory: false,
237
+ }),
238
+ );
239
+
240
+ test('THEN: it has the ons-js-address-mandatory class to indicate that component input is mandatory', () => {
241
+ expect($('.ons-autosuggest').hasClass('ons-js-address-mandatory')).toBe(false);
242
+ });
243
+ });
100
244
  });
101
245
 
102
- it('has special class to indicate that component is not editable', () => {
103
- const $ = cheerio.load(
104
- renderComponent('autosuggest', {
105
- ...EXAMPLE_AUTOSUGGEST,
106
- isEditable: false,
107
- }),
108
- );
246
+ describe('GIVEN: Params: containerClasses', () => {
247
+ describe('WHEN: containerClasses is provided', () => {
248
+ const $ = cheerio.load(
249
+ renderComponent('autosuggest', {
250
+ ...EXAMPLE_AUTOSUGGEST,
251
+ containerClasses: 'extra-class another-extra-class',
252
+ }),
253
+ );
109
254
 
110
- expect($('.ons-autosuggest').hasClass('ons-js-address-not-editable')).toBe(true);
255
+ test('THEN: it has additionally provided container style classes', () => {
256
+ expect($('.ons-autosuggest').hasClass('extra-class')).toBe(true);
257
+ expect($('.ons-autosuggest').hasClass('another-extra-class')).toBe(true);
258
+ });
259
+ });
111
260
  });
112
261
 
113
- it('has special class to indicate that component input is mandatory', () => {
114
- const $ = cheerio.load(
115
- renderComponent('autosuggest', {
116
- ...EXAMPLE_AUTOSUGGEST,
117
- mandatory: true,
118
- }),
119
- );
262
+ describe('GIVEN: Params: resultsThreshold', () => {
263
+ describe('WHEN: resultsThreshold is provided', () => {
264
+ const $ = cheerio.load(
265
+ renderComponent('autosuggest', {
266
+ ...EXAMPLE_AUTOSUGGEST,
267
+ resultsThreshold: 0.5,
268
+ }),
269
+ );
120
270
 
121
- expect($('.ons-autosuggest').hasClass('ons-js-address-mandatory')).toBe(true);
271
+ test('THEN: it has data-result-threshold set to "0.5"', () => {
272
+ expect($('.ons-autosuggest').attr('data-result-threshold')).toBe('0.5');
273
+ });
274
+ });
122
275
  });
123
276
 
124
- it('has additionally provided container style classes', () => {
125
- const $ = cheerio.load(
126
- renderComponent('autosuggest', {
127
- ...EXAMPLE_AUTOSUGGEST,
128
- containerClasses: 'extra-class another-extra-class',
129
- }),
130
- );
277
+ describe('GIVEN: Params: language', () => {
278
+ describe('WHEN: language is provided', () => {
279
+ const $ = cheerio.load(
280
+ renderComponent('autosuggest', {
281
+ ...EXAMPLE_AUTOSUGGEST,
282
+ language: 'en-gb',
283
+ }),
284
+ );
131
285
 
132
- expect($('.ons-autosuggest').hasClass('extra-class')).toBe(true);
133
- expect($('.ons-autosuggest').hasClass('another-extra-class')).toBe(true);
286
+ test('THEN: it has language set to "en-gb"', () => {
287
+ expect($('.ons-autosuggest').attr('data-lang')).toBe('en-gb');
288
+ });
289
+ });
134
290
  });
135
291
 
136
- describe('input', () => {
137
- it('uses the `input` component with the expected parameters', () => {
292
+ describe('GIVEN: Params: input', () => {
293
+ describe('WHEN: input param is provided', () => {
138
294
  const faker = templateFaker();
139
295
  const inputSpy = faker.spy('input');
140
296
 
@@ -197,106 +353,139 @@ describe('macro: autosuggest', () => {
197
353
  },
198
354
  });
199
355
 
200
- expect(inputSpy.occurrences[0]).toHaveProperty('id', 'country-of-birth');
201
- expect(inputSpy.occurrences[0]).toHaveProperty('type', 'text');
202
- expect(inputSpy.occurrences[0]).toHaveProperty('classes', 'ons-js-autosuggest-input extra-class another-extra-class');
203
- expect(inputSpy.occurrences[0]).toHaveProperty('width', '7');
204
- expect(inputSpy.occurrences[0]).toHaveProperty('label.text', 'Current name of country');
205
- expect(inputSpy.occurrences[0]).toHaveProperty('label.description', 'Enter your own answer or select from suggestions');
206
- expect(inputSpy.occurrences[0]).toHaveProperty('label.id', 'country-of-birth-label');
207
- expect(inputSpy.occurrences[0]).toHaveProperty('label.classes', 'extra-label-class');
208
- expect(inputSpy.occurrences[0]).toHaveProperty('autocomplete', 'off');
209
- expect(inputSpy.occurrences[0]).toHaveProperty('legend', 'this is a legend');
210
- expect(inputSpy.occurrences[0]).toHaveProperty('legendClasses', 'legend-extra-class');
211
- expect(inputSpy.occurrences[0]).toHaveProperty('value', 'abc');
212
- expect(inputSpy.occurrences[0]).toHaveProperty('attributes.a', 42);
213
- expect(inputSpy.occurrences[0]).toHaveProperty('error.id', 'error-id');
214
- expect(inputSpy.occurrences[0]).toHaveProperty('error.text', 'An error occurred.');
215
- expect(inputSpy.occurrences[0]).toHaveProperty('mutuallyExclusive', null);
216
- expect(inputSpy.occurrences[0]).toHaveProperty('accessiblePlaceholder', true);
217
- expect(inputSpy.occurrences[0]).toHaveProperty('name', 'test-params');
218
- expect(typeof inputSpy.occurrences[0].autosuggestResults).toBe('string');
219
- expect(inputSpy.occurrences[0]).toHaveProperty('minLength', 1);
220
- expect(inputSpy.occurrences[0]).toHaveProperty('maxLength', 10);
221
- expect(inputSpy.occurrences[0]).toHaveProperty('prefix.title', 'Great British Pounds');
222
- expect(inputSpy.occurrences[0]).toHaveProperty('prefix.text', '£');
223
- expect(inputSpy.occurrences[0]).toHaveProperty('prefix.id', 'gbp-prefix');
224
- expect(inputSpy.occurrences[0]).toHaveProperty('suffix.title', 'Percentage of total');
225
- expect(inputSpy.occurrences[0]).toHaveProperty('suffix.text', '%');
226
- expect(inputSpy.occurrences[0]).toHaveProperty('suffix.id', 'percentage-suffix');
227
- expect(inputSpy.occurrences[0]).toHaveProperty('fieldId', 'field-id-test');
228
- expect(inputSpy.occurrences[0]).toHaveProperty('fieldClasses', 'field-class-test');
229
- expect(inputSpy.occurrences[0]).toHaveProperty('dontWrap', true);
230
- expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.limit', 200);
231
- expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountSingular', 'You have {x} character remaining');
232
- expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountPlural', 'You have {x} characters remaining');
233
- expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountOverLimitSingular', '{x} character too many');
234
- expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountOverLimitPlural', '{x} characters too many');
235
- expect(inputSpy.occurrences[0]).toHaveProperty('searchButton.text', 'Search');
236
- expect(inputSpy.occurrences[0]).toHaveProperty('postTextboxLinkText', 'Post textbox link text');
237
- expect(inputSpy.occurrences[0]).toHaveProperty('postTextboxLinkUrl', 'https://www.ons.gov.uk');
238
- expect(inputSpy.occurrences[0]).toHaveProperty('listeners.click', "function() { console.log('click'); }");
239
- });
240
- });
356
+ test('THEN: id is passed through to the input component', () => {
357
+ expect(inputSpy.occurrences[0]).toHaveProperty('id', 'country-of-birth');
358
+ });
241
359
 
242
- describe('autosuggest results', () => {
243
- it('is rendered `mutallyExclusive` parameter is not defined', () => {
244
- const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
360
+ test('THEN: type is passed through to the input component', () => {
361
+ expect(inputSpy.occurrences[0]).toHaveProperty('type', 'text');
362
+ });
245
363
 
246
- expect($('.ons-autosuggest__results').length).toBe(1);
247
- });
364
+ test('THEN: classes are passed through to the input component', () => {
365
+ expect(inputSpy.occurrences[0]).toHaveProperty('classes', 'ons-js-autosuggest-input extra-class another-extra-class');
366
+ });
248
367
 
249
- it('is not rendered when `mutallyExclusive` parameter is defined', () => {
250
- const $ = cheerio.load(
251
- renderComponent('autosuggest', {
252
- ...EXAMPLE_AUTOSUGGEST,
253
- mutuallyExclusive: { fakeParam: true },
254
- }),
255
- );
368
+ test('THEN: width is passed through to the input component', () => {
369
+ expect(inputSpy.occurrences[0]).toHaveProperty('width', '7');
370
+ });
256
371
 
257
- expect($('.ons-autosuggest__results').length).toBe(0);
258
- });
372
+ test('THEN: label is passed through to the input component', () => {
373
+ expect(inputSpy.occurrences[0]).toHaveProperty('label.text', 'Current name of country');
374
+ expect(inputSpy.occurrences[0]).toHaveProperty('label.description', 'Enter your own answer or select from suggestions');
375
+ expect(inputSpy.occurrences[0]).toHaveProperty('label.id', 'country-of-birth-label');
376
+ expect(inputSpy.occurrences[0]).toHaveProperty('label.classes', 'extra-label-class');
377
+ });
259
378
 
260
- it('renders div with the provided title identifier', () => {
261
- const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
379
+ test('THEN: autocomplete is passed through to the input component', () => {
380
+ expect(inputSpy.occurrences[0]).toHaveProperty('autocomplete', 'off');
381
+ });
262
382
 
263
- expect($('.ons-autosuggest__results-title').attr('id')).toBe('country-of-birth-suggestions');
264
- });
383
+ test('THEN: legend is passed through to the input component', () => {
384
+ expect(inputSpy.occurrences[0]).toHaveProperty('legend', 'this is a legend');
385
+ expect(inputSpy.occurrences[0]).toHaveProperty('legendClasses', 'legend-extra-class');
386
+ });
265
387
 
266
- it('renders div with the provided title text', () => {
267
- const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
388
+ test('THEN: value is passed through to the input component', () => {
389
+ expect(inputSpy.occurrences[0]).toHaveProperty('value', 'abc');
390
+ });
268
391
 
269
- expect($('.ons-autosuggest__results-title').text().trim()).toBe('Suggestions');
270
- });
392
+ test('THEN: custom attribute "a" is passed through to the input component', () => {
393
+ expect(inputSpy.occurrences[0]).toHaveProperty('attributes.a', 42);
394
+ });
271
395
 
272
- it('renders list with a generated identifier', () => {
273
- const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
396
+ test('THEN: error is passed through to the input component', () => {
397
+ expect(inputSpy.occurrences[0]).toHaveProperty('error.id', 'error-id');
398
+ expect(inputSpy.occurrences[0]).toHaveProperty('error.text', 'An error occurred.');
399
+ });
274
400
 
275
- expect($('.ons-autosuggest__listbox').attr('id')).toBe('country-of-birth-listbox');
276
- });
401
+ test('THEN: mutuallyExclusive is passed as null to the input component', () => {
402
+ expect(inputSpy.occurrences[0]).toHaveProperty('mutuallyExclusive', null);
403
+ });
277
404
 
278
- it('renders an accessible list', () => {
279
- const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
405
+ test('THEN: accessiblePlaceholder is passed as true to the input component', () => {
406
+ expect(inputSpy.occurrences[0]).toHaveProperty('accessiblePlaceholder', true);
407
+ });
280
408
 
281
- expect($('.ons-autosuggest__listbox').attr('title')).toBe('Suggestions');
282
- });
409
+ test('THEN: name is passed through to the input component', () => {
410
+ expect(inputSpy.occurrences[0]).toHaveProperty('name', 'test-params');
411
+ });
283
412
 
284
- it('renders instructions with a generated identifier', () => {
285
- const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
413
+ test('THEN: autosuggestResults type is string', () => {
414
+ expect(typeof inputSpy.occurrences[0].autosuggestResults).toBe('string');
415
+ });
416
+
417
+ test('THEN: minLength is passed through to the input component', () => {
418
+ expect(inputSpy.occurrences[0]).toHaveProperty('minLength', 1);
419
+ });
286
420
 
287
- expect($('.ons-autosuggest__instructions').attr('id')).toBe('country-of-birth-instructions');
421
+ test('THEN: maxLength is passed through to the input component', () => {
422
+ expect(inputSpy.occurrences[0]).toHaveProperty('maxLength', 10);
423
+ });
424
+
425
+ test('THEN: prefix is passed through to the input component', () => {
426
+ expect(inputSpy.occurrences[0]).toHaveProperty('prefix.title', 'Great British Pounds');
427
+ expect(inputSpy.occurrences[0]).toHaveProperty('prefix.text', '£');
428
+ expect(inputSpy.occurrences[0]).toHaveProperty('prefix.id', 'gbp-prefix');
429
+ });
430
+
431
+ test('THEN: suffix is passed through to the input component', () => {
432
+ expect(inputSpy.occurrences[0]).toHaveProperty('suffix.title', 'Percentage of total');
433
+ expect(inputSpy.occurrences[0]).toHaveProperty('suffix.text', '%');
434
+ expect(inputSpy.occurrences[0]).toHaveProperty('suffix.id', 'percentage-suffix');
435
+ });
436
+
437
+ test('THEN: field is passed through to the input component', () => {
438
+ expect(inputSpy.occurrences[0]).toHaveProperty('fieldId', 'field-id-test');
439
+ expect(inputSpy.occurrences[0]).toHaveProperty('fieldClasses', 'field-class-test');
440
+ });
441
+
442
+ test('THEN: dontWrap is passed as true to the input component', () => {
443
+ expect(inputSpy.occurrences[0]).toHaveProperty('dontWrap', true);
444
+ });
445
+
446
+ test('THEN: charCheckLimit is passed through to the input component', () => {
447
+ expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.limit', 200);
448
+ expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountSingular', 'You have {x} character remaining');
449
+ expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountPlural', 'You have {x} characters remaining');
450
+ expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountOverLimitSingular', '{x} character too many');
451
+ expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountOverLimitPlural', '{x} characters too many');
452
+ });
453
+
454
+ test('THEN: searchButton text is passed through to the input component', () => {
455
+ expect(inputSpy.occurrences[0]).toHaveProperty('searchButton.text', 'Search');
456
+ });
457
+
458
+ test('THEN: postTextboxLinkText is passed through to the input component', () => {
459
+ expect(inputSpy.occurrences[0]).toHaveProperty('postTextboxLinkText', 'Post textbox link text');
460
+ expect(inputSpy.occurrences[0]).toHaveProperty('postTextboxLinkUrl', 'https://www.ons.gov.uk');
461
+ });
462
+
463
+ test('THEN: click listener is correctly assigned', () => {
464
+ expect(inputSpy.occurrences[0]).toHaveProperty('listeners.click', "function() { console.log('click'); }");
465
+ });
288
466
  });
467
+ });
289
468
 
290
- it('adds aria-atomic=true value to status container', () => {
469
+ describe('GIVEN: Params: mutuallyExclusive', () => {
470
+ describe('WHEN: mutuallyExclusive parameter is not defined', () => {
291
471
  const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
292
472
 
293
- expect($('.ons-autosuggest__status').attr('aria-atomic')).toBe('true');
473
+ test('THEN: autosuggest results are rendered', () => {
474
+ expect($('.ons-autosuggest__results').length).toBe(1);
475
+ });
294
476
  });
295
477
 
296
- it('renders instructions text', () => {
297
- const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
478
+ describe('WHEN: mutuallyExclusive parameter is defined', () => {
479
+ const $ = cheerio.load(
480
+ renderComponent('autosuggest', {
481
+ ...EXAMPLE_AUTOSUGGEST,
482
+ mutuallyExclusive: { fakeParam: true },
483
+ }),
484
+ );
298
485
 
299
- expect($('.ons-autosuggest__instructions').text().trim()).toBe('Use up and down keys to navigate.');
486
+ test('THEN: autosuggest results are not rendered', () => {
487
+ expect($('.ons-autosuggest__results').length).toBe(0);
488
+ });
300
489
  });
301
490
  });
302
491
  });