@ons/design-system 53.0.4 → 54.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 (42) hide show
  1. package/components/accordion/_macro.njk +2 -3
  2. package/components/accordion/_macro.spec.js +3 -40
  3. package/components/accordion/accordion.dom.js +19 -0
  4. package/components/{collapsible/collapsible.group.js → accordion/accordion.js} +12 -5
  5. package/components/accordion/accordion.spec.js +56 -51
  6. package/components/autosuggest/_autosuggest.scss +1 -1
  7. package/components/browser-banner/_browser-banner.scss +39 -0
  8. package/components/browser-banner/_macro.njk +17 -0
  9. package/components/browser-banner/_macro.spec.js +83 -0
  10. package/components/checkboxes/_macro.njk +1 -1
  11. package/components/collapsible/_collapsible.scss +58 -85
  12. package/components/collapsible/_macro.njk +6 -39
  13. package/components/collapsible/_macro.spec.js +0 -53
  14. package/components/collapsible/collapsible.dom.js +3 -12
  15. package/components/collapsible/collapsible.js +3 -45
  16. package/components/collapsible/collapsible.spec.js +6 -139
  17. package/components/cookies-banner/_cookies-banner.scss +15 -7
  18. package/components/cookies-banner/_macro.njk +66 -22
  19. package/components/cookies-banner/_macro.spec.js +172 -114
  20. package/components/cookies-banner/cookies-banner.js +35 -13
  21. package/components/cookies-banner/cookies-banner.spec.js +58 -54
  22. package/components/duration/_macro.njk +1 -1
  23. package/components/duration/_macro.spec.js +1 -1
  24. package/components/fieldset/_fieldset.scss +3 -6
  25. package/components/header/_macro.njk +7 -0
  26. package/components/input/_macro.njk +20 -15
  27. package/components/input/_macro.spec.js +56 -0
  28. package/components/label/_label.scss +1 -1
  29. package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +2 -0
  30. package/components/mutually-exclusive/mutually-exclusive.number.spec.js +1 -0
  31. package/css/census.css +1 -1
  32. package/css/error.css +1 -1
  33. package/css/ids.css +1 -1
  34. package/css/main.css +1 -1
  35. package/js/main.js +1 -0
  36. package/layout/_template.njk +1 -0
  37. package/package.json +1 -1
  38. package/scripts/main.es5.js +1 -1
  39. package/scripts/main.js +2 -2
  40. package/scss/main.scss +1 -0
  41. package/scss/objects/_page.scss +1 -1
  42. package/scss/vars/_colors.scss +1 -0
@@ -1,40 +1,84 @@
1
1
  {% macro onsCookiesBanner(params) %}
