@ons/design-system 72.1.0 → 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 (40) 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.spec.js +373 -184
  8. package/components/back-to-top/back-to-top.dom.js +4 -4
  9. package/components/back-to-top/back-to-top.js +1 -1
  10. package/components/browser-banner/_macro.spec.js +11 -11
  11. package/components/button/_macro.njk +1 -1
  12. package/components/button/_macro.spec.js +405 -351
  13. package/components/button/example-button-group.njk +1 -0
  14. package/components/checkboxes/_checkbox.scss +3 -3
  15. package/components/details/_details.scss +1 -2
  16. package/components/details/example-details-open.njk +10 -0
  17. package/components/external-link/_macro.spec.js +66 -69
  18. package/components/external-link/_test_examples.js +4 -0
  19. package/components/feedback/_macro.spec.js +109 -80
  20. package/components/feedback/_test_examples.js +17 -0
  21. package/components/field/_macro.spec.js +106 -69
  22. package/components/section-navigation/_macro.njk +9 -6
  23. package/components/table-of-contents/_macro.njk +3 -3
  24. package/components/table-of-contents/_macro.spec.js +3 -3
  25. package/components/table-of-contents/{_toc.scss → _table-of-contents.scss} +1 -1
  26. package/components/table-of-contents/table-of-contents.dom.js +13 -0
  27. package/components/table-of-contents/{toc.js → table-of-contents.js} +4 -4
  28. package/components/table-of-contents/{toc.spec.js → table-of-contents.spec.js} +2 -2
  29. package/components/tabs/_tabs.scss +10 -11
  30. package/components/tabs/tabs.js +3 -3
  31. package/components/timeout-modal/timeout-modal.spec.js +1 -1
  32. package/css/main.css +1 -1
  33. package/js/main.js +1 -1
  34. package/package.json +1 -1
  35. package/scripts/main.es5.js +1 -1
  36. package/scripts/main.js +1 -1
  37. package/scss/main.scss +1 -1
  38. package/scss/utilities/_margin.scss +4 -0
  39. package/scss/utilities/_padding.scss +4 -0
  40. package/components/table-of-contents/toc.dom.js +0 -13
@@ -10,6 +10,7 @@
10
10
  onsButton({
11
11
  "type": 'button',
12
12
  "text": 'Cancel',
13
+ "name": 'example',
13
14
  "variants": 'secondary'
14
15
  })
15
16
  }}
@@ -107,7 +107,7 @@ $checkbox-padding: 10px;
107
107
  }
108
108
 
109
109
  .ons-checkbox__other {
110
- margin: 0.5rem 0 0.5rem 0.5rem;
110
+ margin: 0.5rem 0 0.5rem 0.625rem;
111
111
  }
112
112
  }
113
113
 
@@ -170,8 +170,8 @@ $checkbox-padding: 10px;
170
170
  &__other {
171
171
  border-left: 4px solid var(--ons-color-borders-indent);
172
172
  display: block;
173
- margin: 0 1rem 0.5rem;
174
- padding: 0 $checkbox-padding $checkbox-padding $checkbox-padding * 2 - 1;
173
+ margin: 0 1.1875rem 0.5rem;
174
+ padding: 0 $checkbox-padding $checkbox-padding $checkbox-padding * 2;
175
175
  }
176
176
 
