@ons/design-system 70.0.12 → 70.0.14

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.
@@ -14,20 +14,22 @@ const EXAMPLE_TIMEOUT_MODAL_BASIC = {
14
14
  endWithFullStop: true,
15
15
  };
16
16
 
17
+ const { setTimeout } = require('node:timers/promises');
18
+
17
19
  describe('script: timeout modal', () => {
18
20
  describe('when the page loads', () => {
19
21
  beforeEach(async () => {
20
22
  const component = renderComponent('timeout-modal', { ...EXAMPLE_TIMEOUT_MODAL_BASIC, showModalTimeInSeconds: 58 });
21
23
  const template = `
22
- <div class="ons-page">
23
- ${component}
24
- </div>
25
- `;
24
+ <div class="ons-page">
25
+ ${component}
26
+ </div>
27
+ `;
26
28
  await setTestPage('/test', template);
27
29
  });
28
30
 
29
31
  it('displays the modal after the correct number of seconds', async () => {
30
- await page.waitForTimeout(2000);
32
+ await setTimeout(2000);
31
33
  const modalIsVisible = await page.$eval('.ons-modal', (node) => node.classList.contains('ons-u-db'));
32
34
  expect(modalIsVisible).toBe(true);
33
35
  });
@@ -42,17 +44,17 @@ describe('script: timeout modal', () => {
42
44
  });
43
45
 
44
46
  const template = `
45
- <div class="ons-page">
46
- ${component}
47
- </div>
48
- `;
47
+ <div class="ons-page">
48
+ ${component}
49
+ </div>
50
+ `;
49
51
 
50
52
  await setTestPage('/test', template);
51
53
  });
52
54
 
53
55
  it('shows the time counting down', async () => {
54
56
  const timeAtStart = await page.$eval('.ons-js-timeout-timer span', (element) => element.innerHTML);
55
- await page.waitForTimeout(1000);
57
+ await setTimeout(1000);
56
58
  const timeAfterOneSecond = await page.$eval('.ons-js-timeout-timer span', (element) => element.innerHTML);
57
59
  expect(timeAfterOneSecond).not.toEqual(timeAtStart);
58
60
  });
@@ -70,10 +72,10 @@ describe('script: timeout modal', () => {
70
72
  });
71
73
 
72
74
  const template = `
73
- <div class="ons-page">
74
- ${component}
75
- </div>
76
- `;
75
+ <div class="ons-page">
76
+ ${component}
77
+ </div>
78
+ `;
77
79
  await setTestPage('/test', template);
78
80
  });
79
81
 
@@ -95,10 +97,10 @@ describe('script: timeout modal', () => {
95
97
  });
96
98
 
97
99
  const template = `
98
- <div class="ons-page">
99
- ${component}
100
- </div>
101
- `;
100
+ <div class="ons-page">
101
+ ${component}
102
+ </div>
103
+ `;
102
104
  await setTestPage('/test', template);
103
105
  });
104
106
 
@@ -120,10 +122,10 @@ describe('script: timeout modal', () => {
120
122
  });
121
123
 
122
124
  const template = `
123
- <div class="ons-page">
124
- ${component}
125
- </div>
126
- `;
125
+ <div class="ons-page">
126
+ ${component}
127
+ </div>
128
+ `;
127
129
  await setTestPage('/test', template);
128
130
  });
129
131
 
@@ -145,10 +147,10 @@ describe('script: timeout modal', () => {
145
147
  });
146
148
 
147
149
  const template = `
148
- <div class="ons-page">
149
- ${component}
150
- </div>
151
- `;
150
+ <div class="ons-page">
151
+ ${component}
152
+ </div>
153
+ `;
152
154
  await setTestPage('/test', template);
153
155
  });
154
156
 
@@ -170,10 +172,10 @@ describe('script: timeout modal', () => {
170
172
  });
171
173
 
