@ons/design-system 72.1.0 → 72.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/components/accordion/_macro.spec.js +2 -2
- package/components/address-input/_macro.spec.js +245 -322
- package/components/address-input/autosuggest.address.spec.js +16 -14
- package/components/address-output/_macro.spec.js +121 -74
- package/components/address-output/_test_examples.js +8 -0
- package/components/autosuggest/_macro.spec.js +373 -184
- package/components/back-to-top/back-to-top.dom.js +4 -4
- package/components/back-to-top/back-to-top.js +1 -1
- package/components/browser-banner/_macro.spec.js +11 -11
- package/components/button/_button.scss +1 -1
- package/components/button/_macro.njk +1 -1
- package/components/button/_macro.spec.js +405 -351
- package/components/button/example-button-group.njk +1 -0
- package/components/checkboxes/_checkbox.scss +3 -3
- package/components/description-list/_description-list.scss +40 -9
- package/components/description-list/_macro.njk +20 -12
- package/components/description-list/_macro.spec.js +11 -1
- package/components/description-list/example-inline-description-list.njk +58 -0
- package/components/details/_details.scss +1 -2
- package/components/details/example-details-open.njk +10 -0
- package/components/external-link/_macro.spec.js +66 -69
- package/components/external-link/_test_examples.js +4 -0
- package/components/feedback/_macro.spec.js +109 -80
- package/components/feedback/_test_examples.js +17 -0
- package/components/field/_macro.spec.js +106 -69
- package/components/header/_macro.njk +92 -90
- package/components/header/_macro.spec.js +10 -0
- package/components/header/example-header-basic.njk +11 -0
- package/components/hero/_hero.scss +239 -2
- package/components/hero/_macro.njk +7 -0
- package/components/hero/_macro.spec.js +5 -0
- package/components/hero/example-hero-navy-blue.njk +14 -0
- package/components/section-navigation/_macro.njk +9 -6
- package/components/table-of-contents/_macro.njk +3 -3
- package/components/table-of-contents/_macro.spec.js +3 -3
- package/components/table-of-contents/{_toc.scss → _table-of-contents.scss} +1 -1
- package/components/table-of-contents/table-of-contents.dom.js +13 -0
- package/components/table-of-contents/{toc.js → table-of-contents.js} +4 -4
- package/components/table-of-contents/{toc.spec.js → table-of-contents.spec.js} +2 -2
- package/components/tabs/_tabs.scss +10 -11
- package/components/tabs/tabs.js +3 -3
- package/components/timeout-modal/timeout-modal.spec.js +1 -1
- package/css/main.css +1 -1
- package/js/main.js +1 -1
- package/package.json +1 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +1 -1
- package/scss/main.scss +1 -1
- package/scss/utilities/_margin.scss +4 -0
- package/scss/utilities/_padding.scss +4 -0
- package/scss/vars/_colors.scss +2 -0
- package/components/table-of-contents/toc.dom.js +0 -13
|
@@ -5,296 +5,316 @@ import * as cheerio from 'cheerio';
|
|
|
5
5
|
import axe from '../../tests/helpers/axe';
|
|
6
6
|
import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
|
|
7
7
|
|
|
8
|
-
describe('
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
expect($('#example-id').length).toBe(1);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('has additionally provided `attributes`', () => {
|
|
20
|
-
const $ = cheerio.load(
|
|
21
|
-
renderComponent('button', {
|
|
22
|
-
attributes: {
|
|
23
|
-
a: 123,
|
|
24
|
-
b: 456,
|
|
25
|
-
},
|
|
26
|
-
}),
|
|
27
|
-
);
|
|
28
|
-
|
|
29
|
-
expect($('button').attr('a')).toBe('123');
|
|
30
|
-
expect($('button').attr('b')).toBe('456');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('has expected style classes', () => {
|
|
34
|
-
const $ = cheerio.load(renderComponent('button'));
|
|
35
|
-
|
|
36
|
-
expect($('.ons-btn .ons-btn__inner').length).toBe(1);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('has provided variant style classes', () => {
|
|
40
|
-
const $ = cheerio.load(
|
|
41
|
-
renderComponent('button', {
|
|
42
|
-
variants: ['variant-a', 'variant-b'],
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
expect($('.ons-btn').hasClass('ons-btn--variant-a')).toBe(true);
|
|
47
|
-
expect($('.ons-btn').hasClass('ons-btn--variant-b')).toBe(true);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('has download variant style class when `variants` contains `download`', () => {
|
|
51
|
-
const $ = cheerio.load(
|
|
52
|
-
renderComponent('button', {
|
|
53
|
-
url: 'http://example.com',
|
|
54
|
-
variants: 'download',
|
|
55
|
-
}),
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
expect($('.ons-btn').hasClass('ons-btn--download')).toBe(true);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('has `download` icon when `variants` contains "download"', () => {
|
|
62
|
-
const faker = templateFaker();
|
|
63
|
-
const iconsSpy = faker.spy('icon');
|
|
8
|
+
describe('FOR: Macro: Button', () => {
|
|
9
|
+
describe('GIVEN: Params: no params', () => {
|
|
10
|
+
describe('WHEN: there are no params provided', () => {
|
|
11
|
+
test('THEN: has expected style classes', () => {
|
|
12
|
+
const $ = cheerio.load(renderComponent('button'));
|
|
13
|
+
expect($('.ons-btn .ons-btn__inner').length).toBe(1);
|
|
14
|
+
});
|
|
64
15
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
16
|
+
test('THEN: the button is rendered', () => {
|
|
17
|
+
const $ = cheerio.load(renderComponent('button'));
|
|
18
|
+
expect($('button').length).toBe(1);
|
|
19
|
+
});
|
|
68
20
|
});
|
|
69
|
-
|
|
70
|
-
expect(iconsSpy.occurrences[0].iconType).toBe('download');
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('has provided variant style classes when `variants` contains "print"', () => {
|
|
74
|
-
const $ = cheerio.load(
|
|
75
|
-
renderComponent('button', {
|
|
76
|
-
variants: 'print',
|
|
77
|
-
}),
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
expect($('.ons-btn').hasClass('ons-btn--print')).toBe(true);
|
|
81
|
-
expect($('.ons-btn').hasClass('ons-u-d-no')).toBe(true);
|
|
82
|
-
expect($('.ons-btn').hasClass('ons-js-print-btn')).toBe(true);
|
|
83
21
|
});
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
22
|
+
describe('GIVEN: Params: text, name and value', () => {
|
|
23
|
+
describe('WHEN: text, name and value params are provided', () => {
|
|
24
|
+
test('THEN: passes jest-axe checks', async () => {
|
|
25
|
+
const $ = cheerio.load(
|
|
26
|
+
renderComponent('button', {
|
|
27
|
+
text: 'Example button',
|
|
28
|
+
name: 'example',
|
|
29
|
+
value: 'example-value',
|
|
30
|
+
}),
|
|
31
|
+
);
|
|
32
|
+
const results = await axe($.html());
|
|
33
|
+
expect(results).toHaveNoViolations();
|
|
34
|
+
});
|
|
92
35
|
});
|
|
93
|
-
|
|
94
|
-
expect(iconsSpy.occurrences[0].iconType).toBe('print');
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('has provided variant style classes when `variants` contains "loader"', () => {
|
|
98
|
-
const $ = cheerio.load(
|
|
99
|
-
renderComponent('button', {
|
|
100
|
-
variants: 'loader',
|
|
101
|
-
}),
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
expect($('.ons-btn').hasClass('ons-btn--loader')).toBe(true);
|
|
105
|
-
expect($('.ons-btn').hasClass('ons-js-loader')).toBe(true);
|
|
106
|
-
expect($('.ons-btn').hasClass('ons-js-submit-btn')).toBe(true);
|
|
107
36
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
37
|
+
describe('GIVEN: Params: id', () => {
|
|
38
|
+
describe('WHEN: the id param is provided', () => {
|
|
39
|
+
it('THEN: the button has the provided id', () => {
|
|
40
|
+
const $ = cheerio.load(
|
|
41
|
+
renderComponent('button', {
|
|
42
|
+
id: 'example-id',
|
|
43
|
+
}),
|
|
44
|
+
);
|
|
45
|
+
expect($('#example-id').length).toBe(1);
|
|
46
|
+
});
|
|
115
47
|
});
|
|
116
|
-
|
|
117
|
-
expect(iconsSpy.occurrences[0].iconType).toBe('loader');
|
|
118
48
|
});
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
49
|
+
describe('GIVEN: Params: attributes', () => {
|
|
50
|
+
describe('WHEN: the attributes param is provided', () => {
|
|
51
|
+
it('THEN: the button has the additionally provided attributes', () => {
|
|
52
|
+
const $ = cheerio.load(
|
|
53
|
+
renderComponent('button', {
|
|
54
|
+
attributes: {
|
|
55
|
+
a: 123,
|
|
56
|
+
b: 456,
|
|
57
|
+
},
|
|
58
|
+
}),
|
|
59
|
+
);
|
|
60
|
+
expect($('button').attr('a')).toBe('123');
|
|
61
|
+
expect($('button').attr('b')).toBe('456');
|
|
62
|
+
});
|
|
126
63
|
});
|
|
127
|
-
|
|
128
|
-
expect(iconsSpy.occurrences[0].iconType).toBe('chevron');
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
it('has provided variant style classes when `variants` contains "timer"', () => {
|
|
132
|
-
const $ = cheerio.load(
|
|
133
|
-
renderComponent('button', {
|
|
134
|
-
variants: 'timer',
|
|
135
|
-
}),
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
expect($('.ons-btn').hasClass('ons-js-timer')).toBe(true);
|
|
139
|
-
expect($('.ons-btn').hasClass('ons-js-submit-btn')).toBe(true);
|
|
140
64
|
});
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
65
|
+
describe('GIVEN: Params: text', () => {
|
|
66
|
+
describe('WHEN: the text param is provided', () => {
|
|
67
|
+
test('THEN: the button has the label text', () => {
|
|
68
|
+
const $ = cheerio.load(
|
|
69
|
+
renderComponent('button', {
|
|
70
|
+
text: 'Click > me!',
|
|
71
|
+
}),
|
|
72
|
+
);
|
|
73
|
+
expect($('.ons-btn__text').html()).toBe('Click > me!');
|
|
74
|
+
});
|
|
75
|
+
});
|
|
151
76
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
77
|
+
describe('GIVEN: Params: name', () => {
|
|
78
|
+
describe('WHEN: the name param is provided', () => {
|
|
79
|
+
test('THEN: the button renders with the provided name', () => {
|
|
80
|
+
const $ = cheerio.load(
|
|
81
|
+
renderComponent('button', {
|
|
82
|
+
name: 'example',
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
expect($('button').attr('name')).toBe('example');
|
|
86
|
+
});
|
|
87
|
+
});
|
|
162
88
|
});
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
89
|
+
describe('GIVEN: Params: value', () => {
|
|
90
|
+
describe('WHEN: the value param is provided', () => {
|
|
91
|
+
test('THEN: the button renders with the provided value', () => {
|
|
92
|
+
const $ = cheerio.load(
|
|
93
|
+
renderComponent('button', {
|
|
94
|
+
value: 'example-value',
|
|
95
|
+
}),
|
|
96
|
+
);
|
|
97
|
+
expect($('button').attr('value')).toBe('example-value');
|
|
98
|
+
});
|
|
99
|
+
});
|
|
172
100
|
});
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
101
|
+
describe('GIVEN: Params: buttonContext', () => {
|
|
102
|
+
describe('WHEN: buttonContext parameter is provided', () => {
|
|
103
|
+
test('THEN: the button has the provided button context', () => {
|
|
104
|
+
const $ = cheerio.load(
|
|
105
|
+
renderComponent('button', {
|
|
106
|
+
buttonContext: 'button context text',
|
|
107
|
+
}),
|
|
108
|
+
);
|
|
109
|
+
expect($('.ons-btn__context').text()).toBe('button context text');
|
|
110
|
+
});
|
|
111
|
+
});
|
|
182
112
|
});
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
113
|
+
describe('GIVEN: Params: html', () => {
|
|
114
|
+
describe('WHEN: html parameter is provided', () => {
|
|
115
|
+
test('THEN: the button label has the provided html', () => {
|
|
116
|
+
const $ = cheerio.load(
|
|
117
|
+
renderComponent('button', {
|
|
118
|
+
html: 'Click <strong>me</strong>!',
|
|
119
|
+
}),
|
|
120
|
+
);
|
|
121
|
+
expect($('.ons-btn__text').html()).toBe('Click <strong>me</strong>!');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
192
124
|
});
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
125
|
+
describe('GIVEN: Params: iconPosition', () => {
|
|
126
|
+
describe('WHEN: iconPosition is set to before for custom icon', () => {
|
|
127
|
+
test('THEN: renders custom icon before button text', () => {
|
|
128
|
+
const $ = cheerio.load(
|
|
129
|
+
renderComponent('button', {
|
|
130
|
+
text: 'Click me!',
|
|
131
|
+
iconPosition: 'before',
|
|
132
|
+
iconType: 'exit',
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
expect($('.ons-icon + .ons-btn__text').text()).toBe('Click me!');
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('WHEN: iconPosition is set to after for custom icon', () => {
|
|
139
|
+
test('THEN: renders custom icon after button text', () => {
|
|
140
|
+
const $ = cheerio.load(
|
|
141
|
+
renderComponent('button', {
|
|
142
|
+
text: 'Click me!',
|
|
143
|
+
iconPosition: 'after',
|
|
144
|
+
iconType: 'exit',
|
|
145
|
+
}),
|
|
146
|
+
);
|
|
147
|
+
expect($('.ons-btn__text + .ons-icon').prev().text()).toBe('Click me!');
|
|
148
|
+
});
|
|
149
|
+
});
|
|
204
150
|
});
|
|
205
151
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
152
|
+
describe('GIVEN: Params: iconType', () => {
|
|
153
|
+
describe('WHEN: iconType parameter is provided', () => {
|
|
154
|
+
test('THEN: the button has an svg element', () => {
|
|
155
|
+
const $ = cheerio.load(
|
|
156
|
+
renderComponent('button', {
|
|
157
|
+
text: 'Click me!',
|
|
158
|
+
iconPosition: 'after',
|
|
159
|
+
iconType: 'exit',
|
|
160
|
+
}),
|
|
161
|
+
);
|
|
162
|
+
expect($('svg').length).toBe(1);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
216
165
|
});
|
|
217
166
|
|
|
218
|
-
describe('
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
167
|
+
describe('GIVEN: Params: variants', () => {
|
|
168
|
+
describe('WHEN: variants are present', () => {
|
|
169
|
+
test('THEN: the button has the expected variant classes', () => {
|
|
170
|
+
const $ = cheerio.load(
|
|
171
|
+
renderComponent('button', {
|
|
172
|
+
variants: ['variant-a', 'variant-b'],
|
|
173
|
+
}),
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
expect($('.ons-btn').hasClass('ons-btn--variant-a')).toBe(true);
|
|
177
|
+
expect($('.ons-btn').hasClass('ons-btn--variant-b')).toBe(true);
|
|
178
|
+
});
|
|
230
179
|
});
|
|
180
|
+
describe('WHEN: variants contains download', () => {
|
|
181
|
+
test('THEN: the button has the download class', () => {
|
|
182
|
+
const $ = cheerio.load(
|
|
183
|
+
renderComponent('button', {
|
|
184
|
+
url: 'http://example.com',
|
|
185
|
+
variants: 'download',
|
|
186
|
+
}),
|
|
187
|
+
);
|
|
188
|
+
expect($('.ons-btn').hasClass('ons-btn--download')).toBe(true);
|
|
189
|
+
});
|
|
190
|
+
test('THEN: the button has the download icon', () => {
|
|
191
|
+
const faker = templateFaker();
|
|
192
|
+
const iconsSpy = faker.spy('icon');
|
|
231
193
|
|
|
232
|
-
|
|
233
|
-
|
|
194
|
+
faker.renderComponent('button', {
|
|
195
|
+
url: 'http://example.com',
|
|
196
|
+
variants: 'download',
|
|
197
|
+
});
|
|
234
198
|
|
|
235
|
-
|
|
199
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('download');
|
|
200
|
+
});
|
|
201
|
+
test('THEN: the button has the download attribute', () => {
|
|
202
|
+
const $ = cheerio.load(
|
|
203
|
+
renderComponent('button', {
|
|
204
|
+
variants: 'download',
|
|
205
|
+
}),
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
expect($('.ons-btn').attr('download')).toBeDefined();
|
|
209
|
+
});
|
|
236
210
|
});
|
|
211
|
+
describe('WHEN: variants contains loader', () => {
|
|
212
|
+
test('THEN: the button has the loader classes', () => {
|
|
213
|
+
const $ = cheerio.load(
|
|
214
|
+
renderComponent('button', {
|
|
215
|
+
variants: 'loader',
|
|
216
|
+
}),
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
expect($('.ons-btn').hasClass('ons-btn--loader')).toBe(true);
|
|
220
|
+
expect($('.ons-btn').hasClass('ons-js-loader')).toBe(true);
|
|
221
|
+
expect($('.ons-btn').hasClass('ons-js-submit-btn')).toBe(true);
|
|
222
|
+
});
|
|
223
|
+
test('THEN: the button has the loader icon', () => {
|
|
224
|
+
const faker = templateFaker();
|
|
225
|
+
const iconsSpy = faker.spy('icon');
|
|
237
226
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
type: 'special-type',
|
|
242
|
-
}),
|
|
243
|
-
);
|
|
227
|
+
faker.renderComponent('button', {
|
|
228
|
+
variants: 'loader',
|
|
229
|
+
});
|
|
244
230
|
|
|
245
|
-
|
|
231
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('loader');
|
|
232
|
+
});
|
|
246
233
|
});
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
234
|
+
describe('WHEN: variants contains timer', () => {
|
|
235
|
+
test('THEN: the button has the timer classes', () => {
|
|
236
|
+
const $ = cheerio.load(
|
|
237
|
+
renderComponent('button', {
|
|
238
|
+
variants: 'timer',
|
|
239
|
+
}),
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
expect($('.ons-btn').hasClass('ons-js-timer')).toBe(true);
|
|
243
|
+
expect($('.ons-btn').hasClass('ons-js-submit-btn')).toBe(true);
|
|
244
|
+
});
|
|
257
245
|
});
|
|
246
|
+
describe('WHEN: variants contains print', () => {
|
|
247
|
+
test('THEN: renders provided variant style classes', () => {
|
|
248
|
+
const $ = cheerio.load(
|
|
249
|
+
renderComponent('button', {
|
|
250
|
+
variants: 'print',
|
|
251
|
+
}),
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
expect($('.ons-btn').hasClass('ons-btn--print')).toBe(true);
|
|
255
|
+
expect($('.ons-btn').hasClass('ons-u-d-no')).toBe(true);
|
|
256
|
+
expect($('.ons-btn').hasClass('ons-js-print-btn')).toBe(true);
|
|
257
|
+
});
|
|
258
258
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
expect($('button').attr('type')).toBe('submit');
|
|
263
|
-
});
|
|
259
|
+
test('THEN: button has the print icon', () => {
|
|
260
|
+
const faker = templateFaker();
|
|
261
|
+
const iconsSpy = faker.spy('icon');
|
|
264
262
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
renderComponent('button', {
|
|
263
|
+
faker.renderComponent('button', {
|
|
264
|
+
url: 'http://example.com',
|
|
268
265
|
variants: 'print',
|
|
269
|
-
})
|
|
270
|
-
);
|
|
266
|
+
});
|
|
271
267
|
|
|
272
|
-
|
|
268
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('print');
|
|
269
|
+
});
|
|
273
270
|
});
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
271
|
+
});
|
|
272
|
+
describe('GIVEN: Params: type', () => {
|
|
273
|
+
describe('WHEN: type parameter is provided', () => {
|
|
274
|
+
test('THEN: has the provided type attribute', () => {
|
|
275
|
+
const $ = cheerio.load(
|
|
276
|
+
renderComponent('button', {
|
|
277
|
+
type: 'special-type',
|
|
278
|
+
}),
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
expect($('button').attr('type')).toBe('special-type');
|
|
282
|
+
});
|
|
283
283
|
});
|
|
284
|
+
describe('WHEN: type parameter is provided and variant contains print', () => {
|
|
285
|
+
test('THEN: has the provided type attribute', () => {
|
|
286
|
+
const $ = cheerio.load(
|
|
287
|
+
renderComponent('button', {
|
|
288
|
+
type: 'special-type',
|
|
289
|
+
variants: 'print',
|
|
290
|
+
}),
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
expect($('button').attr('type')).toBe('special-type');
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
describe('WHEN: type parameter is not provided', () => {
|
|
297
|
+
test('THEN: defaults to being a submit button', () => {
|
|
298
|
+
const $ = cheerio.load(renderComponent('button'));
|
|
284
299
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
300
|
+
expect($('button').attr('type')).toBe('submit');
|
|
301
|
+
});
|
|
302
|
+
});
|
|
303
|
+
describe('WHEN: type parameter is not provided and variant contains print', () => {
|
|
304
|
+
test('THEN: defaults to being a button', () => {
|
|
305
|
+
const $ = cheerio.load(
|
|
306
|
+
renderComponent('button', {
|
|
307
|
+
variants: 'print',
|
|
308
|
+
}),
|
|
309
|
+
);
|
|
310
|
+
|
|
311
|
+
expect($('button').attr('type')).toBe('button');
|
|
312
|
+
});
|
|
293
313
|
});
|
|
294
314
|
});
|
|
295
315
|
|
|
296
|
-
describe('
|
|
297
|
-
|
|
316
|
+
describe('GIVEN: Params: url', () => {
|
|
317
|
+
describe('WHEN: url parameter is provided', () => {
|
|
298
318
|
const $ = cheerio.load(
|
|
299
319
|
renderComponent('button', {
|
|
300
320
|
text: 'Example button',
|
|
@@ -303,130 +323,164 @@ describe('macro: button', () => {
|
|
|
303
323
|
url: 'http://example.com',
|
|
304
324
|
}),
|
|
305
325
|
);
|
|
326
|
+
test('THEN: passes jest-axe checks', async () => {
|
|
327
|
+
const results = await axe($.html());
|
|
328
|
+
expect(results).toHaveNoViolations();
|
|
329
|
+
});
|
|
306
330
|
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
it('is an `a` element', () => {
|
|
312
|
-
const $ = cheerio.load(
|
|
313
|
-
renderComponent('button', {
|
|
314
|
-
url: 'http://example.com',
|
|
315
|
-
}),
|
|
316
|
-
);
|
|
331
|
+
test('THEN: renders an <a> element', () => {
|
|
332
|
+
expect($('a').length).toBe(1);
|
|
333
|
+
});
|
|
317
334
|
|
|
318
|
-
|
|
319
|
-
|
|
335
|
+
test('THEN: has expected style classes', () => {
|
|
336
|
+
expect($('a').hasClass('ons-btn')).toBe(true);
|
|
337
|
+
expect($('.ons-btn').hasClass('ons-btn--link')).toBe(true);
|
|
338
|
+
expect($('.ons-btn').hasClass('ons-js-submit-btn')).toBe(true);
|
|
339
|
+
});
|
|
320
340
|
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
url: 'http://example.com',
|
|
325
|
-
}),
|
|
326
|
-
);
|
|
341
|
+
test('THEN: the link points to the provided url', () => {
|
|
342
|
+
expect($('a').attr('href')).toBe('http://example.com');
|
|
343
|
+
});
|
|
327
344
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
});
|
|
345
|
+
test('THEN: the link button has the arrow-next icon by default', () => {
|
|
346
|
+
const faker = templateFaker();
|
|
347
|
+
const iconsSpy = faker.spy('icon');
|
|
332
348
|
|
|
333
|
-
|
|
334
|
-
const $ = cheerio.load(
|
|
335
|
-
renderComponent('button', {
|
|
349
|
+
faker.renderComponent('button', {
|
|
336
350
|
url: 'http://example.com',
|
|
337
|
-
})
|
|
338
|
-
);
|
|
351
|
+
});
|
|
339
352
|
|
|
340
|
-
|
|
341
|
-
|
|
353
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('arrow-next');
|
|
354
|
+
});
|
|
342
355
|
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
356
|
+
test('THEN: the role attribute is set to button', () => {
|
|
357
|
+
expect($('.ons-btn').attr('role')).toBe('button');
|
|
358
|
+
});
|
|
346
359
|
|
|
347
|
-
|
|
348
|
-
|
|
360
|
+
test('THEN: the link does not have a name attribute', () => {
|
|
361
|
+
expect($('a').attr('name')).toBeUndefined();
|
|
349
362
|
});
|
|
350
363
|
|
|
351
|
-
|
|
364
|
+
test('THEN: the link does not have a value attribute', () => {
|
|
365
|
+
expect($('a').attr('value')).toBeUndefined();
|
|
366
|
+
});
|
|
352
367
|
});
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
expect($('a').attr('rel')).toBe('noopener');
|
|
368
|
+
describe('WHEN: url parameter is provided and newWindow is true', () => {
|
|
369
|
+
test('THEN: has default new window description', () => {
|
|
370
|
+
const $ = cheerio.load(
|
|
371
|
+
renderComponent('button', {
|
|
372
|
+
url: 'http://example.com',
|
|
373
|
+
newWindow: true,
|
|
374
|
+
}),
|
|
375
|
+
);
|
|
376
|
+
expect($('.ons-btn__new-window-description').text()).toBe('(opens in a new tab)');
|
|
377
|
+
});
|
|
364
378
|
});
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
379
|
+
describe('WHEN: url parameter is provided, newWindow is true and newWindowDescription is provided', () => {
|
|
380
|
+
test('THEN: has custom new window description', () => {
|
|
381
|
+
const $ = cheerio.load(
|
|
382
|
+
renderComponent('button', {
|
|
383
|
+
url: 'http://example.com',
|
|
384
|
+
newWindow: true,
|
|
385
|
+
newWindowDescription: 'custom opens in a new window text',
|
|
386
|
+
}),
|
|
387
|
+
);
|
|
388
|
+
expect($('.ons-btn__new-window-description').text()).toBe('(custom opens in a new window text)');
|
|
373
389
|
});
|
|
374
|
-
|
|
375
|
-
expect(iconsSpy.occurrences[0].iconType).toBe('external-link');
|
|
376
390
|
});
|
|
391
|
+
});
|
|
377
392
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
393
|
+
describe('GIVEN: Params: classes', () => {
|
|
394
|
+
describe('WHEN: classes parameter is provided', () => {
|
|
395
|
+
test('THEN: the button has the additionally provided style classes', () => {
|
|
396
|
+
const $ = cheerio.load(
|
|
397
|
+
renderComponent('button', {
|
|
398
|
+
classes: 'extra-class another-extra-class',
|
|
399
|
+
}),
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
expect($('.ons-btn').hasClass('extra-class')).toBe(true);
|
|
403
|
+
expect($('.ons-btn').hasClass('another-extra-class')).toBe(true);
|
|
404
|
+
});
|
|
386
405
|
});
|
|
406
|
+
describe('WHEN: innerClasses parameter is provided', () => {
|
|
407
|
+
test('THEN: the button inner has the additionally provided inner style classes', () => {
|
|
408
|
+
const $ = cheerio.load(
|
|
409
|
+
renderComponent('button', {
|
|
410
|
+
innerClasses: 'extra-inner-class another-extra-inner-class',
|
|
411
|
+
}),
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
expect($('.ons-btn__inner').hasClass('extra-inner-class')).toBe(true);
|
|
415
|
+
expect($('.ons-btn__inner').hasClass('another-extra-inner-class')).toBe(true);
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
});
|
|
387
419
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
420
|
+
describe('GIVEN: Params: removeDownloadAttribute', () => {
|
|
421
|
+
describe('WHEN: variants contains download and removeDownloadAttribute is true', () => {
|
|
422
|
+
test('THEN: the button does not have the download attribute', () => {
|
|
423
|
+
const $ = cheerio.load(
|
|
424
|
+
renderComponent('button', {
|
|
425
|
+
variants: 'download',
|
|
426
|
+
removeDownloadAttribute: true,
|
|
427
|
+
}),
|
|
428
|
+
);
|
|
429
|
+
|
|
430
|
+
expect($('.ons-btn').attr('download')).toBeUndefined();
|
|
431
|
+
});
|
|
397
432
|
});
|
|
433
|
+
});
|
|
398
434
|
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
435
|
+
describe('GIVEN: Params: noIcon', () => {
|
|
436
|
+
describe('WHEN: noIcon is set to true', () => {
|
|
437
|
+
test('THEN: the button does not have the default arrow-next icon', () => {
|
|
438
|
+
const faker = templateFaker();
|
|
439
|
+
const iconsSpy = faker.spy('icon');
|
|
440
|
+
|
|
441
|
+
faker.renderComponent('button', {
|
|
402
442
|
url: 'http://example.com',
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}),
|
|
406
|
-
);
|
|
443
|
+
noIcon: true,
|
|
444
|
+
});
|
|
407
445
|
|
|
408
|
-
|
|
446
|
+
expect(iconsSpy.occurrences[0]).toBeUndefined();
|
|
447
|
+
});
|
|
409
448
|
});
|
|
449
|
+
describe('WHEN: noIcon is set to false', () => {
|
|
450
|
+
test('THEN: the button has the default arrow-next icon', () => {
|
|
451
|
+
const faker = templateFaker();
|
|
452
|
+
const iconsSpy = faker.spy('icon');
|
|
410
453
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}),
|
|
416
|
-
);
|
|
454
|
+
faker.renderComponent('button', {
|
|
455
|
+
url: 'http://example.com',
|
|
456
|
+
noIcon: false,
|
|
457
|
+
});
|
|
417
458
|
|
|
418
|
-
|
|
459
|
+
expect(iconsSpy.occurrences[0].iconType).toBe('arrow-next');
|
|
460
|
+
});
|
|
419
461
|
});
|
|
462
|
+
});
|
|
420
463
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
464
|
+
describe('GIVEN: Params: listeners', () => {
|
|
465
|
+
describe('WHEN: listeners are provided', () => {
|
|
466
|
+
test('THEN: the button renders each listener', () => {
|
|
467
|
+
const $ = cheerio.load(
|
|
468
|
+
renderComponent('button', {
|
|
469
|
+
id: 'example-id',
|
|
470
|
+
listeners: {
|
|
471
|
+
click: `alert('Input was clicked')`,
|
|
472
|
+
keypress: `alert('Key was pressed')`,
|
|
473
|
+
},
|
|
474
|
+
}),
|
|
475
|
+
);
|
|
476
|
+
const script = $('script').html();
|
|
477
|
+
expect(script).toContain(
|
|
478
|
+
`document.getElementById("example-id").addEventListener('click', function(){ alert('Input was clicked') });`,
|
|
479
|
+
);
|
|
480
|
+
expect(script).toContain(
|
|
481
|
+
`document.getElementById("example-id").addEventListener('keypress', function(){ alert('Key was pressed') });`,
|
|
482
|
+
);
|
|
483
|
+
});
|
|
430
484
|
});
|
|
431
485
|
});
|
|
432
486
|
});
|