@ons/design-system 53.1.1 → 55.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.
- package/components/accordion/_macro.njk +2 -3
- package/components/accordion/_macro.spec.js +3 -40
- package/components/accordion/accordion.dom.js +19 -0
- package/components/{collapsible/collapsible.group.js → accordion/accordion.js} +12 -5
- package/components/accordion/accordion.spec.js +56 -51
- package/components/autosuggest/_autosuggest.scss +4 -4
- package/components/autosuggest/autosuggest.spec.js +12 -2
- package/components/autosuggest/autosuggest.ui.js +4 -7
- package/components/button/_button.scss +28 -7
- package/components/button/_macro.njk +1 -1
- package/components/button/_macro.spec.js +2 -2
- package/components/checkboxes/_checkbox.scss +50 -17
- package/components/collapsible/_collapsible.scss +59 -85
- package/components/collapsible/_macro.njk +6 -39
- package/components/collapsible/_macro.spec.js +0 -53
- package/components/collapsible/collapsible.dom.js +3 -12
- package/components/collapsible/collapsible.js +3 -45
- package/components/collapsible/collapsible.spec.js +6 -139
- package/components/cookies-banner/_cookies-banner.scss +15 -7
- package/components/cookies-banner/_macro.njk +66 -22
- package/components/cookies-banner/_macro.spec.js +172 -114
- package/components/cookies-banner/cookies-banner.js +35 -13
- package/components/cookies-banner/cookies-banner.spec.js +58 -54
- package/components/document-list/document-list.scss +2 -0
- package/components/download-resources/download-resources.js +19 -0
- package/components/download-resources/download-resources.spec.js +95 -0
- package/components/external-link/_macro.njk +1 -1
- package/components/external-link/_macro.spec.js +2 -2
- package/components/fieldset/_fieldset.scss +11 -1
- package/components/fieldset/_macro.njk +9 -8
- package/components/fieldset/_macro.spec.js +27 -5
- package/components/footer/_footer.scss +1 -0
- package/components/header/_macro.njk +2 -5
- package/components/header/_macro.spec.js +0 -16
- package/components/hero/_macro.njk +1 -1
- package/components/hero/_macro.spec.js +1 -1
- package/components/icons/_macro.njk +1 -1
- package/components/input/_input-type.scss +37 -3
- package/components/input/_input.scss +28 -9
- package/components/input/_macro.njk +17 -14
- package/components/input/_macro.spec.js +56 -0
- package/components/label/_label.scss +1 -1
- package/components/label/_macro.njk +27 -15
- package/components/label/_macro.spec.js +31 -0
- package/components/lists/_macro.njk +1 -1
- package/components/lists/_macro.spec.js +2 -2
- package/components/message/_message.scss +1 -0
- package/components/modal/_macro.njk +2 -2
- package/components/modal/_modal.scss +10 -9
- package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +2 -0
- package/components/mutually-exclusive/mutually-exclusive.number.spec.js +1 -0
- package/components/navigation/_macro.njk +0 -1
- package/components/navigation/_macro.spec.js +0 -1
- package/components/pagination/_pagination.scss +1 -0
- package/components/panel/_macro.njk +6 -7
- package/components/panel/_macro.spec.js +23 -20
- package/components/panel/_panel.scss +13 -5
- package/components/phase-banner/_phase-banner.scss +1 -0
- package/components/radios/_radio.scss +16 -4
- package/components/relationships/_relationships.scss +2 -2
- package/components/reply/_macro.njk +2 -2
- package/components/skip-to-content/_skip.scss +2 -1
- package/components/table/_macro.njk +3 -2
- package/components/table/_macro.spec.js +0 -27
- package/components/table/_table.scss +15 -7
- package/components/table/sortable-table.js +1 -0
- package/components/tabs/_tabs.scss +57 -34
- package/components/tabs/tabs.js +4 -2
- package/components/upload/_upload.scss +2 -2
- package/css/census.css +1 -1
- package/css/ids.css +1 -1
- package/css/main.css +1 -1
- package/js/main.js +1 -0
- package/layout/_template.njk +8 -8
- package/package.json +1 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +2 -2
- package/scss/base/_global.scss +1 -0
- package/scss/objects/_page.scss +1 -1
- package/scss/overrides/hcm.scss +205 -46
- package/scss/patternlib.scss +1 -56
- package/scss/vars/_colors.scss +2 -1
|
@@ -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
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
27
|
-
['
|
|
28
|
-
['
|
|
29
|
-
])('
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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
|
-
|
|
40
|
-
|
|
39
|
+
expect($('.ons-cookies-banner').attr('aria-label')).toBe('Cookies banner override');
|
|
40
|
+
});
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
describe('initial banner', () => {
|
|
43
|
+
it('has `statementTitle` title text', () => {
|
|
44
|
+
const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS));
|
|
44
45
|
|
|
45
|
-
|
|
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
|
-
|
|
49
|
-
|
|
52
|
+
it('has `statementText` text', () => {
|
|
53
|
+
const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS));
|
|
50
54
|
|
|
51
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
61
|
+
it('Renders an `accept` button with correct text', () => {
|
|
62
|
+
const faker = templateFaker();
|
|
63
|
+
const buttonSpy = faker.spy('button');
|
|
57
64
|
|
|
58
|
-
|
|
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
|
-
|
|
65
|
-
|
|
67
|
+
expect(buttonSpy.occurrences[0].text).toBe('Accept additional cookies override');
|
|
68
|
+
});
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
.
|
|
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
|
-
|
|
76
|
-
const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_MINIMAL));
|
|
74
|
+
faker.renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS);
|
|
77
75
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
82
|
+
const linkText = $('.ons-cookies-banner__link')
|
|
83
|
+
.text()
|
|
84
|
+
.trim();
|
|
85
|
+
expect(linkText).toBe('Cookie settings override');
|
|
86
|
+
});
|
|
89
87
|
|
|
90
|
-
|
|
88
|
+
it('Renders a link with url', () => {
|
|
89
|
+
const $ = cheerio.load(renderComponent('cookies-banner', EXAMPLE_COOKIES_BANNER_PARAMS));
|
|
91
90
|
|
|
92
|
-
|
|
91
|
+
const linkText = $('.ons-cookies-banner__link').attr('href');
|
|
92
|
+
expect(linkText).toBe('/cookiesoverride');
|
|
93
|
+
});
|
|
93
94
|
});
|
|
94
95
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
112
|
+
expect(buttonSpy.occurrences[2].text).toBe('Hide override');
|
|
113
|
+
});
|
|
100
114
|
|
|
101
|
-
|
|
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('
|
|
106
|
-
it('
|
|
107
|
-
const
|
|
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(
|
|
130
|
+
expect($('.ons-cookies-banner').attr('aria-label')).toBe('Cookies banner');
|
|
113
131
|
});
|
|
114
132
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
133
|
+
describe('initial banner', () => {
|
|
134
|
+
it('has `statementTitle` title text', () => {
|
|
135
|
+
const $ = cheerio.load(renderComponent('cookies-banner', {}));
|
|
118
136
|
|
|
119
|
-
|
|
137
|
+
const statementTitle = $('.ons-cookies-banner__title')
|
|
138
|
+
.text()
|
|
139
|
+
.trim();
|
|
140
|
+
expect(statementTitle).toBe('Cookies on ons.gov.uk');
|
|
141
|
+
});
|
|
120
142
|
|
|
121
|
-
|
|
122
|
-
|
|
143
|
+
it('has `statementText` text', () => {
|
|
144
|
+
const $ = cheerio.load(renderComponent('cookies-banner', {}));
|
|
123
145
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
154
|
+
it('Renders an `accept` button with correct text', () => {
|
|
155
|
+
const faker = templateFaker();
|
|
156
|
+
const buttonSpy = faker.spy('button');
|
|
129
157
|
|
|
130
|
-
|
|
131
|
-
});
|
|
132
|
-
});
|
|
158
|
+
faker.renderComponent('cookies-banner', {});
|
|
133
159
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const faker = templateFaker();
|
|
137
|
-
const buttonSpy = faker.spy('button');
|
|
160
|
+
expect(buttonSpy.occurrences[0].text).toBe('Accept additional cookies');
|
|
161
|
+
});
|
|
138
162
|
|
|
139
|
-
|
|
163
|
+
it('Renders a `reject` button with correct text', () => {
|
|
164
|
+
const faker = templateFaker();
|
|
165
|
+
const buttonSpy = faker.spy('button');
|
|
140
166
|
|
|
141
|
-
|
|
142
|
-
|
|
167
|
+
faker.renderComponent('cookies-banner', {});
|
|
168
|
+
|
|
169
|
+
expect(buttonSpy.occurrences[1].text).toBe('Reject additional cookies');
|
|
170
|
+
});
|
|
143
171
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
const buttonSpy = faker.spy('button');
|
|
172
|
+
it('Renders a link with text', () => {
|
|
173
|
+
const $ = cheerio.load(renderComponent('cookies-banner', {}));
|
|
147
174
|
|
|
148
|
-
|
|
175
|
+
const linkText = $('.ons-cookies-banner__link')
|
|
176
|
+
.text()
|
|
177
|
+
.trim();
|
|
178
|
+
expect(linkText).toBe('View cookies');
|
|
179
|
+
});
|
|
149
180
|
|
|
150
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
189
|
+
describe('confirmation banner', () => {
|
|
190
|
+
it('has `preferencesText` text', () => {
|
|
191
|
+
const $ = cheerio.load(renderComponent('cookies-banner', {}));
|
|
156
192
|
|
|
157
|
-
|
|
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
|
-
|
|
160
|
-
|
|
199
|
+
it('renders a button with text', () => {
|
|
200
|
+
const faker = templateFaker();
|
|
201
|
+
const buttonSpy = faker.spy('button');
|
|
161
202
|
|
|
162
|
-
|
|
163
|
-
const faker = templateFaker();
|
|
164
|
-
const buttonSpy = faker.spy('button');
|
|
203
|
+
faker.renderComponent('cookies-banner', {});
|
|
165
204
|
|
|
166
|
-
|
|
205
|
+
expect(buttonSpy.occurrences[2].text).toBe('Hide');
|
|
206
|
+
});
|
|
167
207
|
|
|
168
|
-
|
|
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.
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
23
|
-
|
|
38
|
+
it(`sets seen cookie message when ${_}`, async () => {
|
|
39
|
+
await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
|
|
24
40
|
|
|
25
|
-
|
|
41
|
+
await page.click(`.ons-js-${action}-cookies`);
|
|
26
42
|
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
49
|
+
it(`should hide the primary message when pressing the ${action} button`, async () => {
|
|
50
|
+
await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
|
|
43
51
|
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
51
|
-
|
|
60
|
+
it(`should show the secondary message when pressing the ${action} button`, async () => {
|
|
61
|
+
await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
|
|
52
62
|
|
|
53
|
-
|
|
63
|
+
await page.click(`.ons-js-${action}-cookies`);
|
|
54
64
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
76
|
-
|
|
76
|
+
await page.click('.ons-js-accept-cookies');
|
|
77
|
+
await page.click('.ons-js-hide-button');
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
83
|
-
|
|
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
|
-
|
|
88
|
+
await setTestPage('/test', EXAMPLE_COOKIES_BANNER_PAGE);
|
|
86
89
|
|
|
87
|
-
|
|
88
|
-
|
|
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
|
});
|
|
@@ -120,6 +120,8 @@
|
|
|
120
120
|
background-color: $color-banner-bg;
|
|
121
121
|
border-bottom: none;
|
|
122
122
|
display: block;
|
|
123
|
+
outline: 2px solid transparent; // Add transparent outline because Windows High Contrast Mode doesn't show background
|
|
124
|
+
outline-offset: -2px;
|
|
123
125
|
padding: 2rem;
|
|
124
126
|
|
|
125
127
|
@include mq(m) {
|
|
@@ -1061,9 +1061,28 @@ Math.easeInOutQuad = function(t, b, c, d) {
|
|
|
1061
1061
|
|
|
1062
1062
|
// Toggle filters visibility on small devices
|
|
1063
1063
|
function toggleFilters(bool) {
|
|
1064
|
+
let resultsOptions = document.getElementsByClassName('ons-adv-filter__results-options')[0];
|
|
1065
|
+
let resultsList = document.getElementsByClassName('ons-js-adv-filter__gallery')[0];
|
|
1066
|
+
let header = document.getElementsByClassName('ons-header')[0];
|
|
1067
|
+
let breadcrumbs = document.getElementsByClassName('ons-breadcrumb')[0];
|
|
1068
|
+
let footer = document.getElementsByClassName('ons-footer')[0];
|
|
1069
|
+
|
|
1064
1070
|
Util.toggleClass(filtersPanel, 'ons-adv-filter__panel--is-visible', bool);
|
|
1065
1071
|
Util.toggleClass(body, 'ons-no-scroll', bool);
|
|
1066
1072
|
filtersTrigger.setAttribute('aria-expanded', bool);
|
|
1073
|
+
filtersTrigger.setAttribute('aria-hidden', bool);
|
|
1074
|
+
Util.toggleClass(filtersTrigger, 'ons-u-d-no', bool);
|
|
1075
|
+
|
|
1076
|
+
Util.toggleClass(resultsOptions, 'ons-u-d-no', bool);
|
|
1077
|
+
Util.toggleClass(resultsList, 'ons-u-d-no', bool);
|
|
1078
|
+
Util.toggleClass(header, 'ons-u-d-no', bool);
|
|
1079
|
+
Util.toggleClass(breadcrumbs, 'ons-u-d-no', bool);
|
|
1080
|
+
Util.toggleClass(footer, 'ons-u-d-no', bool);
|
|
1081
|
+
resultsOptions.setAttribute('aria-hidden', bool);
|
|
1082
|
+
resultsList.setAttribute('aria-hidden', bool);
|
|
1083
|
+
header.setAttribute('aria-hidden', bool);
|
|
1084
|
+
breadcrumbs.setAttribute('aria-hidden', bool);
|
|
1085
|
+
footer.setAttribute('aria-hidden', bool);
|
|
1067
1086
|
}
|
|
1068
1087
|
}
|
|
1069
1088
|
})();
|