@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.
- package/README.md +1 -1
- package/components/accordion/_macro.spec.js +2 -2
- package/components/address-input/_macro.spec.js +245 -322
- package/components/address-input/autosuggest.address.spec.js +16 -14
- package/components/address-output/_macro.spec.js +121 -74
- package/components/address-output/_test_examples.js +8 -0
- package/components/autosuggest/_macro.njk +1 -0
- package/components/autosuggest/_macro.spec.js +373 -178
- package/components/autosuggest/autosuggest.spec.js +3 -1
- package/components/autosuggest/autosuggest.ui.js +39 -10
- package/components/autosuggest/example-autosuggest-country.njk +2 -1
- package/components/autosuggest/fuse-config.js +7 -2
- package/components/back-to-top/back-to-top.dom.js +4 -4
- package/components/back-to-top/back-to-top.js +1 -1
- package/components/browser-banner/_macro.spec.js +11 -11
- package/components/button/_macro.njk +1 -1
- package/components/button/_macro.spec.js +405 -351
- package/components/button/example-button-group.njk +1 -0
- package/components/checkboxes/_checkbox-macro.njk +20 -0
- package/components/checkboxes/_checkbox.scss +3 -3
- package/components/checkboxes/_macro.njk +5 -0
- package/components/checkboxes/_macro.spec.js +35 -0
- package/components/checkboxes/example-checkboxes-with-revealed-text-area-expanded.njk +68 -0
- package/components/checkboxes/example-checkboxes-with-revealed-text-area.njk +67 -0
- package/components/details/_details.scss +1 -2
- package/components/details/example-details-open.njk +10 -0
- package/components/external-link/_macro.spec.js +66 -69
- package/components/external-link/_test_examples.js +4 -0
- package/components/feedback/_macro.spec.js +109 -80
- package/components/feedback/_test_examples.js +17 -0
- package/components/field/_macro.spec.js +106 -69
- package/components/section-navigation/_macro.njk +9 -6
- package/components/summary/_macro.njk +73 -78
- package/components/summary/_macro.spec.js +5 -15
- package/components/summary/_summary.scss +16 -11
- package/components/table-of-contents/_macro.njk +3 -3
- package/components/table-of-contents/_macro.spec.js +3 -3
- package/components/table-of-contents/{_toc.scss → _table-of-contents.scss} +1 -1
- package/components/table-of-contents/table-of-contents.dom.js +13 -0
- package/components/table-of-contents/{toc.js → table-of-contents.js} +4 -4
- package/components/table-of-contents/{toc.spec.js → table-of-contents.spec.js} +2 -2
- package/components/tabs/_tabs.scss +10 -11
- package/components/tabs/tabs.js +3 -3
- package/components/timeout-modal/timeout-modal.spec.js +1 -1
- package/css/main.css +1 -1
- package/js/analytics.js +1 -1
- package/js/main.js +1 -1
- package/package.json +2 -2
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
- package/scss/main.scss +1 -1
- package/scss/objects/_page.scss +1 -1
- package/scss/utilities/_margin.scss +4 -0
- package/scss/utilities/_padding.scss +4 -0
- package/components/table-of-contents/toc.dom.js +0 -13
|
@@ -5,130 +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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
});
|
|
41
108
|
});
|
|
42
109
|
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
);
|
|
45
118
|
|
|
46
|
-
|
|
119
|
+
test('THEN: it has data-min-chars set to "2"', () => {
|
|
120
|
+
expect($('.ons-autosuggest').attr('data-min-chars')).toBe('2');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
47
123
|
});
|
|
48
124
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
+
});
|
|
66
160
|
});
|
|
67
161
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
+
});
|
|
75
175
|
|
|
76
|
-
|
|
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
|
+
});
|
|
77
188
|
});
|
|
78
189
|
|
|
79
|
-
|
|
80
|
-
|
|
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
|
+
);
|
|
81
211
|
|
|
82
|
-
|
|
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
|
+
});
|
|
83
216
|
});
|
|
84
217
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
+
);
|
|
92
226
|
|
|
93
|
-
|
|
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
|
+
});
|
|
94
244
|
});
|
|
95
245
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
+
);
|
|
103
254
|
|
|
104
|
-
|
|
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
|
+
});
|
|
105
260
|
});
|
|
106
261
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
+
);
|
|
114
270
|
|
|
115
|
-
|
|
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
|
+
});
|
|
116
275
|
});
|
|
117
276
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
+
);
|
|
125
285
|
|
|
126
|
-
|
|
127
|
-
|
|
286
|
+
test('THEN: it has language set to "en-gb"', () => {
|
|
287
|
+
expect($('.ons-autosuggest').attr('data-lang')).toBe('en-gb');
|
|
288
|
+
});
|
|
289
|
+
});
|
|
128
290
|
});
|
|
129
291
|
|
|
130
|
-
describe('input', () => {
|
|
131
|
-
|
|
292
|
+
describe('GIVEN: Params: input', () => {
|
|
293
|
+
describe('WHEN: input param is provided', () => {
|
|
132
294
|
const faker = templateFaker();
|
|
133
295
|
const inputSpy = faker.spy('input');
|
|
134
296
|
|
|
@@ -191,106 +353,139 @@ describe('macro: autosuggest', () => {
|
|
|
191
353
|
},
|
|
192
354
|
});
|
|
193
355
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('width', '7');
|
|
198
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('label.text', 'Current name of country');
|
|
199
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('label.description', 'Enter your own answer or select from suggestions');
|
|
200
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('label.id', 'country-of-birth-label');
|
|
201
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('label.classes', 'extra-label-class');
|
|
202
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('autocomplete', 'off');
|
|
203
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('legend', 'this is a legend');
|
|
204
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('legendClasses', 'legend-extra-class');
|
|
205
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('value', 'abc');
|
|
206
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('attributes.a', 42);
|
|
207
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('error.id', 'error-id');
|
|
208
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('error.text', 'An error occurred.');
|
|
209
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('mutuallyExclusive', null);
|
|
210
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('accessiblePlaceholder', true);
|
|
211
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('name', 'test-params');
|
|
212
|
-
expect(typeof inputSpy.occurrences[0].autosuggestResults).toBe('string');
|
|
213
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('minLength', 1);
|
|
214
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('maxLength', 10);
|
|
215
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('prefix.title', 'Great British Pounds');
|
|
216
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('prefix.text', '£');
|
|
217
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('prefix.id', 'gbp-prefix');
|
|
218
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('suffix.title', 'Percentage of total');
|
|
219
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('suffix.text', '%');
|
|
220
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('suffix.id', 'percentage-suffix');
|
|
221
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('fieldId', 'field-id-test');
|
|
222
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('fieldClasses', 'field-class-test');
|
|
223
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('dontWrap', true);
|
|
224
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.limit', 200);
|
|
225
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountSingular', 'You have {x} character remaining');
|
|
226
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountPlural', 'You have {x} characters remaining');
|
|
227
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountOverLimitSingular', '{x} character too many');
|
|
228
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('charCheckLimit.charCountOverLimitPlural', '{x} characters too many');
|
|
229
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('searchButton.text', 'Search');
|
|
230
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('postTextboxLinkText', 'Post textbox link text');
|
|
231
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('postTextboxLinkUrl', 'https://www.ons.gov.uk');
|
|
232
|
-
expect(inputSpy.occurrences[0]).toHaveProperty('listeners.click', "function() { console.log('click'); }");
|
|
233
|
-
});
|
|
234
|
-
});
|
|
356
|
+
test('THEN: id is passed through to the input component', () => {
|
|
357
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('id', 'country-of-birth');
|
|
358
|
+
});
|
|
235
359
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
360
|
+
test('THEN: type is passed through to the input component', () => {
|
|
361
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('type', 'text');
|
|
362
|
+
});
|
|
239
363
|
|
|
240
|
-
|
|
241
|
-
|
|
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
|
+
});
|
|
242
367
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
...EXAMPLE_AUTOSUGGEST,
|
|
247
|
-
mutuallyExclusive: { fakeParam: true },
|
|
248
|
-
}),
|
|
249
|
-
);
|
|
368
|
+
test('THEN: width is passed through to the input component', () => {
|
|
369
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('width', '7');
|
|
370
|
+
});
|
|
250
371
|
|
|
251
|
-
|
|
252
|
-
|
|
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
|
+
});
|
|
253
378
|
|
|
254
|
-
|
|
255
|
-
|
|
379
|
+
test('THEN: autocomplete is passed through to the input component', () => {
|
|
380
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('autocomplete', 'off');
|
|
381
|
+
});
|
|
256
382
|
|
|
257
|
-
|
|
258
|
-
|
|
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
|
+
});
|
|
259
387
|
|
|
260
|
-
|
|
261
|
-
|
|
388
|
+
test('THEN: value is passed through to the input component', () => {
|
|
389
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('value', 'abc');
|
|
390
|
+
});
|
|
262
391
|
|
|
263
|
-
|
|
264
|
-
|
|
392
|
+
test('THEN: custom attribute "a" is passed through to the input component', () => {
|
|
393
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('attributes.a', 42);
|
|
394
|
+
});
|
|
265
395
|
|
|
266
|
-
|
|
267
|
-
|
|
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
|
+
});
|
|
268
400
|
|
|
269
|
-
|
|
270
|
-
|
|
401
|
+
test('THEN: mutuallyExclusive is passed as null to the input component', () => {
|
|
402
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('mutuallyExclusive', null);
|
|
403
|
+
});
|
|
271
404
|
|
|
272
|
-
|
|
273
|
-
|
|
405
|
+
test('THEN: accessiblePlaceholder is passed as true to the input component', () => {
|
|
406
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('accessiblePlaceholder', true);
|
|
407
|
+
});
|
|
274
408
|
|
|
275
|
-
|
|
276
|
-
|
|
409
|
+
test('THEN: name is passed through to the input component', () => {
|
|
410
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('name', 'test-params');
|
|
411
|
+
});
|
|
277
412
|
|
|
278
|
-
|
|
279
|
-
|
|
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
|
+
});
|
|
280
420
|
|
|
281
|
-
|
|
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
|
+
});
|
|
282
466
|
});
|
|
467
|
+
});
|
|
283
468
|
|
|
284
|
-
|
|
469
|
+
describe('GIVEN: Params: mutuallyExclusive', () => {
|
|
470
|
+
describe('WHEN: mutuallyExclusive parameter is not defined', () => {
|
|
285
471
|
const $ = cheerio.load(renderComponent('autosuggest', EXAMPLE_AUTOSUGGEST));
|
|
286
472
|
|
|
287
|
-
|
|
473
|
+
test('THEN: autosuggest results are rendered', () => {
|
|
474
|
+
expect($('.ons-autosuggest__results').length).toBe(1);
|
|
475
|
+
});
|
|
288
476
|
});
|
|
289
477
|
|
|
290
|
-
|
|
291
|
-
const $ = cheerio.load(
|
|
478
|
+
describe('WHEN: mutuallyExclusive parameter is defined', () => {
|
|
479
|
+
const $ = cheerio.load(
|
|
480
|
+
renderComponent('autosuggest', {
|
|
481
|
+
...EXAMPLE_AUTOSUGGEST,
|
|
482
|
+
mutuallyExclusive: { fakeParam: true },
|
|
483
|
+
}),
|
|
484
|
+
);
|
|
292
485
|
|
|
293
|
-
|
|
486
|
+
test('THEN: autosuggest results are not rendered', () => {
|
|
487
|
+
expect($('.ons-autosuggest__results').length).toBe(0);
|
|
488
|
+
});
|
|
294
489
|
});
|
|
295
490
|
});
|
|
296
491
|
});
|
|
@@ -609,6 +609,8 @@ describe('script: autosuggest', () => {
|
|
|
609
609
|
expect(resultsItemCount).toBe(1);
|
|
610
610
|
const warningText = await page.$eval('.ons-autosuggest__warning', (node) => node.textContent);
|
|
611
611
|
expect(warningText.trim()).toBe('!Sorry, there is a problem.');
|
|
612
|
+
const warningContainer = await page.$eval('.ons-autosuggest__warning', (node) => node.id);
|
|
613
|
+
expect(warningContainer).toBe('country-of-birth-listbox');
|
|
612
614
|
});
|
|
613
615
|
|
|
614
616
|
it('the list and results element should be removed from the page', async () => {
|
|
@@ -657,7 +659,7 @@ describe('script: autosuggest', () => {
|
|
|
657
659
|
await page.type('.ons-js-autosuggest-input', 'England', { delay: 20 });
|
|
658
660
|
await page.keyboard.press('ArrowUp');
|
|
659
661
|
await page.keyboard.press('Enter');
|
|
660
|
-
//
|
|
662
|
+
// Unfocus the autosuggest input
|
|
661
663
|
await page.keyboard.press('Tab');
|
|
662
664
|
await page.focus('.ons-js-autosuggest-input');
|
|
663
665
|
|