2
- <div class="ons-cookies-banner" role="region" aria-label="{{ params.ariaLabel | default('Cookies banner')}}">
2
+ {% if params.lang == 'cy' %}
3
+ {% set ariaLabel = 'Cwcis' %}
4
+ {% set serviceName = 'ons.gov.uk' %}
5
+ {% set statementTitle = 'Cwcis ar' %}
6
+ {% set settingsLinkText = 'Gweld cwcis' %}
7
+ {% set settingsLinkURL = '/cwics' %}
8
+ {% set statementText = '<p>Ffeiliau bach a gaiff eu storio ar eich dyfais pan fyddwch yn mynd ar wefan yw cwcis. Rydym ni’n defnyddio rhai cwcis hanfodol i wneud i’r wefan hon weithio.</p><p>Hoffem osod <a href="' + settingsLinkURL + '">cwcis ychwanegol</a> er mwyn cofio eich gosodiadau a deall sut rydych chi’n defnyddio’r wefan. Mae hyn yn ein helpu ni i wella ein gwasanaethau.</p>' %}
9
+ {% set acceptButtonText = 'Derbyn cwcis ychwanegol' %}
10
+ {% set rejectButtonText = 'Gwrthod cwcis ychwanegol' %}
11
+ {% set acceptedText = 'Rydych chi wedi derbyn yr holl gwcis ychwanegol.' %}
12
+ {% set rejectedText = 'Rydych chi wedi gwrthod yr holl gwcis ychwanegol. ' %}
13
+ {% set preferencesText = 'Gallwch chi <a href="' + settingsLinkURL + '">newid eich dewisiadau o ran cwcis</a> ar unrhyw adeg.' %}
14
+ {% set confirmationButtonText = 'Cuddio' %}
15
+ {% set confirmationButtonTextAria = 'neges hon' %}
16
+ {% else %}
17
+ {% set ariaLabel = 'Cookies banner' %}
18
+ {% set serviceName = 'ons.gov.uk' %}
19
+ {% set statementTitle = 'Cookies on' %}
20
+ {% set settingsLinkText = 'View cookies' %}
21
+ {% set settingsLinkURL = '/cookies' %}
22
+ {% set statementText = '<p>Cookies are small files stored on your device when you visit a website. We use some essential cookies to make this website work.</p><p>We would like to set <a href="' + settingsLinkURL + '">additional cookies</a> to remember your settings and understand how you use the site. This helps us to improve our services. </p>' %}
23
+ {% set acceptButtonText = 'Accept additional cookies' %}
24
+ {% set rejectButtonText = 'Reject additional cookies' %}
25
+ {% set acceptedText = 'You have accepted all additional cookies.' %}
26
+ {% set rejectedText = 'You have rejected all additional cookies.' %}
27
+ {% set preferencesText = 'You can <a href="' + settingsLinkURL + '">change your cookie preferences</a> at any time.' %}
28
+ {% set confirmationButtonText = 'Hide' %}
29
+ {% set confirmationButtonTextAria = 'this message' %}
30
+ {% endif %}
31
+
32
+ <div class="ons-cookies-banner" role="region" aria-label="{{ params.ariaLabel | default(ariaLabel)}}">
3
33
  <div class="ons-container ons-cookies-banner__primary">
4
34
  <div class="ons-grid">
5
35
  <div class="ons-grid__col ons-col-8@m">
6
- <h2 class="ons-cookies-banner__title ons-u-mb-xs">{{ params.statementTitle }}</h2>
7
- <p class="ons-cookies-banner__desc">{{ params.statementText | safe }}</p>
8
- {% from "components/button/_macro.njk" import onsButton %}
9
- {{
10
- onsButton({
11
- "type": 'button',
12
- "text": params.primaryButtonText | default('Accept all cookies'),
13
- "classes": 'ons-btn--small ons-js-accept-cookies ons-u-mb-xs@xxs@s ons-cookies-banner__btn'
14
- })
15
- }}
16
- {{
17
- onsButton({
18
- "type": 'button',
19
- "url": params.secondaryButtonUrl,
20
- "text": params.secondaryButtonText | default('Set cookie preferences'),
21
- "classes": 'ons-btn--small ons-u-ml-no@xxs@s ons-cookies-banner__btn'
22
- })
23
- }}
36
+ <h2 class="ons-cookies-banner__title ons-u-mb-xs">{{ params.statementTitle | default(statementTitle) }} {{ params.serviceName | default(serviceName) }}</h2>
37
+ <div class="ons-cookies-banner__statement">{{ params.statementText | default(statementText) | safe }}</div>
38
+ </div>
39
+ </div>
40
+ <div class="ons-grid ons-grid--flex ons-u-mt-s">
41
+ <div class="ons-grid__col">
42
+ {% from "components/button/_macro.njk" import onsButton %}
43
+ {{
44
+ onsButton({
45
+ "type": 'button',
46
+ "attributes": {
47
+ "data-button": 'accept'
48
+ },
49
+ "text": params.acceptButtonText | default(acceptButtonText),
50
+ "classes": 'ons-btn--small ons-js-accept-cookies ons-cookies-banner__btn'
51
+ })
52
+ }}
53
+ </div>
54
+ <div class="ons-grid__col">
55
+ {{
56
+ onsButton({
57
+ "type": 'button',
58
+ "attributes": {
59
+ "data-button": 'reject'
60
+ },
61
+ "text": params.rejectButtonText | default(rejectButtonText),
62
+ "classes": 'ons-btn--small ons-js-reject-cookies ons-cookies-banner__btn'
63
+ })
64
+ }}
65
+ </div>
66
+ <div class="ons-grid__col">
67
+ <a class="ons-cookies-banner__link" href="{{ params.settingsLinkURL | default(settingsLinkURL) }}">{{ params.settingsLinkText | default(settingsLinkText) }}</a>
24
68
  </div>
