@ons/design-system 50.0.1 → 51.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 -13
- 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 +3 -1
- 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/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 +11 -48
- package/components/footer/_macro.spec.js +549 -0
- package/components/header/_macro.njk +2 -2
- 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.spec.js +59 -0
- package/components/mutually-exclusive/_macro.njk +1 -1
- package/components/mutually-exclusive/_macro.spec.js +182 -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 +25 -33
- 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 +1 -1
|
@@ -0,0 +1,423 @@
|
|
|
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_PANEL_BASIC = {
|
|
9
|
+
id: 'panel',
|
|
10
|
+
body: 'Some panel text',
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
describe('macro: panel', () => {
|
|
14
|
+
describe.each([
|
|
15
|
+
['info', 'Important information:'],
|
|
16
|
+
['error', 'Error:'],
|
|
17
|
+
['warn', 'Warning:'],
|
|
18
|
+
['warn-branded', 'Warning:'],
|
|
19
|
+
['branded', 'Important information:'],
|
|
20
|
+
['success', 'Completed:'],
|
|
21
|
+
['announcement', 'Announcement:'],
|
|
22
|
+
])('mode: %s', (panelType, accessibleText) => {
|
|
23
|
+
it('passes jest-axe checks', async () => {
|
|
24
|
+
const $ = cheerio.load(
|
|
25
|
+
renderComponent('panel', {
|
|
26
|
+
...EXAMPLE_PANEL_BASIC,
|
|
27
|
+
type: panelType,
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
const results = await axe($.html());
|
|
31
|
+
expect(results).toHaveNoViolations();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('has correct class', () => {
|
|
35
|
+
const $ = cheerio.load(
|
|
36
|
+
renderComponent('panel', {
|
|
37
|
+
...EXAMPLE_PANEL_BASIC,
|
|
38
|
+
type: panelType,
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
expect($('.ons-panel').hasClass(`ons-panel--${panelType}`)).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('has the provided `body` text', () => {
|
|
46
|
+
const $ = cheerio.load(
|
|
47
|
+
renderComponent('panel', {
|
|
48
|
+
...EXAMPLE_PANEL_BASIC,
|
|
49
|
+
type: panelType,
|
|
50
|
+
}),
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
expect(
|
|
54
|
+
$('.ons-panel__body')
|
|
55
|
+
.text()
|
|
56
|
+
.trim(),
|
|
57
|
+
).toBe('Some panel text');
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('calls with content', () => {
|
|
61
|
+
const $ = cheerio.load(renderComponent('panel', { EXAMPLE_PANEL_BASIC, type: panelType }, 'Example content...'));
|
|
62
|
+
|
|
63
|
+
const content = $('.ons-panel__body')
|
|
64
|
+
.text()
|
|
65
|
+
.trim();
|
|
66
|
+
expect(content).toBe('Example content...');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('has the provided `id` attribute', () => {
|
|
70
|
+
const $ = cheerio.load(
|
|
71
|
+
renderComponent('panel', {
|
|
72
|
+
...EXAMPLE_PANEL_BASIC,
|
|
73
|
+
type: panelType,
|
|
74
|
+
}),
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
expect($('#panel').length).toBe(1);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('has custom classes applied', () => {
|
|
81
|
+
const $ = cheerio.load(
|
|
82
|
+
renderComponent('panel', {
|
|
83
|
+
...EXAMPLE_PANEL_BASIC,
|
|
84
|
+
type: panelType,
|
|
85
|
+
classes: 'ons-custom-class',
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
expect($('.ons-panel').hasClass('ons-custom-class')).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('has additionally provided `attributes`', () => {
|
|
93
|
+
const $ = cheerio.load(
|
|
94
|
+
renderComponent('panel', {
|
|
95
|
+
...EXAMPLE_PANEL_BASIC,
|
|
96
|
+
type: panelType,
|
|
97
|
+
attributes: {
|
|
98
|
+
a: '123',
|
|
99
|
+
b: '456',
|
|
100
|
+
},
|
|
101
|
+
}),
|
|
102
|
+
);
|
|
103
|
+
expect($('.ons-panel').attr('a')).toBe('123');
|
|
104
|
+
expect($('.ons-panel').attr('b')).toBe('456');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('has visually hidden accessible element', () => {
|
|
108
|
+
const $ = cheerio.load(
|
|
109
|
+
renderComponent('panel', {
|
|
110
|
+
...EXAMPLE_PANEL_BASIC,
|
|
111
|
+
type: panelType,
|
|
112
|
+
}),
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
expect($('.ons-panel__assistive-text').length).toBe(1);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('has the default visually hidden accessible text', () => {
|
|
119
|
+
const $ = cheerio.load(
|
|
120
|
+
renderComponent('panel', {
|
|
121
|
+
...EXAMPLE_PANEL_BASIC,
|
|
122
|
+
type: panelType,
|
|
123
|
+
}),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
expect(
|
|
127
|
+
$('.ons-panel__assistive-text')
|
|
128
|
+
.text()
|
|
129
|
+
.trim(),
|
|
130
|
+
).toBe(accessibleText);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('has the provided visually hidden accessible text', () => {
|
|
134
|
+
const $ = cheerio.load(
|
|
135
|
+
renderComponent('panel', {
|
|
136
|
+
...EXAMPLE_PANEL_BASIC,
|
|
137
|
+
type: panelType,
|
|
138
|
+
assistiveTextPrefix: 'Some helpful text:',
|
|
139
|
+
}),
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(
|
|
143
|
+
$('.ons-panel__assistive-text')
|
|
144
|
+
.text()
|
|
145
|
+
.trim(),
|
|
146
|
+
).toBe('Some helpful text:');
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('mode: info', () => {
|
|
151
|
+
it('has the default title tag', () => {
|
|
152
|
+
const $ = cheerio.load(
|
|
153
|
+
renderComponent('panel', {
|
|
154
|
+
...EXAMPLE_PANEL_BASIC,
|
|
155
|
+
title: 'Panel title',
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
const titleTag = $('.ons-panel__title')[0].tagName;
|
|
160
|
+
expect(titleTag).toBe('div');
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('has the provided `titleTag`', () => {
|
|
164
|
+
const $ = cheerio.load(
|
|
165
|
+
renderComponent('panel', {
|
|
166
|
+
...EXAMPLE_PANEL_BASIC,
|
|
167
|
+
title: 'Panel title',
|
|
168
|
+
titleTag: 'h3',
|
|
169
|
+
}),
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
const titleTag = $('.ons-panel__title')[0].tagName;
|
|
173
|
+
expect(titleTag).toBe('h3');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it('has the provided `title` text', () => {
|
|
177
|
+
const $ = cheerio.load(
|
|
178
|
+
renderComponent('panel', {
|
|
179
|
+
...EXAMPLE_PANEL_BASIC,
|
|
180
|
+
title: 'Panel title',
|
|
181
|
+
}),
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
const titleText = $('.ons-panel__title').text();
|
|
185
|
+
expect(titleText).toBe('Panel title');
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
describe('mode: error', () => {
|
|
190
|
+
it('has the default id set', () => {
|
|
191
|
+
const $ = cheerio.load(
|
|
192
|
+
renderComponent('panel', {
|
|
193
|
+
...EXAMPLE_PANEL_BASIC,
|
|
194
|
+
title: 'Error title',
|
|
195
|
+
type: 'error',
|
|
196
|
+
}),
|
|
197
|
+
);
|
|
198
|
+
|
|
199
|
+
expect($('#error-summary-title').length).toBe(1);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('has H2 as the default title tag', () => {
|
|
203
|
+
const $ = cheerio.load(
|
|
204
|
+
renderComponent('panel', {
|
|
205
|
+
...EXAMPLE_PANEL_BASIC,
|
|
206
|
+
title: 'Error title',
|
|
207
|
+
type: 'error',
|
|
208
|
+
}),
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
const titleTag = $('.ons-panel__title')[0].tagName;
|
|
212
|
+
expect(titleTag).toBe('h2');
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('has aria-labelledby attribute set with default value', () => {
|
|
216
|
+
const $ = cheerio.load(
|
|
217
|
+
renderComponent('panel', {
|
|
218
|
+
...EXAMPLE_PANEL_BASIC,
|
|
219
|
+
title: 'Error title',
|
|
220
|
+
type: 'error',
|
|
221
|
+
}),
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
expect($('.ons-panel').attr('aria-labelledby')).toBe('error-summary-title');
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('has the role attribute set to alert', () => {
|
|
228
|
+
const $ = cheerio.load(
|
|
229
|
+
renderComponent('panel', {
|
|
230
|
+
...EXAMPLE_PANEL_BASIC,
|
|
231
|
+
title: 'Error title',
|
|
232
|
+
type: 'error',
|
|
233
|
+
}),
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
expect($('.ons-panel').attr('role')).toBe('alert');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('has the tabindex attribute set to -1', () => {
|
|
240
|
+
const $ = cheerio.load(
|
|
241
|
+
renderComponent('panel', {
|
|
242
|
+
...EXAMPLE_PANEL_BASIC,
|
|
243
|
+
title: 'Error title',
|
|
244
|
+
type: 'error',
|
|
245
|
+
}),
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
expect($('.ons-panel').attr('tabindex')).toBe('-1');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('has the autofocus attribute set to autofocus', () => {
|
|
252
|
+
const $ = cheerio.load(
|
|
253
|
+
renderComponent('panel', {
|
|
254
|
+
...EXAMPLE_PANEL_BASIC,
|
|
255
|
+
title: 'Error title',
|
|
256
|
+
type: 'error',
|
|
257
|
+
}),
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
expect($('.ons-panel').attr('autofocus')).toBe('autofocus');
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('does not have the autofocus attribute set if `dsExample` is provided', () => {
|
|
264
|
+
const $ = cheerio.load(
|
|
265
|
+
renderComponent('panel', {
|
|
266
|
+
...EXAMPLE_PANEL_BASIC,
|
|
267
|
+
title: 'Error title',
|
|
268
|
+
type: 'error',
|
|
269
|
+
dsExample: true,
|
|
270
|
+
}),
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
expect($('.ons-panel').attr('autofocus')).toBe(undefined);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe('mode: spacious', () => {
|
|
278
|
+
it('has the correct class set', () => {
|
|
279
|
+
const $ = cheerio.load(
|
|
280
|
+
renderComponent('panel', {
|
|
281
|
+
...EXAMPLE_PANEL_BASIC,
|
|
282
|
+
spacious: true,
|
|
283
|
+
}),
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
expect($('.ons-panel').hasClass('ons-panel--spacious')).toBe(true);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe('mode: announcement', () => {
|
|
291
|
+
it('creates containers with the correct classes', () => {
|
|
292
|
+
const $ = cheerio.load(
|
|
293
|
+
renderComponent('panel', {
|
|
294
|
+
...EXAMPLE_PANEL_BASIC,
|
|
295
|
+
type: 'announcement',
|
|
296
|
+
}),
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
expect($('.ons-announcement').length).toBe(1);
|
|
300
|
+
expect($('.ons-container').length).toBe(1);
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
it('has `arrow-forward` icon', () => {
|
|
304
|
+
const faker = templateFaker();
|
|
305
|
+
const iconsSpy = faker.spy('icons');
|
|
306
|
+
|
|
307
|
+
faker.renderComponent('panel', {
|
|
308
|
+
...EXAMPLE_PANEL_BASIC,
|
|
309
|
+
type: 'announcement',
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('arrow-forward');
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
|
|
316
|
+
describe('mode: bare', () => {
|
|
317
|
+
it('has the correct class set', () => {
|
|
318
|
+
const $ = cheerio.load(
|
|
319
|
+
renderComponent('panel', {
|
|
320
|
+
...EXAMPLE_PANEL_BASIC,
|
|
321
|
+
type: 'bare',
|
|
322
|
+
}),
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
expect($('.ons-panel').hasClass('ons-panel--bare')).toBe(true);
|
|
326
|
+
});
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
describe('mode: warn', () => {
|
|
330
|
+
it('has a default "!" prefix', () => {
|
|
331
|
+
const $ = cheerio.load(
|
|
332
|
+
renderComponent('panel', {
|
|
333
|
+
...EXAMPLE_PANEL_BASIC,
|
|
334
|
+
type: 'warn',
|
|
335
|
+
}),
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
expect(
|
|
339
|
+
$('.ons-panel__icon')
|
|
340
|
+
.text()
|
|
341
|
+
.trim(),
|
|
342
|
+
).toBe('!');
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
describe('mode: warn-branded', () => {
|
|
347
|
+
it('creates a container div', () => {
|
|
348
|
+
const $ = cheerio.load(
|
|
349
|
+
renderComponent('panel', {
|
|
350
|
+
...EXAMPLE_PANEL_BASIC,
|
|
351
|
+
type: 'warn-branded',
|
|
352
|
+
}),
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
expect($('.ons-census-warning').length).toBe(1);
|
|
356
|
+
expect($('.ons-container').length).toBe(1);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('has a default "!" prefix', () => {
|
|
360
|
+
const $ = cheerio.load(
|
|
361
|
+
renderComponent('panel', {
|
|
362
|
+
...EXAMPLE_PANEL_BASIC,
|
|
363
|
+
type: 'warn-branded',
|
|
364
|
+
}),
|
|
365
|
+
);
|
|
366
|
+
|
|
367
|
+
expect(
|
|
368
|
+
$('.ons-panel__icon')
|
|
369
|
+
.text()
|
|
370
|
+
.trim(),
|
|
371
|
+
).toBe('!');
|
|
372
|
+
});
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
describe('mode: custom icon', () => {
|
|
376
|
+
it('passes jest-axe checks', async () => {
|
|
377
|
+
const $ = cheerio.load(
|
|
378
|
+
renderComponent('panel', {
|
|
379
|
+
...EXAMPLE_PANEL_BASIC,
|
|
380
|
+
iconType: 'check',
|
|
381
|
+
}),
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
const results = await axe($.html());
|
|
385
|
+
expect(results).toHaveNoViolations();
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
it('has a custom icon `iconType`', () => {
|
|
389
|
+
const faker = templateFaker();
|
|
390
|
+
const iconsSpy = faker.spy('icons');
|
|
391
|
+
|
|
392
|
+
faker.renderComponent('panel', {
|
|
393
|
+
...EXAMPLE_PANEL_BASIC,
|
|
394
|
+
iconType: 'check',
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('check');
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it('has the default icon size set', () => {
|
|
401
|
+
const $ = cheerio.load(
|
|
402
|
+
renderComponent('panel', {
|
|
403
|
+
...EXAMPLE_PANEL_BASIC,
|
|
404
|
+
iconType: 'check',
|
|
405
|
+
}),
|
|
406
|
+
);
|
|
407
|
+
|
|
408
|
+
expect($('.ons-panel__icon').hasClass('ons-u-fs-r')).toBe(true);
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it.each(['r', 'm', 'l', 'xl'])('has the correct class for the provided `iconSize` override (%s)', customIconSize => {
|
|
412
|
+
const $ = cheerio.load(
|
|
413
|
+
renderComponent('panel', {
|
|
414
|
+
...EXAMPLE_PANEL_BASIC,
|
|
415
|
+
iconType: 'check',
|
|
416
|
+
iconSize: customIconSize,
|
|
417
|
+
}),
|
|
418
|
+
);
|
|
419
|
+
|
|
420
|
+
expect($('.ons-panel__icon').hasClass(`ons-u-fs-${customIconSize}`)).toBe(true);
|
|
421
|
+
});
|
|
422
|
+
});
|
|
423
|
+
});
|
|
@@ -0,0 +1,137 @@
|
|
|
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_PASSWORD_MINIMAL = {
|
|
9
|
+
id: 'example-password',
|
|
10
|
+
name: 'example-password-name',
|
|
11
|
+
label: {
|
|
12
|
+
text: 'Label text',
|
|
13
|
+
description: 'Description text',
|
|
14
|
+
classes: 'extra-label-class',
|
|
15
|
+
},
|
|
16
|
+
showPasswordText: 'Show password',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const EXAMPLE_PASSWORD = {
|
|
20
|
+
...EXAMPLE_PASSWORD_MINIMAL,
|
|
21
|
+
fieldId: 'example-password-field',
|
|
22
|
+
fieldClasses: 'extra-field-class',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const EXAMPLE_PASSWORD_WITH_ERROR = {
|
|
26
|
+
...EXAMPLE_PASSWORD,
|
|
27
|
+
error: {
|
|
28
|
+
id: 'example-error',
|
|
29
|
+
text: 'Error text...',
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
describe('macro: password', () => {
|
|
34
|
+
it('passes jest-axe checks', async () => {
|
|
35
|
+
const $ = cheerio.load(renderComponent('password', EXAMPLE_PASSWORD));
|
|
36
|
+
|
|
37
|
+
const results = await axe($.html());
|
|
38
|
+
expect(results).toHaveNoViolations();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('passes jest-axe checks when error is shown', async () => {
|
|
42
|
+
const $ = cheerio.load(renderComponent('password', EXAMPLE_PASSWORD_WITH_ERROR));
|
|
43
|
+
|
|
44
|
+
const results = await axe($.html());
|
|
45
|
+
expect(results).toHaveNoViolations();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('provides expected parameters to the inner `field` component', () => {
|
|
49
|
+
const faker = templateFaker();
|
|
50
|
+
const fieldSpy = faker.spy('field');
|
|
51
|
+
|
|
52
|
+
cheerio.load(faker.renderComponent('password', EXAMPLE_PASSWORD));
|
|
53
|
+
|
|
54
|
+
expect(fieldSpy.occurrences[0]).toEqual({
|
|
55
|
+
id: 'example-password-field',
|
|
56
|
+
classes: 'ons-js-password extra-field-class',
|
|
57
|
+
error: undefined,
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('provides expected parameters to the inner `field` component when there is an error', () => {
|
|
62
|
+
const faker = templateFaker();
|
|
63
|
+
const fieldSpy = faker.spy('field');
|
|
64
|
+
|
|
65
|
+
cheerio.load(faker.renderComponent('password', EXAMPLE_PASSWORD_WITH_ERROR));
|
|
66
|
+
|
|
67
|
+
expect(fieldSpy.occurrences[0]).toEqual({
|
|
68
|
+
id: 'example-password-field',
|
|
69
|
+
classes: 'ons-js-password extra-field-class',
|
|
70
|
+
error: {
|
|
71
|
+
id: 'example-error',
|
|
72
|
+
text: 'Error text...',
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('provides expected parameters to the inner `label` component', () => {
|
|
78
|
+
const faker = templateFaker();
|
|
79
|
+
const labelSpy = faker.spy('label');
|
|
80
|
+
|
|
81
|
+
cheerio.load(faker.renderComponent('password', EXAMPLE_PASSWORD));
|
|
82
|
+
|
|
83
|
+
expect(labelSpy.occurrences[0]).toEqual({
|
|
84
|
+
for: 'example-password',
|
|
85
|
+
text: 'Label text',
|
|
86
|
+
description: 'Description text',
|
|
87
|
+
classes: 'extra-label-class',
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('provides expected parameters to the inner `checkbox` component', () => {
|
|
92
|
+
const faker = templateFaker();
|
|
93
|
+
const checkboxSpy = faker.spy('checkboxes/checkbox');
|
|
94
|
+
|
|
95
|
+
cheerio.load(faker.renderComponent('password', EXAMPLE_PASSWORD));
|
|
96
|
+
|
|
97
|
+
expect(checkboxSpy.occurrences[0]).toEqual({
|
|
98
|
+
id: 'example-password-toggle',
|
|
99
|
+
classes: 'ons-js-password-toggle-wrap ons-checkbox--toggle ons-u-d-no',
|
|
100
|
+
inputClasses: 'ons-js-password-toggle',
|
|
101
|
+
name: 'show-password',
|
|
102
|
+
label: {
|
|
103
|
+
text: 'Show password',
|
|
104
|
+
},
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('provides expected parameters to the inner `input` component', () => {
|
|
109
|
+
const faker = templateFaker();
|
|
110
|
+
const inputSpy = faker.spy('input');
|
|
111
|
+
|
|
112
|
+
cheerio.load(faker.renderComponent('password', EXAMPLE_PASSWORD));
|
|
113
|
+
|
|
114
|
+
expect(inputSpy.occurrences[0]).toEqual({
|
|
115
|
+
id: 'example-password',
|
|
116
|
+
name: 'example-password-name',
|
|
117
|
+
type: 'password',
|
|
118
|
+
classes: 'ons-u-mt-xs ons-js-password-input',
|
|
119
|
+
dontWrap: true,
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('provides expected parameters to the inner `input` component when error is shown', () => {
|
|
124
|
+
const faker = templateFaker();
|
|
125
|
+
const inputSpy = faker.spy('input');
|
|
126
|
+
|
|
127
|
+
cheerio.load(faker.renderComponent('password', EXAMPLE_PASSWORD_WITH_ERROR));
|
|
128
|
+
|
|
129
|
+
expect(inputSpy.occurrences[0]).toEqual({
|
|
130
|
+
id: 'example-password',
|
|
131
|
+
name: 'example-password-name',
|
|
132
|
+
type: 'password',
|
|
133
|
+
classes: 'ons-u-mt-xs ons-js-password-input ons-input--error',
|
|
134
|
+
dontWrap: true,
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
|
|
2
|
+
|
|
3
|
+
const EXAMPLE_PASSWORD_MINIMAL = {
|
|
4
|
+
id: 'example-password',
|
|
5
|
+
name: 'example-password-name',
|
|
6
|
+
label: {
|
|
7
|
+
text: 'Label text',
|
|
8
|
+
description: 'Description text',
|
|
9
|
+
classes: 'extra-label-class',
|
|
10
|
+
},
|
|
11
|
+
showPasswordText: 'Show password',
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
describe('script: password', () => {
|
|
15
|
+
it('has input of type `password` initially', async () => {
|
|
16
|
+
await setTestPage('/test', renderComponent('password', EXAMPLE_PASSWORD_MINIMAL));
|
|
17
|
+
|
|
18
|
+
const inputType = await page.evaluate(() => document.querySelector('#example-password').type);
|
|
19
|
+
expect(inputType).toBe('password');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('has input of type `text` when "Show password" toggle is clicked', async () => {
|
|
23
|
+
await setTestPage('/test', renderComponent('password', EXAMPLE_PASSWORD_MINIMAL));
|
|
24
|
+
|
|
25
|
+
await page.click('#example-password-toggle');
|
|
26
|
+
|
|
27
|
+
const inputType = await page.evaluate(() => document.querySelector('#example-password').type);
|
|
28
|
+
expect(inputType).toBe('text');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('has input of type `password` when "Show password" toggle is clicked twice', async () => {
|
|
32
|
+
await setTestPage('/test', renderComponent('password', EXAMPLE_PASSWORD_MINIMAL));
|
|
33
|
+
|
|
34
|
+
await page.click('#example-password-toggle');
|
|
35
|
+
await page.click('#example-password-toggle');
|
|
36
|
+
|
|
37
|
+
const inputType = await page.evaluate(() => document.querySelector('#example-password').type);
|
|
38
|
+
expect(inputType).toBe('password');
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
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_PHASE_BANNER_MINIMAL = {
|
|
9
|
+
html: 'Example content with a <a href="#">link</a>',
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
describe('macro: phase-banner', () => {
|
|
13
|
+
it('passes jest-axe checks with', async () => {
|
|
14
|
+
const $ = cheerio.load(renderComponent('phase-banner', EXAMPLE_PHASE_BANNER_MINIMAL));
|
|
15
|
+
|
|
16
|
+
const results = await axe($.html());
|
|
17
|
+
expect(results).toHaveNoViolations();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it('has expected html content', () => {
|
|
21
|
+
const $ = cheerio.load(renderComponent('phase-banner', EXAMPLE_PHASE_BANNER_MINIMAL));
|
|
22
|
+
|
|
23
|
+
const htmlContent = $('.ons-phase-banner__desc')
|
|
24
|
+
.html()
|
|
25
|
+
.trim();
|
|
26
|
+
expect(htmlContent).toBe('Example content with a <a href="#">link</a>');
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('has the "Beta" badge by default', () => {
|
|
30
|
+
const $ = cheerio.load(renderComponent('phase-banner', EXAMPLE_PHASE_BANNER_MINIMAL));
|
|
31
|
+
|
|
32
|
+
const badgeText = $('.ons-phase-banner__badge')
|
|
33
|
+
.text()
|
|
34
|
+
.trim();
|
|
35
|
+
expect(badgeText).toBe('Beta');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('has the provided `badge` text', () => {
|
|
39
|
+
const $ = cheerio.load(
|
|
40
|
+
renderComponent('phase-banner', {
|
|
41
|
+
...EXAMPLE_PHASE_BANNER_MINIMAL,
|
|
42
|
+
badge: 'Alpha',
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const badgeText = $('.ons-phase-banner__badge')
|
|
47
|
+
.text()
|
|
48
|
+
.trim();
|
|
49
|
+
expect(badgeText).toBe('Alpha');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('has no badge when `hideBadge` is true', () => {
|
|
53
|
+
const $ = cheerio.load(
|
|
54
|
+
renderComponent('phase-banner', {
|
|
55
|
+
...EXAMPLE_PHASE_BANNER_MINIMAL,
|
|
56
|
+
hideBadge: true,
|
|
57
|
+
}),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
expect($('.ons-phase-banner__badge').length).toBe(0);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('has `container--wide` class when `wide` is true', () => {
|
|
64
|
+
const $ = cheerio.load(
|
|
65
|
+
renderComponent('phase-banner', {
|
|
66
|
+
...EXAMPLE_PHASE_BANNER_MINIMAL,
|
|
67
|
+
wide: true,
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
expect($('.ons-container').hasClass('ons-container--wide')).toBe(true);
|
|
72
|
+
});
|
|
73
|
+
});
|