@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
package/README.md CHANGED
@@ -106,38 +106,60 @@ Mixed markdown files are easier to maintain when each section that is fenced wit
106
106
 
107
107
  ## Testing
108
108
 
109
- To test locally ensure you've followed all the steps above to install dependencies. You can have three options:
109
+ This project uses [jest](https://jestjs.io/docs/cli) and supports its command line options.
110
110
 
111
- ### Run tests locally in watch mode
111
+ ```bash
112
+ yarn test [jest-args]
113
+ ```
112
114
 
113
- This will watch your test files and JavaScript for changes and rerun the test suite each time a change is detected.
115
+ ### Run macro, unit and in-browser interaction tests
114
116
 
115
- _Note_: This will only run tests on the ES6 bundle.
117
+ Macros and units are tested in the Node execution environment whereas interaction tests are ran in the web browser using [puppeteer](https://developer.chrome.com/docs/puppeteer/).
116
118
 
117
119
  ```bash
118
- yarn test:local
120
+ yarn test
119
121
  ```
120
122
 
121
- ### Run ES6 and ES5 bundle tests
123
+ ### Run specific tests
124
+
125
+ Tests can be filtered using the [`testNamePattern`](https://jestjs.io/docs/cli#--testnamepatternregex) jest argument.
122
126
 
123
- Running this will run the test suite twice, once against the ES6 bundle and again against the ES5 bundle. However, as local tests only run on evergreen browsers it will be unlikely that you see the ES5 testing fail if the ES6 testing passes.
127
+ To run all macro tests:
124
128
 
125
129
  ```bash
126
- yarn test
130
+ yarn test --testNamePattern="macro:"
131
+ ```
132
+
133
+ To run tests associated with a specific macro:
134
+
135
+ ```bash
136
+ yarn test --testNamePattern="macro: button"
127
137
  ```
128
138
 
129
- ### Run tests in BrowserStack
139
+ To run all axe tests:
130
140
 
131
- All unit tests are automatically cross browser tested in [BrowserStack](https://www.browserstack.com) by [TravisCI](https://travis-ci.org/ONSdigital/design-system) when a pull request is created or if a change is pushed to an existing pull request.
141
+ ```bash
142
+ yarn test --testNamePattern="axe"
143
+ ```
132
144
 
133
- You can also run cross browser testing in BrowserStack manually against your local branch by running this command:
145
+ ### Run tests locally in watch mode
134
146
 
135
- _Note_: You will need to set your `BROWSER_STACK_USERNAME` and `BROWSER_STACK_ACCESS_KEY` environment variables to allow authentication with BrowserStack. Username and access keys can be found under _Automate_ on the [BrowserStack settings page](https://www.browserstack.com/accounts/settings).
147
+ This will watch for changed files based on git uncommitted files.
136
148
 
137
149
  ```bash
138
- yarn test:browserstack
150
+ yarn test --watch
139
151
  ```
140
152
 
153
+ _Note_: This command is of limited use since JavaScript and SCSS files will only be processed and bundled once each time the above command is ran. This command is only useful when working on JavaScript units that can be tested without bundling.
154
+
155
+ ### Testing tips
156
+
157
+ It is sometimes useful to adjust the following settings when writing tests or diagnosing issues:
158
+
159
+ - `headless` in 'jest-puppeteer.config.js' - when set to `false` will show web browser whilst running tests. Many browser windows open since jest runs tests in parallel so it is useful to also adjust the `test` script inside 'package.json' such that it targets a specific test file. `await page.waitForTimeout(100000)` can be temporarily added to a test to allow yourself time to inspect the browser that appears.
160
+
161
+ - `testTimeout` in 'jest.config.js' - set to a high value such as `1000000` to prevent tests from timing out when doing the above.
162
+
141
163
  ## Run visual regression tests
142
164
 
143
165
  To run visual regression (VR) tests on pull requests using our VR testing tool [percy.io](https://percy.io) you must include `[test-visual]` in your commit message e.g. `git commit -m "Update button border width [test-visual]"`. This prevents unnecessary builds and saves the limited quota we have available.
@@ -28,7 +28,7 @@
28
28
 
29
29
  {% if params.error is not defined %}
30
30
  {% call onsPanel({
31
- "classes": "ons-u-mb-s"
31
+ "classes": "ons-u-mb-s" + (' ' + params.classes if params.classes is defined and params.classes)
32
32
  })
33
33
  %}
34
34
  {{ content | safe }}
@@ -0,0 +1,162 @@
1
+ /** @jest-environment jsdom */
2
+
3
+ import * as cheerio from 'cheerio';
4
+
5
+ import axe from '../../tests/helpers/axe';
6
+ import { renderComponent } from '../../tests/helpers/rendering';
7
+
8
+ describe('macro: access-code', () => {
9
+ it('passes jest-axe checks', async () => {
10
+ const $ = cheerio.load(
11
+ renderComponent('access-code', {
12
+ id: 'example-access-code',
13
+ label: {
14
+ text: 'Enter your 16-character access code',
15
+ description: 'Keep this code safe. You will need to enter it every time you access your study',
16
+ },
17
+ }),
18
+ );
19
+
20
+ const results = await axe($.html());
21
+ expect(results).toHaveNoViolations();
22
+ });
23
+
24
+ it('has the provided `id` attribute', () => {
25
+ const $ = cheerio.load(
26
+ renderComponent('access-code', {
27
+ id: 'example-id',
28
+ }),
29
+ );
30
+
31
+ expect($('#example-id').length).toBe(1);
32
+ });
33
+
34
+ it('has the provided `name` attribute', () => {
35
+ const $ = cheerio.load(
36
+ renderComponent('access-code', {
37
+ name: 'special-name',
38
+ }),
39
+ );
40
+
41
+ expect($('input').attr('name')).toBe('special-name');
42
+ });
43
+
44
+ it('has a default `type` of "text"', () => {
45
+ const $ = cheerio.load(renderComponent('access-code'));
46
+
47
+ expect($('input').attr('type')).toBe('text');
48
+ });
49
+
50
+ it('has the provided `type` attribute', () => {
51
+ const $ = cheerio.load(
52
+ renderComponent('access-code', {
53
+ type: 'number',
54
+ }),
55
+ );
56
+
57
+ expect($('input').attr('inputmode')).toBe('numeric');
58
+ });
59
+
60
+ it('has additionally provided style classes', () => {
61
+ const $ = cheerio.load(
62
+ renderComponent('access-code', {
63
+ classes: 'extra-class another-extra-class',
64
+ }),
65
+ );
66
+
67
+ expect($('.ons-panel--info').hasClass('extra-class')).toBe(true);
68
+ expect($('.ons-panel--info').hasClass('another-extra-class')).toBe(true);
69
+ });
70
+
71
+ it('has provided label text and description', () => {
72
+ const $ = cheerio.load(
73
+ renderComponent('access-code', {
74
+ label: {
75
+ text: 'Enter your 16-character access code',
76
+ description: 'Keep this code safe. You will need to enter it every time you access your study',
77
+ },
78
+ }),
79
+ );
80
+
81
+ expect($('.ons-label--with-description').text()).toBe('Enter your 16-character access code');
82
+ expect($('.ons-input--with-description').text()).toBe(
83
+ 'Keep this code safe. You will need to enter it every time you access your study',
84
+ );
85
+ });
86
+
87
+ it('has provided maximum length attribute including spaces required for groupSize', () => {
88
+ const $ = cheerio.load(
89
+ renderComponent('access-code', {
90
+ maxlength: 6,
91
+ groupSize: 3,
92
+ }),
93
+ );
94
+
95
+ expect($('input').attr('maxlength')).toBe('7');
96
+ });
97
+
98
+ it('has provided group size attribute', () => {
99
+ const $ = cheerio.load(
100
+ renderComponent('access-code', {
101
+ groupSize: 2,
102
+ }),
103
+ );
104
+
105
+ expect($('input').attr('data-group-size')).toBe('2');
106
+ });
107
+
108
+ it('has autocomplete disabled on its text input', () => {
109
+ const $ = cheerio.load(renderComponent('access-code'));
110
+
111
+ expect($('input').attr('autocomplete')).toBe('off');
112
+ });
113
+
114
+ it('has automatic capitalization on its text input', () => {
115
+ const $ = cheerio.load(renderComponent('access-code'));
116
+
117
+ expect($('input').attr('autocapitalize')).toBe('characters');
118
+ });
119
+
120
+ it('has provided security message text', () => {
121
+ const $ = cheerio.load(
122
+ renderComponent('access-code', {
123
+ securityMessage: 'Example security message.',
124
+ }),
125
+ );
126
+
127
+ expect(
128
+ $('.ons-panel__body')
129
+ .text()
130
+ .trim(),
131
+ ).toBe('Example security message.');
132
+ });
133
+
134
+ it('has provided `postTextBoxLinkText` and `postTextBoxLinkUrl`', () => {
135
+ const $ = cheerio.load(
136
+ renderComponent('access-code', {
137
+ postTextboxLinkText: 'Example link text',
138
+ postTextboxLinkUrl: '#3',
139
+ }),
140
+ );
141
+
142
+ expect(
143
+ $('a[href="#3"]')
144
+ .text()
145
+ .trim(),
146
+ ).toBe('Example link text');
147
+ });
148
+
149
+ it('has provided `error` output', () => {
150
+ const $ = cheerio.load(
151
+ renderComponent('access-code', {
152
+ error: {
153
+ id: 'uac-error',
154
+ text: 'Enter an access code',
155
+ },
156
+ }),
157
+ );
158
+
159
+ expect($('#uac-error').length).toBe(1);
160
+ expect($('.ons-panel__error > strong').text()).toBe('Enter an access code');
161
+ });
162
+ });
@@ -0,0 +1,26 @@
1
+ import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
2
+
3
+ describe('script: access-code', () => {
4
+ describe('Data grouping', () => {
5
+ it('correctly formats user input with spaces', async () => {
6
+ await setTestPage(
7
+ '/test',
8
+ renderComponent('access-code', {
9
+ id: 'test-access-code',
10
+ groupSize: 5,
11
+ }),
12
+ );
13
+
14
+ await page.focus('#test-access-code');
15
+ await page.keyboard.type('1234');
16
+
17
+ const valueSample1 = await page.$eval('#test-access-code', element => element.value);
18
+ expect(valueSample1).toBe('1234');
19
+
20
+ await page.keyboard.type('5678');
21
+
22
+ const valueSample2 = await page.$eval('#test-access-code', element => element.value);
23
+ expect(valueSample2).toBe('12345 678');
24
+ });
25
+ });
26
+ });
@@ -0,0 +1,224 @@
1
+ /** @jest-environment jsdom */
2
+
3
+ import * as cheerio from 'cheerio';
4
+
5
+ import axe from '../../tests/helpers/axe';
6
+ import { renderComponent } from '../../tests/helpers/rendering';
7
+
8
+ const EXAMPLE_ACCORDION_WITH_TWO_ITEMS = {
9
+ id: 'accordion-identifier',
10
+ itemsList: [
11
+ {
12
+ title: 'Title for item 1',
13
+ content: 'Content for item 1',
14
+ },
15
+ {
16
+ title: 'Title for item 2',
17
+ content: 'Content for item 2',
18
+ },
19
+ ],
20
+ };
21
+
22
+ const EXAMPLE_ACCORDION = {
23
+ ...EXAMPLE_ACCORDION_WITH_TWO_ITEMS,
24
+ allButton: {
25
+ open: 'Open label',
26
+ close: 'Close label',
27
+ },
28
+ };
29
+
30
+ describe('macro: accordion', () => {
31
+ it('passes jest-axe checks', async () => {
32
+ const $ = cheerio.load(renderComponent('accordion', EXAMPLE_ACCORDION));
33
+
34
+ const results = await axe($.html());
35
+ expect(results).toHaveNoViolations();
36
+ });
37
+
38
+ it('has the provided `id` attribute', () => {
39
+ const $ = cheerio.load(renderComponent('accordion', EXAMPLE_ACCORDION_WITH_TWO_ITEMS));
40
+
41
+ expect($('.ons-accordion').attr('id')).toBe('accordion-identifier');
42
+ });
43
+
44
+ it('has additionally provided style classes', () => {
45
+ const $ = cheerio.load(
46
+ renderComponent('accordion', {
47
+ ...EXAMPLE_ACCORDION_WITH_TWO_ITEMS,
48
+ classes: 'extra-class another-extra-class',
49
+ }),
50
+ );
51
+
52
+ expect($('.ons-accordion').hasClass('extra-class')).toBe(true);
53
+ expect($('.ons-accordion').hasClass('another-extra-class')).toBe(true);
54
+ });
55
+
56
+ describe('item', () => {
57
+ it('has provided variant style classes', () => {
58
+ const $ = cheerio.load(
59
+ renderComponent('accordion', {
60
+ ...EXAMPLE_ACCORDION_WITH_TWO_ITEMS,
61
+ variants: ['variant-a', 'variant-b'],
62
+ }),
63
+ );
64
+
65
+ expect($('.ons-collapsible--variant-a').length).toBe(2);
66
+ expect($('.ons-collapsible--variant-b').length).toBe(2);
67
+ });
68
+
69
+ it('has provided title text', () => {
70
+ const $ = cheerio.load(renderComponent('accordion', EXAMPLE_ACCORDION_WITH_TWO_ITEMS));
71
+
72
+ const titleText = $('.ons-collapsible__title')
73
+ .first()
74
+ .text()
75
+ .trim();
76
+ expect(titleText).toBe('Title for item 1');
77
+ });
78
+
79
+ it('has title with provided tag override', () => {
80
+ const $ = cheerio.load(
81
+ renderComponent('accordion', {
82
+ itemsList: [
83
+ {
84
+ title: 'Title for item 1',
85
+ titleTag: 'h5',
86
+ content: 'Content for item 1',
87
+ },
88
+ ],
89
+ }),
90
+ );
91
+
92
+ const titleTag = $('.ons-collapsible__title')[0].tagName;
93
+ expect(titleTag).toBe('h5');
94
+ });
95
+
96
+ it('has provided content text', () => {
97
+ const $ = cheerio.load(renderComponent('accordion', EXAMPLE_ACCORDION_WITH_TWO_ITEMS));
98
+
99
+ const titleText = $('.ons-collapsible__content')
100
+ .first()
101
+ .text()
102
+ .trim();
103
+ expect(titleText).toBe('Content for item 1');
104
+ });
105
+
106
+ it('outputs a button with the expected class', () => {
107
+ const $ = cheerio.load(
108
+ renderComponent('accordion', {
109
+ itemsList: [
110
+ {
111
+ title: 'Title for item 1',
112
+ button: {
113
+ open: 'Open label',
114
+ close: 'Close label',
115
+ },
116
+ },
117
+ {
118
+ title: 'Title for item 2',
119
+ button: {
120
+ open: 'Open label',
121
+ close: 'Close label',
122
+ },
123
+ },
124
+ ],
125
+ }),
126
+ );
127
+
128
+ expect($('button.ons-js-collapsible-button').length).toBe(2);
129
+ });
130
+
131
+ it('has additionally provided `attributes`', () => {
132
+ const $ = cheerio.load(
133
+ renderComponent('accordion', {
134
+ itemsList: [
135
+ {
136
+ title: 'Title for item 1',
137
+ attributes: {
138
+ a: 123,
139
+ b: 456,
140
+ },
141
+ },
142
+ ],
143
+ }),
144
+ );
145
+
146
+ expect($('.ons-collapsible').attr('a')).toBe('123');
147
+ expect($('.ons-collapsible').attr('b')).toBe('456');
148
+ });
149
+
150
+ it('has additionally provided `headingAttributes`', () => {
151
+ const $ = cheerio.load(
152
+ renderComponent('accordion', {
153
+ itemsList: [
154
+ {
155
+ title: 'Title for item 1',
156
+ headingAttributes: {
157
+ a: 123,
158
+ b: 456,
159
+ },
160
+ },
161
+ ],
162
+ }),
163
+ );
164
+
165
+ expect($('.ons-collapsible__heading').attr('a')).toBe('123');
166
+ expect($('.ons-collapsible__heading').attr('b')).toBe('456');
167
+ });
168
+
169
+ it('has additionally provided `contentAttributes`', () => {
170
+ const $ = cheerio.load(
171
+ renderComponent('accordion', {
172
+ itemsList: [
173
+ {
174
+ title: 'Title for item 1',
175
+ content: 'Content for item 1',
176
+ contentAttributes: {
177
+ a: 123,
178
+ b: 456,
179
+ },
180
+ },
181
+ ],
182
+ }),
183
+ );
184
+
185
+ expect($('.ons-collapsible__content').attr('a')).toBe('123');
186
+ expect($('.ons-collapsible__content').attr('b')).toBe('456');
187
+ });
188
+ });
189
+
190
+ describe('toggle all button', () => {
191
+ it('outputs a button with the expected class', () => {
192
+ const $ = cheerio.load(
193
+ renderComponent('accordion', {
194
+ ...EXAMPLE_ACCORDION_WITH_TWO_ITEMS,
195
+ allButton: {
196
+ open: 'Open label',
197
+ close: 'Close label',
198
+ },
199
+ }),
200
+ );
201
+
202
+ expect($('button.ons-js-collapsible-all').length).toBe(1);
203
+ });
204
+
205
+ it('has additionally provided `attributes`', () => {
206
+ const $ = cheerio.load(
207
+ renderComponent('accordion', {
208
+ ...EXAMPLE_ACCORDION_WITH_TWO_ITEMS,
209
+ allButton: {
210
+ open: 'Open label',
211
+ close: 'Close label',
212
+ attributes: {
213
+ a: 123,
214
+ b: 456,
215
+ },
216
+ },
217
+ }),
218
+ );
219
+
220
+ expect($('button.ons-js-collapsible-all').attr('a')).toBe('123');
221
+ expect($('button.ons-js-collapsible-all').attr('b')).toBe('456');
222
+ });
223
+ });
224
+ });
@@ -0,0 +1,134 @@
1
+ import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
2
+
3
+ const EXAMPLE_ACCORDION_WITH_THREE_ITEMS = {
4
+ id: 'example-accordion',
5
+ itemsList: [
6
+ {
7
+ title: 'Title for item 1',
8
+ content: 'Content for item 1',
9
+ button: {
10
+ open: 'Open item',
11
+ close: 'Close item',
12
+ },
13
+ },
14
+ {
15
+ title: 'Title for item 2',
16
+ content: 'Content for item 2',
17
+ button: {
18
+ open: 'Open item',
19
+ close: 'Close item',
20
+ },
21
+ },
22
+ {
23
+ title: 'Title for item 3',
24
+ content: 'Content for item 3',
25
+ button: {
26
+ open: 'Open item',
27
+ close: 'Close item',
28
+ },
29
+ },
30
+ ],
31
+ };
32
+
33
+ const EXAMPLE_ACCORDION_WITH_ALL_BUTTON = {
34
+ ...EXAMPLE_ACCORDION_WITH_THREE_ITEMS,
35
+ allButton: {
36
+ open: 'Open all',
37
+ close: 'Close all',
38
+ attributes: {
39
+ 'data-test-trigger': true,
40
+ },
41
+ },
42
+ };
43
+
44
+ describe('script: accordion', () => {
45
+ it('begins with all items closed', async () => {
46
+ await setTestPage('/test', renderComponent('accordion', EXAMPLE_ACCORDION_WITH_THREE_ITEMS));
47
+
48
+ const openItemCount = await page.$$eval('.ons-collapsible--open', elements => elements.length);
49
+ expect(openItemCount).toBe(0);
50
+ });
51
+
52
+ it('begins with all items open when specified', async () => {
53
+ await setTestPage(
54
+ '/test',
55
+ renderComponent('accordion', {
56
+ ...EXAMPLE_ACCORDION_WITH_THREE_ITEMS,
57
+ open: true,
58
+ }),
59
+ );
60
+
61
+ const openItemCount = await page.$$eval('.ons-collapsible--open', elements => elements.length);
62
+ expect(openItemCount).toBe(3);
63
+ });
64
+
65
+ it('opens all items when accordion "Open all" button is clicked', async () => {
66
+ await setTestPage('/test', renderComponent('accordion', EXAMPLE_ACCORDION_WITH_ALL_BUTTON));
67
+
68
+ await page.click('button[data-test-trigger]');
69
+
70
+ const openItemCount = await page.$$eval('.ons-collapsible--open', elements => elements.length);
71
+ expect(openItemCount).toBe(3);
72
+ });
73
+
74
+ it('closes all items when accordion "Open all" button is clicked twice', async () => {
75
+ await setTestPage('/test', renderComponent('accordion', EXAMPLE_ACCORDION_WITH_ALL_BUTTON));
76
+
77
+ await page.click('button[data-test-trigger]');
78
+ await page.click('button[data-test-trigger]');
79
+
80
+ const openItemCount = await page.$$eval('.ons-collapsible--open', elements => elements.length);
81
+ expect(openItemCount).toBe(0);
82
+ });
83
+
84
+ it('starts with the toggle all button labelled as "Open all"', async () => {
85
+ await setTestPage('/test', renderComponent('accordion', EXAMPLE_ACCORDION_WITH_ALL_BUTTON));
86
+
87
+ const buttonText = await page.$eval('button[data-test-trigger]', element => element.innerText);
88
+ expect(buttonText.trim()).toBe('Open all');
89
+ });
90
+
91
+ it('sets toggle all button label to "Hide all" when clicked', async () => {
92
+ await setTestPage('/test', renderComponent('accordion', EXAMPLE_ACCORDION_WITH_ALL_BUTTON));
93
+
94
+ await page.click('button[data-test-trigger]');
95
+
96
+ const buttonText = await page.$eval('button[data-test-trigger]', element => element.innerText);
97
+ expect(buttonText.trim()).toBe('Close all');
98
+ });
99
+
100
+ it('sets toggle all button label to "Hide all" when all items are shown', async () => {
101
+ await setTestPage('/test', renderComponent('accordion', EXAMPLE_ACCORDION_WITH_ALL_BUTTON));
102
+
103
+ await page.click('#example-accordion-1 .ons-collapsible__btn');
104
+ await page.click('#example-accordion-2 .ons-collapsible__btn');
105
+ await page.click('#example-accordion-3 .ons-collapsible__btn');
106
+
107
+ const buttonText = await page.$eval('button[data-test-trigger]', element => element.innerText);
108
+ expect(buttonText.trim()).toBe('Close all');
109
+ });
110
+
111
+ it('opens an item when its open button is clicked', async () => {
112
+ await setTestPage('/test', renderComponent('accordion', EXAMPLE_ACCORDION_WITH_THREE_ITEMS));
113
+
114
+ await page.click('#example-accordion-2 .ons-collapsible__btn');
115
+ await page.click('#example-accordion-3 .ons-collapsible__btn');
116
+
117
+ const openItemCount = await page.$$eval('.ons-collapsible--open', elements => elements.length);
118
+ expect(openItemCount).toBe(2);
119
+ });
120
+
121
+ it('closes an item when its open button is clicked twice', async () => {
122
+ await setTestPage('/test', renderComponent('accordion', EXAMPLE_ACCORDION_WITH_THREE_ITEMS));
123
+
124
+ await page.click('#example-accordion-2 .ons-collapsible__btn');
125
+ await page.click('#example-accordion-3 .ons-collapsible__btn');
126
+ await page.click('#example-accordion-3 .ons-collapsible__btn');
127
+
128
+ const isItem2Open = await page.$eval('#example-accordion-2', element => element.classList.contains('ons-collapsible--open'));
129
+ expect(isItem2Open).toBe(true);
130
+
131
+ const isItem3Open = await page.$eval('#example-accordion-3', element => element.classList.contains('ons-collapsible--open'));
132
+ expect(isItem3Open).toBe(false);
133
+ });
134
+ });
@@ -11,6 +11,7 @@
11
11
  {{
12
12
  onsInput({
13
13
  "id": params.id + "-organisation",
14
+ "value": params.organisation.value,
14
15
  "label": {
15
16
  "text": params.organisation.label
16
17
  },
@@ -132,7 +133,6 @@
132
133
  "ariaYouHaveSelected": params.ariaYouHaveSelected,
133
134
  "ariaMinChars": params.ariaMinChars,
134
135
  "minChars": params.minChars,
135
- "ariaResultsLabel": params.ariaResultsLabel,
136
136
  "ariaOneResult": params.ariaOneResult,
137
137
  "ariaNResults": params.ariaNResults,
138
138
  "ariaLimitedResults": params.ariaLimitedResults,