@ons/design-system 72.1.0 → 72.1.2
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.spec.js +373 -184
- 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/_button.scss +1 -1
- 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.scss +3 -3
- package/components/description-list/_description-list.scss +40 -9
- package/components/description-list/_macro.njk +20 -12
- package/components/description-list/_macro.spec.js +11 -1
- package/components/description-list/example-inline-description-list.njk +58 -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/header/_macro.njk +92 -90
- package/components/header/_macro.spec.js +10 -0
- package/components/header/example-header-basic.njk +11 -0
- package/components/hero/_hero.scss +239 -2
- package/components/hero/_macro.njk +7 -0
- package/components/hero/_macro.spec.js +5 -0
- package/components/hero/example-hero-navy-blue.njk +14 -0
- package/components/section-navigation/_macro.njk +9 -6
- 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/main.js +1 -1
- package/package.json +1 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
- package/scss/main.scss +1 -1
- package/scss/utilities/_margin.scss +4 -0
- package/scss/utilities/_padding.scss +4 -0
- package/scss/vars/_colors.scss +2 -0
- 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
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
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
|
-
|
|
86
|
-
|
|
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
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
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
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
-
|
|
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
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
133
|
-
|
|
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
|
-
|
|
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
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
360
|
+
test('THEN: type is passed through to the input component', () => {
|
|
361
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('type', 'text');
|
|
362
|
+
});
|
|
245
363
|
|
|
246
|
-
|
|
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
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
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
|
-
|
|
261
|
-
|
|
379
|
+
test('THEN: autocomplete is passed through to the input component', () => {
|
|
380
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('autocomplete', 'off');
|
|
381
|
+
});
|
|
262
382
|
|
|
263
|
-
|
|
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
|
-
|
|
267
|
-
|
|
388
|
+
test('THEN: value is passed through to the input component', () => {
|
|
389
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('value', 'abc');
|
|
390
|
+
});
|
|
268
391
|
|
|
269
|
-
|
|
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
|
-
|
|
273
|
-
|
|
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
|
-
|
|
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
|
-
|
|
279
|
-
|
|
405
|
+
test('THEN: accessiblePlaceholder is passed as true to the input component', () => {
|
|
406
|
+
expect(inputSpy.occurrences[0]).toHaveProperty('accessiblePlaceholder', true);
|
|
407
|
+
});
|
|
280
408
|
|
|
281
|
-
|
|
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
|
-
|
|
285
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
473
|
+
test('THEN: autosuggest results are rendered', () => {
|
|
474
|
+
expect($('.ons-autosuggest__results').length).toBe(1);
|
|
475
|
+
});
|
|
294
476
|
});
|
|
295
477
|
|
|
296
|
-
|
|
297
|
-
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
|
+
);
|
|
298
485
|
|
|
299
|
-
|
|
486
|
+
test('THEN: autosuggest results are not rendered', () => {
|
|
487
|
+
expect($('.ons-autosuggest__results').length).toBe(0);
|
|
488
|
+
});
|
|
300
489
|
});
|
|
301
490
|
});
|
|
302
491
|
});
|