@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,540 @@
1
+ import puppeteer from 'puppeteer';
2
+
3
+ import { setViewport } from '../../tests/helpers/puppeteer';
4
+ import { renderComponent, renderTemplate, setTestPage } from '../../tests/helpers/rendering';
5
+
6
+ const EXAMPLE_PAGE = `
7
+ <div class="ons-js-adv-filter">
8
+ ${renderComponent('button', {
9
+ type: 'button',
10
+ text: 'Show filters',
11
+ classes: 'ons-adv-filter__trigger ons-js-adv-filter__trigger',
12
+ 'aria-label': 'Toggle filters',
13
+ 'aria-expanded': 'false',
14
+ 'aria-controls': 'filter-panel',
15
+ })}
16
+
17
+ <div class="ons-adv-filter__panel ons-js-adv-filter__panel" id="filter-panel">
18
+ <h2>Filters</h2>
19
+ <form class="ons-js-adv-filter__form" method="POST">
20
+ ${renderComponent('button', {
21
+ type: 'reset',
22
+ text: 'Reset all filters',
23
+ classes: 'ons-adv-filter__reset ons-js-adv-filter__reset',
24
+ })}
25
+
26
+ <div class="ons-adv-filter__item ons-js-adv-filter__item" data-default-text="All audiences" data-multi-select-text="{n} filters selected">
27
+ <fieldset class="ons-fieldset" aria-controls="adv-filter-gallery">
28
+ <legend class="ons-fieldset__legend">Audience</legend>
29
+ <div class="ons-adv-filter__selection">
30
+ <span>Active filters: </span>
31
+ <span class="ons-js-adv-filter__selection">All audiences</span>
32
+ </div>
33
+ ${renderComponent('checkboxes', {
34
+ dontWrap: 'true',
35
+ legend: 'Audience',
36
+ name: 'audience',
37
+ checkboxes: [
38
+ {
39
+ classes: 'ons-checkbox--toggle',
40
+ id: 'community-groups',
41
+ label: {
42
+ text: 'Community groups',
43
+ },
44
+ value: 'community-groups',
45
+ attributes: {
46
+ 'data-filter': 'community-groups',
47
+ },
48
+ },
49
+ {
50
+ classes: 'ons-checkbox--toggle',
51
+ id: 'general-public',
52
+ label: {
53
+ text: 'General public',
54
+ },
55
+ value: 'general-public',
56
+ attributes: {
57
+ 'data-filter': 'general-public',
58
+ },
59
+ },
60
+ ],
61
+ })}
62
+ </fieldset>
63
+ </div>
64
+
65
+ <div class="ons-adv-filter__item ons-js-adv-filter__item" data-default-text="All types" data-multi-select-text="{n} filters selected">
66
+ <fieldset class="ons-fieldset" aria-controls="adv-filter-gallery">
67
+ <legend class="ons-fieldset__legend">Type</legend>
68
+ <div class="ons-adv-filter__selection">
69
+ <span>Active filters: </span>
70
+ <span class="ons-js-adv-filter__selection">All types</span>
71
+ </div>
72
+ ${renderComponent('checkboxes', {
73
+ dontWrap: 'true',
74
+ legend: 'Type',
75
+ name: 'type',
76
+ checkboxes: [
77
+ {
78
+ classes: 'ons-checkbox--toggle',
79
+ id: 'booklet',
80
+ label: {
81
+ text: 'Booklet',
82
+ },
83
+ value: 'booklet',
84
+ attributes: {
85
+ 'data-filter': 'booklet',
86
+ },
87
+ },
88
+ {
89
+ classes: 'ons-checkbox--toggle',
90
+ id: 'logo',
91
+ label: {
92
+ text: 'Logo',
93
+ },
94
+ value: 'logo',
95
+ attributes: {
96
+ 'data-filter': 'logo',
97
+ },
98
+ },
99
+ ],
100
+ })}
101
+ </fieldset>
102
+ </div>
103
+
104
+ <div class="ons-adv-filter__actions">
105
+ ${renderComponent('button', {
106
+ type: 'button',
107
+ html: 'Show (<span class="ons-js-adv-filter__show-results">7</span> results',
108
+ classes: 'ons-js-adv-filter__show',
109
+ })}
110
+ ${renderComponent('button', {
111
+ type: 'button',
112
+ html: 'Close',
113
+ classes: 'ons-js-adv-filter__close',
114
+ })}
115
+ </div>
116
+ </form>
117
+ </div>
118
+
119
+ <div class="ons-adv-filter__results-options">
120
+ <div class="ons-adv-filter__results-count">
121
+ <span class="ons-js-adv-filter__results-count">9</span> results of 150
122
+ </div>
123
+
124
+ <div class="ons-adv-filter__results-sort">
125
+ <label class="ons-label" for="sort">Sort by</label>
126
+ <select class="ons-input ons-input--select" id="sort" name="sort" aria-controls="adv-filter-gallery" data-sort="true">
127
+ <option value="index" data-sort-number="true">Latest</option>
128
+ <option value="index" data-sort-order="desc" data-sort-number="true">Oldest</option>
129
+ </select>
130
+ </div>
131
+ </div>
132
+
133
+ ${renderComponent('document-list', {
134
+ id: 'adv-filter-gallery',
135
+ classes: 'ons-adv-filter__gallery ons-js-adv-filter__gallery',
136
+ attributes: {
137
+ 'data-filter-animation': 'off',
138
+ },
139
+ documents: [
140
+ {
141
+ classes: 'ons-filter__item ons-js-filter__item',
142
+ attributes: {
143
+ 'data-filter': 'general-public booklet',
144
+ 'data-sort-index': '1',
145
+ },
146
+ url: '/example-booklet-1',
147
+ title: 'Example booklet 1',
148
+ description: 'The first example booklet.',
149
+ },
150
+ {
151
+ classes: 'ons-filter__item ons-js-filter__item',
152
+ attributes: {
153
+ 'data-filter': 'general-public booklet logo',
154
+ 'data-sort-index': '2',
155
+ },
156
+ url: '/example-booklet-2',
157
+ title: 'Example booklet 2 with logo',
158
+ description: 'The second example booklet with a logo.',
159
+ },
160
+ {
161
+ classes: 'ons-filter__item ons-js-filter__item',
162
+ attributes: {
163
+ 'data-filter': 'logo',
164
+ 'data-sort-index': '3',
165
+ },
166
+ url: '/example-logo',
167
+ title: 'Example logo',
168
+ description: 'An example logo.',
169
+ },
170
+ ],
171
+ })}
172
+
173
+ <div class="ons-adv-filter__no-results" data-fallback-gallery-id="adv-filter-gallery">
174
+ <h2>No results found</h2>
175
+ <p>Try selecting different filters to get results.</p>
176
+ </div>
177
+ </div>
178
+ `;
179
+
180
+ const RENDERED_EXAMPLE_PAGE = renderTemplate(EXAMPLE_PAGE);
181
+
182
+ describe('script: download-resources', () => {
183
+ describe('no filtering', () => {
184
+ beforeEach(async () => {
185
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
186
+ });
187
+
188
+ it('shows all documents', async () => {
189
+ const hiddenTitles = await getHiddenDocumentTitles(page);
190
+ expect(hiddenTitles).toEqual([]);
191
+ });
192
+
193
+ it('updates filter selection labels ', async () => {
194
+ const filterSelectionLabels = await getFilterSelectionLabels(page);
195
+ expect(filterSelectionLabels).toEqual(['All audiences', 'All types']);
196
+ });
197
+
198
+ it('updates result count text', async () => {
199
+ const resultsCount = await page.$eval('.ons-js-adv-filter__results-count', node => node.textContent.trim());
200
+ expect(resultsCount).toBe('3');
201
+ });
202
+
203
+ it('hides the "No results" content', async () => {
204
+ const isHidden = await page.$eval('.ons-adv-filter__no-results', node => node.classList.contains('ons-u-hidden'));
205
+ expect(isHidden).toBe(true);
206
+ });
207
+ });
208
+
209
+ describe('filtering one parameter where there are no results', () => {
210
+ beforeEach(async () => {
211
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
212
+ await page.click('#community-groups');
213
+ });
214
+
215
+ it('hides all documents', async () => {
216
+ const hiddenTitles = await getHiddenDocumentTitles(page);
217
+ expect(hiddenTitles).toEqual(['Example booklet 1', 'Example booklet 2 with logo', 'Example logo']);
218
+ });
219
+
220
+ it('updates filter selection labels ', async () => {
221
+ const filterSelectionLabels = await getFilterSelectionLabels(page);
222
+ expect(filterSelectionLabels).toEqual(['Community groups', 'All types']);
223
+ });
224
+
225
+ it('updates result count text', async () => {
226
+ const resultsCount = await page.$eval('.ons-js-adv-filter__results-count', node => node.textContent.trim());
227
+ expect(resultsCount).toBe('0');
228
+ });
229
+
230
+ it('shows the "No results" content', async () => {
231
+ const isHidden = await page.$eval('.ons-adv-filter__no-results', node => node.classList.contains('ons-u-hidden'));
232
+ expect(isHidden).toBe(false);
233
+ });
234
+ });
235
+
236
+ describe('filtering one parameter where there are results', () => {
237
+ beforeEach(async () => {
238
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
239
+ await page.click('#general-public');
240
+ });
241
+
242
+ it('hides non-matching documents', async () => {
243
+ const hiddenTitles = await getHiddenDocumentTitles(page);
244
+ expect(hiddenTitles).toEqual(['Example logo']);
245
+ });
246
+
247
+ it('updates filter selection labels ', async () => {
248
+ const filterSelectionLabels = await getFilterSelectionLabels(page);
249
+ expect(filterSelectionLabels).toEqual(['General public', 'All types']);
250
+ });
251
+
252
+ it('updates result count text', async () => {
253
+ const resultsCount = await page.$eval('.ons-js-adv-filter__results-count', node => node.textContent.trim());
254
+ expect(resultsCount).toBe('2');
255
+ });
256
+
257
+ it('hides the "No results" content', async () => {
258
+ const isHidden = await page.$eval('.ons-adv-filter__no-results', node => node.classList.contains('ons-u-hidden'));
259
+ expect(isHidden).toBe(true);
260
+ });
261
+ });
262
+
263
+ describe('filtering two values of the same parameter', () => {
264
+ beforeEach(async () => {
265
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
266
+ await page.click('#booklet');
267
+ await page.click('#logo');
268
+ });
269
+
270
+ it('hides non-matching documents', async () => {
271
+ const hiddenTitles = await getHiddenDocumentTitles(page);
272
+ expect(hiddenTitles).toEqual([]);
273
+ });
274
+
275
+ it('updates filter selection labels ', async () => {
276
+ const filterSelectionLabels = await getFilterSelectionLabels(page);
277
+ expect(filterSelectionLabels).toEqual(['All audiences', '2 filters selected']);
278
+ });
279
+
280
+ it('updates result count text', async () => {
281
+ const resultsCount = await page.$eval('.ons-js-adv-filter__results-count', node => node.textContent.trim());
282
+ expect(resultsCount).toBe('3');
283
+ });
284
+
285
+ it('hides the "No results" content', async () => {
286
+ const isHidden = await page.$eval('.ons-adv-filter__no-results', node => node.classList.contains('ons-u-hidden'));
287
+ expect(isHidden).toBe(true);
288
+ });
289
+ });
290
+
291
+ describe('filtering two parameters where there are no results', () => {
292
+ beforeEach(async () => {
293
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
294
+ await page.click('#community-groups');
295
+ await page.click('#booklet');
296
+ });
297
+
298
+ it('hides all documents', async () => {
299
+ const hiddenTitles = await getHiddenDocumentTitles(page);
300
+ expect(hiddenTitles).toEqual(['Example booklet 1', 'Example booklet 2 with logo', 'Example logo']);
301
+ });
302
+
303
+ it('updates filter selection labels ', async () => {
304
+ const filterSelectionLabels = await getFilterSelectionLabels(page);
305
+ expect(filterSelectionLabels).toEqual(['Community groups', 'Booklet']);
306
+ });
307
+
308
+ it('updates result count text', async () => {
309
+ const resultsCount = await page.$eval('.ons-js-adv-filter__results-count', node => node.textContent.trim());
310
+ expect(resultsCount).toBe('0');
311
+ });
312
+
313
+ it('shows the "No results" content', async () => {
314
+ const isHidden = await page.$eval('.ons-adv-filter__no-results', node => node.classList.contains('ons-u-hidden'));
315
+ expect(isHidden).toBe(false);
316
+ });
317
+ });
318
+
319
+ describe('filtering two parameters where results match both', () => {
320
+ beforeEach(async () => {
321
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
322
+ await page.click('#general-public');
323
+ await page.click('#booklet');
324
+ });
325
+
326
+ it('hides non-matching documents', async () => {
327
+ const hiddenTitles = await getHiddenDocumentTitles(page);
328
+ expect(hiddenTitles).toEqual(['Example logo']);
329
+ });
330
+
331
+ it('updates filter selection labels ', async () => {
332
+ const filterSelectionLabels = await getFilterSelectionLabels(page);
333
+ expect(filterSelectionLabels).toEqual(['General public', 'Booklet']);
334
+ });
335
+
336
+ it('updates result count text', async () => {
337
+ const resultsCount = await page.$eval('.ons-js-adv-filter__results-count', node => node.textContent.trim());
338
+ expect(resultsCount).toBe('2');
339
+ });
340
+
341
+ it('hides the "No results" content', async () => {
342
+ const isHidden = await page.$eval('.ons-adv-filter__no-results', node => node.classList.contains('ons-u-hidden'));
343
+ expect(isHidden).toBe(true);
344
+ });
345
+ });
346
+
347
+ describe('filtering two parameters where results do not match both', () => {
348
+ beforeEach(async () => {
349
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
350
+ await page.click('#general-public');
351
+ await page.click('#logo');
352
+ });
353
+
354
+ it('hides non-matching documents ', async () => {
355
+ const hiddenTitles = await getHiddenDocumentTitles(page);
356
+ expect(hiddenTitles).toEqual(['Example booklet 1', 'Example logo']);
357
+ });
358
+
359
+ it('updates filter selection labels ', async () => {
360
+ const filterSelectionLabels = await getFilterSelectionLabels(page);
361
+ expect(filterSelectionLabels).toEqual(['General public', 'Logo']);
362
+ });
363
+
364
+ it('updates result count text', async () => {
365
+ const resultsCount = await page.$eval('.ons-js-adv-filter__results-count', node => node.textContent.trim());
366
+ expect(resultsCount).toBe('1');
367
+ });
368
+
369
+ it('hides the "No results" content', async () => {
370
+ const isHidden = await page.$eval('.ons-adv-filter__no-results', node => node.classList.contains('ons-u-hidden'));
371
+ expect(isHidden).toBe(true);
372
+ });
373
+ });
374
+
375
+ describe('adding and then removing a filter', () => {
376
+ beforeEach(async () => {
377
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
378
+ await page.click('#general-public');
379
+ await page.click('#logo');
380
+ await page.click('#logo');
381
+ });
382
+
383
+ it('hides non-matching documents ', async () => {
384
+ const hiddenTitles = await getHiddenDocumentTitles(page);
385
+ expect(hiddenTitles).toEqual(['Example logo']);
386
+ });
387
+
388
+ it('updates filter selection labels ', async () => {
389
+ const filterSelectionLabels = await getFilterSelectionLabels(page);
390
+ expect(filterSelectionLabels).toEqual(['General public', 'All types']);
391
+ });
392
+
393
+ it('updates result count text', async () => {
394
+ const resultsCount = await page.$eval('.ons-js-adv-filter__results-count', node => node.textContent.trim());
395
+ expect(resultsCount).toBe('2');
396
+ });
397
+
398
+ it('hides the "No results" content', async () => {
399
+ const isHidden = await page.$eval('.ons-adv-filter__no-results', node => node.classList.contains('ons-u-hidden'));
400
+ expect(isHidden).toBe(true);
401
+ });
402
+ });
403
+
404
+ describe('sorting', () => {
405
+ beforeEach(async () => {
406
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
407
+ });
408
+
409
+ it('sorts ascending by default', async () => {
410
+ const shownTitles = await getShownDocumentTitles(page);
411
+ expect(shownTitles).toEqual(['Example booklet 1', 'Example booklet 2 with logo', 'Example logo']);
412
+ });
413
+
414
+ it('sorts descending when "sort" selection is set to "desc"', async () => {
415
+ await page.type('#sort', 'O');
416
+
417
+ const shownTitles = await getShownDocumentTitles(page);
418
+ expect(shownTitles).toEqual(['Example logo', 'Example booklet 2 with logo', 'Example booklet 1']);
419
+ });
420
+ });
421
+
422
+ describe('"Reset all filters" button', () => {
423
+ beforeEach(async () => {
424
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
425
+ await page.click('#general-public');
426
+ await page.click('#logo');
427
+ await page.click('.ons-js-adv-filter__reset');
428
+ });
429
+
430
+ it('resets state of all filter checkboxes ', async () => {
431
+ const selector = '.ons-js-adv-filter__item .ons-js-checkbox';
432
+ const checkboxStates = await page.$$eval(selector, nodes => nodes.map(node => `${node.id}: ${node.checked}`));
433
+
434
+ expect(checkboxStates).toEqual(['community-groups: false', 'general-public: false', 'booklet: false', 'logo: false']);
435
+ });
436
+
437
+ it('shows all documents ', async () => {
438
+ const hiddenTitles = await getHiddenDocumentTitles(page);
439
+ expect(hiddenTitles).toEqual([]);
440
+ });
441
+
442
+ it('updates filter selection labels ', async () => {
443
+ const filterSelectionLabels = await getFilterSelectionLabels(page);
444
+ expect(filterSelectionLabels).toEqual(['All audiences', 'All types']);
445
+ });
446
+
447
+ it('updates result count text', async () => {
448
+ const resultsCount = await page.$eval('.ons-js-adv-filter__results-count', node => node.textContent.trim());
449
+ expect(resultsCount).toBe('3');
450
+ });
451
+
452
+ it('hides the "No results" content', async () => {
453
+ const isHidden = await page.$eval('.ons-adv-filter__no-results', node => node.classList.contains('ons-u-hidden'));
454
+ expect(isHidden).toBe(true);
455
+ });
456
+ });
457
+
458
+ describe('when the viewport is large', () => {
459
+ beforeEach(async () => {
460
+ await setViewport(page, { width: 1650, height: 1050 });
461
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
462
+ });
463
+
464
+ afterEach(async () => {
465
+ // Clear viewport size and browser emulation after each test.
466
+ await jestPuppeteer.resetPage();
467
+ });
468
+
469
+ it('hides elements that are only needed for mobile', async () => {
470
+ const displayStyle = await page.$eval('.ons-adv-filter__trigger', node => getComputedStyle(node).display);
471
+ expect(displayStyle).toBe('none');
472
+ });
473
+
474
+ it('shows filter elements', async () => {
475
+ const displayStyle = await page.$eval('.ons-adv-filter__panel', node => getComputedStyle(node).display);
476
+ expect(displayStyle).not.toBe('none');
477
+ });
478
+ });
479
+
480
+ describe('when the viewport is small', () => {
481
+ beforeEach(async () => {
482
+ await page.emulate(puppeteer.devices['iPhone X']);
483
+ await setTestPage('/test', RENDERED_EXAMPLE_PAGE);
484
+ });
485
+
486
+ afterEach(async () => {
487
+ // Clear viewport size and browser emulation after each test.
488
+ await jestPuppeteer.resetPage();
489
+ });
490
+
491
+ it('shows elements that are only needed for mobile', async () => {
492
+ const displayStyle = await page.$eval('.ons-adv-filter__trigger', node => getComputedStyle(node).display);
493
+ expect(displayStyle).not.toBe('none');
494
+ });
495
+
496
+ it('hides filter elements', async () => {
497
+ const displayStyle = await page.$eval('.ons-adv-filter__panel', node => getComputedStyle(node).display);
498
+ expect(displayStyle).toBe('none');
499
+ });
500
+
501
+ it('shows filter elements when the "Show filters" button is pressed', async () => {
502
+ await page.click('.ons-js-adv-filter__trigger');
503
+
504
+ const displayStyle = await page.$eval('.ons-adv-filter__panel', node => getComputedStyle(node).display);
505
+ expect(displayStyle).not.toBe('none');
506
+ });
507
+
508
+ it('hides filter elements when the "Show (n results)" button is pressed', async () => {
509
+ await page.click('.ons-js-adv-filter__trigger');
510
+ await page.click('.ons-js-adv-filter__show');
511
+
512
+ const displayStyle = await page.$eval('.ons-adv-filter__panel', node => getComputedStyle(node).display);
513
+ expect(displayStyle).toBe('none');
514
+ });
515
+
516
+ it('hides filter elements when the "Close" button is pressed', async () => {
517
+ await page.click('.ons-js-adv-filter__trigger');
518
+ await page.click('.ons-js-adv-filter__close');
519
+
520
+ const displayStyle = await page.$eval('.ons-adv-filter__panel', node => getComputedStyle(node).display);
521
+ expect(displayStyle).toBe('none');
522
+ });
523
+ });
524
+ });
525
+
526
+ async function getTextContent(page, selector) {
527
+ return await page.$$eval(selector, nodes => nodes.map(node => node.textContent.trim()));
528
+ }
529
+
530
+ async function getFilterSelectionLabels(page) {
531
+ return await getTextContent(page, '.ons-js-adv-filter__selection');
532
+ }
533
+
534
+ async function getHiddenDocumentTitles(page) {
535
+ return await getTextContent(page, '.ons-js-filter__item.ons-u-hidden .ons-document-list__item-title');
536
+ }
537
+
538
+ async function getShownDocumentTitles(page) {
539
+ return await getTextContent(page, '.ons-js-filter__item:not(.ons-u-hidden) .ons-document-list__item-title');
540
+ }
@@ -17,7 +17,6 @@
17
17
 
