@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,59 @@
1
+ import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
2
+
3
+ const EXAMPLE_MODAL = {
4
+ title: 'Modal title',
5
+ body: 'Modal body text',
6
+ btnText: 'Modal button',
7
+ };
8
+
9
+ describe('script: modal', () => {
10
+ beforeEach(async () => {
11
+ const component = renderComponent('modal', EXAMPLE_MODAL);
12
+ const template = `
13
+ <div class="ons-page">
14
+ <button id="launcher" data-modal-id="dialog">Launcher</button>
15
+ ${component}
16
+ </div>
17
+ `;
18
+ await setTestPage('/test', template);
19
+ });
20
+
21
+ describe('when the modal launcher is clicked', () => {
22
+ beforeEach(async () => {
23
+ await page.focus('#launcher');
24
+ await page.keyboard.press('Enter');
25
+ });
26
+
27
+ it('displays the modal', async () => {
28
+ const modalIsVisible = await page.$eval('.ons-modal', node => node.classList.contains('ons-u-db'));
29
+ expect(modalIsVisible).toBe(true);
30
+ });
31
+
32
+ it('has the correct body class added', async () => {
33
+ const bodyClassAddition = await page.$eval('body', node => node.classList.contains('ons-modal-overlay'));
34
+ expect(bodyClassAddition).toBe(true);
35
+ });
36
+
37
+ describe('when the modal close button is clicked', () => {
38
+ beforeEach(async () => {
39
+ await page.focus('.ons-js-modal-btn');
40
+ await page.keyboard.press('Enter');
41
+ });
42
+
43
+ it('hides the modal', async () => {
44
+ const modalIsVisible = await page.$eval('.ons-modal', node => node.classList.contains('ons-u-db'));
45
+ expect(modalIsVisible).toBe(false);
46
+ });
47
+
48
+ it('has the body class removed', async () => {
49
+ const bodyClassAddition = await page.$eval('body', node => node.classList.contains('ons-modal-overlay'));
50
+ expect(bodyClassAddition).toBe(false);
51
+ });
52
+
53
+ it('focuses the last active element', async () => {
54
+ const activeElementId = await page.evaluate(() => document.activeElement.id);
55
+ expect(activeElementId).toBe('launcher');
56
+ });
57
+ });
58
+ });
59
+ });
@@ -2,9 +2,11 @@
2
2
  {% macro onsMutuallyExclusive(params) %}
3
3
  {% from "components/fieldset/_macro.njk" import onsFieldset %}
4
4
  {% from "components/checkboxes/_checkbox-macro.njk" import onsCheckbox %}
5
+ {% from "components/radios/_macro.njk" import onsRadios %}
5
6
 