25
69
  </div>
26
70
  </div>
27
71
  <div class="ons-container ons-cookies-banner__confirmation ons-u-d-no">
28
72
  <div class="ons-grid ons-grid--flex ons-grid--between ons-grid--gutterless ons-grid--no-wrap@s ons-grid--vertical-center">
29
73
  <div class="ons-grid__col ons-grid__col--flex ons-col-auto ons-u-flex-shrink@s">
30
- <p class="ons-cookies-banner__desc ons-u-mb-no@s ons-u-mr-s@s">{{ params.confirmationText | safe }}</p>
74
+ <p class="ons-cookies-banner__desc ons-u-mb-no@s ons-u-mr-s@s"><span class="ons-js-accepted-text ons-u-d-no">{{ params.acceptedText | default(acceptedText) | safe }} </span><span class="ons-js-rejected-text ons-u-d-no">{{ params.rejectedText | default(rejectedText) | safe }} </span><span class="ons-cookies-banner__preferences-text">{{ params.preferencesText | default(preferencesText) | safe }}</span></p>
31
75
  </div>
32
76
  <div class="ons-grid__col">
33
77
  {{
34
78
  onsButton({
35
79
  "type": 'button',
36
- "text": params.confirmationButtonText | default('Hide'),
37
- "buttonContext": params.confirmationButtonTextAria | default('the cookie message'),
80
+ "text": params.confirmationButtonText | default(confirmationButtonText),
81
+ "buttonContext": params.confirmationButtonTextAria | default(confirmationButtonTextAria),
38
82
  "classes": 'ons-btn--secondary ons-btn--small ons-js-hide-button'
39
83
  })
40
84
  }}
@@ -5,167 +5,225 @@ import * as cheerio from 'cheerio';
5
5
  import axe from '../../tests/helpers/axe';
6
6
  import { renderComponent, templateFaker } from '../../tests/helpers/rendering';
7
7
 
