@ons/design-system 49.2.0 → 51.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (167) hide show
  1. package/README.md +35 -13
  2. package/components/access-code/_macro.njk +1 -1
  3. package/components/access-code/_macro.spec.js +162 -0
  4. package/components/access-code/uac.spec.js +26 -0
  5. package/components/accordion/_macro.spec.js +224 -0
  6. package/components/accordion/accordion.spec.js +134 -0
  7. package/components/address-input/_macro.njk +1 -1
  8. package/components/address-input/_macro.spec.js +465 -0
  9. package/components/address-input/autosuggest.address.js +5 -4
  10. package/components/address-input/autosuggest.address.setter.js +3 -1
  11. package/components/address-input/autosuggest.address.spec.js +733 -0
  12. package/components/address-output/_macro.njk +6 -6
  13. package/components/address-output/_macro.spec.js +122 -0
  14. package/components/autosuggest/_macro.njk +1 -1
  15. package/components/autosuggest/_macro.spec.js +229 -0
  16. package/components/autosuggest/autosuggest.helpers.js +2 -3
  17. package/components/autosuggest/autosuggest.helpers.spec.js +85 -0
  18. package/components/autosuggest/autosuggest.js +4 -2
  19. package/components/autosuggest/autosuggest.spec.js +625 -0
  20. package/components/autosuggest/autosuggest.ui.js +6 -2
  21. package/components/breadcrumbs/_macro.spec.js +129 -0
  22. package/components/button/_macro.njk +5 -5
  23. package/components/button/_macro.spec.js +446 -0
  24. package/components/button/button.spec.js +290 -0
  25. package/components/call-to-action/_macro.njk +3 -1
  26. package/components/call-to-action/_macro.spec.js +52 -0
  27. package/components/card/_macro.njk +26 -19
  28. package/components/card/_macro.spec.js +261 -0
  29. package/components/char-check-limit/_macro.spec.js +73 -0
  30. package/components/char-check-limit/character-check.spec.js +196 -0
  31. package/components/char-check-limit/character-limit.js +1 -1
  32. package/components/checkboxes/_checkbox-macro.njk +2 -2
  33. package/components/checkboxes/_checkbox-macro.spec.js +419 -0
  34. package/components/checkboxes/_macro.njk +3 -5
  35. package/components/checkboxes/_macro.spec.js +306 -0
  36. package/components/checkboxes/checkboxes.spec.js +208 -0
  37. package/components/code-highlight/_macro.spec.js +56 -0
  38. package/components/code-highlight/code-highlight.spec.js +18 -0
  39. package/components/collapsible/_macro.spec.js +204 -0
  40. package/components/collapsible/collapsible.js +2 -1
  41. package/components/collapsible/collapsible.spec.js +236 -0
  42. package/components/content-pagination/_macro.spec.js +199 -0
  43. package/components/cookies-banner/_macro.njk +1 -1
  44. package/components/cookies-banner/_macro.spec.js +171 -0
  45. package/components/cookies-banner/cookies-banner.spec.js +90 -0
  46. package/components/date-input/_macro.njk +8 -5
  47. package/components/date-input/_macro.spec.js +286 -0
  48. package/components/document-list/_macro.njk +3 -5
  49. package/components/document-list/_macro.spec.js +491 -0
  50. package/components/download-resources/download-resources.spec.js +540 -0
  51. package/components/duration/_macro.njk +7 -6
  52. package/components/duration/_macro.spec.js +251 -0
  53. package/components/error/_macro.spec.js +97 -0
  54. package/components/external-link/_macro.spec.js +60 -0
  55. package/components/feedback/_macro.njk +5 -3
  56. package/components/feedback/_macro.spec.js +122 -0
  57. package/components/field/_macro.njk +2 -2
  58. package/components/field/_macro.spec.js +97 -0
  59. package/components/fieldset/_macro.njk +3 -3
  60. package/components/fieldset/_macro.spec.js +173 -0
  61. package/components/footer/_macro.njk +11 -48
  62. package/components/footer/_macro.spec.js +549 -0
  63. package/components/header/_macro.njk +2 -2
  64. package/components/header/_macro.spec.js +562 -0
  65. package/components/hero/_hero.scss +0 -3
  66. package/components/hero/_macro.njk +4 -4
  67. package/components/hero/_macro.spec.js +224 -0
  68. package/components/icons/_macro.njk +15 -15
  69. package/components/icons/_macro.spec.js +140 -0
  70. package/components/images/_macro.njk +1 -1
  71. package/components/images/_macro.spec.js +121 -0
  72. package/components/input/_input-type.scss +12 -5
  73. package/components/input/_macro.njk +6 -7
  74. package/components/input/_macro.spec.js +658 -0
  75. package/components/label/_macro.spec.js +189 -0
  76. package/components/language-selector/_macro.spec.js +129 -0
  77. package/components/lists/_list.scss +4 -0
  78. package/components/lists/_macro.njk +4 -7
  79. package/components/lists/_macro.spec.js +618 -0
  80. package/components/message/_macro.spec.js +137 -0
  81. package/components/message-list/_macro.njk +7 -7
  82. package/components/message-list/_macro.spec.js +159 -0
  83. package/components/metadata/_macro.spec.js +167 -0
  84. package/components/modal/_macro.njk +6 -6
  85. package/components/modal/_macro.spec.js +87 -0
  86. package/components/modal/modal.js +0 -16
  87. package/components/modal/modal.spec.js +59 -0
  88. package/components/mutually-exclusive/_macro.njk +38 -21
  89. package/components/mutually-exclusive/_macro.spec.js +182 -0
  90. package/components/mutually-exclusive/mutually-exclusive.checkboxes.spec.js +203 -0
  91. package/components/mutually-exclusive/mutually-exclusive.date.spec.js +142 -0
  92. package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +141 -0
  93. package/components/mutually-exclusive/mutually-exclusive.email.spec.js +117 -0
  94. package/components/mutually-exclusive/mutually-exclusive.js +32 -23
  95. package/components/mutually-exclusive/mutually-exclusive.multiple-options.checkboxes.spec.js +213 -0
  96. package/components/mutually-exclusive/mutually-exclusive.number.spec.js +125 -0
  97. package/components/mutually-exclusive/mutually-exclusive.textarea.spec.js +131 -0
  98. package/components/navigation/_macro.njk +6 -6
  99. package/components/navigation/_macro.spec.js +327 -0
  100. package/components/navigation/navigation.dom.js +1 -1
  101. package/components/navigation/navigation.spec.js +232 -0
  102. package/components/pagination/_macro.njk +1 -1
  103. package/components/pagination/_macro.spec.js +411 -0
  104. package/components/panel/_macro.njk +6 -6
  105. package/components/panel/_macro.spec.js +423 -0
  106. package/components/password/_macro.spec.js +137 -0
  107. package/components/password/password.spec.js +40 -0
  108. package/components/phase-banner/_macro.spec.js +73 -0
  109. package/components/promotional-banner/_macro.spec.js +97 -0
  110. package/components/question/_macro.njk +25 -33
  111. package/components/question/_macro.spec.js +309 -0
  112. package/components/quote/_macro.spec.js +81 -0
  113. package/components/radios/_macro.njk +98 -102
  114. package/components/radios/_macro.spec.js +575 -0
  115. package/components/radios/radios.spec.js +180 -0
  116. package/components/related-content/_macro.njk +1 -0
  117. package/components/related-content/_macro.spec.js +142 -0
  118. package/components/relationships/_macro.spec.js +108 -0
  119. package/components/relationships/relationships.spec.js +84 -0
  120. package/components/reply/_macro.njk +2 -2
  121. package/components/reply/_macro.spec.js +69 -0
  122. package/components/reply/reply.spec.js +78 -0
  123. package/components/search/_macro.njk +14 -12
  124. package/components/search/_macro.spec.js +44 -0
  125. package/components/search/_search.scss +7 -7
  126. package/components/section-navigation/_macro.njk +7 -2
  127. package/components/section-navigation/_macro.spec.js +206 -0
  128. package/components/select/_macro.njk +3 -3
  129. package/components/select/_macro.spec.js +203 -0
  130. package/components/select/select.spec.js +56 -0
  131. package/components/share-page/_macro.njk +2 -2
  132. package/components/share-page/_macro.spec.js +110 -0
  133. package/components/skip-to-content/_macro.spec.js +57 -0
  134. package/components/skip-to-content/skip-to-content.spec.js +44 -0
  135. package/components/status/_macro.spec.js +77 -0
  136. package/components/summary/_macro.njk +5 -5
  137. package/components/summary/_macro.spec.js +472 -0
  138. package/components/table/_macro.njk +2 -2
  139. package/components/table/_macro.spec.js +557 -0
  140. package/components/table/table.spec.js +155 -0
  141. package/components/table-of-contents/_macro.njk +35 -35
  142. package/components/table-of-contents/_macro.spec.js +178 -0
  143. package/components/table-of-contents/toc.js +29 -25
  144. package/components/table-of-contents/toc.spec.js +61 -0
  145. package/components/tabs/_macro.njk +1 -1
  146. package/components/tabs/_macro.spec.js +79 -0
  147. package/components/tabs/tabs.spec.js +162 -0
  148. package/components/text-indent/_macro.spec.js +52 -0
  149. package/components/textarea/_macro.njk +7 -5
  150. package/components/textarea/_macro.spec.js +300 -0
  151. package/components/textarea/textarea.spec.js +98 -0
  152. package/components/timeline/_macro.njk +3 -3
  153. package/components/timeline/_macro.spec.js +81 -0
  154. package/components/timeout-modal/_macro.spec.js +68 -0
  155. package/components/timeout-modal/timeout-modal.spec.js +226 -0
  156. package/components/timeout-panel/_macro.njk +0 -1
  157. package/components/timeout-panel/_macro.spec.js +54 -0
  158. package/components/timeout-panel/timeout-panel.dom.js +1 -2
  159. package/components/timeout-panel/timeout-panel.spec.js +161 -0
  160. package/components/upload/_macro.spec.js +75 -0
  161. package/components/video/_macro.spec.js +34 -0
  162. package/css/census.css +1 -1
  163. package/css/main.css +1 -1
  164. package/js/cookies-settings.spec.js +154 -0
  165. package/package.json +10 -23
  166. package/scripts/main.es5.js +1 -1
  167. package/scripts/main.js +2 -2
