@ons/design-system 53.1.0 → 54.0.1
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 +8 -1
- package/components/checkboxes/_checkbox.scss +7 -7
- package/components/checkboxes/_macro.njk +1 -1
- package/components/collapsible/_collapsible.scss +58 -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/duration/_macro.njk +1 -1
- package/components/duration/_macro.spec.js +1 -1
- package/components/fieldset/_fieldset.scss +3 -6
- package/components/input/_input-type.scss +34 -3
- package/components/input/_input.scss +16 -8
- package/components/input/_macro.njk +17 -14
- package/components/input/_macro.spec.js +56 -0
- package/components/label/_label.scss +1 -1
- package/components/mutually-exclusive/mutually-exclusive.duration.spec.js +2 -0
- package/components/mutually-exclusive/mutually-exclusive.number.spec.js +1 -0
- package/components/radios/_radio.scss +2 -2
- package/components/relationships/_relationships.scss +2 -2
- package/components/table/_table.scss +3 -2
- package/components/tabs/_tabs.scss +55 -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/package.json +1 -1
- package/scripts/main.es5.js +1 -1
- package/scripts/main.js +2 -2
- package/scss/objects/_page.scss +1 -1
- package/scss/patternlib.scss +0 -56
- package/scss/vars/_colors.scss +2 -1
|
@@ -1,40 +1,84 @@
|
|
|
1
1
|
{% macro onsCookiesBanner(params) %}
|
|
2
|
-
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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.
|
|
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(
|
|
37
|
-
"buttonContext": params.confirmationButtonTextAria | default(
|
|
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
|
|
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
|
|