8
- const EXAMPLE_COOKIES_BANNER_MINIMAL = {
9
- statementTitle: 'Tell us whether you accept cookies',
10
- statementText:
11
- 'We use <a href="#0">cookies to collect information</a> about how you use census.gov.uk. We use this information to make the website work as well as possible and improve our services.',
12
- confirmationText: 'You’ve accepted all cookies. You can <a href="#0">change your cookie preferences</a> at any time.',
13
- };
14
-
15
- const EXAMPLE_COOKIES_BANNER = {
16
- ...EXAMPLE_COOKIES_BANNER_MINIMAL,
17
- ariaLabel: 'the cookies banner',
18
- primaryButtonText: 'Accept cookies',
19
- secondaryButtonText: 'Set preferences',
20
- secondaryButtonUrl: 'https://example.com/cookies/set-preferences',
21
- confirmationButtonText: 'Close',
22
- confirmationButtonTextAria: 'the cookie banner',
8
+ const EXAMPLE_COOKIES_BANNER_PARAMS = {
9
+ ariaLabel: 'Cookies banner override',
10
+ serviceName: 'ons.gov.uk override',
11
+ statementTitle: 'Cookies on override',
12
+ settingsLinkText: 'Cookie settings override',
13
+ settingsLinkURL: '/cookiesoverride',
14
+ statementText: 'Statement override',
15
+ acceptButtonText: 'Accept additional cookies override',
16
+ rejectButtonText: 'Reject additional cookies override',
17
+ preferencesText: 'Text override',
18
+ confirmationButtonText: 'Hide override',
19
+ confirmationButtonTextAria: 'the cookie message override',
23
20
  };
24
21
 
25
22
  describe('macro: cookies-banner', () => {
26
- it.each([
27
- ['minimal parameters', EXAMPLE_COOKIES_BANNER_MINIMAL],
28
- ['all parameters', EXAMPLE_COOKIES_BANNER],
29
- ])('passes jest-axe checks with %s', async (_, params) => {
30
- const $ = cheerio.load(renderComponent('cookies-banner', params));
31
-
32
- const results = await axe($.html());
33
- expect(results).toHaveNoViolations();
23
+ describe.each([
24
+ ['default parameters', {}],
25
+ ['provided parameters', EXAMPLE_COOKIES_BANNER_PARAMS],
26
+ ])('mode: %s', (_, params) => {
27
+ it('passes jest-axe checks', async () => {
28
+ const $ = cheerio.load(renderComponent('cookies-banner', params));
29
+
30
+ const results = await axe($.html());
31
+ expect(results).toHaveNoViolations();
32
+ });
34
33
  });
35
34
 
36
- it('has a `role` of "region"', () => {
37
- const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_MINIMAL));
35
+ describe('mode: provided parameters', () => {
36
+ it('has the correct `aria-label`', () => {
37
+ const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS));
38
38
 
39
- expect($('.ons-cookies-banner').attr('role')).toBe('region');
40
- });
39
+ expect($('.ons-cookies-banner').attr('aria-label')).toBe('Cookies banner override');
40
+ });
41
41
 
42
- it('has a default `aria-label` of "Cookies banner"', () => {
43
- const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_MINIMAL));
42
+ describe('initial banner', () => {
43
+ it('has `statementTitle` title text', () => {
44
+ const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS));
44
45
 
45
- expect($('.ons-cookies-banner').attr('aria-label')).toBe('Cookies banner');
46
- });
46
+ const statementTitle = $('.ons-cookies-banner__title')
47
+ .text()
48
+ .trim();
49
+ expect(statementTitle).toBe('Cookies on override ons.gov.uk override');
50
+ });
47
51
 
48
- it('has the provided `ariaLabel` for `aria-label`', () => {
49
- const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER));
52
+ it('has `statementText` text', () => {
53
+ const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS));
50
54
 
51
- expect($('.ons-cookies-banner').attr('aria-label')).toBe('the cookies banner');
52
- });
55
+ const statementText = $('.ons-cookies-banner__primary .ons-cookies-banner__statement')
56
+ .html()
57
+ .trim();
58
+ expect(statementText).toBe('Statement override');
59
+ });
53
60
 
54
- describe('content', () => {
55
- it('has provided `statementTitle` title text', () => {
56
- const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_MINIMAL));
61
+ it('Renders an `accept` button with correct text', () => {
62
+ const faker = templateFaker();
63
+ const buttonSpy = faker.spy('button');
57
64
 
58
- const statementTitle = $('.ons-cookies-banner__title')
59
- .text()
60
- .trim();
61
- expect(statementTitle).toBe('Tell us whether you accept cookies');
62
- });
65
+ faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS);
63
66
 
64
- it('has provided `statementText` text', () => {
65
- const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_MINIMAL));
67
+ expect(buttonSpy.occurrences[0].text).toBe('Accept additional cookies override');
68
+ });
66
69
 
67
- const statementText = $('.ons-cookies-banner__primary .ons-cookies-banner__desc')
68
- .html()
69
- .trim();
70
- expect(statementText).toBe(
71
- 'We use <a href="#0">cookies to collect information</a> about how you use census.gov.uk. We use this information to make the website work as well as possible and improve our services.',
72
- );
73
- });
70
+ it('Renders a `reject` button with correct text', () => {
71
+ const faker = templateFaker();
72
+ const buttonSpy = faker.spy('button');
74
73
 
75
- it('has provided `confirmationText` text', () => {
76
- const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_MINIMAL));
74
+ faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS);
77
75
 
78
- const statementText = $('.ons-cookies-banner__confirmation .ons-cookies-banner__desc')
79
- .html()
80
- .trim();
81
- expect(statementText).toBe('You’ve accepted all cookies. You can <a href="#0">change your cookie preferences</a> at any time.');
82
- });
83
- });
76
+ expect(buttonSpy.occurrences[1].text).toBe('Reject additional cookies override');
77
+ });
78
+
79
+ it('Renders a link with text', () => {
80
+ const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS));
84
81
 
