@ons/design-system 50.0.1 → 53.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/_button.scss +75 -33
- package/components/button/_macro.njk +6 -6
- 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.njk +5 -2
- package/components/external-link/_macro.spec.js +77 -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/_footer.scss +19 -4
- package/components/footer/_macro.njk +106 -137
- package/components/footer/_macro.spec.js +678 -0
- package/components/header/_header.scss +65 -46
- package/components/header/_macro.njk +173 -121
- package/components/header/_macro.spec.js +618 -0
- package/components/hero/_hero.scss +30 -143
- package/components/hero/_macro.njk +12 -23
- package/components/hero/_macro.spec.js +218 -0
- package/components/icons/_macro.njk +258 -30
- 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/_input.scss +8 -0
- 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.njk +1 -1
- package/components/language-selector/_macro.spec.js +137 -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 +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 +45 -38
- package/components/navigation/_macro.spec.js +329 -0
- package/components/navigation/_navigation.scss +20 -4
- 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 +14 -21
- package/components/related-content/_macro.spec.js +133 -0
- package/components/related-content/_section-macro.njk +10 -0
- package/components/related-content/_section-macro.spec.js +43 -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 +6 -4
- 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 +3 -1
- package/css/ids.css +2 -0
- package/css/main.css +1 -1
- package/img/dummy-brand-logo.svg +1 -0
- package/js/cookies-settings.spec.js +154 -0
- package/layout/_template.njk +7 -4
- package/package.json +10 -23
- package/scripts/main.es5.js +2 -2
- package/scripts/main.js +1 -1
- package/scss/ids.scss +2 -0
- package/scss/settings/_census.scss +141 -0
- package/scss/settings/_ids.scss +48 -0
- package/scss/utilities/_margin.scss +1 -0
- package/scss/vars/_colors.scss +5 -2
|
@@ -0,0 +1,446 @@
|
|
|
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
|
+
describe('macro: button', () => {
|
|
9
|
+
it('has the provided `id` attribute', () => {
|
|
10
|
+
const $ = cheerio.load(
|
|
11
|
+
renderComponent('button', {
|
|
12
|
+
id: 'example-id',
|
|
13
|
+
}),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect($('#example-id').length).toBe(1);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it('is an `a` element when `dsExample` is truthy', () => {
|
|
20
|
+
const $ = cheerio.load(
|
|
21
|
+
renderComponent('button', {
|
|
22
|
+
dsExample: true,
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
expect($('a').length).toBe(1);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('has additionally provided `attributes`', () => {
|
|
30
|
+
const $ = cheerio.load(
|
|
31
|
+
renderComponent('button', {
|
|
32
|
+
attributes: {
|
|
33
|
+
a: 123,
|
|
34
|
+
b: 456,
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect($('button').attr('a')).toBe('123');
|
|
40
|
+
expect($('button').attr('b')).toBe('456');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('has expected style classes', () => {
|
|
44
|
+
const $ = cheerio.load(renderComponent('button'));
|
|
45
|
+
|
|
46
|
+
expect($('.ons-btn .ons-btn__inner').length).toBe(1);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('has provided variant style classes', () => {
|
|
50
|
+
const $ = cheerio.load(
|
|
51
|
+
renderComponent('button', {
|
|
52
|
+
variants: ['variant-a', 'variant-b'],
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
expect($('.ons-btn').hasClass('ons-btn--variant-a')).toBe(true);
|
|
57
|
+
expect($('.ons-btn').hasClass('ons-btn--variant-b')).toBe(true);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('has download variant style class when `buttonStyle` is `download`', () => {
|
|
61
|
+
const $ = cheerio.load(
|
|
62
|
+
renderComponent('button', {
|
|
63
|
+
url: 'http://example.com',
|
|
64
|
+
buttonStyle: 'download',
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
expect($('.ons-btn').hasClass('ons-btn--download')).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('has `download` icon when `buttonStyle` is "download"', () => {
|
|
72
|
+
const faker = templateFaker();
|
|
73
|
+
const iconsSpy = faker.spy('icons');
|
|
74
|
+
|
|
75
|
+
faker.renderComponent('button', {
|
|
76
|
+
url: 'http://example.com',
|
|
77
|
+
buttonStyle: 'download',
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('download');
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('has provided variant style classes when `buttonStyle` is "print"', () => {
|
|
84
|
+
const $ = cheerio.load(
|
|
85
|
+
renderComponent('button', {
|
|
86
|
+
buttonStyle: 'print',
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
expect($('.ons-btn').hasClass('ons-btn--print')).toBe(true);
|
|
91
|
+
expect($('.ons-btn').hasClass('ons-u-d-no')).toBe(true);
|
|
92
|
+
expect($('.ons-btn').hasClass('ons-js-print-btn')).toBe(true);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('has `print` icon when `buttonStyle` is "print"', () => {
|
|
96
|
+
const faker = templateFaker();
|
|
97
|
+
const iconsSpy = faker.spy('icons');
|
|
98
|
+
|
|
99
|
+
faker.renderComponent('button', {
|
|
100
|
+
url: 'http://example.com',
|
|
101
|
+
buttonStyle: 'print',
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('print');
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('has provided variant style classes when `submitType` is "loader"', () => {
|
|
108
|
+
const $ = cheerio.load(
|
|
109
|
+
renderComponent('button', {
|
|
110
|
+
submitType: 'loader',
|
|
111
|
+
}),
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
expect($('.ons-btn').hasClass('ons-btn--loader')).toBe(true);
|
|
115
|
+
expect($('.ons-btn').hasClass('ons-js-loader')).toBe(true);
|
|
116
|
+
expect($('.ons-btn').hasClass('ons-js-submit-btn')).toBe(true);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('has `loader` icon when `submitType` is "loader"', () => {
|
|
120
|
+
const faker = templateFaker();
|
|
121
|
+
const iconsSpy = faker.spy('icons');
|
|
122
|
+
|
|
123
|
+
faker.renderComponent('button', {
|
|
124
|
+
submitType: 'loader',
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('loader');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('has `chevron` icon when `buttonStyle` is "mobile"', () => {
|
|
131
|
+
const faker = templateFaker();
|
|
132
|
+
const iconsSpy = faker.spy('icons');
|
|
133
|
+
|
|
134
|
+
faker.renderComponent('button', {
|
|
135
|
+
buttonStyle: 'mobile',
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('chevron');
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it('has provided variant style classes when `submitType` is "timer"', () => {
|
|
142
|
+
const $ = cheerio.load(
|
|
143
|
+
renderComponent('button', {
|
|
144
|
+
submitType: 'timer',
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
expect($('.ons-btn').hasClass('ons-js-timer')).toBe(true);
|
|
149
|
+
expect($('.ons-btn').hasClass('ons-js-submit-btn')).toBe(true);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('has additionally provided style classes', () => {
|
|
153
|
+
const $ = cheerio.load(
|
|
154
|
+
renderComponent('button', {
|
|
155
|
+
classes: 'extra-class another-extra-class',
|
|
156
|
+
}),
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
expect($('.ons-btn').hasClass('extra-class')).toBe(true);
|
|
160
|
+
expect($('.ons-btn').hasClass('another-extra-class')).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('has additionally provided inner style classes', () => {
|
|
164
|
+
const $ = cheerio.load(
|
|
165
|
+
renderComponent('button', {
|
|
166
|
+
innerClasses: 'extra-inner-class another-extra-inner-class',
|
|
167
|
+
}),
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
expect($('.ons-btn__inner').hasClass('extra-inner-class')).toBe(true);
|
|
171
|
+
expect($('.ons-btn__inner').hasClass('another-extra-inner-class')).toBe(true);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('has label text when `text` is provided', () => {
|
|
175
|
+
const $ = cheerio.load(
|
|
176
|
+
renderComponent('button', {
|
|
177
|
+
text: 'Click > me!',
|
|
178
|
+
}),
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
expect($('.ons-btn__text').html()).toBe('Click > me!');
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('has label text when `html` is provided', () => {
|
|
185
|
+
const $ = cheerio.load(
|
|
186
|
+
renderComponent('button', {
|
|
187
|
+
html: 'Click <strong>me</strong>!',
|
|
188
|
+
}),
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
expect($('.ons-btn__text').html()).toBe('Click <strong>me</strong>!');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('has button context text when `buttonContext` is provided', () => {
|
|
195
|
+
const $ = cheerio.load(
|
|
196
|
+
renderComponent('button', {
|
|
197
|
+
buttonContext: 'button context text',
|
|
198
|
+
}),
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
expect($('.ons-btn__context').text()).toBe('button context text');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('has custom icon before button text', () => {
|
|
205
|
+
const $ = cheerio.load(
|
|
206
|
+
renderComponent('button', {
|
|
207
|
+
text: 'Click me!',
|
|
208
|
+
iconPosition: 'before',
|
|
209
|
+
iconType: 'exit',
|
|
210
|
+
}),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
expect($('.ons-svg-icon + .ons-btn__text').text()).toBe('Click me!');
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it('has custom icon after button text', () => {
|
|
217
|
+
const $ = cheerio.load(
|
|
218
|
+
renderComponent('button', {
|
|
219
|
+
text: 'Click me!',
|
|
220
|
+
iconPosition: 'after',
|
|
221
|
+
iconType: 'exit',
|
|
222
|
+
}),
|
|
223
|
+
);
|
|
224
|
+
|
|
225
|
+
expect(
|
|
226
|
+
$('.ons-btn__text + .ons-svg-icon')
|
|
227
|
+
.prev()
|
|
228
|
+
.text(),
|
|
229
|
+
).toBe('Click me!');
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
describe('mode: standard', () => {
|
|
233
|
+
it('passes jest-axe checks', async () => {
|
|
234
|
+
const $ = cheerio.load(
|
|
235
|
+
renderComponent('button', {
|
|
236
|
+
text: 'Example button',
|
|
237
|
+
name: 'example',
|
|
238
|
+
value: 'example-value',
|
|
239
|
+
}),
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const results = await axe($.html());
|
|
243
|
+
expect(results).toHaveNoViolations();
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('is an `button` element', () => {
|
|
247
|
+
const $ = cheerio.load(renderComponent('button'));
|
|
248
|
+
|
|
249
|
+
expect($('button').length).toBe(1);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('has the provided `type` attribute', () => {
|
|
253
|
+
const $ = cheerio.load(
|
|
254
|
+
renderComponent('button', {
|
|
255
|
+
type: 'special-type',
|
|
256
|
+
}),
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
expect($('button').attr('type')).toBe('special-type');
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('has the provided `type` attribute even if `buttonStyle` is provided', () => {
|
|
263
|
+
const $ = cheerio.load(
|
|
264
|
+
renderComponent('button', {
|
|
265
|
+
type: 'special-type',
|
|
266
|
+
buttonStyle: 'print',
|
|
267
|
+
}),
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
expect($('button').attr('type')).toBe('special-type');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('defaults to being a "submit" button when `type` is not provided', () => {
|
|
274
|
+
const $ = cheerio.load(renderComponent('button'));
|
|
275
|
+
|
|
276
|
+
expect($('button').attr('type')).toBe('submit');
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('defaults to being a "button" when `type` is not provided and `buttonStyle` is set to "print"', () => {
|
|
280
|
+
const $ = cheerio.load(
|
|
281
|
+
renderComponent('button', {
|
|
282
|
+
buttonStyle: 'print',
|
|
283
|
+
}),
|
|
284
|
+
);
|
|
285
|
+
|
|
286
|
+
expect($('button').attr('type')).toBe('button');
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
it('has the provided `value` attribute', () => {
|
|
290
|
+
const $ = cheerio.load(
|
|
291
|
+
renderComponent('button', {
|
|
292
|
+
value: 'special-value',
|
|
293
|
+
}),
|
|
294
|
+
);
|
|
295
|
+
|
|
296
|
+
expect($('button').attr('value')).toBe('special-value');
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it('has the provided `name` attribute', () => {
|
|
300
|
+
const $ = cheerio.load(
|
|
301
|
+
renderComponent('button', {
|
|
302
|
+
name: 'special-name',
|
|
303
|
+
}),
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
expect($('button').attr('name')).toBe('special-name');
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
describe('mode: link', () => {
|
|
311
|
+
it('passes jest-axe checks', async () => {
|
|
312
|
+
const $ = cheerio.load(
|
|
313
|
+
renderComponent('button', {
|
|
314
|
+
text: 'Example button',
|
|
315
|
+
name: 'example',
|
|
316
|
+
value: 'example-value',
|
|
317
|
+
url: 'http://example.com',
|
|
318
|
+
}),
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
const results = await axe($.html());
|
|
322
|
+
expect(results).toHaveNoViolations();
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it('is an `a` element', () => {
|
|
326
|
+
const $ = cheerio.load(
|
|
327
|
+
renderComponent('button', {
|
|
328
|
+
url: 'http://example.com',
|
|
329
|
+
}),
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
expect($('a').length).toBe(1);
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
it('has expected style classes', () => {
|
|
336
|
+
const $ = cheerio.load(
|
|
337
|
+
renderComponent('button', {
|
|
338
|
+
url: 'http://example.com',
|
|
339
|
+
}),
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
expect($('a').hasClass('ons-btn')).toBe(true);
|
|
343
|
+
expect($('.ons-btn').hasClass('ons-btn--link')).toBe(true);
|
|
344
|
+
expect($('.ons-btn').hasClass('ons-js-submit-btn')).toBe(true);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('has the provided link', () => {
|
|
348
|
+
const $ = cheerio.load(
|
|
349
|
+
renderComponent('button', {
|
|
350
|
+
url: 'http://example.com',
|
|
351
|
+
}),
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
expect($('a').attr('href')).toBe('http://example.com');
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
it('has `arrow-next` icon by default', () => {
|
|
358
|
+
const faker = templateFaker();
|
|
359
|
+
const iconsSpy = faker.spy('icons');
|
|
360
|
+
|
|
361
|
+
faker.renderComponent('button', {
|
|
362
|
+
url: 'http://example.com',
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('arrow-next');
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it('opens in a new window when `newWindow` is `true`', () => {
|
|
369
|
+
const $ = cheerio.load(
|
|
370
|
+
renderComponent('button', {
|
|
371
|
+
url: 'http://example.com',
|
|
372
|
+
newWindow: true,
|
|
373
|
+
}),
|
|
374
|
+
);
|
|
375
|
+
|
|
376
|
+
expect($('a').attr('target')).toBe('_blank');
|
|
377
|
+
expect($('a').attr('rel')).toBe('noopener');
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
it('has `external-link` icon when `newWindow` is `true`', () => {
|
|
381
|
+
const faker = templateFaker();
|
|
382
|
+
const iconsSpy = faker.spy('icons');
|
|
383
|
+
|
|
384
|
+
faker.renderComponent('button', {
|
|
385
|
+
url: 'http://example.com',
|
|
386
|
+
newWindow: true,
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('external-link');
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it('has the `button` role', () => {
|
|
393
|
+
const $ = cheerio.load(
|
|
394
|
+
renderComponent('button', {
|
|
395
|
+
url: 'http://example.com',
|
|
396
|
+
}),
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
expect($('.ons-btn').attr('role')).toBe('button');
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
it('has a default new window description when `newWindow` is `true`', () => {
|
|
403
|
+
const $ = cheerio.load(
|
|
404
|
+
renderComponent('button', {
|
|
405
|
+
url: 'http://example.com',
|
|
406
|
+
newWindow: true,
|
|
407
|
+
}),
|
|
408
|
+
);
|
|
409
|
+
|
|
410
|
+
expect($('.ons-btn__new-window-description').text()).toBe('(opens in a new tab)');
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
it('has a custom new window description when `newWindow` is `true` and `newWindowDescription` is provided', () => {
|
|
414
|
+
const $ = cheerio.load(
|
|
415
|
+
renderComponent('button', {
|
|
416
|
+
url: 'http://example.com',
|
|
417
|
+
newWindow: true,
|
|
418
|
+
newWindowDescription: 'custom opens in a new window text',
|
|
419
|
+
}),
|
|
420
|
+
);
|
|
421
|
+
|
|
422
|
+
expect($('.ons-btn__new-window-description').text()).toBe('(custom opens in a new window text)');
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it('has the `download` attribute when `buttonStyle` is "download"', () => {
|
|
426
|
+
const $ = cheerio.load(
|
|
427
|
+
renderComponent('button', {
|
|
428
|
+
buttonStyle: 'download',
|
|
429
|
+
}),
|
|
430
|
+
);
|
|
431
|
+
|
|
432
|
+
expect($('.ons-btn').attr('download')).toBeDefined();
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
it('does not have the `download` attribute when `buttonStyle` is "download" and `removeDownloadAttribute` is `true`', () => {
|
|
436
|
+
const $ = cheerio.load(
|
|
437
|
+
renderComponent('button', {
|
|
438
|
+
buttonStyle: 'download',
|
|
439
|
+
removeDownloadAttribute: true,
|
|
440
|
+
}),
|
|
441
|
+
);
|
|
442
|
+
|
|
443
|
+
expect($('.ons-btn').attr('download')).toBeUndefined();
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
});
|