@ons/design-system 72.0.1 → 72.1.1

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.
Files changed (55) hide show
  1. package/README.md +1 -1
  2. package/components/accordion/_macro.spec.js +2 -2
  3. package/components/address-input/_macro.spec.js +245 -322
  4. package/components/address-input/autosuggest.address.spec.js +16 -14
  5. package/components/address-output/_macro.spec.js +121 -74
  6. package/components/address-output/_test_examples.js +8 -0
  7. package/components/autosuggest/_macro.njk +1 -0
  8. package/components/autosuggest/_macro.spec.js +373 -178
  9. package/components/autosuggest/autosuggest.spec.js +3 -1
  10. package/components/autosuggest/autosuggest.ui.js +39 -10
  11. package/components/autosuggest/example-autosuggest-country.njk +2 -1
  12. package/components/autosuggest/fuse-config.js +7 -2
  13. package/components/back-to-top/back-to-top.dom.js +4 -4
  14. package/components/back-to-top/back-to-top.js +1 -1
  15. package/components/browser-banner/_macro.spec.js +11 -11
  16. package/components/button/_macro.njk +1 -1
  17. package/components/button/_macro.spec.js +405 -351
  18. package/components/button/example-button-group.njk +1 -0
  19. package/components/checkboxes/_checkbox-macro.njk +20 -0
  20. package/components/checkboxes/_checkbox.scss +3 -3
  21. package/components/checkboxes/_macro.njk +5 -0
  22. package/components/checkboxes/_macro.spec.js +35 -0
  23. package/components/checkboxes/example-checkboxes-with-revealed-text-area-expanded.njk +68 -0
  24. package/components/checkboxes/example-checkboxes-with-revealed-text-area.njk +67 -0
  25. package/components/details/_details.scss +1 -2
  26. package/components/details/example-details-open.njk +10 -0
  27. package/components/external-link/_macro.spec.js +66 -69
  28. package/components/external-link/_test_examples.js +4 -0
  29. package/components/feedback/_macro.spec.js +109 -80
  30. package/components/feedback/_test_examples.js +17 -0
  31. package/components/field/_macro.spec.js +106 -69
  32. package/components/section-navigation/_macro.njk +9 -6
  33. package/components/summary/_macro.njk +73 -78
  34. package/components/summary/_macro.spec.js +5 -15
  35. package/components/summary/_summary.scss +16 -11
  36. package/components/table-of-contents/_macro.njk +3 -3
  37. package/components/table-of-contents/_macro.spec.js +3 -3
  38. package/components/table-of-contents/{_toc.scss → _table-of-contents.scss} +1 -1
  39. package/components/table-of-contents/table-of-contents.dom.js +13 -0
  40. package/components/table-of-contents/{toc.js → table-of-contents.js} +4 -4
  41. package/components/table-of-contents/{toc.spec.js → table-of-contents.spec.js} +2 -2
  42. package/components/tabs/_tabs.scss +10 -11
  43. package/components/tabs/tabs.js +3 -3
  44. package/components/timeout-modal/timeout-modal.spec.js +1 -1
  45. package/css/main.css +1 -1
  46. package/js/analytics.js +1 -1
  47. package/js/main.js +1 -1
  48. package/package.json +2 -2
  49. package/scripts/main.es5.js +1 -1
  50. package/scripts/main.js +1 -1
  51. package/scss/main.scss +1 -1
  52. package/scss/objects/_page.scss +1 -1
  53. package/scss/utilities/_margin.scss +4 -0
  54. package/scss/utilities/_padding.scss +4 -0
  55. 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('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('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
- faker.renderComponent('button', {
66
- url: 'http://example.com',
67
- variants: 'download',
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
- it('has `print` icon when `variants` contains "print"', () => {
86
- const faker = templateFaker();
87
- const iconsSpy = faker.spy('icon');
88
-
89
- faker.renderComponent('button', {
90
- url: 'http://example.com',
91
- variants: 'print',
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
- it('has `loader` icon when `variants` contains "loader"', () => {
110
- const faker = templateFaker();
111
- const iconsSpy = faker.spy('icon');
112
-
113
- faker.renderComponent('button', {
114
- variants: 'loader',
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
- it('has `chevron` icon when `variants` contains "mobile"', () => {
121
- const faker = templateFaker();
122
- const iconsSpy = faker.spy('icon');
123
-
124
- faker.renderComponent('button', {
125
- variants: 'mobile',
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
- it('has additionally provided style classes', () => {
143
- const $ = cheerio.load(
144
- renderComponent('button', {
145
- classes: 'extra-class another-extra-class',
146
- }),
147
- );
148
-
149
- expect($('.ons-btn').hasClass('extra-class')).toBe(true);
150
- expect($('.ons-btn').hasClass('another-extra-class')).toBe(true);
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
- it('has additionally provided inner style classes', () => {
154
- const $ = cheerio.load(
155
- renderComponent('button', {
156
- innerClasses: 'extra-inner-class another-extra-inner-class',
157
- }),
158
- );
159
-
160
- expect($('.ons-btn__inner').hasClass('extra-inner-class')).toBe(true);
161
- expect($('.ons-btn__inner').hasClass('another-extra-inner-class')).toBe(true);
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
- it('has label text when `text` is provided', () => {
165
- const $ = cheerio.load(
166
- renderComponent('button', {
167
- text: 'Click > me!',
168
- }),
169
- );
170
-
171
- expect($('.ons-btn__text').html()).toBe('Click > me!');
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
- it('has label text when `html` is provided', () => {
175
- const $ = cheerio.load(
176
- renderComponent('button', {
177
- html: 'Click <strong>me</strong>!',
178
- }),
179
- );
180
-
181
- expect($('.ons-btn__text').html()).toBe('Click <strong>me</strong>!');
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
- it('has button context text when `buttonContext` is provided', () => {
185
- const $ = cheerio.load(
186
- renderComponent('button', {
187
- buttonContext: 'button context text',
188
- }),
189
- );
190
-
191
- expect($('.ons-btn__context').text()).toBe('button context text');
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
- it('has custom icon before button text', () => {
195
- const $ = cheerio.load(
196
- renderComponent('button', {
197
- text: 'Click me!',
198
- iconPosition: 'before',
199
- iconType: 'exit',
200
- }),
201
- );
202
-
203
- expect($('.ons-icon + .ons-btn__text').text()).toBe('Click me!');
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
- it('has custom icon after button text', () => {
207
- const $ = cheerio.load(
208
- renderComponent('button', {
209
- text: 'Click me!',
210
- iconPosition: 'after',
211
- iconType: 'exit',
212
- }),
213
- );
214
-
215
- expect($('.ons-btn__text + .ons-icon').prev().text()).toBe('Click me!');
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('mode: standard', () => {
219
- it('passes jest-axe checks', async () => {
220
- const $ = cheerio.load(
221
- renderComponent('button', {
222
- text: 'Example button',
223
- name: 'example',
224
- value: 'example-value',
225
- }),
226
- );
227
-
228
- const results = await axe($.html());
229
- expect(results).toHaveNoViolations();
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
- it('is an `button` element', () => {
233
- const $ = cheerio.load(renderComponent('button'));
194
+ faker.renderComponent('button', {
195
+ url: 'http://example.com',
196
+ variants: 'download',
197
+ });
234
198
 
235
- expect($('button').length).toBe(1);
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
- it('has the provided `type` attribute', () => {
239
- const $ = cheerio.load(
240
- renderComponent('button', {
241
- type: 'special-type',
242
- }),
243
- );
227
+ faker.renderComponent('button', {
228
+ variants: 'loader',
229
+ });
244
230
 
245
- expect($('button').attr('type')).toBe('special-type');
231
+ expect(iconsSpy.occurrences[0].iconType).toBe('loader');
232
+ });
246
233
  });
247
-
248
- it('has the provided `type` attribute even if print variant is provided', () => {
249
- const $ = cheerio.load(
250
- renderComponent('button', {
251
- type: 'special-type',
252
- variants: 'print',
253
- }),
254
- );
255
-
256
- expect($('button').attr('type')).toBe('special-type');
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
- it('defaults to being a "submit" button when `type` is not provided', () => {
260
- const $ = cheerio.load(renderComponent('button'));
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
- it('defaults to being a "button" when `type` is not provided and `variants` contains "print"', () => {
266
- const $ = cheerio.load(
267
- renderComponent('button', {
263
+ faker.renderComponent('button', {
264
+ url: 'http://example.com',
268
265
  variants: 'print',
269
- }),
270
- );
266
+ });
271
267
 
272
- expect($('button').attr('type')).toBe('button');
268
+ expect(iconsSpy.occurrences[0].iconType).toBe('print');
269
+ });
273
270
  });
274
-
275
- it('has the provided `value` attribute', () => {
276
- const $ = cheerio.load(
277
- renderComponent('button', {
278
- value: 'special-value',
279
- }),
280
- );
281
-
282
- expect($('button').attr('value')).toBe('special-value');
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
- it('has the provided `name` attribute', () => {
286
- const $ = cheerio.load(
287
- renderComponent('button', {
288
- name: 'special-name',
289
- }),
290
- );
291
-
292
- expect($('button').attr('name')).toBe('special-name');
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('mode: link', () => {
297
- it('passes jest-axe checks', async () => {
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
- const results = await axe($.html());
308
- expect(results).toHaveNoViolations();
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
- expect($('a').length).toBe(1);
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
- it('has expected style classes', () => {
322
- const $ = cheerio.load(
323
- renderComponent('button', {
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
- expect($('a').hasClass('ons-btn')).toBe(true);
329
- expect($('.ons-btn').hasClass('ons-btn--link')).toBe(true);
330
- expect($('.ons-btn').hasClass('ons-js-submit-btn')).toBe(true);
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
- it('has the provided link', () => {
334
- const $ = cheerio.load(
335
- renderComponent('button', {
349
+ faker.renderComponent('button', {
336
350
  url: 'http://example.com',
337
- }),
338
- );
351
+ });
339
352
 
340
- expect($('a').attr('href')).toBe('http://example.com');
341
- });
353
+ expect(iconsSpy.occurrences[0].iconType).toBe('arrow-next');
354
+ });
342
355
 
343
- it('has `arrow-next` icon by default', () => {
344
- const faker = templateFaker();
345
- const iconsSpy = faker.spy('icon');
356
+ test('THEN: the role attribute is set to button', () => {
357
+ expect($('.ons-btn').attr('role')).toBe('button');
358
+ });
346
359
 
347
- faker.renderComponent('button', {
348
- url: 'http://example.com',
360
+ test('THEN: the link does not have a name attribute', () => {
361
+ expect($('a').attr('name')).toBeUndefined();
349
362
  });
350
363
 
351
- expect(iconsSpy.occurrences[0].iconType).toBe('arrow-next');
364
+ test('THEN: the link does not have a value attribute', () => {
365
+ expect($('a').attr('value')).toBeUndefined();
366
+ });
352
367
  });
353
-
354
- it('opens in a new window when `newWindow` is `true`', () => {
355
- const $ = cheerio.load(
356
- renderComponent('button', {
357
- url: 'http://example.com',
358
- newWindow: true,
359
- }),
360
- );
361
-
362
- expect($('a').attr('target')).toBe('_blank');
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
- it('has `external-link` icon when `newWindow` is `true`', () => {
367
- const faker = templateFaker();
368
- const iconsSpy = faker.spy('icon');
369
-
370
- faker.renderComponent('button', {
371
- url: 'http://example.com',
372
- newWindow: true,
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
- it('has the `button` role', () => {
379
- const $ = cheerio.load(
380
- renderComponent('button', {
381
- url: 'http://example.com',
382
- }),
383
- );
384
-
385
- expect($('.ons-btn').attr('role')).toBe('button');
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
- it('has a default new window description when `newWindow` is `true`', () => {
389
- const $ = cheerio.load(
390
- renderComponent('button', {
391
- url: 'http://example.com',
392
- newWindow: true,
393
- }),
394
- );
395
-
396
- expect($('.ons-btn__new-window-description').text()).toBe('(opens in a new tab)');
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
- it('has a custom new window description when `newWindow` is `true` and `newWindowDescription` is provided', () => {
400
- const $ = cheerio.load(
401
- renderComponent('button', {
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
- newWindow: true,
404
- newWindowDescription: 'custom opens in a new window text',
405
- }),
406
- );
443
+ noIcon: true,
444
+ });
407
445
 
408
- expect($('.ons-btn__new-window-description').text()).toBe('(custom opens in a new window text)');
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
- it('has the `download` attribute when `variants` contains "download"', () => {
412
- const $ = cheerio.load(
413
- renderComponent('button', {
414
- variants: 'download',
415
- }),
416
- );
454
+ faker.renderComponent('button', {
455
+ url: 'http://example.com',
456
+ noIcon: false,
457
+ });
417
458
 
418
- expect($('.ons-btn').attr('download')).toBeDefined();
459
+ expect(iconsSpy.occurrences[0].iconType).toBe('arrow-next');
460
+ });
419
461
  });
462
+ });
420
463
 
421
- it('does not have the `download` attribute when `variants` contains "download" and `removeDownloadAttribute` is `true`', () => {
422
- const $ = cheerio.load(
423
- renderComponent('button', {
424
- variants: 'download',
425
- removeDownloadAttribute: true,
426
- }),
427
- );
428
-
429
- expect($('.ons-btn').attr('download')).toBeUndefined();
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(&#39;Input was clicked&#39;) });`,
479
+ );
480
+ expect(script).toContain(
481
+ `document.getElementById("example-id").addEventListener('keypress', function(){ alert(&#39;Key was pressed&#39;) });`,
482
+ );
483
+ });
430
484
  });
431
485
  });
432
486
  });