85
- describe('primary button', () => {
86
- it('assumes default text "Accept all cookies"', () => {
87
- const faker = templateFaker();
88
- const buttonSpy = faker.spy('button');
82
+ const linkText = $('.ons-cookies-banner__link')
83
+ .text()
84
+ .trim();
85
+ expect(linkText).toBe('Cookie settings override');
86
+ });
89
87
 
90
- faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_MINIMAL);
88
+ it('Renders a link with url', () => {
89
+ const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS));
91
90
 
92
- expect(buttonSpy.occurrences[0].text).toBe('Accept all cookies');
91
+ const linkText = $('.ons-cookies-banner__link').attr('href');
92
+ expect(linkText).toBe('/cookiesoverride');
93
+ });
93
94
  });
94
95
 
95
- it('has provided `primaryButtonText` text', () => {
96
- const faker = templateFaker();
97
- const buttonSpy = faker.spy('button');
96
+ describe('confirmation banner', () => {
97
+ it('has `preferencesText` text', () => {
98
+ const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS));
99
+
100
+ const preferencesText = $('.ons-cookies-banner__confirmation .ons-cookies-banner__preferences-text')
101
+ .html()
102
+ .trim();
103
+ expect(preferencesText).toBe('Text override');
104
+ });
105
+
106
+ it('renders a button with text', () => {
107
+ const faker = templateFaker();
108
+ const buttonSpy = faker.spy('button');
109
+
110
+ faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS);
98
111
 
99
- faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER);
112
+ expect(buttonSpy.occurrences[2].text).toBe('Hide override');
113
+ });
100
114
 
101
- expect(buttonSpy.occurrences[0].text).toBe('Accept cookies');
115
+ it('has the correct `confirmationButtonTextAria` for `buttonContext`', () => {
116
+ const faker = templateFaker();
117
+ const buttonSpy = faker.spy('button');
118
+
119
+ faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS);
120
+
121
+ expect(buttonSpy.occurrences[2].buttonContext).toBe('the cookie message override');
122
+ });
102
123
  });
103
124
  });
104
125
 