6
- {# Resolves caller issue in jijna: https://github.com/pallets/jinja/issues/371 #}
7
+ {# Resolves caller issue in Jinja: https://github.com/pallets/jinja/issues/371 #}
7
8
  {% set content = caller() %}
9
+ {% set exclusiveOptionsLength = params.exclusiveOptions | length %}
8
10
 
9
11
  {% call onsFieldset({
10
12
  "id": params.id,
@@ -22,26 +24,41 @@
22
24
  {% if params.autosuggestResults is defined and params.autosuggestResults %}
23
25
  {{ params.autosuggestResults | safe }}
24
26
  {% endif %}
25
- <p class="ons-checkboxes--mutually-exclusive__item ons-u-mt-s">
26
- <span class="ons-checkboxes__label ons-u-fs-r--b" aria-hidden="true">{{ params.or }}</span>
27
- {{
28
- onsCheckbox({
29
- "id": params.checkbox.id,
30
- "name": params.checkbox.name,
31
- "value": params.checkbox.value,
32
- "checked": params.checkbox.checked,
33
- "classes": params.checkbox.classes,
34
- "attributes": params.checkbox.attributes,
35
- "deselectMessage": params.deselectMessage,
36
- "inputClasses": "ons-js-exclusive-checkbox",
37
- "label": {
38
- "text": '<span class="ons-u-vh">' + params.or + ', </span> ' + params.checkbox.label.text,
39
- "description": params.checkbox.label.description
40
- }
41
- })
42
- }}
43
- </p>
44
- <span class="ons-js-exclusive-alert ons-u-vh" role="alert" aria-live="polite" data-group-adjective="{{ params.deselectGroupAdjective }}" data-checkbox-adjective="{{ params.deselectCheckboxAdjective }}"></span>
27
+ {% if exclusiveOptionsLength == 1 %}
28
+ <p class="ons-checkboxes--mutually-exclusive__item ons-u-mt-s">
29
+ <span class="ons-checkboxes__label ons-u-fs-r--b" aria-hidden="true">{{ params.or }}</span>
30
+ {{
31
+ onsCheckbox({
32
+ "id": params.exclusiveOptions[0].id,
33
+ "name": params.exclusiveOptions[0].name,
34
+ "value": params.exclusiveOptions[0].value,
35
+ "checked": params.exclusiveOptions[0].checked,
36
+ "classes": params.exclusiveOptions[0].classes,
37
+ "attributes": params.exclusiveOptions[0].attributes,
38
+ "deselectMessage": params.deselectMessage,
39
+ "inputClasses": "ons-js-exclusive-option",
40
+ "label": {
41
+ "text": '<span class="ons-u-vh">' + params.or + ', </span> ' + params.exclusiveOptions[0].label.text,
42
+ "description": params.exclusiveOptions[0].label.description
43
+ }
44
+ })
45
+ }}
46
+ </p>
47
+ {% elif exclusiveOptionsLength > 1 %}
48
+ <p class="ons-checkboxes--mutually-exclusive__item ons-u-mt-s">
49
+ <span class="ons-checkboxes__label ons-u-fs-r--b" aria-hidden="true">{{ params.or }}</span>
50
+ {{
51
+ onsRadios({
52
+ "dontWrap": true,
53
+ "radios": params.exclusiveOptions,
54
+ "inputClasses": "ons-js-exclusive-option",
55
+ "name": "mutuallyExclusiveRadio",
56
+ "deselectMessage": params.deselectMessage
57
+ })
58
+ }}
59
+ </p>
60
+ {% endif %}
61
+ <span class="ons-js-exclusive-alert ons-u-vh" role="alert" aria-live="polite" data-group-adjective="{{ params.deselectGroupAdjective }}" data-option-adjective="{{ params.deselectExclusiveOptionAdjective }}"></span>
45
62
  </div>
46
63
  {% endcall %}
47
64
  {% endmacro %}
@@ -0,0 +1,182 @@
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
+ const EXAMPLE_CHECKBOX_OPTION = {
9
+ id: 'example-option-id',
10
+ name: 'example-option-name',
11
+ value: 'example-option-value',
12
+ checked: false,
13
+ classes: 'extra-option-class',
14
+ attributes: {
15
+ 'data-attribute': 'Example attribute',
16
+ },
17
+ label: {
18
+ text: 'Example option text',
19
+ description: 'Example option description',
20
+ },
21
+ };
22
+
23
+ const EXAMPLE_MUTUALLY_EXCLUSIVE = {
24
+ id: 'example-mutually-exclusive',
25
+ classes: 'extra-class',
26
+ exclusiveOptions: [EXAMPLE_CHECKBOX_OPTION],
27
+ or: 'Or',
28
+ deselectMessage: 'Selecting this will uncheck all other checkboxes',
29
+ deselectGroupAdjective: 'Group was unselected',
30
+ deselectExclusiveOptionAdjective: 'Exclusive option was unselected',
31
+ legend: 'Legend text',
32
+ legendClasses: 'extra-legend-class',
33
+ description: 'An example description.',
34
+ attributes: { a: 42 },
35
+ dontWrap: true,
36
+ legendIsQuestionTitle: true,
37
+ error: {
38
+ id: 'file-error',
39
+ text: 'Select a file that is an XLS, XLSX or PDF',
40
+ },
41
+ };
42
+
43
+ const EXAMPLE_MUTUALLY_EXCLUSIVE_RADIOS = {
44
+ ...EXAMPLE_MUTUALLY_EXCLUSIVE,
45
+ exclusiveOptions: [
46
+ {
47
+ id: 'house',
48
+ label: {
49
+ text: 'House or bungalow',
50
+ },
51
+ value: 'house',
52
+ },
53
+ {
54
+ id: 'flat',
55
+ label: {
56
+ text: 'Flat, maisonette or apartment',
57
+ },
58
+ value: 'flat',
59
+ },
60
+ ],
61
+ };
62
+
63
+ const FAKE_FIELD = '<span id="fake-field">Fake field</span>';
64
+
65
+ describe('macro: mutually-exclusive', () => {
66
+ it('passes jest-axe checks', async () => {
67
+ const $ = cheerio.load(renderComponent('mutually-exclusive', EXAMPLE_MUTUALLY_EXCLUSIVE, FAKE_FIELD));
68
+
69
+ const results = await axe($.html());
70
+ expect(results).toHaveNoViolations();
71
+ });
72
+
73
+ it('renders `fieldset` component with the expected parameters', () => {
74
+ const faker = templateFaker();
75
+ const fieldsetSpy = faker.spy('fieldset');
76
+
77
+ faker.renderComponent('mutually-exclusive', EXAMPLE_MUTUALLY_EXCLUSIVE, FAKE_FIELD);
78
+
79
+ expect(fieldsetSpy.occurrences).toContainEqual({
80
+ id: 'example-mutually-exclusive',
81
+ classes: 'extra-class',
82
+ legend: 'Legend text',
83
+ legendClasses: 'extra-legend-class',
84
+ description: 'An example description.',
85
+ attributes: EXAMPLE_MUTUALLY_EXCLUSIVE.attributes,
86
+ dontWrap: true,
87
+ legendIsQuestionTitle: true,
88
+ error: EXAMPLE_MUTUALLY_EXCLUSIVE.error,
89
+ });
90
+ });
91
+
92
+ it('renders inner field via `caller` mechanism', () => {
93
+ const $ = cheerio.load(renderComponent('mutually-exclusive', EXAMPLE_MUTUALLY_EXCLUSIVE, FAKE_FIELD));
94
+
95
+ expect($('.ons-mutually-exclusive > #fake-field').length).toBe(1);
96
+ });
97
+
98
+ it('renders `autosuggestResults` after the field', () => {
99
+ const $ = cheerio.load(
100
+ renderComponent(
101
+ 'mutually-exclusive',
102
+ {
103
+ ...EXAMPLE_MUTUALLY_EXCLUSIVE,
104
+ autosuggestResults: '<span id="autosuggest-results"></span>',
105
+ },
106
+ FAKE_FIELD,
107
+ ),
108
+ );
109
+
110
+ expect($('#fake-field + #autosuggest-results').length).toBe(1);
111
+ });
112
+
113
+ it('renders `deselectGroupAdjective` and `deselectExclusiveOptionAdjective` for the alert', () => {
114
+ const $ = cheerio.load(renderComponent('mutually-exclusive', EXAMPLE_MUTUALLY_EXCLUSIVE, FAKE_FIELD));
115
+
116
+ expect($('.ons-js-exclusive-alert').attr('data-group-adjective')).toBe('Group was unselected');
117
+ expect($('.ons-js-exclusive-alert').attr('data-option-adjective')).toBe('Exclusive option was unselected');
118
+ });
119
+
120
+ describe('mode: with single checkbox', () => {
121
+ it('renders visually hidden "Or" label', () => {
122
+ const $ = cheerio.load(renderComponent('mutually-exclusive', EXAMPLE_MUTUALLY_EXCLUSIVE, FAKE_FIELD));
123
+
124
+ expect(
125
+ $('.ons-checkboxes__label')
126
+ .text()
127
+ .trim(),
128
+ ).toBe('Or');
129
+ });
130
+
131
+ it('renders a checkbox component with the expected parameters', () => {
132
+ const faker = templateFaker();
133
+ const checkboxSpy = faker.spy('checkboxes/checkbox');
134
+
135
+ faker.renderComponent('mutually-exclusive', EXAMPLE_MUTUALLY_EXCLUSIVE, FAKE_FIELD);
136
+
137
+ expect(checkboxSpy.occurrences).toContainEqual({
138
+ id: 'example-option-id',
139
+ name: 'example-option-name',
140
+ value: 'example-option-value',
141
+ checked: false,
142
+ classes: 'extra-option-class',
143
+ attributes: {
144
+ 'data-attribute': 'Example attribute',
145
+ },
146
+ deselectMessage: 'Selecting this will uncheck all other checkboxes',
147
+ inputClasses: 'ons-js-exclusive-option',
148
+ label: {
149
+ text: '<span class="ons-u-vh">Or, </span> Example option text',
150
+ description: 'Example option description',
151
+ },
152
+ });
153
+ });
154
+ });
155
+
156
+ describe('mode: with multiple radio options', () => {
157
+ it('renders visually hidden "Or" label', () => {
158
+ const $ = cheerio.load(renderComponent('mutually-exclusive', EXAMPLE_MUTUALLY_EXCLUSIVE_RADIOS, FAKE_FIELD));
159
+
160
+ expect(
161
+ $('.ons-checkboxes__label')
162
+ .text()
163
+ .trim(),
164
+ ).toBe('Or');
165
+ });
166
+
167
+ it('renders a radios component with the expected parameters', () => {
168
+ const faker = templateFaker();
169
+ const radiosSpy = faker.spy('radios');
170
+
171
+ faker.renderComponent('mutually-exclusive', EXAMPLE_MUTUALLY_EXCLUSIVE_RADIOS, FAKE_FIELD);
172
+
173
+ expect(radiosSpy.occurrences).toContainEqual({
174
+ dontWrap: true,
175
+ radios: EXAMPLE_MUTUALLY_EXCLUSIVE_RADIOS.exclusiveOptions,
176
+ inputClasses: 'ons-js-exclusive-option',
177
+ name: 'mutuallyExclusiveRadio',
178
+ deselectMessage: 'Selecting this will uncheck all other checkboxes',
179
+ });
180
+ });
181
+ });
182
+ });
@@ -0,0 +1,203 @@
1
+ import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
2
+
3
+ const SCREEN_READER_TIMEOUT_DELAY = 300;
4
+
5
+ const EXAMPLE_MUTUALLY_EXCLUSIVE_CHECKBOXES_PARAMS = {
6
+ legend: 'What type of central heating do you have?',
7
+ checkboxesLabel: 'Select all that apply',
8
+ name: 'mutually-exclusive',
9
+ checkboxes: [
10
+ {
11
+ id: 'gas',
12
+ label: {
13
+ text: 'Gas',
14
+ },
15
+ value: 'gas',
16
+ },
17
+ {
18
+ id: 'electric',
19
+ label: {
20
+ text: 'Electric',
21
+ },
22
+ value: 'electric',
23
+ },
24
+ {
25
+ id: 'solid-fuel',
26
+ label: {
27
+ text: 'Solid fuel',
28
+ },
29
+ value: 'solid-fuel',
30
+ },
31
+ {
32
+ id: 'other-fuel',
33
+ label: {
34
+ text: 'Other',
35
+ },
36
+ value: 'other',
37
+ other: {
38
+ id: 'other-fuel-textbox',
39
+ name: 'other-fuel-answer',
40
+ label: {
41
+ text: 'Please specify',
42
+ },
43
+ },
44
+ },
45
+ ],
46
+ mutuallyExclusive: {
47
+ or: 'or',
48
+ deselectMessage: 'Selecting this will uncheck all other checkboxes',
49
+ deselectGroupAdjective: 'deselected',
50
+ deselectExclusiveOptionAdjective: 'deselected',
51
+ exclusiveOptions: [
52
+ {
53
+ id: 'no-central-heating',
54
+ label: {
55
+ text: 'No central heating',
56
+ },
57
+ value: 'no-central-heating',
58
+ },
59
+ ],
60
+ },
61
+ };
62
+
63
+ describe('script: mutually-exclusive', () => {
64
+ describe('checkboxes', () => {
65
+ beforeEach(async () => {
66
+ await setTestPage('/test', renderComponent('checkboxes', EXAMPLE_MUTUALLY_EXCLUSIVE_CHECKBOXES_PARAMS));
67
+ });
68
+
69
+ describe('Given the user has clicked multiple non-exclusive options', () => {
70
+ beforeEach(async () => {
71
+ await page.click('#gas');
72
+ await page.click('#electric');
73
+ await page.click('#other-fuel');
74
+ await page.type('#other-fuel-textbox', 'Biofuel');
75
+ });
76
+
77
+ describe('when the user clicks the mutually exclusive option', () => {
78
+ beforeEach(async () => {
79
+ await page.click('#no-central-heating');
80
+ });
81
+
82
+ it('then the mutually exclusive option is checked', async () => {
83
+ const isChecked = await page.$eval('#no-central-heating', node => node.checked);
84
+ expect(isChecked).toBe(true);
85
+ });
86
+
87
+ it('then the checkboxes are not checked', async () => {
88
+ expect(await page.$eval('#gas', node => node.checked)).toBe(false);
89
+ expect(await page.$eval('#electric', node => node.checked)).toBe(false);
90
+ expect(await page.$eval('#solid-fuel', node => node.checked)).toBe(false);
91
+ expect(await page.$eval('#other-fuel', node => node.checked)).toBe(false);
92
+ expect(await page.$eval('#other-fuel-textbox', node => node.value)).toBe('');
93
+ });
94
+
95
+ it('then the aria-live message should reflect the removed non exclusive options', async () => {
96
+ await page.waitForTimeout(SCREEN_READER_TIMEOUT_DELAY);
97
+
98
+ const alertText = await page.$eval('.ons-js-exclusive-alert', node => node.textContent);
99
+ expect(alertText).toBe('Gas deselected. Electric deselected. Other deselected. Please specify deselected.');
100
+ });
101
+ });
102
+ });
103
+
104
+ describe('Given the user has clicked the mutually exclusive option', () => {
105
+ beforeEach(async () => {
106
+ await page.click('#no-central-heating');
107
+ });
108
+
109
+ describe('when the user clicks the non-exclusive options', () => {
110
+ beforeEach(async () => {
111
+ await page.click('#gas');
112
+ await page.click('#electric');
113
+ await page.click('#other-fuel');
114
+ });
115
+
116
+ it('then the expected checkboxes are checked', async () => {
117
+ expect(await page.$eval('#gas', node => node.checked)).toBe(true);
118
+ expect(await page.$eval('#electric', node => node.checked)).toBe(true);
119
+ expect(await page.$eval('#solid-fuel', node => node.checked)).toBe(false);
120
+ expect(await page.$eval('#other-fuel', node => node.checked)).toBe(true);
121
+ });
122
+
123
+ it('then the exclusive option should not be checked', async () => {
124
+ expect(await page.$eval('#no-central-heating', node => node.checked)).toBe(false);
125
+ });
126
+
127
+ it('then the aria-live message should reflect the removed exclusive option', async () => {
128
+ await page.waitForTimeout(SCREEN_READER_TIMEOUT_DELAY);
129
+
130
+ const alertText = await page.$eval('.ons-js-exclusive-alert', node => node.textContent);
131
+ expect(alertText).toBe('No central heating deselected.');
132
+ });
133
+
134
+ describe('and the user deselects an non-exclusive option', () => {
135
+ beforeEach(async () => {
136
+ await page.click('#electric');
137
+ });
138
+
139
+ it('the aria-live message should not be updated', async () => {
140
+ await page.waitForTimeout(SCREEN_READER_TIMEOUT_DELAY);
141
+
142
+ const alertText = await page.$eval('.ons-js-exclusive-alert', node => node.textContent);
143
+ expect(alertText).toBe('No central heating deselected.');
144
+ });
145
+ });
146
+ });
147
+ });
148
+
149
+ describe('Given the user has not clicked the mutually exclusive option', () => {
150
+ describe('when the user clicks multiple non-exclusive options', () => {
151
+ beforeEach(async () => {
152
+ await page.click('#gas');
153
+ await page.click('#electric');
154
+ await page.click('#other-fuel');
155
+ });
156
+
157
+ it('then the expected checkboxes are checked', async () => {
158
+ expect(await page.$eval('#gas', node => node.checked)).toBe(true);
159
+ expect(await page.$eval('#electric', node => node.checked)).toBe(true);
160
+ expect(await page.$eval('#solid-fuel', node => node.checked)).toBe(false);
161
+ expect(await page.$eval('#other-fuel', node => node.checked)).toBe(true);
162
+ });
163
+
164
+ it('then the exclusive option should not be checked', async () => {
165
+ expect(await page.$eval('#no-central-heating', node => node.checked)).toBe(false);
166
+ });
167
+
168
+ it('then the aria-live message should say nothing', async () => {
169
+ await page.waitForTimeout(SCREEN_READER_TIMEOUT_DELAY);
170
+
171
+ const alertText = await page.$eval('.ons-js-exclusive-alert', node => node.textContent);
172
+ expect(alertText).toBe('');
173
+ });
174
+ });
175
+ });
176
+
177
+ describe('Given the user has not clicked any of the non-exclusive options', () => {
178
+ describe('when the user clicks the mutually exclusive option', () => {
179
+ beforeEach(async () => {
180
+ await page.click('#no-central-heating');
181
+ });
182
+
183
+ it('then the expected checkboxes are not checked', async () => {
184
+ expect(await page.$eval('#gas', node => node.checked)).toBe(false);
185
+ expect(await page.$eval('#electric', node => node.checked)).toBe(false);
186
+ expect(await page.$eval('#solid-fuel', node => node.checked)).toBe(false);
187
+ expect(await page.$eval('#other-fuel', node => node.checked)).toBe(false);
188
+ });
189
+
190
+ it('then the exclusive option should be checked', async () => {
191
+ expect(await page.$eval('#no-central-heating', node => node.checked)).toBe(true);
192
+ });
193
+
194
+ it('then the aria-live message should say nothing', async () => {
195
+ await page.waitForTimeout(SCREEN_READER_TIMEOUT_DELAY);
196
+
197
+ const alertText = await page.$eval('.ons-js-exclusive-alert', node => node.textContent);
198
+ expect(alertText).toBe('');
199
+ });
200
+ });
201
+ });
202
+ });
203
+ });
@@ -0,0 +1,142 @@
1
+ import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
2
+
3
+ const SCREEN_READER_TIMEOUT_DELAY = 300;
4
+
5
+ const EXAMPLE_MUTUALLY_EXCLUSIVE_DATE_PARAMS = {
6
+ id: 'date-mutually-exclusive',
7
+ legendOrLabel: 'When did you leave your last paid job?',
8
+ description: 'For example, 31 3 2018',
9
+ day: {
10
+ label: {
11
+ text: 'Day',
12
+ },
13
+ name: 'day-exclusive',
14
+ },
15
+ month: {
16
+ label: {
17
+ text: 'Month',
18
+ },
19
+ name: 'month-exclusive',
20
+ },
21
+ year: {
22
+ label: {
23
+ text: 'Year',
24
+ },
25
+ name: 'year-exclusive',
26
+ },
27
+ mutuallyExclusive: {
28
+ or: 'Or',
29
+ deselectMessage: 'Selecting this will clear the date if one has been inputted',
30
+ deselectGroupAdjective: 'cleared',
31
+ deselectExclusiveOptionAdjective: 'deselected',
32
+ exclusiveOptions: [
33
+ {
34
+ id: 'date-exclusive-exclusive-option',
35
+ name: 'no-paid-job',
36
+ value: 'no-paid-job',
37
+ label: {
38
+ text: 'I have never had a paid job',
39
+ },
40
+ },
41
+ ],
42
+ },
43
+ };
44
+
45
+ describe('script: mutually-exclusive', () => {
46
+ describe('date', () => {
47
+ beforeEach(async () => {
48
+ await setTestPage('/test', renderComponent('date-input', EXAMPLE_MUTUALLY_EXCLUSIVE_DATE_PARAMS));
49
+ });
50
+
51
+ describe('Given the user populated the date input', () => {
52
+ beforeEach(async () => {
53
+ await page.type('#date-mutually-exclusive-day', '14');
54
+ await page.type('#date-mutually-exclusive-month', '12');
55
+ await page.type('#date-mutually-exclusive-year', '2018');
56
+ });
57
+
58
+ describe('when the user clicks the mutually exclusive option', () => {
59
+ beforeEach(async () => {
60
+ await page.click('#date-exclusive-exclusive-option');
61
+ });
62
+
63
+ it('then the mutually exclusive option should be checked', async () => {
64
+ const isChecked = await page.$eval('#date-exclusive-exclusive-option', node => node.checked);
65
+ expect(isChecked).toBe(true);
66
+ });
67
+
68
+ it('then the date input should be cleared', async () => {
69
+ const dayValue = await page.$eval('#date-mutually-exclusive-day', node => node.value);
70
+ expect(dayValue).toBe('');
71
+ const monthValue = await page.$eval('#date-mutually-exclusive-month', node => node.value);
72
+ expect(monthValue).toBe('');
73
+ const yearValue = await page.$eval('#date-mutually-exclusive-year', node => node.value);
74
+ expect(yearValue).toBe('');
75
+ });
76
+
77
+ it('then the aria alert should tell the user that the date input has been cleared', async () => {
78
+ await page.waitForTimeout(SCREEN_READER_TIMEOUT_DELAY);
79
+
80
+ const alertText = await page.$eval('.ons-js-exclusive-alert', node => node.textContent);
81
+ expect(alertText).toBe('Day cleared. Month cleared. Year cleared.');
82
+ });
83
+ });
84
+ });
85
+
86
+ describe('Given the user has checked the mutually exclusive exclusive option', () => {
87
+ beforeEach(async () => {
88
+ await page.click('#date-exclusive-exclusive-option');
89
+ });
90
+
91
+ describe('when the user populates the dateInput', () => {
92
+ beforeEach(async () => {
93
+ await page.type('#date-mutually-exclusive-day', '14');
94
+ await page.type('#date-mutually-exclusive-month', '12');
95
+ await page.type('#date-mutually-exclusive-year', '2018');
96
+ });
97
+
98
+ it('then the mutually exclusive option should be checked', async () => {
99
+ const isChecked = await page.$eval('#date-exclusive-exclusive-option', node => node.checked);
100
+ expect(isChecked).toBe(false);
101
+ });
102
+
103
+ it('then the aria alert should tell the user that the exclusive option has been unchecked', async () => {
104
+ await page.waitForTimeout(SCREEN_READER_TIMEOUT_DELAY);
105
+
106
+ const alertText = await page.$eval('.ons-js-exclusive-alert', node => node.textContent);
107
+ expect(alertText).toBe('I have never had a paid job deselected.');
108
+ });
109
+ });
110
+ });
111
+
112
+ describe('Given the user has not populated the date input or checked the exclusive option', () => {
113
+ describe('when the user populates the date input', () => {
114
+ beforeEach(async () => {
115
+ await page.type('#date-mutually-exclusive-day', '14');
116
+ await page.type('#date-mutually-exclusive-month', '12');
117
+ await page.type('#date-mutually-exclusive-year', '2018');
118
+ });
119
+
120
+ it('then the aria alert shouldnt say anything', async () => {
121
+ await page.waitForTimeout(SCREEN_READER_TIMEOUT_DELAY);
122
+
123
+ const alertText = await page.$eval('.ons-js-exclusive-alert', node => node.textContent);
124
+ expect(alertText).toBe('');
125
+ });
126
+ });
127
+
128
+ describe('when the user clicks the mutually exclusive option', () => {
129
+ beforeEach(async () => {
130
+ await page.click('#date-exclusive-exclusive-option');
131
+ });
132
+
133
+ it('then the aria alert shouldnt say anything', async () => {
134
+ await page.waitForTimeout(SCREEN_READER_TIMEOUT_DELAY);
135
+
136
+ const alertText = await page.$eval('.ons-js-exclusive-alert', node => node.textContent);
137
+ expect(alertText).toBe('');
138
+ });
139
+ });
140
+ });
141
+ });
142
+ });