@ons/design-system 53.1.1 → 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.
@@ -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
 
@@ -1,10 +1,6 @@
1
1
  import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
2
2
 
3
- const EXAMPLE_COOKIES_BANNER_PAGE = renderComponent('cookies-banner', {
4
- statementTitle: 'Tell us whether you accept cookies',
5
- statementText: 'We use <a href="#0">cookies to collect information</a> about how you use census.gov.uk.',
6
- confirmationText: 'You’ve accepted all cookies. You can <a href="#0">change your cookie preferences</a> at any time.',
7
- });
3
+ const EXAMPLE_COOKIES_BANNER_PAGE = renderComponent('cookies-banner', {});
8
4
 
9
5
  describe('script: cookies-banner', () => {
10
6
  beforeEach(async () => {
@@ -18,73 +14,81 @@ describe('script: cookies-banner', () => {
18
14
  const displayStyle = await page.$eval('.ons-cookies-banner', node => window.getComputedStyle(node).getPropertyValue('display'));
19
15
  expect(displayStyle).toBe('block');
20
16
  });
17
+ describe.each([
18
+ ['accepting cookies', 'accept', true],
19
+ ['rejecting cookies', 'reject', false],
20
+ ])('action: %s', (_, action, value) => {
21
+ it(`sets all cookies to ${value} when ${_}`, async () => {
22
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
23
+
24
+ await page.click(`.ons-js-${action}-cookies`);
25
+
26
+ const cookies = await page.cookies();
27
+ const ons_cookie_policy = cookies.find(cookie => cookie.name === 'ons_cookie_policy');
28
+ const policy = JSON.parse(ons_cookie_policy.value.replace(/'/g, '"'));
29
+
30
+ expect(policy).toEqual({
31
+ essential: true,
32
+ settings: value,
33
+ usage: value,
34
+ campaigns: value,
35
+ });
36
+ });
21
37
 
22
- it('sets all cookies to true when accepting cookies', async () => {
23
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
38
+ it(`sets seen cookie message when ${_}`, async () => {
39
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
24
40
 
25
- await page.click('.ons-js-accept-cookies');
41
+ await page.click(`.ons-js-${action}-cookies`);
26
42
 
27
- const cookies = await page.cookies();
28
- const ons_cookie_policy = cookies.find(cookie => cookie.name === 'ons_cookie_policy');
29
- const policy = JSON.parse(ons_cookie_policy.value.replace(/'/g, '"'));
43
+ const cookies = await page.cookies();
44
+ const ons_cookie_message_displayed = cookies.find(cookie => cookie.name === 'ons_cookie_message_displayed');
30
45
 
31
- expect(policy).toEqual({
32
- essential: true,
33
- settings: true,
34
- usage: true,
35
- campaigns: true,
46
+ expect(ons_cookie_message_displayed.value).toBe('true');
36
47
  });
37
- });
38
-
39
- it('sets seen cookie message when accepting cookies', async () => {
40
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
41
48
 
42
- await page.click('.ons-js-accept-cookies');
49
+ it(`should hide the primary message when pressing the ${action} button`, async () => {
50
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
43
51
 
44
- const cookies = await page.cookies();
45
- const ons_cookie_message_displayed = cookies.find(cookie => cookie.name === 'ons_cookie_message_displayed');
52
+ await page.click(`.ons-js-${action}-cookies`);
46
53
 
47
- expect(ons_cookie_message_displayed.value).toBe('true');
48
- });
54
+ const displayStyle = await page.$eval('.ons-cookies-banner__primary', node =>
55
+ window.getComputedStyle(node).getPropertyValue('display'),
56
+ );
57
+ expect(displayStyle).toBe('none');
58
+ });
49
59
 
50
- it('should hide the primary message when pressing the accept button', async () => {
51
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
60
+ it(`should show the secondary message when pressing the ${action} button`, async () => {
61
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
52
62
 
53
- await page.click('.ons-js-accept-cookies');
63
+ await page.click(`.ons-js-${action}-cookies`);
54
64
 
55
- const displayStyle = await page.$eval('.ons-cookies-banner__primary', node =>
56
- window.getComputedStyle(node).getPropertyValue('display'),
57
- );
58
- expect(displayStyle).toBe('none');
65
+ const displayStyle = await page.$eval('.ons-cookies-banner__confirmation', node =>
66
+ window.getComputedStyle(node).getPropertyValue('display'),
67
+ );
68
+ expect(displayStyle).not.toBe('none');
69
+ });
59
70
  });
60
71
 
61
- it('should show the secondary message when pressing the accept button', async () => {
62
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
63
-
64
- await page.click('.ons-js-accept-cookies');
65
-
66
- const displayStyle = await page.$eval('.ons-cookies-banner__confirmation', node =>
67
- window.getComputedStyle(node).getPropertyValue('display'),
68
- );
69
- expect(displayStyle).not.toBe('none');
70
- });
71
- //...
72
- it('should hide the secondary message when pressing the hide button', async () => {
73
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
72
+ describe('confirmation banner', () => {
73
+ it('should hide the confirmation message when pressing the hide button', async () => {
74
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
74
75
 
75
- await page.click('.ons-js-accept-cookies');
76
- await page.click('.ons-js-hide-button');
76
+ await page.click('.ons-js-accept-cookies');
77
+ await page.click('.ons-js-hide-button');
77
78
 
78
- const displayStyle = await page.$eval('.ons-cookies-banner', node => window.getComputedStyle(node).getPropertyValue('display'));
79
- expect(displayStyle).toBe('none');
79
+ const displayStyle = await page.$eval('.ons-cookies-banner', node => window.getComputedStyle(node).getPropertyValue('display'));
80
+ expect(displayStyle).toBe('none');
81
+ });
80
82
  });
81
83
 
82
- it('does not show the banner if user has acknowledged the banner previously and consent cookie is present', async () => {
83
- await page.setCookie({ name: 'ons_cookie_message_displayed', value: 'true' });
84
+ describe('cookie preferences confirmed', () => {
85
+ it('does not show the banner if user has acknowledged the banner previously and consent cookie is present', async () => {
86
+ await page.setCookie({ name: 'ons_cookie_message_displayed', value: 'true' });
84
87
 
85
- await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
88
+ await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
86
89
 
87
- const displayStyle = await page.$eval('.ons-cookies-banner', node => window.getComputedStyle(node).getPropertyValue('display'));
88
- expect(displayStyle).toBe('none');
90
+ const displayStyle = await page.$eval('.ons-cookies-banner', node => window.getComputedStyle(node).getPropertyValue('display'));
91
+ expect(displayStyle).toBe('none');
92
+ });
89
93
  });
90
94
  });
@@ -27,7 +27,7 @@
27
27
  type="{{ type }}"
28
28
  id="{{ params.id }}"
29
29
  class="ons-input ons-input--text ons-input-type__input{% if params.error is defined and params.error %} ons-input--error{% endif %}{% if params.searchButton is defined and params.searchButton %} ons-search__input{% endif %}{% if params.classes is defined and params.classes %} {{ params.classes }}{% endif %}{% if params.width is defined and params.width %} ons-input{% if params.type is defined and (params.type == 'number' or params.type == 'tel') %}-number{% endif %}--w-{{ params.width }}{% endif %}{{ exclusiveClass }}{{ inputPlaceholder }}"
30
- {% if params.prefix is defined and params.prefix or params.suffix is defined and params.suffix %}aria-labelledby="{{ params.prefix.id if params.prefix }}{{ params.suffix.id if params.suffix }}"{% endif %}
30
+ {% if ((params.prefix is defined and params.prefix) and (params.prefix.id is defined and params.prefix.id)) or ((params.suffix is defined and params.suffix) and (params.suffix.id is defined and params.suffix.id)) %}aria-labelledby="{{ params.prefix.id if params.prefix.id }}{{ params.suffix.id if params.suffix.id }}"{% endif %}
31
31
  {% if params.name is defined and params.name %}name="{{ params.name }}"{% endif %}
32
32
  {% if params.value is defined and params.value %}value="{{ params.value }}"{% endif %}
33
33
  {% if params.accept is defined and params.accept %}accept="{{ params.accept }}"{% endif %}
@@ -71,21 +71,26 @@
71
71
  {% endif %}
72
72
 
73
73
  {% if params.prefix is defined and params.prefix or params.suffix is defined and params.suffix %}
74
- {% if params.prefix is defined and params.prefix %}
75
- {% set prefixClass = " ons-input-type--prefix" %}
76
- {% endif %}
74
+ {% if (params.prefix is defined and params.prefix and params.prefix.id is defined and params.prefix.id) or (params.suffix is defined and params.suffix and params.suffix.id is defined and params.suffix.id) %}
75
+ {% if (params.prefix.title is defined and params.prefix.title) or (params.suffix.title is defined and params.suffix.title) %}
76
+ {% if params.prefix is defined and params.prefix %}
77
+ {% set prefixClass = " ons-input-type--prefix" %}
78
+ {% endif %}
77
79
 
78
- <span class="ons-input-type{{ prefixClass }}">
79
- <span class="ons-input-type__inner">
80
- {{ input | safe }}
81
- {% set abbr = params.prefix or params.suffix %}
82
- <abbr
83
- {% if abbr.id is defined and abbr.id %}id="{{ abbr.id }}" {% endif %}
84
- class="ons-input-type__type ons-js-input-abbr"
85
- title="{{ abbr.title }}"
86
- >{{ abbr.text or abbr.title }}</abbr>
87
- </span>
88
- </span>
80
+ <span class="ons-input-type{{ prefixClass }}">
81
+ <span class="ons-input-type__inner">
82
+ {{ input | safe }}
83
+
84
+ {% set abbr = params.prefix or params.suffix %}
85
+ <abbr
86
+ id="{{ abbr.id }}"
87
+ class="ons-input-type__type ons-js-input-abbr"
88
+ title="{{ abbr.title }}"
89
+ >{{ abbr.text or abbr.title }}</abbr>
90
+ </span>
91
+ </span>
92
+ {% endif %}
93
+ {% endif %}
89
94
  {% elif params.searchButton is defined and params.searchButton %}
90
95
  <span class="ons-grid--flex ons-search">
91
96
  {% call onsSearch({