@ons/design-system 50.0.0 → 52.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -15
- package/components/access-code/_macro.njk +1 -1
- package/components/access-code/_macro.spec.js +162 -0
- package/components/access-code/uac.spec.js +26 -0
- package/components/accordion/_macro.spec.js +224 -0
- package/components/accordion/accordion.spec.js +134 -0
- package/components/address-input/_macro.njk +1 -1
- package/components/address-input/_macro.spec.js +465 -0
- package/components/address-input/autosuggest.address.js +5 -4
- package/components/address-input/autosuggest.address.setter.js +9 -3
- package/components/address-input/autosuggest.address.spec.js +733 -0
- package/components/address-output/_macro.njk +6 -6
- package/components/address-output/_macro.spec.js +122 -0
- package/components/autosuggest/_macro.njk +1 -1
- package/components/autosuggest/_macro.spec.js +229 -0
- package/components/autosuggest/autosuggest.helpers.js +2 -3
- package/components/autosuggest/autosuggest.helpers.spec.js +85 -0
- package/components/autosuggest/autosuggest.js +4 -2
- package/components/autosuggest/autosuggest.spec.js +625 -0
- package/components/autosuggest/autosuggest.ui.js +6 -2
- package/components/breadcrumbs/_macro.spec.js +129 -0
- package/components/button/_macro.njk +5 -5
- package/components/button/_macro.spec.js +446 -0
- package/components/button/button.spec.js +290 -0
- package/components/call-to-action/_macro.njk +3 -1
- package/components/call-to-action/_macro.spec.js +52 -0
- package/components/card/_macro.njk +26 -19
- package/components/card/_macro.spec.js +261 -0
- package/components/char-check-limit/_macro.spec.js +73 -0
- package/components/char-check-limit/character-check.spec.js +196 -0
- package/components/char-check-limit/character-limit.js +1 -1
- package/components/checkboxes/_checkbox-macro.spec.js +419 -0
- package/components/checkboxes/_macro.njk +1 -3
- package/components/checkboxes/_macro.spec.js +306 -0
- package/components/checkboxes/checkbox-with-autoselect.js +2 -1
- package/components/checkboxes/checkboxes.spec.js +208 -0
- package/components/code-highlight/_macro.spec.js +56 -0
- package/components/code-highlight/code-highlight.spec.js +18 -0
- package/components/collapsible/_macro.spec.js +204 -0
- package/components/collapsible/collapsible.js +2 -1
- package/components/collapsible/collapsible.spec.js +236 -0
- package/components/content-pagination/_macro.spec.js +199 -0
- package/components/cookies-banner/_macro.njk +1 -1
- package/components/cookies-banner/_macro.spec.js +171 -0
- package/components/cookies-banner/cookies-banner.spec.js +90 -0
- package/components/date-input/_macro.njk +6 -3
- package/components/date-input/_macro.spec.js +286 -0
- package/components/document-list/_macro.njk +3 -5
- package/components/document-list/_macro.spec.js +491 -0
- package/components/download-resources/download-resources.spec.js +540 -0
- package/components/duration/_macro.njk +7 -6
- package/components/duration/_macro.spec.js +251 -0
- package/components/error/_macro.spec.js +97 -0
- package/components/external-link/_macro.spec.js +60 -0
- package/components/feedback/_macro.njk +5 -3
- package/components/feedback/_macro.spec.js +122 -0
- package/components/field/_macro.njk +2 -2
- package/components/field/_macro.spec.js +97 -0
- package/components/fieldset/_macro.njk +3 -3
- package/components/fieldset/_macro.spec.js +173 -0
- package/components/footer/_macro.njk +12 -49
- package/components/footer/_macro.spec.js +549 -0
- package/components/header/_macro.njk +3 -3
- package/components/header/_macro.spec.js +562 -0
- package/components/hero/_hero.scss +0 -3
- package/components/hero/_macro.njk +4 -4
- package/components/hero/_macro.spec.js +224 -0
- package/components/icons/_macro.njk +15 -15
- package/components/icons/_macro.spec.js +140 -0
- package/components/images/_macro.njk +1 -1
- package/components/images/_macro.spec.js +121 -0
- package/components/input/_input-type.scss +12 -5
- package/components/input/_macro.njk +4 -5
- package/components/input/_macro.spec.js +658 -0
- package/components/label/_macro.spec.js +189 -0
- package/components/language-selector/_macro.spec.js +129 -0
- package/components/lists/_list.scss +4 -0
- package/components/lists/_macro.njk +4 -7
- package/components/lists/_macro.spec.js +618 -0
- package/components/message/_macro.spec.js +137 -0
- package/components/message-list/_macro.njk +7 -7
- package/components/message-list/_macro.spec.js +159 -0
- package/components/metadata/_macro.spec.js +167 -0
- package/components/modal/_macro.njk +6 -6
- package/components/modal/_macro.spec.js +87 -0
- package/components/modal/modal.js +0 -16
- package/components/modal/modal.spec.js +59 -0
- package/components/mutually-exclusive/_macro.njk +2 -2
- package/components/mutually-exclusive/_macro.spec.js +184 -0
- package/components/mutually-exclusive/mutually-exclusive.checkboxes.spec.js +203 -0
- package/components/mutually-exclusive/mutually-exclusive.date.spec.js +142 -0
- package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +141 -0
- package/components/mutually-exclusive/mutually-exclusive.email.spec.js +117 -0
- package/components/mutually-exclusive/mutually-exclusive.multiple-options.checkboxes.spec.js +213 -0
- package/components/mutually-exclusive/mutually-exclusive.number.spec.js +125 -0
- package/components/mutually-exclusive/mutually-exclusive.textarea.spec.js +131 -0
- package/components/navigation/_macro.njk +6 -6
- package/components/navigation/_macro.spec.js +327 -0
- package/components/navigation/navigation.dom.js +1 -1
- package/components/navigation/navigation.spec.js +232 -0
- package/components/pagination/_macro.njk +1 -1
- package/components/pagination/_macro.spec.js +411 -0
- package/components/panel/_macro.njk +6 -6
- package/components/panel/_macro.spec.js +423 -0
- package/components/password/_macro.spec.js +137 -0
- package/components/password/password.spec.js +40 -0
- package/components/phase-banner/_macro.spec.js +73 -0
- package/components/promotional-banner/_macro.spec.js +97 -0
- package/components/question/_macro.njk +16 -22
- package/components/question/_macro.spec.js +309 -0
- package/components/quote/_macro.spec.js +81 -0
- package/components/radios/_macro.njk +3 -6
- package/components/radios/_macro.spec.js +575 -0
- package/components/radios/radios.spec.js +180 -0
- package/components/related-content/_macro.njk +1 -0
- package/components/related-content/_macro.spec.js +142 -0
- package/components/relationships/_macro.spec.js +108 -0
- package/components/relationships/relationships.spec.js +84 -0
- package/components/reply/_macro.njk +2 -2
- package/components/reply/_macro.spec.js +69 -0
- package/components/reply/reply.spec.js +78 -0
- package/components/search/_macro.njk +14 -12
- package/components/search/_macro.spec.js +44 -0
- package/components/search/_search.scss +7 -7
- package/components/section-navigation/_macro.njk +7 -2
- package/components/section-navigation/_macro.spec.js +206 -0
- package/components/select/_macro.njk +3 -3
- package/components/select/_macro.spec.js +203 -0
- package/components/select/select.spec.js +56 -0
- package/components/share-page/_macro.njk +2 -2
- package/components/share-page/_macro.spec.js +110 -0
- package/components/skip-to-content/_macro.spec.js +57 -0
- package/components/skip-to-content/skip-to-content.spec.js +44 -0
- package/components/status/_macro.spec.js +77 -0
- package/components/summary/_macro.njk +5 -5
- package/components/summary/_macro.spec.js +472 -0
- package/components/table/_macro.njk +2 -2
- package/components/table/_macro.spec.js +557 -0
- package/components/table/table.spec.js +155 -0
- package/components/table-of-contents/_macro.njk +35 -35
- package/components/table-of-contents/_macro.spec.js +178 -0
- package/components/table-of-contents/toc.js +29 -25
- package/components/table-of-contents/toc.spec.js +61 -0
- package/components/tabs/_macro.njk +1 -1
- package/components/tabs/_macro.spec.js +79 -0
- package/components/tabs/tabs.spec.js +162 -0
- package/components/text-indent/_macro.spec.js +52 -0
- package/components/textarea/_macro.njk +5 -3
- package/components/textarea/_macro.spec.js +300 -0
- package/components/textarea/textarea.spec.js +98 -0
- package/components/timeline/_macro.njk +3 -3
- package/components/timeline/_macro.spec.js +81 -0
- package/components/timeout-modal/_macro.spec.js +68 -0
- package/components/timeout-modal/timeout-modal.spec.js +226 -0
- package/components/timeout-panel/_macro.njk +0 -1
- package/components/timeout-panel/_macro.spec.js +54 -0
- package/components/timeout-panel/timeout-panel.dom.js +1 -2
- package/components/timeout-panel/timeout-panel.spec.js +161 -0
- package/components/upload/_macro.spec.js +75 -0
- package/components/video/_macro.spec.js +34 -0
- package/css/census.css +1 -1
- package/css/main.css +1 -1
- package/js/cookies-settings.spec.js +154 -0
- package/package.json +10 -23
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +2 -2
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
|
|
3
|
+
import * as cheerio from 'cheerio';
|
|
4
|
+
|
|
5
|
+
import axe from '../../tests/helpers/axe';
|
|
6
|
+
import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
|
|
7
|
+
|
|
8
|
+
const EXAMPLE_CHECKBOX_ITEM = {
|
|
9
|
+
id: 'example-checkbox-id',
|
|
10
|
+
name: 'example-checkbox-name',
|
|
11
|
+
value: '123',
|
|
12
|
+
label: {
|
|
13
|
+
classes: 'extra-label-class',
|
|
14
|
+
text: 'Example checkbox',
|
|
15
|
+
description: 'Example label description.',
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const EXAMPLE_CHECKBOX_ITEM_CHECKBOXES = {
|
|
20
|
+
id: 'example-item-checkboxes',
|
|
21
|
+
name: 'example-item-checkboxes',
|
|
22
|
+
value: 'checkboxes',
|
|
23
|
+
label: {
|
|
24
|
+
text: 'Example item with checkboxes',
|
|
25
|
+
},
|
|
26
|
+
other: {
|
|
27
|
+
otherType: 'checkboxes',
|
|
28
|
+
selectAllChildren: true,
|
|
29
|
+
id: 'example-checkboxes',
|
|
30
|
+
name: 'example-checkboxes-name',
|
|
31
|
+
legend: 'Select preferred times of day',
|
|
32
|
+
legendClasses: 'extra-legend-class',
|
|
33
|
+
attributes: { a: 42 },
|
|
34
|
+
checkboxes: [
|
|
35
|
+
{
|
|
36
|
+
value: 'morning',
|
|
37
|
+
id: 'morning',
|
|
38
|
+
label: {
|
|
39
|
+
text: 'Morning',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
value: 'afternoon',
|
|
44
|
+
id: 'afternoon',
|
|
45
|
+
label: {
|
|
46
|
+
text: 'Afternoon',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const EXAMPLE_CHECKBOXES = {
|
|
54
|
+
name: 'example-checkboxes-name',
|
|
55
|
+
legend: 'Legend text',
|
|
56
|
+
checkboxesLabel: 'Select all that apply',
|
|
57
|
+
checkboxesLabelClasses: 'extra-checkboxes-label-class',
|
|
58
|
+
checkboxes: [EXAMPLE_CHECKBOX_ITEM],
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const EXAMPLE_CHECKBOXES_WITH_ERROR = {
|
|
62
|
+
...EXAMPLE_CHECKBOXES,
|
|
63
|
+
error: {
|
|
64
|
+
id: 'example-error-id',
|
|
65
|
+
text: 'An unexpected error occurred.',
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const EXAMPLE_CHECKBOXES_WITH_MUTUALLY_EXCLUSIVE_WITH_ERROR = {
|
|
70
|
+
...EXAMPLE_CHECKBOXES_WITH_ERROR,
|
|
71
|
+
dontWrap: true,
|
|
72
|
+
mutuallyExclusive: {
|
|
73
|
+
or: 'Or',
|
|
74
|
+
deselectMessage: 'Selecting this will clear your feedback',
|
|
75
|
+
deselectGroupAdjective: 'cleared',
|
|
76
|
+
deselectExclusiveOptionAdjective: 'deselected',
|
|
77
|
+
exclusiveOptions: [
|
|
78
|
+
{
|
|
79
|
+
id: 'feedback-exclusive-option',
|
|
80
|
+
name: 'no-feedback',
|
|
81
|
+
value: 'no-feedback',
|
|
82
|
+
label: {
|
|
83
|
+
text: 'I dont want to provide feedback',
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
describe('macro: checkboxes', () => {
|
|
91
|
+
it('passes jest-axe checks', async () => {
|
|
92
|
+
const $ = cheerio.load(renderComponent('checkboxes', EXAMPLE_CHECKBOXES));
|
|
93
|
+
|
|
94
|
+
const results = await axe($.html());
|
|
95
|
+
expect(results).toHaveNoViolations();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('renders `fieldset` component with the expected parameters', () => {
|
|
99
|
+
const faker = templateFaker();
|
|
100
|
+
const fieldsetSpy = faker.spy('fieldset');
|
|
101
|
+
|
|
102
|
+
faker.renderComponent('checkboxes', {
|
|
103
|
+
...EXAMPLE_CHECKBOXES_WITH_ERROR,
|
|
104
|
+
id: 'example-id',
|
|
105
|
+
classes: 'extra-class',
|
|
106
|
+
legendClasses: 'extra-legend-class',
|
|
107
|
+
description: 'An example description.',
|
|
108
|
+
dontWrap: true,
|
|
109
|
+
legendIsQuestionTitle: false,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
expect(fieldsetSpy.occurrences[0]).toEqual({
|
|
113
|
+
id: 'example-id',
|
|
114
|
+
classes: 'extra-class',
|
|
115
|
+
legend: 'Legend text',
|
|
116
|
+
legendClasses: 'extra-legend-class',
|
|
117
|
+
description: 'An example description.',
|
|
118
|
+
dontWrap: true,
|
|
119
|
+
legendIsQuestionTitle: false,
|
|
120
|
+
error: EXAMPLE_CHECKBOXES_WITH_ERROR.error,
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('label', () => {
|
|
125
|
+
it('has the expected text', () => {
|
|
126
|
+
const $ = cheerio.load(renderComponent('checkboxes', EXAMPLE_CHECKBOXES));
|
|
127
|
+
|
|
128
|
+
expect(
|
|
129
|
+
$('.ons-checkboxes__label')
|
|
130
|
+
.text()
|
|
131
|
+
.trim(),
|
|
132
|
+
).toBe('Select all that apply');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('has additionally provided `checkboxesLabelClasses`', () => {
|
|
136
|
+
const $ = cheerio.load(renderComponent('checkboxes', EXAMPLE_CHECKBOXES));
|
|
137
|
+
|
|
138
|
+
expect($('.ons-checkboxes__label').hasClass('extra-checkboxes-label-class')).toBe(true);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
describe('mutually exclusive', () => {
|
|
143
|
+
it('has the `ons-js-exclusive-group-item` class', () => {
|
|
144
|
+
const $ = cheerio.load(renderComponent('checkboxes', EXAMPLE_CHECKBOXES_WITH_MUTUALLY_EXCLUSIVE_WITH_ERROR));
|
|
145
|
+
|
|
146
|
+
expect($('.ons-js-exclusive-group-item').length).toBe(1);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('renders mutually exclusive component', () => {
|
|
150
|
+
const faker = templateFaker();
|
|
151
|
+
const mutuallyExclusiveSpy = faker.spy('mutually-exclusive');
|
|
152
|
+
|
|
153
|
+
faker.renderComponent('checkboxes', {
|
|
154
|
+
...EXAMPLE_CHECKBOXES_WITH_MUTUALLY_EXCLUSIVE_WITH_ERROR,
|
|
155
|
+
id: 'example-field-id',
|
|
156
|
+
classes: 'extra-class',
|
|
157
|
+
legend: 'Legend text',
|
|
158
|
+
legendClasses: 'extra-legend-class',
|
|
159
|
+
description: 'Example description text',
|
|
160
|
+
legendIsQuestionTitle: true,
|
|
161
|
+
attributes: { a: 42 },
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
expect(mutuallyExclusiveSpy.occurrences).toContainEqual({
|
|
165
|
+
id: 'example-field-id',
|
|
166
|
+
description: 'Example description text',
|
|
167
|
+
classes: 'extra-class',
|
|
168
|
+
legend: 'Legend text',
|
|
169
|
+
legendClasses: 'extra-legend-class',
|
|
170
|
+
dontWrap: true,
|
|
171
|
+
legendIsQuestionTitle: true,
|
|
172
|
+
attributes: { a: 42 },
|
|
173
|
+
exclusiveOptions: EXAMPLE_CHECKBOXES_WITH_MUTUALLY_EXCLUSIVE_WITH_ERROR.mutuallyExclusive.exclusiveOptions,
|
|
174
|
+
or: 'Or',
|
|
175
|
+
deselectMessage: 'Selecting this will clear your feedback',
|
|
176
|
+
deselectGroupAdjective: 'cleared',
|
|
177
|
+
deselectExclusiveOptionAdjective: 'deselected',
|
|
178
|
+
error: EXAMPLE_CHECKBOXES_WITH_ERROR.error,
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe('checkbox items', () => {
|
|
184
|
+
it('renders a border around each item by default', () => {
|
|
185
|
+
const $ = cheerio.load(renderComponent('checkboxes', EXAMPLE_CHECKBOXES));
|
|
186
|
+
|
|
187
|
+
expect($('.ons-checkboxes__item').hasClass('ons-checkboxes__item--no-border')).toBe(false);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('does not render a border around each item when `borderless` is `false`', () => {
|
|
191
|
+
const $ = cheerio.load(
|
|
192
|
+
renderComponent('checkboxes', {
|
|
193
|
+
...EXAMPLE_CHECKBOXES,
|
|
194
|
+
borderless: true,
|
|
195
|
+
}),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
expect($('.ons-checkboxes__item').hasClass('ons-checkboxes__item--no-border')).toBe(true);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('does not mark radio with a class indicating that all child options should be selected', () => {
|
|
202
|
+
const $ = cheerio.load(
|
|
203
|
+
renderComponent('checkboxes', {
|
|
204
|
+
...EXAMPLE_CHECKBOXES,
|
|
205
|
+
checkboxes: [EXAMPLE_CHECKBOX_ITEM],
|
|
206
|
+
}),
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
expect($('.ons-js-other').hasClass('ons-js-select-all-children')).toBe(false);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('marks radio with a class indicating that all child options should be selected', () => {
|
|
213
|
+
const $ = cheerio.load(
|
|
214
|
+
renderComponent('checkboxes', {
|
|
215
|
+
...EXAMPLE_CHECKBOXES,
|
|
216
|
+
checkboxes: [EXAMPLE_CHECKBOX_ITEM_CHECKBOXES],
|
|
217
|
+
}),
|
|
218
|
+
);
|
|
219
|
+
|
|
220
|
+
expect($('.ons-js-other').hasClass('ons-js-select-all-children')).toBe(true);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('renders `checkboxes/checkbox` component', () => {
|
|
224
|
+
const faker = templateFaker();
|
|
225
|
+
const checkboxSpy = faker.spy('checkboxes/checkbox');
|
|
226
|
+
|
|
227
|
+
faker.renderComponent('checkboxes', {
|
|
228
|
+
...EXAMPLE_CHECKBOXES,
|
|
229
|
+
borderless: true,
|
|
230
|
+
checkboxes: [
|
|
231
|
+
{
|
|
232
|
+
...EXAMPLE_CHECKBOX_ITEM,
|
|
233
|
+
classes: 'extra-checkbox-item-class',
|
|
234
|
+
checked: false,
|
|
235
|
+
disabled: false,
|
|
236
|
+
attributes: { a: '123', b: '456' },
|
|
237
|
+
},
|
|
238
|
+
],
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
expect(checkboxSpy.occurrences).toContainEqual({
|
|
242
|
+
id: 'example-checkbox-id',
|
|
243
|
+
name: 'example-checkbox-name',
|
|
244
|
+
classes: 'extra-checkbox-item-class ons-checkbox--no-border',
|
|
245
|
+
inputClasses: '',
|
|
246
|
+
borderless: true,
|
|
247
|
+
checked: false,
|
|
248
|
+
disabled: false,
|
|
249
|
+
attributes: { a: '123', b: '456' },
|
|
250
|
+
label: {
|
|
251
|
+
classes: 'extra-label-class',
|
|
252
|
+
description: 'Example label description.',
|
|
253
|
+
for: 'example-checkbox-id',
|
|
254
|
+
text: 'Example checkbox',
|
|
255
|
+
},
|
|
256
|
+
value: '123',
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe('toggle selection button', () => {
|
|
262
|
+
const params = {
|
|
263
|
+
...EXAMPLE_CHECKBOXES,
|
|
264
|
+
autoSelect: {
|
|
265
|
+
selectAllText: 'Select all',
|
|
266
|
+
unselectAllText: 'Unselect all',
|
|
267
|
+
context: 'following checkboxes',
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
it('renders `button` component', () => {
|
|
272
|
+
const faker = templateFaker();
|
|
273
|
+
const buttonSpy = faker.spy('button');
|
|
274
|
+
|
|
275
|
+
faker.renderComponent('checkboxes', params);
|
|
276
|
+
|
|
277
|
+
expect(buttonSpy.occurrences[0]).toHaveProperty(
|
|
278
|
+
'html',
|
|
279
|
+
'<span class="ons-js-button-text">Select all</span><span class="ons-u-vh"> following checkboxes</span>',
|
|
280
|
+
);
|
|
281
|
+
expect(buttonSpy.occurrences[0]).toHaveProperty('variants', ['small', 'secondary']);
|
|
282
|
+
expect(buttonSpy.occurrences[0]).toHaveProperty('classes', 'ons-u-mb-s ons-js-auto-selector');
|
|
283
|
+
expect(buttonSpy.occurrences[0]).toHaveProperty('attributes.data-select-all', 'Select all');
|
|
284
|
+
expect(buttonSpy.occurrences[0]).toHaveProperty('attributes.data-unselect-all', 'Unselect all');
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it('does not render `button` component when a checkbox has an `other` input', () => {
|
|
288
|
+
const faker = templateFaker();
|
|
289
|
+
const buttonSpy = faker.spy('button');
|
|
290
|
+
|
|
291
|
+
faker.renderComponent('checkboxes', {
|
|
292
|
+
...params,
|
|
293
|
+
checkboxes: [
|
|
294
|
+
{
|
|
295
|
+
...EXAMPLE_CHECKBOX_ITEM,
|
|
296
|
+
other: {
|
|
297
|
+
label: { text: 'Example input' },
|
|
298
|
+
},
|
|
299
|
+
},
|
|
300
|
+
],
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
expect(buttonSpy.occurrences.length).toBe(0);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
});
|
|
@@ -21,7 +21,8 @@ export default class CheckboxWithAutoSelect {
|
|
|
21
21
|
this.unselectAllText = this.button.getAttribute('data-unselect-all');
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
handleButtonEvent() {
|
|
24
|
+
handleButtonEvent(event) {
|
|
25
|
+
event.preventDefault();
|
|
25
26
|
this.checkboxes.forEach(checkbox => {
|
|
26
27
|
checkbox.checked = this.allChecked === false ? true : false;
|
|
27
28
|
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
|
|
2
|
+
|
|
3
|
+
describe('script: checkboxes', () => {
|
|
4
|
+
describe('automatic selection', () => {
|
|
5
|
+
const params = {
|
|
6
|
+
legend: 'What are your favourite pizza toppings?',
|
|
7
|
+
checkboxesLabel: 'Select all that apply',
|
|
8
|
+
name: 'food-other',
|
|
9
|
+
autoSelect: {
|
|
10
|
+
selectAllText: 'Select all',
|
|
11
|
+
unselectAllText: 'Unselect all',
|
|
12
|
+
context: 'following checkboxes',
|
|
13
|
+
},
|
|
14
|
+
checkboxes: [
|
|
15
|
+
{
|
|
16
|
+
id: 'bacon-other',
|
|
17
|
+
label: {
|
|
18
|
+
text: 'Bacon',
|
|
19
|
+
},
|
|
20
|
+
value: 'bacon',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: 'olives-other',
|
|
24
|
+
label: {
|
|
25
|
+
text: 'Olives',
|
|
26
|
+
},
|
|
27
|
+
value: 'olives',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
id: 'other-checkbox',
|
|
31
|
+
label: {
|
|
32
|
+
text: 'Other',
|
|
33
|
+
description: 'An answer is required',
|
|
34
|
+
},
|
|
35
|
+
value: 'other',
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
beforeEach(async () => {
|
|
41
|
+
await setTestPage('/test', renderComponent('checkboxes', params));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
describe('and the autoselect button is clicked', () => {
|
|
45
|
+
beforeEach(async () => {
|
|
46
|
+
await page.click('.ons-js-auto-selector');
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('all checkboxes should be checked', async () => {
|
|
50
|
+
const checkedStates = await page.$$eval('.ons-js-checkbox', nodes => nodes.map(node => node.checked));
|
|
51
|
+
expect(checkedStates).toEqual([true, true, true]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('the button text should have changed', async () => {
|
|
55
|
+
const buttonText = await page.$eval('.ons-js-button-text', node => node.textContent);
|
|
56
|
+
expect(buttonText).toBe('Unselect all');
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('and the autoselect button is clicked to select all and clicked again', () => {
|
|
61
|
+
beforeEach(async () => {
|
|
62
|
+
await page.click('.ons-js-auto-selector');
|
|
63
|
+
await page.click('.ons-js-auto-selector');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('all checkboxes should be unchecked', async () => {
|
|
67
|
+
const checkedStates = await page.$$eval('.ons-js-checkbox', nodes => nodes.map(node => node.checked));
|
|
68
|
+
expect(checkedStates).toEqual([false, false, false]);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('the button text should have changed', async () => {
|
|
72
|
+
const buttonText = await page.$eval('.ons-js-button-text', node => node.textContent);
|
|
73
|
+
expect(buttonText).toBe('Select all');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('when all except one checkbox is checked', () => {
|
|
78
|
+
beforeEach(async () => {
|
|
79
|
+
await page.$eval('#olives-other', node => (node.checked = true));
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('the button text should be select all', async () => {
|
|
83
|
+
const buttonText = await page.$eval('.ons-js-button-text', node => node.textContent);
|
|
84
|
+
expect(buttonText).toBe('Select all');
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe('when the only unchecked checkbox is checked', () => {
|
|
89
|
+
beforeEach(async () => {
|
|
90
|
+
await page.click('#bacon-other');
|
|
91
|
+
await page.click('#olives-other');
|
|
92
|
+
await page.click('#other-checkbox');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('the button text should be unselect all', async () => {
|
|
96
|
+
const buttonText = await page.$eval('.ons-js-button-text', node => node.textContent);
|
|
97
|
+
expect(buttonText).toBe('Unselect all');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('reveal and fieldset', function() {
|
|
103
|
+
const params = {
|
|
104
|
+
legend: 'What are your favourite pizza toppings?',
|
|
105
|
+
checkboxesLabel: 'Select all that apply',
|
|
106
|
+
name: 'food-other',
|
|
107
|
+
checkboxes: [
|
|
108
|
+
{
|
|
109
|
+
id: 'bacon-other',
|
|
110
|
+
label: {
|
|
111
|
+
text: 'Bacon',
|
|
112
|
+
},
|
|
113
|
+
value: 'bacon',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
id: 'olives-other',
|
|
117
|
+
label: {
|
|
118
|
+
text: 'Olives',
|
|
119
|
+
},
|
|
120
|
+
value: 'olives',
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
id: 'other-checkbox',
|
|
124
|
+
label: {
|
|
125
|
+
text: 'Other',
|
|
126
|
+
description: 'An answer is required',
|
|
127
|
+
},
|
|
128
|
+
value: 'other',
|
|
129
|
+
other: {
|
|
130
|
+
id: 'other-textbox',
|
|
131
|
+
name: 'other-answer',
|
|
132
|
+
legend: 'Please specify other',
|
|
133
|
+
otherType: 'checkboxes',
|
|
134
|
+
checkboxes: [
|
|
135
|
+
{
|
|
136
|
+
id: 'inner-bacon-other',
|
|
137
|
+
label: {
|
|
138
|
+
text: 'Bacon',
|
|
139
|
+
},
|
|
140
|
+
value: 'bacon',
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
id: 'inner-olives-other',
|
|
144
|
+
label: {
|
|
145
|
+
text: 'Olives',
|
|
146
|
+
},
|
|
147
|
+
value: 'olives',
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
beforeEach(async () => {
|
|
156
|
+
await setTestPage('/test', renderComponent('checkboxes', params));
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('checkboxes with other options should be given aria-expanded attributes', async () => {
|
|
160
|
+
const ariaExpanded = await page.$eval('#other-checkbox', node => node.getAttribute('aria-expanded'));
|
|
161
|
+
expect(ariaExpanded).toBe('false');
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe('and a checkbox with an other input is checked', () => {
|
|
165
|
+
beforeEach(async () => {
|
|
166
|
+
await page.click('#other-checkbox');
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('has aria-expanded attribute should be set to true', async () => {
|
|
170
|
+
const ariaExpanded = await page.$eval('#other-checkbox', node => node.getAttribute('aria-expanded'));
|
|
171
|
+
expect(ariaExpanded).toBe('true');
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('and any other checkbox is changed', () => {
|
|
175
|
+
beforeEach(async () => {
|
|
176
|
+
await page.click('#bacon-other');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('the checkbox with an other input aria-expanded attribute not change', async () => {
|
|
180
|
+
const ariaExpanded = await page.$eval('#other-checkbox', node => node.getAttribute('aria-expanded'));
|
|
181
|
+
expect(ariaExpanded).toBe('true');
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('and a child of other checkbox is checked', () => {
|
|
186
|
+
beforeEach(async () => {
|
|
187
|
+
await page.click('#inner-bacon-other');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('and a checkbox with an other input is unchecked', () => {
|
|
191
|
+
beforeEach(async () => {
|
|
192
|
+
await page.click('#other-checkbox');
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('its aria-expanded attribute should be set to false', async () => {
|
|
196
|
+
const ariaExpanded = await page.$eval('#other-checkbox', node => node.getAttribute('aria-expanded'));
|
|
197
|
+
expect(ariaExpanded).toBe('false');
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it('the child of other checkbox should be unchecked', async () => {
|
|
201
|
+
const innerInputChecked = await page.$eval('#inner-bacon-other', node => node.checked);
|
|
202
|
+
expect(innerInputChecked).toBe(false);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** @jest-environment jsdom */
|
|
2
|
+
|
|
3
|
+
import * as cheerio from 'cheerio';
|
|
4
|
+
|
|
5
|
+
import axe from '../../tests/helpers/axe';
|
|
6
|
+
import { renderComponent } from '../../tests/helpers/rendering';
|
|
7
|
+
|
|
8
|
+
describe('macro: code-highlight', () => {
|
|
9
|
+
it('passes jest-axe checks', async () => {
|
|
10
|
+
const $ = cheerio.load(
|
|
11
|
+
renderComponent('code-highlight', {
|
|
12
|
+
language: 'js',
|
|
13
|
+
code: 'let a = 42;',
|
|
14
|
+
}),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const results = await axe($.html());
|
|
18
|
+
expect(results).toHaveNoViolations();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('has the default language modifier style class "markup" when not specified', () => {
|
|
22
|
+
const $ = cheerio.load(
|
|
23
|
+
renderComponent('code-highlight', {
|
|
24
|
+
code: '<p>Example paragraph...</p>',
|
|
25
|
+
}),
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
expect($('.ons-patternlib-example__code').hasClass('ons-language-markup')).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('has the provided language modifier style class "markup" when not specified', () => {
|
|
32
|
+
const $ = cheerio.load(
|
|
33
|
+
renderComponent('code-highlight', {
|
|
34
|
+
language: 'js',
|
|
35
|
+
code: 'let a = 42;',
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect($('.ons-patternlib-example__code').hasClass('ons-language-js')).toBe(true);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('has the provided code', () => {
|
|
43
|
+
const $ = cheerio.load(
|
|
44
|
+
renderComponent('code-highlight', {
|
|
45
|
+
language: 'js',
|
|
46
|
+
code: 'let a = 42;',
|
|
47
|
+
}),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(
|
|
51
|
+
$('.ons-patternlib-example__code')
|
|
52
|
+
.text()
|
|
53
|
+
.trim(),
|
|
54
|
+
).toBe('let a = 42;');
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
|
|
2
|
+
|
|
3
|
+
describe('script: code-highlight', () => {
|
|
4
|
+
describe('mode: link', () => {
|
|
5
|
+
it('highlights tokens in code', async () => {
|
|
6
|
+
await setTestPage(
|
|
7
|
+
'/test',
|
|
8
|
+
renderComponent('code-highlight', {
|
|
9
|
+
language: 'js',
|
|
10
|
+
code: 'let a = 42;',
|
|
11
|
+
}),
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
const tokenCount = await page.$$eval('.ons-patternlib-example__code .token', elements => elements.length);
|
|
15
|
+
expect(tokenCount).toBeGreaterThanOrEqual(1);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
});
|