18
18
  {% set fields %}
19
19
  {% if params.field1 is defined and params.field1 %}
20
-
21
20
  {{ onsInput({
22
21
  "id": params.field1.id,
23
22
  "classes": (" ons-input--error" if (params.error is defined and params.error and params.field1.error is defined and params.field1.error) or (numberOfFields > 1 and params.error is defined and params.error and not params.field1.error and not params.field2.error) else "") + (" ons-js-exclusive-group-item" if params.mutuallyExclusive else ""),
@@ -26,8 +25,9 @@
26
25
  "name": params.field1.name,
27
26
  "value": params.field1.value,
28
27
  "suffix": {
29
- "title": params.field1.suffix,
30
- "text": params.field1.suffix
28
+ "text": params.field1.suffix.text,
29
+ "title": params.field1.suffix.title | default(params.field1.suffix.text),
30
+ "id": params.field1.suffix.id
31
31
  },
32
32
  "label": {
33
33
  "text": params.legendOrLabel if numberOfFields < 2,
@@ -48,8 +48,9 @@
48
48
  "name": params.field2.name,
49
49
  "value": params.field2.value,
50
50
  "suffix": {
51
- "title": params.field2.suffix,
52
- "text": params.field2.suffix
51
+ "text": params.field2.suffix.text,
52
+ "title": params.field2.suffix.title | default(params.field2.suffix.text),
53
+ "id": params.field2.suffix.id
53
54
  },
54
55
  "label": {
55
56
  "text": params.legendOrLabel if numberOfFields < 2,
@@ -65,7 +66,7 @@
65
66
  {% if params.mutuallyExclusive is defined and params.mutuallyExclusive %}
66
67
  {% set mutuallyExclusive = params.mutuallyExclusive | setAttributes({
67
68
  "id": params.id,
68
- "legend": params.legend,
69
+ "legend": params.legendOrLabel,
69
70
  "legendClasses": params.legendClasses,
70
71
  "description": params.description,
71
72
  "error": params.error,