105
- describe('secondary button', () => {
106
- it('assumes default text "Set cookie preferences"', () => {
107
- const faker = templateFaker();
108
- const buttonSpy = faker.spy('button');
109
-
110
- faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_MINIMAL);
126
+ describe('mode: default parameters', () => {
127
+ it('has the correct `aria-label`', () => {
128
+ const $ = cheerio.load(renderComponent('cookies-banner', {}));
111
129
 
112
- expect(buttonSpy.occurrences[1].text).toBe('Set cookie preferences');
130
+ expect($('.ons-cookies-banner').attr('aria-label')).toBe('Cookies banner');
113
131
  });
114
132
 
115
- it('has provided `secondaryButtonText` text', () => {
116
- const faker = templateFaker();
117
- const buttonSpy = faker.spy('button');
133
+ describe('initial banner', () => {
134
+ it('has `statementTitle` title text', () => {
135
+ const $ = cheerio.load(renderComponent('cookies-banner', {}));
118
136
 
119
- faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER);
137
+ const statementTitle = $('.ons-cookies-banner__title')
138
+ .text()
139
+ .trim();
140
+ expect(statementTitle).toBe('Cookies on ons.gov.uk');
141
+ });
120
142
 
121
- expect(buttonSpy.occurrences[1].text).toBe('Set preferences');
122
- });
143
+ it('has `statementText` text', () => {
144
+ const $ = cheerio.load(renderComponent('cookies-banner', {}));
123
145
 
124
- it('has provided `secondaryButtonUrl`', () => {
125
- const faker = templateFaker();
126
- const buttonSpy = faker.spy('button');
146
+ const statementText = $('.ons-cookies-banner__primary .ons-cookies-banner__statement')
147
+ .html()
148
+ .trim();
149
+ expect(statementText).toBe(
150
+ '<p>Cookies are small files stored on your device when you visit a website. We use some essential cookies to make this website work.</p><p>We would like to set <a href="/cookies">additional cookies</a> to remember your settings and understand how you use the site. This helps us to improve our services. </p>',
151
+ );
152
+ });
127
153
 
128
- faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER);
154
+ it('Renders an `accept` button with correct text', () => {
155
+ const faker = templateFaker();
156
+ const buttonSpy = faker.spy('button');
129
157
 
130
- expect(buttonSpy.occurrences[1].url).toBe('https://example.com/cookies/set-preferences');
131
- });
132
- });
158
+ faker.renderComponent('cookies-banner', {});
133
159
 
134
- describe('confirmation button', () => {
135
- it('assumes default text "Hide"', () => {
136
- const faker = templateFaker();
137
- const buttonSpy = faker.spy('button');
160
+ expect(buttonSpy.occurrences[0].text).toBe('Accept additional cookies');
161
+ });
138
162
 
139
- faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_MINIMAL);
163
+ it('Renders a `reject` button with correct text', () => {
164
+ const faker = templateFaker();
165
+ const buttonSpy = faker.spy('button');
140
166
 
141
- expect(buttonSpy.occurrences[2].text).toBe('Hide');
142
- });
167
+ faker.renderComponent('cookies-banner', {});
168
+
169
+ expect(buttonSpy.occurrences[1].text).toBe('Reject additional cookies');
170
+ });
143
171
 
144
- it('has provided `confirmationButtonText` text', () => {
145
- const faker = templateFaker();
146
- const buttonSpy = faker.spy('button');
172
+ it('Renders a link with text', () => {
173
+ const $ = cheerio.load(renderComponent('cookies-banner', {}));
147
174
 
148
- faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER);
175
+ const linkText = $('.ons-cookies-banner__link')
176
+ .text()
177
+ .trim();
178
+ expect(linkText).toBe('View cookies');
179
+ });
149
180
 
150
- expect(buttonSpy.occurrences[2].text).toBe('Close');
181
+ it('Renders a link with url', () => {
182
+ const $ = cheerio.load(renderComponent('cookies-banner', {}));
183
+
184
+ const linkText = $('.ons-cookies-banner__link').attr('href');
185
+ expect(linkText).toBe('/cookies');
186
+ });
151
187
  });
152
188
 
153
- it('has a default `buttonContext` of "cookie banner"', () => {
154
- const faker = templateFaker();
155
- const buttonSpy = faker.spy('button');
189
+ describe('confirmation banner', () => {
190
+ it('has `preferencesText` text', () => {
191
+ const $ = cheerio.load(renderComponent('cookies-banner', {}));
156
192
 
157
- faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_MINIMAL);
193
+ const preferencesText = $('.ons-cookies-banner__confirmation .ons-cookies-banner__preferences-text')
194
+ .html()
195
+ .trim();
196
+ expect(preferencesText).toBe('You can <a href="/cookies">change your cookie preferences</a> at any time.');
197
+ });
158
198
 
159
- expect(buttonSpy.occurrences[2].buttonContext).toBe('the cookie message');
160
- });
199
+ it('renders a button with text', () => {
200
+ const faker = templateFaker();
201
+ const buttonSpy = faker.spy('button');
161
202
 
162
- it('has the provided `confirmationButtonTextAria` for `buttonContext`', () => {
163
- const faker = templateFaker();
164
- const buttonSpy = faker.spy('button');
203
+ faker.renderComponent('cookies-banner', {});
165
204
 
166
- faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER);
205
+ expect(buttonSpy.occurrences[2].text).toBe('Hide');
206
+ });
167
207
 
168
- expect(buttonSpy.occurrences[2].buttonContext).toBe('the cookie banner');
208
+ it('has the correct `confirmationButtonTextAria` for `buttonContext`', () => {
209
+ const faker = templateFaker();
210
+ const buttonSpy = faker.spy('button');
211
+
212
+ faker.renderComponent('cookies-banner', {});
213
+
214
+ expect(buttonSpy.occurrences[2].buttonContext).toBe('this message');
215
+ });
216
+ });
217
+ });
218
+
219
+ describe('mode: Welsh language', () => {
220
+ it('has the welsh version of default values', () => {
221
+ const $ = cheerio.load(renderComponent('cookies-banner', { lang: 'cy' }));
222
+
223
+ const statementTitle = $('.ons-cookies-banner__title')
224
+ .text()
225
+ .trim();
226
+ expect(statementTitle).toBe('Cwcis ar ons.gov.uk');
169
227
  });
170
228
  });
171
229
  });