172
174
  const template = `
173
- <div class="ons-page">
174
- ${component}
175
- </div>
176
- `;
175
+ <div class="ons-page">
176
+ ${component}
177
+ </div>
178
+ `;
177
179
  await setTestPage('/test', template);
178
180
  });
179
181
 
@@ -183,7 +185,7 @@ describe('script: timeout modal', () => {
183
185
  });
184
186
 
185
187
  it('then redirects to the provided `redirectUrl`', async () => {
186
- await page.waitForTimeout(2000);
188
+ await setTimeout(2000);
187
189
  expect(page.url()).toContain('#!');
188
190
  });
189
191
  });
@@ -197,10 +199,10 @@ describe('script: timeout modal', () => {
197
199
  });
198
200
 
199
201
  const template = `
200
- <div class="ons-page">
201
- ${component}
202
- </div>
203
- `;
202
+ <div class="ons-page">
203
+ ${component}
204
+ </div>
205
+ `;
204
206
 
205
207
  await setTestPage('/test', template);
206
208
  });
@@ -213,11 +215,14 @@ describe('script: timeout modal', () => {
213
215
 
214
216
  it('closes the modal', async () => {
215
217
  const modalIsVisible = await page.$eval('.ons-modal', (node) => node.classList.contains('ons-u-db'));
218
+
219
+ await setTimeout(50);
220
+
216
221
  expect(modalIsVisible).toBe(false);
217
222
  });
218
223
 
219
224
  it('restarts the timer and displays the modal after the correct number of seconds', async () => {
220
- await page.waitForTimeout(2000);
225
+ await setTimeout(2000);
221
226
  const modalIsVisible = await page.$eval('.ons-modal', (node) => node.classList.contains('ons-u-db'));
222
227
  expect(modalIsVisible).toBe(true);
223
228
  });
@@ -13,6 +13,8 @@ const EXAMPLE_TIMEOUT_PANEL_BASIC = {
13
13
  endWithFullStop: true,
14
14
  };
15
15
 
16
+ const { setTimeout } = require('node:timers/promises');
17
+
16
18
  describe('script: timeout panel', () => {
17
19
  describe('when the page loads', () => {
18
20
  beforeEach(async () => {
@@ -29,7 +31,7 @@ describe('script: timeout panel', () => {
29
31
 
30
32
  it('shows the time counting down', async () => {
31
33
  const timeAtStart = await page.$eval('.ons-js-timeout-timer', (element) => element.innerHTML);
32
- await page.waitForTimeout(1000);
34
+ await setTimeout(1000);
33
35
  const timeAfterOneSecond = await page.$eval('.ons-js-timeout-timer', (element) => element.innerHTML);
34
36
  expect(timeAfterOneSecond).not.toEqual(timeAtStart);
35
37
  });
@@ -130,7 +132,7 @@ describe('script: timeout panel', () => {
130
132
  });
131
133
 
132
134
  it('then redirects to the provided `redirectUrl`', async () => {
133
- await page.waitForTimeout(2000);
135
+ await setTimeout(2000);
134
136
  expect(page.url()).toContain('#!');
135
137
  });
136
138
  });
@@ -1,10 +1,13 @@
1
1
  import { renderComponent, setTestPage } from '../../tests/helpers/rendering';
2
2
 
3
+ const { setTimeout } = require('node:timers/promises');
4
+
3
5
  const EXAMPLE_VIDEO_YOUTUBE = {
4
6
  videoEmbedUrl: 'https://www.youtube.com/embed/_EGJlvkgbPo',
5
7
  title: 'Census 2021 promotional TV advert',
6
8
  linkText: 'Example link text',
7
9
  };
10
+
8
11
  const EXAMPLE_VIDEO_VIMEO = {
9
12
  videoEmbedUrl: 'https://player.vimeo.com/video/838454524?h=24551a3754',
10
13
  title: 'Vimeo Video',
@@ -14,112 +17,133 @@ const EXAMPLE_VIDEO_VIMEO = {
14
17
  const EXAMPLE_APPROVED_COOKIE = JSON.stringify({ campaigns: true }).replace(/"/g, "'");
15
18
 
16
19
  describe('script: video', () => {
17
- beforeEach(async () => {
18
- const client = await page.target().createCDPSession();
19
- await client.send('Network.clearBrowserCookies');
20
- });
21
-
22
- it('should show the placeholder content', async () => {
23
- await setTestPage('/test', renderComponent('video', EXAMPLE_VIDEO_YOUTUBE));
24
-
25
- const displayStyle = await page.$eval('.ons-js-video-placeholder', (node) =>
26
- window.getComputedStyle(node).getPropertyValue('display'),
27
- );
28
- expect(displayStyle).toBe('block');
29
- });
30
-
31
- it('should not show the iframe', async () => {
32
- await setTestPage('/test', renderComponent('video', EXAMPLE_VIDEO_YOUTUBE));
33
-
34
- const displayStyle = await page.$eval('.ons-js-video-iframe', (node) => window.getComputedStyle(node).getPropertyValue('display'));
35
- expect(displayStyle).toBe('none');
36
- });
37
-
38
- describe('when cookies are accepted on page load', () => {
20
+ describe('YouTube videos', () => {
39
21
  beforeEach(async () => {
40
- await page.setCookie({
41
- name: 'ons_cookie_policy',
42
- value: EXAMPLE_APPROVED_COOKIE,
43
- });
22
+ const client = await page.createCDPSession();
23
+ await client.send('Network.clearBrowserCookies');
24
+ });
44
25
 
26
+ it('should show the placeholder content', async () => {
45
27
  await setTestPage('/test', renderComponent('video', EXAMPLE_VIDEO_YOUTUBE));
46
- });
47
28
 
48
- it('should hide the placeholder content', async () => {
49
29
  const displayStyle = await page.$eval('.ons-js-video-placeholder', (node) =>
50
30
  window.getComputedStyle(node).getPropertyValue('display'),
51
31
  );
52
- expect(displayStyle).toBe('none');
53
- }, 10000);
32
+ expect(displayStyle).toBe('block');
33
+ });
34
+
35
+ it('should not show the iframe', async () => {
36
+ await setTestPage('/test', renderComponent('video', EXAMPLE_VIDEO_YOUTUBE));
54
37
 
55
- it('should show the iframe', async () => {
56
38
  const displayStyle = await page.$eval('.ons-js-video-iframe', (node) =>
57
39
  window.getComputedStyle(node).getPropertyValue('display'),
58
40
  );
59
- expect(displayStyle).toBe('block');
60
- }, 10000);
41
+ expect(displayStyle).toBe('none');
42
+ });
61
43
 
62
- it('should add the correct modifier class', async () => {
63
- const hasClass = await page.$eval('.ons-js-video', (node) => node.classList.contains('ons-video--hasIframe'));
64
- expect(hasClass).toBe(true);
65
- }, 10000);
44
+ describe('when cookies are accepted on page load', () => {
45
+ beforeEach(async () => {
46
+ await page.setCookie({
47
+ name: 'ons_cookie_policy',
48
+ value: EXAMPLE_APPROVED_COOKIE,
49
+ });
66
50
 
67
- it('should not add dnt to YouTube videos', async () => {
68
- const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
69
- expect(src.includes('?dnt=1')).toBe(false);
70
- }, 10000);
51
+ await setTestPage('/test', renderComponent('video', EXAMPLE_VIDEO_YOUTUBE));
52
+ });
71
53
 
72
- it('should add dnt to Vimeo videos', async () => {
73
- await setTestPage('/test', renderComponent('video', EXAMPLE_VIDEO_VIMEO));
54
+ it('should hide the placeholder content', async () => {
55
+ const displayStyle = await page.$eval('.ons-js-video-placeholder', (node) =>
56
+ window.getComputedStyle(node).getPropertyValue('display'),
57
+ );
58
+ expect(displayStyle).toBe('none');
59
+ }, 10000);
60
+
61
+ it('should show the iframe', async () => {
62
+ const displayStyle = await page.$eval('.ons-js-video-iframe', (node) =>
63
+ window.getComputedStyle(node).getPropertyValue('display'),
64
+ );
65
+ expect(displayStyle).toBe('block');
66
+ }, 10000);
67
+
68
+ it('should add the correct modifier class', async () => {
69
+ const hasClass = await page.$eval('.ons-js-video', (node) => node.classList.contains('ons-video--hasIframe'));
70
+ expect(hasClass).toBe(true);
71
+ }, 10000);
72
+
73
+ it('should not add dnt', async () => {
74
+ const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
75
+ expect(src.includes('?dnt=1')).toBe(false);
76
+ }, 10000);
77
+ });
74
78
 
75
- const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
76
- expect(src.includes('?dnt=1')).toBe(true);
77
- }, 10000);
78
- });
79
+ describe('when cookies are accepted via banner', () => {
80
+ beforeEach(async () => {
81
+ await setTestPage(
82
+ '/test',
83
+ `${renderComponent('video', EXAMPLE_VIDEO_YOUTUBE)}
84
+ <div class="ons-cookies-banner ons-u-db"><button class="ons-js-accept-cookies">Accept</button></div>`,
85
+ );
86
+ await page.click('.ons-js-accept-cookies');
87
+ });
79
88
 
80
- describe('when cookies are accepted via banner', () => {
81
- beforeEach(async () => {
82
- await setTestPage(
83
- '/test',
84
- `${renderComponent('video', EXAMPLE_VIDEO_YOUTUBE)}
85
- <div class="ons-cookies-banner ons-u-db"><button class="ons-js-accept-cookies">Accept</button></div>`,
86
- );
87
- await page.click('.ons-js-accept-cookies');
88
- });
89
+ it('should hide the placeholder content', async () => {
90
+ const displayStyle = await page.$eval('.ons-js-video-placeholder', (node) =>
91
+ window.getComputedStyle(node).getPropertyValue('display'),
92
+ );
93
+ expect(displayStyle).toBe('none');
94
+ });
89
95
 
90
- it('should hide the placeholder content', async () => {
91
- const displayStyle = await page.$eval('.ons-js-video-placeholder', (node) =>
92
- window.getComputedStyle(node).getPropertyValue('display'),
93
- );
94
- expect(displayStyle).toBe('none');
96
+ it('should show the iframe', async () => {
97
+ const displayStyle = await page.$eval('.ons-js-video-iframe', (node) =>
98
+ window.getComputedStyle(node).getPropertyValue('display'),
99
+ );
100
+ expect(displayStyle).toBe('block');
101
+ });
102
+
103
+ it('should add the correct modifier class', async () => {
104
+ const hasClass = await page.$eval('.ons-js-video', (node) => node.classList.contains('ons-video--hasIframe'));
105
+ expect(hasClass).toBe(true);
106
+ }, 10000);
107
+
108
+ it('should not add dnt', async () => {
109
+ const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
110
+ expect(src.includes('?dnt=1')).toBe(false);
111
+ }, 10000);
95
112
  });
113
+ });
96
114
 
97
- it('should show the iframe', async () => {
98
- const displayStyle = await page.$eval('.ons-js-video-iframe', (node) =>
99
- window.getComputedStyle(node).getPropertyValue('display'),
100
- );
101
- expect(displayStyle).toBe('block');
115
+ describe('Vimeo videos', () => {
116
+ describe('when cookies are accepted on page load', () => {
117
+ it('should add dnt', async () => {
118
+ await page.setCookie({
119
+ name: 'ons_cookie_policy',
120
+ value: EXAMPLE_APPROVED_COOKIE,
121
+ });
122
+ await setTestPage('/test', renderComponent('video', EXAMPLE_VIDEO_VIMEO));
123
+
124
+ const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
125
+
126
+ await setTimeout(100);
127
+
128
+ expect(src.includes('?dnt=1')).toBe(true);
129
+ }, 10000);
102
130
  });
103
131
 
104
- it('should add the correct modifier class', async () => {
105
- const hasClass = await page.$eval('.ons-js-video', (node) => node.classList.contains('ons-video--hasIframe'));
106
- expect(hasClass).toBe(true);
107
- }, 10000);
108
- it('should not add dnt to YouTube videos', async () => {
109
- const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
110
- expect(src.includes('?dnt=1')).toBe(false);
111
- }, 10000);
112
-
113
- it('should add dnt to Vimeo videos', async () => {
114
- await setTestPage(
115
- '/test',
116
- `${renderComponent('video', EXAMPLE_VIDEO_VIMEO)}
117
- <div class="ons-cookies-banner ons-u-db"><button class="ons-js-accept-cookies">Accept</button></div>`,
118
- );
119
- await page.click('.ons-js-accept-cookies');
132
+ describe('when cookies are accepted on page load', () => {
133
+ it('when cookies are accepted via banner, should add dnt', async () => {
134
+ await setTestPage(
135
+ '/test',
136
+ `${renderComponent('video', EXAMPLE_VIDEO_VIMEO)}
137
+ <div class="ons-cookies-banner ons-u-db"><button class="ons-js-accept-cookies">Accept</button></div>`,
138
+ );
139
+ await page.click('.ons-js-accept-cookies');
120
140
 
121
- const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
122
- expect(src.includes('?dnt=1')).toBe(true);
123
- }, 10000);
141
+ const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
142
+
143
+ await setTimeout(100);
144
+
145
+ expect(src.includes('?dnt=1')).toBe(true);
146
+ }, 10000);
147
+ });
124
148
  });
125
149
  });
@@ -38,7 +38,7 @@ const EXAMPLE_PART_COOKIES_SETTINGS_PAGE = `
38
38
 
39
39
  describe('script: cookies-settings', () => {
40
40
  beforeEach(async () => {
41
- const client = await page.target().createCDPSession();
41
+ const client = await page.createCDPSession();
42
42
  await client.send('Network.clearBrowserCookies');
43
43
  });
44
44
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ons/design-system",
3
3
  "description": "ONS Design System built CSS, JS, and Nunjucks templates",
4
- "version": "70.0.12",
4
+ "version": "70.0.14",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -11,6 +11,7 @@
11
11
  "start": "gulp start",
12
12
  "watch": "gulp watch",
13
13
  "test": "gulp build-assets && TEST_PORT=3020 TEST_WITH_PUPPETEER=1 jest '.*\\.spec\\.js'",
14
+ "test:clear-cache": "jest --clearCache",
14
15
  "test:no-build": "TEST_PORT=3020 TEST_WITH_PUPPETEER=1 jest '.*\\.spec\\.js'",
15
16
  "test:with-log": "yarn test --no-color 2>test.log",
16
17
  "test:start-server": "TEST_PORT=3020 gulp start-dev-server",
@@ -98,7 +99,7 @@
98
99
  "jest": "^29.6.1",
99
100
  "jest-axe": "^8.0.0",
100
101
  "jest-environment-jsdom": "^29.6.1",
101
- "jest-puppeteer": "^9.0.0",
102
+ "jest-puppeteer": "^10.0.0",
102
103
  "lighthouse": "^11.0.0",
103
104
  "lint-staged": "^15.2.0",
104
105
  "lodash": "^4.17.21",
@@ -111,7 +112,7 @@
111
112
  "prepend-file": "^2.0.1",
112
113
  "prettier": "^3.2.5",
113
114
  "prettier-plugin-jinja-template": "^1.4.0",
114
- "puppeteer": "^21.0.2",
115
+ "puppeteer": "^22.0.0",
115
116
  "remark-cli": "^12.0.0",
116
117
  "remark-lint": "^9.1.2",
117
118
  "remark-preset-lint-recommended": "^6.1.3",