@@ -0,0 +1,129 @@
1
+ /** @jest-environment jsdom */
2
+
3
+ import * as cheerio from 'cheerio';
4
+
5
+ import axe from '../../tests/helpers/axe';
6
+ import { mapAll } from '../../tests/helpers/cheerio';
7
+ import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
8
+
9
+ const EXAMPLE_BREADCRUMBS_MINIMAL = {
10
+ itemsList: [
11
+ {
12
+ url: 'https://example.com/',
13
+ text: 'Home',
14
+ },
15
+ {
16
+ url: 'https://example.com/guide/',
17
+ text: 'Guide',
18
+ },
19
+ ],
20
+ };
21
+
22
+ const EXAMPLE_BREADCRUMBS = {
23
+ classes: 'extra-class another-extra-class',
24
+ ariaLabel: 'Breadcrumbs label',
25
+ id: 'example-breadcrumbs',
26
+ itemsList: [
27
+ {
28
+ itemClasses: 'item-extra-class item-another-extra-class',
29
+ linkClasses: 'link-extra-class link-another-extra-class',
30
+ url: 'https://example.com/',
31
+ text: 'Home',
32
+ attributes: {
33
+ 'data-a': '123',
34
+ 'data-b': '456',
35
+ },
36
+ id: 'first-breadcrumb',
37
+ },
38
+ {
39
+ url: 'https://example.com/guide/',
40
+ text: 'Guide',
41
+ id: 'second-breadcrumb',
42
+ attributes: {
43
+ 'data-a': '789',
44
+ 'data-b': 'ABC',
45
+ },
46
+ },
47
+ ],
48
+ };
49
+
50
+ describe('macro: breadcrumbs', () => {
51
+ it('passes jest-axe checks', async () => {
52
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS));
53
+
54
+ const results = await axe($.html());
55
+ expect(results).toHaveNoViolations();
56
+ });
57
+
58
+ it('has additionally provided style classes', () => {
59
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS));
60
+
61
+ expect($('.ons-breadcrumb').hasClass('extra-class')).toBe(true);
62
+ expect($('.ons-breadcrumb').hasClass('another-extra-class')).toBe(true);
63
+ });
64
+
65
+ it('has a default `aria-label` of "Breadcrumbs"', () => {
66
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS_MINIMAL));
67
+
68
+ expect($('.ons-breadcrumb').attr('aria-label')).toBe('Breadcrumbs');
69
+ });
70
+
71
+ it('has the provided `ariaLabel` for `aria-label`', () => {
72
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS));
73
+
74
+ expect($('.ons-breadcrumb').attr('aria-label')).toBe('Breadcrumbs label');
75
+ });
76
+
77
+ it('has the provided `id`', () => {
78
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS));
79
+
80
+ expect($('.ons-breadcrumb').attr('id')).toBe('example-breadcrumbs');
81
+ });
82
+
83
+ it('has additionally provided style classes on `item` element', () => {
84
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS));
85
+
86
+ expect($('.ons-breadcrumb__item:first').hasClass('item-extra-class')).toBe(true);
87
+ expect($('.ons-breadcrumb__item:first').hasClass('item-another-extra-class')).toBe(true);
88
+ });
89
+
90
+ it('has additionally provided style classes on `link` element', () => {
91
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS));
92
+
93
+ expect($('.ons-breadcrumb__link:first').hasClass('link-extra-class')).toBe(true);
94
+ expect($('.ons-breadcrumb__link:first').hasClass('link-another-extra-class')).toBe(true);
95
+ });
96
+
97
+ it('has provided `url` on `link` elements', () => {
98
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS));
99
+
100
+ const urls = mapAll($('.ons-breadcrumb__link'), node => node.attr('href'));
101
+ expect(urls).toEqual(['https://example.com/', 'https://example.com/guide/']);
102
+ });
103
+
104
+ it('has provided `text` on `link` elements', () => {
105
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS));
106
+
107
+ const labels = mapAll($('.ons-breadcrumb__link'), node => node.text().trim());
108
+ expect(labels).toEqual(['Home', 'Guide']);
109
+ });
110
+
111
+ it('has provided `attributes` on `link` elements', () => {
112
+ const $ = cheerio.load(renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS));
113
+
114
+ const testValuesA = mapAll($('.ons-breadcrumb__link'), node => node.attr('data-a'));
115
+ expect(testValuesA).toEqual(['123', '789']);
116
+ const testValuesB = mapAll($('.ons-breadcrumb__link'), node => node.attr('data-b'));
117
+ expect(testValuesB).toEqual(['456', 'ABC']);
118
+ });
119
+
120
+ it('has a "chevron" icon for each breadcrumb item', () => {
121
+ const faker = templateFaker();
122
+ const iconsSpy = faker.spy('icons');
123
+
124
+ faker.renderComponent('breadcrumbs', EXAMPLE_BREADCRUMBS_MINIMAL);
125
+
126
+ const iconTypes = iconsSpy.occurrences.map(occurrence => occurrence.iconType);
127
+ expect(iconTypes).toEqual(['chevron', 'chevron']);
128
+ });
129
+ });
@@ -49,8 +49,8 @@
49
49
  {% endif %}