@@ -5,14 +5,17 @@ export default class CookiesBanner {
5
5
  this.component = component;
6
6
  this.primaryBanner = this.component.querySelector('.ons-cookies-banner__primary');
7
7
  this.confirmBanner = this.component.querySelector('.ons-cookies-banner__confirmation');
8
- this.button = this.component.querySelector('.ons-js-accept-cookies');
8
+ this.acceptButton = this.component.querySelector('.ons-js-accept-cookies');
9
+ this.rejectButton = this.component.querySelector('.ons-js-reject-cookies');
9
10
  this.hideButton = this.component.querySelector('.ons-js-hide-button');
10
-
11
+ this.acceptedText = this.component.querySelector('.ons-js-accepted-text');
12
+ this.rejectedText = this.component.querySelector('.ons-js-rejected-text');
11
13
  this.setupCookiesEvents();
12
14
  }
13
15
 
14
16
  setupCookiesEvents() {
15
- this.button.addEventListener('click', this.setCookiesConsent.bind(this));
17
+ this.acceptButton.addEventListener('click', this.setCookiesConsent.bind(this));
18
+ this.rejectButton.addEventListener('click', this.setCookiesConsent.bind(this));
16
19
  this.hideButton.addEventListener('click', this.hideConfirmBanner.bind(this));
17
20
 
18
21
  this.showCookiesMessage();
@@ -35,35 +38,54 @@ export default class CookiesBanner {
35
38
 
36
39
  setCookiesConsent(event) {
37
40
  event.preventDefault();
41
+ let actionText;
42
+ const action = event.target.getAttribute('data-button');
38
43
 
39
- approveAllCookieTypes();
44
+ if (action == 'accept') {
45
+ this.acceptCookies();
46
+ actionText = this.acceptedText;
47
+ } else if (action == 'reject') {
48
+ setDefaultConsentCookie();
49
+ actionText = this.rejectedText;
50
+ }
51
+
52
+ this.hidePrimaryCookiesBanner(actionText);
53
+ this.checkPage(action);
40
54
  cookie('ons_cookie_message_displayed', 'true', { days: 365 });
55
+ }
41
56
 
42
- this.hidePrimaryCookiesBanner();
57
+ acceptCookies() {
58
+ approveAllCookieTypes();
59
+ if (typeof loadGTM != 'undefined') {
60
+ loadGTM();
61
+ }
62
+ }
43
63
 
64
+ checkPage(action) {
44
65
  const isOnSettingsPage = document.querySelector('[data-module="cookie-settings"]');
45
66
  if (isOnSettingsPage) {
46
- this.updateRadios();
47
- }
48
-
49
- if (typeof loadGTM != 'undefined') {
50
- loadGTM();
67
+ this.updateRadios(action);
51
68
  }
52
69
  }
53
70
 
54
- updateRadios() {
71
+ updateRadios(action) {
55
72
  const radios = [...document.querySelectorAll('.ons-js-radio')];
56
73
  radios.forEach(radio => {
57
- radio.value == 'off' ? (radio.checked = false) : (radio.checked = true);
74
+ if (action == 'reject') {
75
+ radio.value == 'off' ? (radio.checked = true) : (radio.checked = false);
76
+ } else if (action == 'accept') {
77
+ radio.value == 'off' ? (radio.checked = false) : (radio.checked = true);
78
+ }
58
79
  });
59
80
  }
60
81
 
61
- hidePrimaryCookiesBanner() {
82
+ hidePrimaryCookiesBanner(text) {
62
83
  if (this.component) {
63
84
  this.primaryBanner.style.display = 'none';
64
85
  this.confirmBanner.classList.remove('ons-u-d-no');
65
86
  this.confirmBanner.setAttribute('aria-live', 'polite');
66
87
  this.confirmBanner.setAttribute('role', 'status');
88
+ text.classList.remove('ons-u-d-no');
67
89
  }
68
90
  }
69
91