177
177
  &__input:checked + &__label::before {
@@ -68,7 +68,6 @@ $details-caret-width: 1.75rem;
68
68
 
69
69
  &--open & {
70
70
  &__icon {
71
- left: -0.1rem;
72
71
  top: 0.2rem;
73
72
  transform: rotate(90deg);
74
73
  }
@@ -76,7 +75,7 @@ $details-caret-width: 1.75rem;
76
75
  &__content {
77
76
  border-left: 4px solid var(--ons-color-borders-indent);
78
77
  display: block;
79
- margin: 1rem 0 0;
78
+ margin: 1rem 0 0 0.5rem;
80
79
  padding: 0 0 0 1.5rem;
81
80
  }
82
81
  }
@@ -0,0 +1,10 @@
1
+ {% from "components/details/_macro.njk" import onsDetails %}
2
+
3
+ {{
4
+ onsDetails({
5
+ "id": "details-example",
6
+ "title": "What is a photovoltaic system?",
7
+ "content": "<p>A typical photovoltaic system employs solar panels, each comprising a number of solar cells, which generate electrical power. PV installations may be ground-mounted, rooftop mounted or wall mounted. The mount may be fixed, or use a solar tracker to follow the sun across the sky.</p>",
8
+ "open": true
9
+ })
10
+ }}
@@ -4,79 +4,76 @@ import * as cheerio from 'cheerio';
4
4
 
5
5
  import axe from '../../tests/helpers/axe';
6
6
  import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
7
-
8
- const EXAMPLE_EXTERNAL_LINK = {
9
- url: 'http://example.com',
10
- text: 'Example link',
11
- };
12
-
13
- describe('macro: external-link', () => {
14
- it('passes jest-axe checks', async () => {
15
- const $ = cheerio.load(renderComponent('external-link', EXAMPLE_EXTERNAL_LINK));
16
-
17
- const results = await axe($.html());
18
- expect(results).toHaveNoViolations();
19
- });
20
-
21
- it('has additionally provided style classes', () => {
22
- const $ = cheerio.load(
23
- renderComponent('external-link', {
24
- ...EXAMPLE_EXTERNAL_LINK,
25
- classes: 'extra-class another-extra-class',
26
- }),
27
- );
28
-
29
- expect($('.ons-external-link').hasClass('extra-class')).toBe(true);
30
- expect($('.ons-external-link').hasClass('another-extra-class')).toBe(true);
31
- });
32
-
33
- it('has the expected hyperlink URL', async () => {
34
- const $ = cheerio.load(renderComponent('external-link', EXAMPLE_EXTERNAL_LINK));
35
-
36
- const $hyperlink = $('a.ons-external-link');
37
- expect($hyperlink.attr('href')).toBe('http://example.com');
38
- });
39
-
40
- it('opens in a new window when `newWindow` is `true`', () => {
41
- const $ = cheerio.load(renderComponent('external-link', EXAMPLE_EXTERNAL_LINK));
42
-
43
- expect($('a').attr('target')).toBe('_blank');
44
- expect($('a').attr('rel')).toBe('noopener');
45
- });
46
-
47
- it('has the expected link text', async () => {
48
- const $ = cheerio.load(renderComponent('external-link', EXAMPLE_EXTERNAL_LINK));
49
-
50
- const $hyperlink = $('a.ons-external-link .ons-external-link__text');
51
- expect($hyperlink.text().trim()).toBe('Example link');
52
- });
53
-
54
- it('has a default new window description', async () => {
55
- const $ = cheerio.load(renderComponent('external-link', EXAMPLE_EXTERNAL_LINK));
56
-
57
- expect($('.ons-external-link__new-window-description').text()).toBe('(opens in a new tab)');
7
+ import { EXAMPLE_EXTERNAL_LINK } from './_test_examples';
8
+
9
+ describe('FOR: Macro: External-link', () => {
10
+ describe('GIVEN: Params: required', () => {
11
+ describe('WHEN: all required params are provided', () => {
12
+ const $ = cheerio.load(renderComponent('external-link', EXAMPLE_EXTERNAL_LINK));
13
+ test('THEN: jest-axe checks pass', async () => {
14
+ const results = await axe($.html());
15
+ expect(results).toHaveNoViolations();
16
+ });
17
+
18
+ test('THEN: the link points to the expected URL', async () => {
19
+ const $hyperlink = $('a.ons-external-link');
20
+ expect($hyperlink.attr('href')).toBe('http://example.com');
21
+ });
22
+
23
+ test('THEN: the link has the expected link text', async () => {
24
+ const $hyperlink = $('a.ons-external-link .ons-external-link__text');
25
+ expect($hyperlink.text().trim()).toBe('Example link');
26
+ });
27
+
28
+ test('THEN: the link has a default new window description', async () => {
29
+ expect($('.ons-external-link__new-window-description').text()).toBe('(opens in a new tab)');
30
+ });
31
+
32
+ test('THEN: the link has the external-link icon', async () => {
33
+ const faker = templateFaker();
34
+ const iconsSpy = faker.spy('icon');
35
+ faker.renderComponent('external-link', {
36
+ ...EXAMPLE_EXTERNAL_LINK,
37
+ });
38
+ expect(iconsSpy.occurrences[0].iconType).toBe('external-link');
39
+ });
40
+ });
58
41
  });
59
42
 
60
- it('has a custom new window description when `newWindowDescription` is provided', () => {
61
- const $ = cheerio.load(
62
- renderComponent('external-link', {
63
- ...EXAMPLE_EXTERNAL_LINK,
64
- newWindowDescription: 'custom opens in a new tab text',
65
- }),
66
- );
67
-
68
- expect($('.ons-external-link__new-window-description').text()).toBe('(custom opens in a new tab text)');
43
+ describe('GIVEN: Params: classes', () => {
44
+ describe('WHEN: additional style classes are provided with the classes param', () => {
45
+ const $ = cheerio.load(
46
+ renderComponent('external-link', {
47
+ ...EXAMPLE_EXTERNAL_LINK,
48
+ classes: 'extra-class another-extra-class',
49
+ }),
50
+ );
51
+ test('THEN: renders with provided classes', () => {
52
+ expect($('.ons-external-link').hasClass('extra-class')).toBe(true);
53
+ expect($('.ons-external-link').hasClass('another-extra-class')).toBe(true);
54
+ });
55
+ });
69
56
  });
70
57
 
71
- it('has an "external-link" icon', async () => {
72
- const faker = templateFaker();
73
- const iconsSpy = faker.spy('icon');
74
-
75
- faker.renderComponent('external-link', {
76
- ...EXAMPLE_EXTERNAL_LINK,
77
- newWindowDescription: 'custom opens in a new tab text',
58
+ describe('GIVEN: Params: newWindowDescription', () => {
59
+ describe('WHEN: newWindowDescription param is provided', () => {
60
+ const $ = cheerio.load(
61
+ renderComponent('external-link', {
62
+ ...EXAMPLE_EXTERNAL_LINK,
63
+ newWindowDescription: 'custom opens in a new tab text',
64
+ }),
65
+ );
66
+ test('THEN: has the expected new window description', () => {
67
+ expect($('.ons-external-link__new-window-description').text()).toBe('(custom opens in a new tab text)');
68
+ });
69
+
70
+ test('THEN: the target attribute is set to _blank so that the link opens in a new window', () => {
71
+ expect($('a').attr('target')).toBe('_blank');
72
+ });
73
+
74
+ test('THEN: the rel attribute is set to noopener', () => {
75
+ expect($('a').attr('rel')).toBe('noopener');
76
+ });
78
77
  });
79
-
80
- expect(iconsSpy.occurrences[0].iconType).toBe('external-link');
81
78
  });
82
79
  });
@@ -0,0 +1,4 @@
1
+ export const EXAMPLE_EXTERNAL_LINK = {
2
+ url: 'http://example.com',
3
+ text: 'Example link',
4
+ };
@@ -4,103 +4,132 @@ import * as cheerio from 'cheerio';
4
4
 
5
5
  import axe from '../../tests/helpers/axe';
6
6
  import { renderComponent } from '../../tests/helpers/rendering';
7
-
8
- const EXAMPLE_FEEDBACK_MINIMAL = {
9
- heading: 'Feedback heading',
10
- content: 'Feedback content...',
11
- linkUrl: 'http://example.com',
12
- linkText: 'Feedback link text',
13
- };
14
-
15
- const EXAMPLE_FEEDBACK_FULL = {
16
- id: 'example-feedback',
17
- classes: 'extra-class',
18
- heading: 'Feedback heading',
19
- headingLevel: 5,
20
- headingClasses: 'extra-heading-class another-extra-heading-class',
21
- content: 'Feedback content...',
22
- linkUrl: 'http://example.com',
23
- linkText: 'Feedback link text',
24
- };
25
-
26
- describe('macro: feedback', () => {
27
- it('passes jest-axe checks with minimum parameters', async () => {
28
- const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_MINIMAL));
29
-
30
- const results = await axe($.html());
31
- expect(results).toHaveNoViolations();
7
+ import { EXAMPLE_FEEDBACK, EXAMPLE_FEEDBACK_ALL_PARAMS } from './_test_examples';
8
+
9
+ describe('FOR: Macro: Feedback', () => {
10
+ describe('GIVEN: Params: required', () => {
11
+ describe('WHEN: all required params are provided', () => {
12
+ const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK));
13
+ test('THEN: jest-axe checks pass', async () => {
14
+ const results = await axe($.html());
15
+ expect(results).toHaveNoViolations();
16
+ });
17
+
18
+ test('THEN: the title has a default headingLevel of 2', () => {
19
+ expect($(`h2.ons-feedback__heading`).text().trim()).toBe('Feedback heading');
20
+ });
21
+ });
32
22
  });
33
23
 
34
- it('passes jest-axe checks with full parameters', async () => {
35
- const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_FULL));
36
-
37
- const results = await axe($.html());
38
- expect(results).toHaveNoViolations();
24
+ describe('GIVEN: Params: all', () => {
25
+ describe('WHEN: all params are provided', () => {
26
+ const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_ALL_PARAMS));
27
+ test('THEN: jest-axe checks pass', async () => {
28
+ const results = await axe($.html());
29
+ expect(results).toHaveNoViolations();
30
+ });
31
+ });
39
32
  });
40
33
 
41
- it('has the provided `id` attribute', () => {
42
- const $ = cheerio.load(
43
- renderComponent('feedback', {
44
- id: 'example-id',
45
- }),
46
- );
47
-
48
- expect($('#example-id').length).toBe(1);
34
+ describe('GIVEN: Params: id', () => {
35
+ describe('WHEN: id is provided', () => {
36
+ const $ = cheerio.load(
37
+ renderComponent('feedback', {
38
+ ...EXAMPLE_FEEDBACK,
39
+ id: 'example-id',
40
+ }),
41
+ );
42
+ test('THEN: renders with provided id', () => {
43
+ expect($('#example-id').length).toBe(1);
44
+ });
45
+ });
49
46
  });
50
47
 
51
- it('has additionally provided style classes', () => {
52
- const $ = cheerio.load(
53
- renderComponent('feedback', {
54
- classes: 'extra-class another-extra-class',
55
- }),
56
- );
57
-
58
- expect($('.ons-feedback').hasClass('extra-class')).toBe(true);
59
- expect($('.ons-feedback').hasClass('another-extra-class')).toBe(true);
48
+ describe('GIVEN: Params: classes', () => {
49
+ describe('WHEN: additional style classes are provided', () => {
50
+ const $ = cheerio.load(
51
+ renderComponent('feedback', {
52
+ ...EXAMPLE_FEEDBACK,
53
+ classes: 'extra-class another-extra-class',
54
+ }),
55
+ );
56
+ test('THEN: renders with provided classes', () => {
57
+ expect($('.ons-feedback').hasClass('extra-class')).toBe(true);
58
+ expect($('.ons-feedback').hasClass('another-extra-class')).toBe(true);
59
+ });
60
+ });
60
61
  });
61
62
 
62
- it.each([
63
- [1, 'h1'],
64
- [4, 'h4'],
65
- ])('has the correct element type for the provided `headingLevel` (%i -> %s)', (headingLevel, expectedTitleTag) => {
66
- const $ = cheerio.load(
67
- renderComponent('feedback', {
68
- ...EXAMPLE_FEEDBACK_MINIMAL,
69
- headingLevel,
70
- }),
71
- );
72
-
73
- expect($(`${expectedTitleTag}.ons-feedback__heading`).text().trim()).toBe('Feedback heading');
63
+ describe('GIVEN: Params: heading', () => {
64
+ describe('WHEN: heading is provided', () => {
65
+ const $ = cheerio.load(
66
+ renderComponent('feedback', {
67
+ ...EXAMPLE_FEEDBACK,
68
+ }),
69
+ );
70
+ test('THEN: renders with provided heading text', () => {
71
+ expect($('.ons-feedback__heading').text().trim()).toBe('Feedback heading');
72
+ });
73
+ });
74
74
  });
75
75
 
76
- it('has a default `headingLevel` of 2', () => {
77
- const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_MINIMAL));
78
-
79
- expect($(`h2.ons-feedback__heading`).text().trim()).toBe('Feedback heading');
76
+ describe('GIVEN: Params: headingLevel', () => {
77
+ describe('WHEN: headingLevel is provided', () => {
78
+ test.each([
79
+ [1, 'h1'],
80
+ [4, 'h4'],
81
+ ])('THEN: has the correct heading element type for the provided headingLevel (%i -> %s)', (headingLevel, expectedTitleTag) => {
82
+ const $ = cheerio.load(
83
+ renderComponent('feedback', {
84
+ ...EXAMPLE_FEEDBACK,
85
+ headingLevel,
86
+ }),
87
+ );
88
+ const titleTag = $(`${expectedTitleTag}.ons-feedback__heading`)[0].tagName;
89
+ expect(titleTag).toBe(expectedTitleTag);
90
+ });
91
+ });
80
92
  });
81
93
 
82
- it('has additional heading style classes', () => {
83
- const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_FULL));
84
-
85
- expect($('.ons-feedback__heading').hasClass('extra-heading-class')).toBe(true);
86
- expect($('.ons-feedback__heading').hasClass('another-extra-heading-class')).toBe(true);
94
+ describe('GIVEN: Params: headingClasses', () => {
95
+ describe('WHEN: additional heading style classes are provided', () => {
96
+ const $ = cheerio.load(
97
+ renderComponent('feedback', {
98
+ ...EXAMPLE_FEEDBACK,
99
+ headingClasses: 'extra-heading-class another-extra-heading-class',
100
+ }),
101
+ );
102
+ test('THEN: renders with provided classes', () => {
103
+ expect($('.ons-feedback__heading').hasClass('extra-heading-class')).toBe(true);
104
+ expect($('.ons-feedback__heading').hasClass('another-extra-heading-class')).toBe(true);
105
+ });
106
+ });
87
107
  });
88
108
 
89
- it('has a paragraph with the provided `content`', () => {
90
- const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_MINIMAL));
91
-
92
- expect($('p').text().trim()).toBe('Feedback content...');
109
+ describe('GIVEN: Params: content', () => {
110
+ describe('WHEN: content is provided', () => {
111
+ const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK));
112
+ test('THEN: renders paragraph with the provided content', () => {
113
+ expect($('p').text().trim()).toBe('Feedback content...');
114
+ });
115
+ });
93
116
  });
94
117
 
95
- it('has a link with the provided `linkUrl`', () => {
96
- const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_MINIMAL));
97
-
98
- expect($('.ons-feedback__link').attr('href')).toBe('http://example.com');
118
+ describe('GIVEN: Params: linkUrl', () => {
119
+ describe('WHEN: linkUrl is provided', () => {
120
+ const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK));
121
+ test('THEN: renders a link with the provided linkUrl', () => {
122
+ expect($('.ons-feedback__link').attr('href')).toBe('http://example.com');
123
+ });
124
+ });
99
125
  });
100
126
 
101
- it('has a link with the provided `linkText`', () => {
102
- const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK_MINIMAL));
103
-
104
- expect($('.ons-feedback__link').text().trim()).toBe('Feedback link text');
127
+ describe('GIVEN: Params: linkText', () => {
128
+ describe('WHEN: linkText is provided', () => {
129
+ const $ = cheerio.load(renderComponent('feedback', EXAMPLE_FEEDBACK));
130
+ test('THEN: renders a link with the provided linkText', () => {
131
+ expect($('.ons-feedback__link').text().trim()).toBe('Feedback link text');
132
+ });
133
+ });
105
134
  });
106
135
  });
@@ -0,0 +1,17 @@
1
+ export const EXAMPLE_FEEDBACK = {
2
+ heading: 'Feedback heading',
3
+ content: 'Feedback content...',
4
+ linkUrl: 'http://example.com',
5
+ linkText: 'Feedback link text',
6
+ };
7
+
8
+ export const EXAMPLE_FEEDBACK_ALL_PARAMS = {
9
+ id: 'example-feedback',
10
+ classes: 'extra-class',
11
+ heading: 'Feedback heading',
12
+ headingLevel: 5,
13
+ headingClasses: 'extra-heading-class another-extra-heading-class',
14
+ content: 'Feedback content...',
15
+ linkUrl: 'http://example.com',
16
+ linkText: 'Feedback link text',
17
+ };
@@ -5,91 +5,128 @@ 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
- const EXAMPLE_FIELD_BASIC = {
9
- id: 'example-field',
10
- };
11
-
12
- describe('macro: field', () => {
13
- it('passes jest-axe checks', async () => {
14
- const $ = cheerio.load(renderComponent('field', EXAMPLE_FIELD_BASIC));
15
-
16
- const results = await axe($.html());
17
- expect(results).toHaveNoViolations();
8
+ describe('FOR: Macro: Field', () => {
9
+ describe('GIVEN: Params: none', () => {
10
+ describe('WHEN: no params are provided', () => {
11
+ const $ = cheerio.load(renderComponent('field'));
12
+ test('THEN: passes jest-axe checks', async () => {
13
+ const results = await axe($.html());
14
+ expect(results).toHaveNoViolations();
15
+ });
16
+ });
18
17
  });
19
18
 
20
- it('has the provided `id` attribute', () => {
21
- const $ = cheerio.load(renderComponent('field', EXAMPLE_FIELD_BASIC));
22
-
23
- expect($('.ons-field').attr('id')).toBe('example-field');
19
+ describe('GIVEN: Params: id', () => {
20
+ describe('WHEN: id is provided', () => {
21
+ const $ = cheerio.load(
22
+ renderComponent('field', {
23
+ id: 'example-field',
24
+ }),
25
+ );
26
+ test('THEN: renders with the provided id', () => {
27
+ expect($('.ons-field').attr('id')).toBe('example-field');
28
+ });
29
+ });
24
30
  });
25
31
 
26
- it('has additionally provided style classes', () => {
27
- const $ = cheerio.load(
28
- renderComponent('field', {
29
- ...EXAMPLE_FIELD_BASIC,
30
- classes: 'extra-class another-extra-class',
31
- }),
32
- );
33
-
34
- expect($('.ons-field').hasClass('extra-class')).toBe(true);
35
- expect($('.ons-field').hasClass('another-extra-class')).toBe(true);
32
+ describe('GIVEN: Params: classes', () => {
33
+ describe('WHEN: additional style classes are provided', () => {
34
+ const $ = cheerio.load(
35
+ renderComponent('field', {
36
+ classes: 'extra-class another-extra-class',
37
+ }),
38
+ );
39
+ test('THEN: renders with provided classes', () => {
40
+ expect($('.ons-field').hasClass('extra-class')).toBe(true);
41
+ expect($('.ons-field').hasClass('another-extra-class')).toBe(true);
42
+ });
43
+ });
36
44
  });
37
45
 
38
- it('has correct class when `inline` is provided', () => {
39
- const $ = cheerio.load(
40
- renderComponent('field', {
41
- ...EXAMPLE_FIELD_BASIC,
42
- inline: true,
43
- }),
44
- );
45
-
46
- expect($('.ons-field').hasClass('ons-field--inline')).toBe(true);
46
+ describe('GIVEN: Params: inline', () => {
47
+ describe('WHEN: inline is provided', () => {
48
+ const $ = cheerio.load(
49
+ renderComponent('field', {
50
+ inline: true,
51
+ }),
52
+ );
53
+ test('THEN: renders with the inline class', () => {
54
+ expect($('.ons-field').hasClass('ons-field--inline')).toBe(true);
55
+ });
56
+ });
47
57
  });
48
58
 
49
- it('has additionally provided `attributes`', () => {
50
- const $ = cheerio.load(
51
- renderComponent('field', {
52
- ...EXAMPLE_FIELD_BASIC,
53
- attributes: {
54
- a: 123,
55
- b: 456,
56
- },
57
- }),
58
- );
59
-
60
- expect($('.ons-field').attr('a')).toBe('123');
61
- expect($('.ons-field').attr('b')).toBe('456');
59
+ describe('GIVEN: Params: attributes', () => {
60
+ describe('WHEN: custom attributes are provided', () => {
61
+ const $ = cheerio.load(
62
+ renderComponent('field', {
63
+ attributes: {
64
+ a: 123,
65
+ b: 456,
66
+ },
67
+ }),
68
+ );
69
+ test('THEN: renders with additionally provided attributes', () => {
70
+ expect($('.ons-field').attr('a')).toBe('123');
71
+ expect($('.ons-field').attr('b')).toBe('456');
72
+ });
73
+ });
62
74
  });
63
75
 
64
- it('has the correct element with `dontWrap`', () => {
65
- const $ = cheerio.load(
66
- renderComponent('field', {
67
- ...EXAMPLE_FIELD_BASIC,
68
- dontWrap: true,
69
- }),
70
- );
71
-
72
- expect($('.ons-field').length).toBe(0);
73
- });
76
+ describe('GIVEN: Params: dontWrap', () => {
77
+ describe('WHEN: dontWrap is set to true', () => {
78
+ const $ = cheerio.load(
79
+ renderComponent('field', {
80
+ dontWrap: true,
81
+ }),
82
+ );
83
+ test('THEN: renders the content without being wrapped in a field div', () => {
84
+ expect($('.ons-field').length).toBe(0);
85
+ });
86
+ });
74
87
 
75
- it('calls with content', () => {
76
- const $ = cheerio.load(renderComponent('field', EXAMPLE_FIELD_BASIC, 'Example content...'));
88
+ describe('WHEN: dontWrap is set to false', () => {
89
+ const $ = cheerio.load(
90
+ renderComponent('field', {
91
+ dontWrap: false,
92
+ }),
93
+ );
94
+ test('THEN: renders the content wrapped in a field div', () => {
95
+ expect($('.ons-field').length).toBe(1);
96
+ });
97
+ });
77
98
 
78
- const content = $('.ons-field').html().trim();
79
- expect(content).toEqual(expect.stringContaining('Example content...'));
99
+ describe('WHEN: dontWrap is not provided', () => {
100
+ const $ = cheerio.load(renderComponent('field', {}));
101
+ test('THEN: renders the content wrapped in a field div', () => {
102
+ expect($('.ons-field').length).toBe(1);
103
+ });
104
+ });
80
105
  });
81
106
 
82
- it('calls the error component when `error` is provided', () => {
83
- const faker = templateFaker();
84
- const errorSpy = faker.spy('error');
85
-
86
- faker.renderComponent('field', {
87
- ...EXAMPLE_FIELD_BASIC,
88
- error: { text: 'There is an error' },
107
+ describe('GIVEN: Params: error', () => {
108
+ describe('WHEN: error is provided', () => {
109
+ const faker = templateFaker();
110
+ const errorSpy = faker.spy('error');
111
+
112
+ faker.renderComponent('field', {
113
+ error: { text: 'There is an error' },
114
+ });
115
+ test('THEN" calls the error component', () => {
116
+ expect(errorSpy.occurrences[0]).toEqual({
117
+ text: 'There is an error',
118
+ });
119
+ });
89
120
  });
121
+ });
90
122
 
91
- expect(errorSpy.occurrences[0]).toEqual({
92
- text: 'There is an error',
123
+ describe('GIVEN: Content', () => {
124
+ describe('WHEN: field is called with content provided', () => {
125
+ const $ = cheerio.load(renderComponent('field', {}, 'Example content...'));
126
+ const content = $('.ons-field').html().trim();
127
+ test('THEN: renders the field with the provided content', () => {
128
+ expect(content).toEqual(expect.stringContaining('Example content...'));
129
+ });
93
130
  });
94
131
  });
95
132
  });