@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,251 @@
|
|
|
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_DURATION_INPUT_BASE = {
|
|
9
|
+
id: 'duration',
|
|
10
|
+
legendOrLabel: 'How long have you lived at this address?',
|
|
11
|
+
description: 'Enter “0” into the years field if you have lived at this address for less than a year',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const EXAMPLE_FIELD_1 = {
|
|
15
|
+
field1: {
|
|
16
|
+
id: 'address-duration-years',
|
|
17
|
+
name: 'address-duration-years',
|
|
18
|
+
value: '0',
|
|
19
|
+
suffix: {
|
|
20
|
+
text: 'Years',
|
|
21
|
+
id: 'address-duration-years-suffix',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const EXAMPLE_FIELD_2 = {
|
|
27
|
+
field2: {
|
|
28
|
+
id: 'address-duration-months',
|
|
29
|
+
name: 'address-duration-months',
|
|
30
|
+
value: '0',
|
|
31
|
+
suffix: {
|
|
32
|
+
text: 'Months',
|
|
33
|
+
id: 'address-duration-months-suffix',
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const EXAMPLE_DURATION_SINGLE_FIELD = {
|
|
39
|
+
...EXAMPLE_DURATION_INPUT_BASE,
|
|
40
|
+
...EXAMPLE_FIELD_1,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const EXAMPLE_DURATION_MULTIPLE_FIELDS = {
|
|
44
|
+
...EXAMPLE_DURATION_INPUT_BASE,
|
|
45
|
+
...EXAMPLE_FIELD_1,
|
|
46
|
+
...EXAMPLE_FIELD_2,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
describe('macro: duration', () => {
|
|
50
|
+
describe('mode: multiple fields', () => {
|
|
51
|
+
it('passes jest-axe checks', async () => {
|
|
52
|
+
const $ = cheerio.load(renderComponent('duration', EXAMPLE_DURATION_MULTIPLE_FIELDS));
|
|
53
|
+
const results = await axe($.html());
|
|
54
|
+
expect(results).toHaveNoViolations();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('has the expected `input` output for `field1`', () => {
|
|
58
|
+
const faker = templateFaker();
|
|
59
|
+
const inputSpy = faker.spy('input');
|
|
60
|
+
|
|
61
|
+
faker.renderComponent('duration', EXAMPLE_DURATION_MULTIPLE_FIELDS);
|
|
62
|
+
|
|
63
|
+
expect(inputSpy.occurrences[0]).toEqual({
|
|
64
|
+
id: 'address-duration-years',
|
|
65
|
+
type: 'number',
|
|
66
|
+
width: '2',
|
|
67
|
+
classes: '',
|
|
68
|
+
value: '0',
|
|
69
|
+
attributes: undefined,
|
|
70
|
+
classes: '',
|
|
71
|
+
error: '',
|
|
72
|
+
fieldId: '',
|
|
73
|
+
label: {
|
|
74
|
+
description: '',
|
|
75
|
+
text: '',
|
|
76
|
+
},
|
|
77
|
+
name: 'address-duration-years',
|
|
78
|
+
suffix: {
|
|
79
|
+
id: 'address-duration-years-suffix',
|
|
80
|
+
text: 'Years',
|
|
81
|
+
title: 'Years',
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
expect(inputSpy.occurrences[1]).toEqual({
|
|
86
|
+
id: 'address-duration-months',
|
|
87
|
+
type: 'number',
|
|
88
|
+
width: '2',
|
|
89
|
+
classes: '',
|
|
90
|
+
value: '0',
|
|
91
|
+
attributes: undefined,
|
|
92
|
+
classes: '',
|
|
93
|
+
error: '',
|
|
94
|
+
fieldId: '',
|
|
95
|
+
label: {
|
|
96
|
+
description: '',
|
|
97
|
+
text: '',
|
|
98
|
+
},
|
|
99
|
+
name: 'address-duration-months',
|
|
100
|
+
suffix: {
|
|
101
|
+
id: 'address-duration-months-suffix',
|
|
102
|
+
text: 'Months',
|
|
103
|
+
title: 'Months',
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('has the group class div', () => {
|
|
109
|
+
const $ = cheerio.load(renderComponent('duration', EXAMPLE_DURATION_MULTIPLE_FIELDS));
|
|
110
|
+
const div = $('.ons-field:first-child').parent();
|
|
111
|
+
expect($(div).hasClass('ons-field-group')).toBe(true);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it('has the expected `fieldset` output', () => {
|
|
115
|
+
const faker = templateFaker();
|
|
116
|
+
const fieldsetSpy = faker.spy('fieldset');
|
|
117
|
+
|
|
118
|
+
faker.renderComponent('duration', {
|
|
119
|
+
...EXAMPLE_DURATION_MULTIPLE_FIELDS,
|
|
120
|
+
legendClasses: 'custom-legend-class',
|
|
121
|
+
dontWrap: true,
|
|
122
|
+
legendIsQuestionTitle: true,
|
|
123
|
+
error: false,
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
expect(fieldsetSpy.occurrences[0]).toEqual({
|
|
127
|
+
id: 'duration',
|
|
128
|
+
legend: 'How long have you lived at this address?',
|
|
129
|
+
description: 'Enter “0” into the years field if you have lived at this address for less than a year',
|
|
130
|
+
legendClasses: 'ons-u-mb-xs custom-legend-class',
|
|
131
|
+
dontWrap: true,
|
|
132
|
+
legendIsQuestionTitle: true,
|
|
133
|
+
error: false,
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('mode: multiple fields with mutually exclusive', () => {
|
|
139
|
+
it('has the correct class on each input', async () => {
|
|
140
|
+
const $ = cheerio.load(
|
|
141
|
+
renderComponent('duration', {
|
|
142
|
+
...EXAMPLE_DURATION_MULTIPLE_FIELDS,
|
|
143
|
+
mutuallyExclusive: {
|
|
144
|
+
legendClasses: 'custom-legend-class',
|
|
145
|
+
dontWrap: true,
|
|
146
|
+
legendIsQuestionTitle: true,
|
|
147
|
+
error: false,
|
|
148
|
+
mutuallyExclusive: {
|
|
149
|
+
checkbox: {},
|
|
150
|
+
or: 'Or',
|
|
151
|
+
deselectMessage: 'Deselect message',
|
|
152
|
+
deselectGroupAdjective: 'Deselect group adjective',
|
|
153
|
+
deselectExclusiveOptionAdjective: 'Deselect checkbox adjective',
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const exclusiveClassCount = $('.ons-js-exclusive-group-item').length;
|
|
160
|
+
expect(exclusiveClassCount).toBe(2);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('has the expected `mutuallyExclusive` output', () => {
|
|
164
|
+
const faker = templateFaker();
|
|
165
|
+
const mutuallyExclusiveSpy = faker.spy('mutually-exclusive');
|
|
166
|
+
|
|
167
|
+
faker.renderComponent('duration', {
|
|
168
|
+
...EXAMPLE_DURATION_MULTIPLE_FIELDS,
|
|
169
|
+
legendClasses: 'custom-legend-class',
|
|
170
|
+
dontWrap: true,
|
|
171
|
+
legendIsQuestionTitle: true,
|
|
172
|
+
error: false,
|
|
173
|
+
mutuallyExclusive: {
|
|
174
|
+
checkbox: {},
|
|
175
|
+
or: 'Or',
|
|
176
|
+
deselectMessage: 'Deselect message',
|
|
177
|
+
deselectGroupAdjective: 'Deselect group adjective',
|
|
178
|
+
deselectExclusiveOptionAdjective: 'Deselect checkbox adjective',
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
expect(mutuallyExclusiveSpy.occurrences[0]).toEqual({
|
|
183
|
+
id: 'duration',
|
|
184
|
+
legend: 'How long have you lived at this address?',
|
|
185
|
+
description: 'Enter “0” into the years field if you have lived at this address for less than a year',
|
|
186
|
+
legendClasses: 'custom-legend-class',
|
|
187
|
+
dontWrap: true,
|
|
188
|
+
legendIsQuestionTitle: true,
|
|
189
|
+
error: false,
|
|
190
|
+
checkbox: {},
|
|
191
|
+
or: 'Or',
|
|
192
|
+
deselectMessage: 'Deselect message',
|
|
193
|
+
deselectGroupAdjective: 'Deselect group adjective',
|
|
194
|
+
deselectExclusiveOptionAdjective: 'Deselect checkbox adjective',
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
describe('mode: single field', () => {
|
|
200
|
+
it('passes jest-axe checks', async () => {
|
|
201
|
+
const $ = cheerio.load(renderComponent('duration', EXAMPLE_DURATION_SINGLE_FIELD));
|
|
202
|
+
|
|
203
|
+
const results = await axe($.html());
|
|
204
|
+
expect(results).toHaveNoViolations();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it('has the expected `input` output for the field', () => {
|
|
208
|
+
const faker = templateFaker();
|
|
209
|
+
const inputSpy = faker.spy('input');
|
|
210
|
+
|
|
211
|
+
faker.renderComponent('duration', EXAMPLE_DURATION_SINGLE_FIELD);
|
|
212
|
+
|
|
213
|
+
expect(inputSpy.occurrences[0]).toEqual({
|
|
214
|
+
id: 'address-duration-years',
|
|
215
|
+
type: 'number',
|
|
216
|
+
width: '2',
|
|
217
|
+
classes: '',
|
|
218
|
+
value: '0',
|
|
219
|
+
attributes: undefined,
|
|
220
|
+
classes: '',
|
|
221
|
+
error: undefined,
|
|
222
|
+
fieldId: 'duration',
|
|
223
|
+
label: {
|
|
224
|
+
text: 'How long have you lived at this address?',
|
|
225
|
+
description: 'Enter “0” into the years field if you have lived at this address for less than a year',
|
|
226
|
+
},
|
|
227
|
+
name: 'address-duration-years',
|
|
228
|
+
suffix: {
|
|
229
|
+
id: 'address-duration-years-suffix',
|
|
230
|
+
text: 'Years',
|
|
231
|
+
title: 'Years',
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('has the expected `error` output', () => {
|
|
237
|
+
const faker = templateFaker();
|
|
238
|
+
const errorSpy = faker.spy('error');
|
|
239
|
+
|
|
240
|
+
faker.renderComponent('duration', {
|
|
241
|
+
...EXAMPLE_DURATION_SINGLE_FIELD,
|
|
242
|
+
error: { text: 'Put something else', dsExample: false },
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
expect(errorSpy.occurrences[0]).toEqual({
|
|
246
|
+
text: 'Put something else',
|
|
247
|
+
dsExample: false,
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
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 FAKE_NESTED_CONTENT = '<span class="test--nested">Nested content...</span>';
|
|
9
|
+
|
|
10
|
+
describe('macro: error', () => {
|
|
11
|
+
it('passes jest-axe checks', async () => {
|
|
12
|
+
const $ = cheerio.load(
|
|
13
|
+
renderComponent(
|
|
14
|
+
'error',
|
|
15
|
+
{
|
|
16
|
+
text: 'Example error text.',
|
|
17
|
+
id: 'example-error',
|
|
18
|
+
},
|
|
19
|
+
FAKE_NESTED_CONTENT,
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const results = await axe($.html());
|
|
24
|
+
expect(results).toHaveNoViolations();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('has the provided `text` text', () => {
|
|
28
|
+
const $ = cheerio.load(
|
|
29
|
+
renderComponent(
|
|
30
|
+
'error',
|
|
31
|
+
{
|
|
32
|
+
text: 'Example error text.',
|
|
33
|
+
id: 'example-error',
|
|
34
|
+
},
|
|
35
|
+
FAKE_NESTED_CONTENT,
|
|
36
|
+
),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(
|
|
40
|
+
$('.ons-panel__error')
|
|
41
|
+
.text()
|
|
42
|
+
.trim(),
|
|
43
|
+
).toBe('Example error text.');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('applies the provided `attributes` to the error content paragraph', () => {
|
|
47
|
+
const $ = cheerio.load(
|
|
48
|
+
renderComponent(
|
|
49
|
+
'error',
|
|
50
|
+
{
|
|
51
|
+
text: 'Example error text.',
|
|
52
|
+
id: 'example-error',
|
|
53
|
+
attributes: {
|
|
54
|
+
'data-test-a': 'foo',
|
|
55
|
+
'data-test-b': 'bar',
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
FAKE_NESTED_CONTENT,
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
expect($('.ons-panel__error').attr('data-test-a')).toBe('foo');
|
|
63
|
+
expect($('.ons-panel__error').attr('data-test-b')).toBe('bar');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('renders output using a `panel` component', () => {
|
|
67
|
+
const faker = templateFaker();
|
|
68
|
+
const panelSpy = faker.spy('panel');
|
|
69
|
+
|
|
70
|
+
faker.renderComponent(
|
|
71
|
+
'error',
|
|
72
|
+
{
|
|
73
|
+
text: 'Example error text.',
|
|
74
|
+
id: 'example-error',
|
|
75
|
+
},
|
|
76
|
+
FAKE_NESTED_CONTENT,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(panelSpy.occurrences[0].type).toBe('error');
|
|
80
|
+
expect(panelSpy.occurrences[0].id).toBe('example-error');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('renders output using a `panel` component with expected nested content', () => {
|
|
84
|
+
const $ = cheerio.load(
|
|
85
|
+
renderComponent(
|
|
86
|
+
'error',
|
|
87
|
+
{
|
|
88
|
+
text: 'Example error text.',
|
|
89
|
+
id: 'example-error',
|
|
90
|
+
},
|
|
91
|
+
FAKE_NESTED_CONTENT,
|
|
92
|
+
),
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
expect($('.ons-panel .test--nested').text()).toBe('Nested content...');
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
const EXAMPLE_EXTERNAL_LINK = {
|
|
9
|
+
url: 'http://example.com',
|
|
10
|
+
linkText: 'Example link',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
describe('macro: external-link', () => {
|
|
14
|
+
it('passes jest-axe checks', async () => {
|
|
15
|
+
const $ = cheerio.load(renderComponent('external-link', EXAMPLE_EXTERNAL_LINK));
|
|
16
|
+
|
|
17
|
+
const results = await axe($.html());
|
|
18
|
+
expect(results).toHaveNoViolations();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('has additionally provided style classes', () => {
|
|
22
|
+
const $ = cheerio.load(
|
|
23
|
+
renderComponent('external-link', {
|
|
24
|
+
...EXAMPLE_EXTERNAL_LINK,
|
|
25
|
+
classes: 'extra-class another-extra-class',
|
|
26
|
+
}),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
expect($('.ons-external-link').hasClass('extra-class')).toBe(true);
|
|
30
|
+
expect($('.ons-external-link').hasClass('another-extra-class')).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('has the expected hyperlink URL', async () => {
|
|
34
|
+
const $ = cheerio.load(renderComponent('external-link', EXAMPLE_EXTERNAL_LINK));
|
|
35
|
+
|
|
36
|
+
const $hyperlink = $('a.ons-external-link');
|
|
37
|
+
expect($hyperlink.attr('href')).toBe('http://example.com');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('opens in a new window when `newWindow` is `true`', () => {
|
|
41
|
+
const $ = cheerio.load(renderComponent('external-link', EXAMPLE_EXTERNAL_LINK));
|
|
42
|
+
|
|
43
|
+
expect($('a').attr('target')).toBe('_blank');
|
|
44
|
+
expect($('a').attr('rel')).toBe('noopener');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('has the expected link text', async () => {
|
|
48
|
+
const $ = cheerio.load(renderComponent('external-link', EXAMPLE_EXTERNAL_LINK));
|
|
49
|
+
|
|
50
|
+
const $hyperlink = $('a.ons-external-link');
|
|
51
|
+
expect($hyperlink.text().trim()).toBe('Example link');
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('has an "external-link" icon', async () => {
|
|
55
|
+
const $ = cheerio.load(renderComponent('external-link', EXAMPLE_EXTERNAL_LINK));
|
|
56
|
+
|
|
57
|
+
const $svg = $('.ons-external-link__icon svg');
|
|
58
|
+
expect($svg.length).toBe(1);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{% macro onsFeedback(params) %}
|
|
2
2
|
{% set headingLevel = params.headingLevel | default("2") %}
|
|
3
|
-
<div id="params.id" class="ons-feedback{% if params.classes is defined and params.classes %} {{ params.classes }}{% endif %}">
|
|
4
|
-
<h{{ headingLevel }}{
|
|
5
|
-
|
|
3
|
+
<div {% if params.id is defined and params.id %} id="{{ params.id }}"{% endif %} class="ons-feedback{% if params.classes is defined and params.classes %} {{ params.classes }}{% endif %}">
|
|
4
|
+
<h{{ headingLevel }} class="ons-feedback__heading{{ ' ' + params.headingClasses if params.headingClasses is defined and params.headingClasses }}">
|
|
5
|
+
{{ params.heading }}
|
|
6
|
+
</h{{ headingLevel }}>
|
|
7
|
+
<p class="ons-feedback__content">{{- params.content | safe -}}</p>
|
|
6
8
|
<a href="{{ params.url }}" class="ons-feedback__link">{{- params.linkText -}}</a>
|
|
7
9
|
</div>
|
|
8
10
|
{% endmacro %}
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
const EXAMPLE_FEEDBACK_MINIMAL = {
|
|
9
|
+
heading: 'Feedback heading',
|
|
10
|
+
content: 'Feedback content...',
|
|
11
|
+
url: 'http://example.com',
|
|
12
|
+
linkText: 'Feedback link text',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const EXAMPLE_FEEDBACK_FULL = {
|
|
16
|
+
id: 'example-feedback',
|
|
17
|
+
classes: 'extra-class',
|
|
18
|
+
heading: 'Feedback heading',
|
|
19
|
+
headingLevel: 5,
|
|
20
|
+
headingClasses: 'extra-heading-class another-extra-heading-class',
|
|
21
|
+
content: 'Feedback content...',
|
|
22
|
+
url: 'http://example.com',
|
|
23
|
+
linkText: 'Feedback link text',
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('macro: feedback', () => {
|
|
27
|
+
it('passes jest-axe checks with minimum parameters', async () => {
|
|
28
|
+
const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_MINIMAL));
|
|
29
|
+
|
|
30
|
+
const results = await axe($.html());
|
|
31
|
+
expect(results).toHaveNoViolations();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('passes jest-axe checks with full parameters', async () => {
|
|
35
|
+
const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_FULL));
|
|
36
|
+
|
|
37
|
+
const results = await axe($.html());
|
|
38
|
+
expect(results).toHaveNoViolations();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('has the provided `id` attribute', () => {
|
|
42
|
+
const $ = cheerio.load(
|
|
43
|
+
renderComponent('feedback', {
|
|
44
|
+
id: 'example-id',
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
expect($('#example-id').length).toBe(1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('has additionally provided style classes', () => {
|
|
52
|
+
const $ = cheerio.load(
|
|
53
|
+
renderComponent('feedback', {
|
|
54
|
+
classes: 'extra-class another-extra-class',
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
expect($('.ons-feedback').hasClass('extra-class')).toBe(true);
|
|
59
|
+
expect($('.ons-feedback').hasClass('another-extra-class')).toBe(true);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it.each([
|
|
63
|
+
[1, 'h1'],
|
|
64
|
+
[4, 'h4'],
|
|
65
|
+
])('has the correct element type for the provided `headingLevel` (%i -> %s)', (headingLevel, expectedTitleTag) => {
|
|
66
|
+
const $ = cheerio.load(
|
|
67
|
+
renderComponent('feedback', {
|
|
68
|
+
...EXAMPLE_FEEDBACK_MINIMAL,
|
|
69
|
+
headingLevel,
|
|
70
|
+
}),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
expect(
|
|
74
|
+
$(`${expectedTitleTag}.ons-feedback__heading`)
|
|
75
|
+
.text()
|
|
76
|
+
.trim(),
|
|
77
|
+
).toBe('Feedback heading');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('has a default `headingLevel` of 2', () => {
|
|
81
|
+
const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_MINIMAL));
|
|
82
|
+
|
|
83
|
+
expect(
|
|
84
|
+
$(`h2.ons-feedback__heading`)
|
|
85
|
+
.text()
|
|
86
|
+
.trim(),
|
|
87
|
+
).toBe('Feedback heading');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('has additional heading style classes', () => {
|
|
91
|
+
const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_FULL));
|
|
92
|
+
|
|
93
|
+
expect($('.ons-feedback__heading').hasClass('extra-heading-class')).toBe(true);
|
|
94
|
+
expect($('.ons-feedback__heading').hasClass('another-extra-heading-class')).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('has a paragraph with the provided `content`', () => {
|
|
98
|
+
const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_MINIMAL));
|
|
99
|
+
|
|
100
|
+
expect(
|
|
101
|
+
$('p')
|
|
102
|
+
.text()
|
|
103
|
+
.trim(),
|
|
104
|
+
).toBe('Feedback content...');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('has a link with the provided `url`', () => {
|
|
108
|
+
const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_MINIMAL));
|
|
109
|
+
|
|
110
|
+
expect($('.ons-feedback__link').attr('href')).toBe('http://example.com');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('has a link with the provided `linkText`', () => {
|
|
114
|
+
const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_MINIMAL));
|
|
115
|
+
|
|
116
|
+
expect(
|
|
117
|
+
$('.ons-feedback__link')
|
|
118
|
+
.text()
|
|
119
|
+
.trim(),
|
|
120
|
+
).toBe('Feedback link text');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
|
|
8
8
|
{% set field %}
|
|
9
9
|
{% if params.dontWrap is defined and params.dontWrap %}
|
|
10
|
-
{{ caller() }}
|
|
10
|
+
{{- caller() if caller -}}
|
|
11
11
|
{% else %}
|
|
12
12
|
<div
|
|
13
13
|
{% if params.id is defined and params.id %}id="{{ params.id }}"{% endif %}
|
|
14
14
|
class="ons-field{% if params.inline is defined and params.inline %} ons-field--inline{% endif %}{% if params.classes is defined and params.classes %} {{ params.classes }}{% endif %}"
|
|
15
15
|
{% if params.attributes is defined and params.attributes %}{% for attribute, value in (params.attributes.items() if params.attributes is mapping and params.attributes.items else params.attributes) %}{{ attribute }}{% if value is defined and value %}="{{ value }}"{% endif %} {% endfor %}{% endif %}
|
|
16
16
|
>
|
|
17
|
-
{{ caller() }}
|
|
17
|
+
{{- caller() if caller -}}
|
|
18
18
|
</div>
|
|
19
19
|
{% endif %}
|
|
20
20
|
{% endset %}
|
|
@@ -0,0 +1,97 @@
|
|
|
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_FIELD_BASIC = {
|
|
9
|
+
id: 'example-field',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
describe('macro: field', () => {
|
|
13
|
+
it('passes jest-axe checks', async () => {
|
|
14
|
+
const $ = cheerio.load(renderComponent('field', EXAMPLE_FIELD_BASIC));
|
|
15
|
+
|
|
16
|
+
const results = await axe($.html());
|
|
17
|
+
expect(results).toHaveNoViolations();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('has the provided `id` attribute', () => {
|
|
21
|
+
const $ = cheerio.load(renderComponent('field', EXAMPLE_FIELD_BASIC));
|
|
22
|
+
|
|
23
|
+
expect($('.ons-field').attr('id')).toBe('example-field');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('has additionally provided style classes', () => {
|
|
27
|
+
const $ = cheerio.load(
|
|
28
|
+
renderComponent('field', {
|
|
29
|
+
...EXAMPLE_FIELD_BASIC,
|
|
30
|
+
classes: 'extra-class another-extra-class',
|
|
31
|
+
}),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
expect($('.ons-field').hasClass('extra-class')).toBe(true);
|
|
35
|
+
expect($('.ons-field').hasClass('another-extra-class')).toBe(true);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('has correct class when `inline` is provided', () => {
|
|
39
|
+
const $ = cheerio.load(
|
|
40
|
+
renderComponent('field', {
|
|
41
|
+
...EXAMPLE_FIELD_BASIC,
|
|
42
|
+
inline: true,
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
expect($('.ons-field').hasClass('ons-field--inline')).toBe(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('has additionally provided `attributes`', () => {
|
|
50
|
+
const $ = cheerio.load(
|
|
51
|
+
renderComponent('field', {
|
|
52
|
+
...EXAMPLE_FIELD_BASIC,
|
|
53
|
+
attributes: {
|
|
54
|
+
a: 123,
|
|
55
|
+
b: 456,
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
expect($('.ons-field').attr('a')).toBe('123');
|
|
61
|
+
expect($('.ons-field').attr('b')).toBe('456');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('has the correct element with `dontWrap`', () => {
|
|
65
|
+
const $ = cheerio.load(
|
|
66
|
+
renderComponent('field', {
|
|
67
|
+
...EXAMPLE_FIELD_BASIC,
|
|
68
|
+
dontWrap: true,
|
|
69
|
+
}),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
expect($('.ons-field').length).toBe(0);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('calls with content', () => {
|
|
76
|
+
const $ = cheerio.load(renderComponent('field', EXAMPLE_FIELD_BASIC, 'Example content...'));
|
|
77
|
+
|
|
78
|
+
const content = $('.ons-field')
|
|
79
|
+
.html()
|
|
80
|
+
.trim();
|
|
81
|
+
expect(content).toEqual(expect.stringContaining('Example content...'));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('calls the error component when `error` is provided', () => {
|
|
85
|
+
const faker = templateFaker();
|
|
86
|
+
const errorSpy = faker.spy('error');
|
|
87
|
+
|
|
88
|
+
faker.renderComponent('field', {
|
|
89
|
+
...EXAMPLE_FIELD_BASIC,
|
|
90
|
+
error: { text: 'There is an error' },
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
expect(errorSpy.occurrences[0]).toEqual({
|
|
94
|
+
text: 'There is an error',
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
{% set fieldset -%}
|
|
5
5
|
{% if params.dontWrap is defined and params.dontWrap -%}
|
|
6
6
|
<div class="ons-input-items">
|
|
7
|
-
{{- caller() -}}
|
|
7
|
+
{{- caller() if caller -}}
|
|
8
8
|
</div>
|
|
9
9
|
{%- elif (params.legend is defined and params.legend) or (params.legendIsQuestionTitle is defined and params.legendIsQuestionTitle) -%}
|
|
10
10
|
<fieldset
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
{{- params.legend | safe -}}
|
|
19
19
|
</h1>
|
|
20
20
|
{%- else -%}
|
|
21
|
-
{{- params.legend | safe -}}
|
|
21
|
+
<span class="ons-fieldset__legend-title">{{- params.legend | safe -}}</span>
|
|
22
22
|
{%- endif -%}
|
|
23
23
|
{%- if params.description is defined and params.description -%}
|
|
24
24
|
<div class="ons-fieldset__description{% if params.legendIsQuestionTitle %} ons-fieldset__description--title ons-u-mb-m{% endif %}">
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
</div>
|
|
27
27
|
{%- endif -%}
|
|
28
28
|
</legend>
|
|
29
|
-
{{- caller() -}}
|
|
29
|
+
{{- caller() if caller -}}
|
|
30
30
|
</fieldset>
|
|
31
31
|
{%- endif %}
|
|
32
32
|
{%- endset %}
|