50
50
  class="ons-btn{% if params.classes is defined and params.classes %} {{ params.classes }}{% endif %}{% if params.variants is defined and params.variants %}{% if params.variants is not string %}{% for variant in params.variants %} ons-btn--{{ variant }}{% endfor %}{% else %} ons-btn--{{ params.variants }}{% endif %}{% endif %}{% if params.url is defined and params.url %} ons-btn--link ons-js-submit-btn{% endif %}{% if params.buttonStyle == "download" %} ons-btn--download{% endif %}{% if params.buttonStyle == "print" %} ons-btn--print ons-u-d-no ons-js-print-btn{% endif %}{% if params.submitType == "loader" %} ons-btn--loader ons-js-loader ons-js-submit-btn{% endif %}{% if params.submitType == "timer" %} ons-js-timer ons-js-submit-btn{% endif %}"
51
51
  {% if params.id is defined and params.id %}id="{{ params.id }}"{% endif %}
52
- {% if params.value is defined and params.value %}value="{{ params.value }}"{% endif %}
53
- {% if params.name is defined and params.name and tag != "a" %}name="{{ params.name }}"{% elif params.name is defined and params.name and tag == "a" %}id="{{ params.name }}"{% endif %}
52
+ {% if params.value is defined and params.value and tag != "a" %}value="{{ params.value }}"{% endif %}
53
+ {% if params.name is defined and params.name and tag != "a" %}name="{{ params.name }}"{% endif %}
54
54
  {% if params.url is defined and params.url and params.newWindow is defined and params.newWindow %}target="_blank" rel="noopener"{% endif %}
55
55
  {% if params.buttonStyle == "download" and (params.removeDownloadAttribute is not defined or not params.removeDownloadAttribute or params.removeDownloadAttribute != true) %} download{% endif %}
56
56
  {% if params.attributes is defined and params.attributes %}{% for attribute, value in (params.attributes.items() if params.attributes is mapping and params.attributes.items else params.attributes) %} {{attribute}}="{{value}}"{% endfor %}{% endif %}
@@ -65,7 +65,7 @@
65
65
  })
66
66
  }}
67
67
  {% endif -%}
68
- {{- params.html | safe if params.html is defined and params.html else params.text -}}
68
+ <span class="ons-btn__text">{{- params.html | safe if params.html is defined and params.html else params.text -}}</span>
69
69
  {%- if iconPosition == "after" %}
70
70
  {{
71
71
  onsIcon({
@@ -80,9 +80,9 @@
80
80
  "iconType": iconType
81
81
  })
82
82
  }}
83
- <span class="ons-u-vh@xxs@s">{{- params.html | safe if params.html is defined and params.html else params.text -}}</span>
83
+ <span class="ons-btn__text ons-u-vh@xxs@s">{{- params.html | safe if params.html is defined and params.html else params.text -}}</span>
84
84
  {% else -%}
85
- {{- params.html | safe if params.html is defined and params.html else params.text -}}
85
+ <span class="ons-btn__text">{{- params.html | safe if params.html is defined and params.html else params.text -}}</span>
86
86
  {% endif -%}
87
87
  </span>
88
88
  {% if params.url is defined and params.url and params.newWindow is defined and params.newWindow %}
@@ -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 &gt; 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 window');
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
+ });