@comicrelief/component-library 8.53.1 → 8.53.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. package/dist/components/Atoms/Picture/Picture.js +1 -0
  2. package/dist/components/Molecules/CTA/CTAMultiCard/__snapshots__/CTAMultiCard.test.js.snap +48 -24
  3. package/dist/components/Molecules/CTA/CTASingleCard/__snapshots__/CTASingleCard.test.js.snap +128 -96
  4. package/dist/components/Molecules/CTA/shared/CTACard.js +2 -1
  5. package/dist/components/Organisms/DynamicGallery/DynamicGallery.js +43 -24
  6. package/dist/components/Organisms/DynamicGallery/DynamicGallery.md +1 -1
  7. package/dist/components/Organisms/DynamicGallery/DynamicGallery.style.js +29 -16
  8. package/dist/components/Organisms/DynamicGallery/_DynamicGalleryColumn.js +8 -3
  9. package/dist/components/Organisms/DynamicGallery/_Lightbox.js +45 -24
  10. package/dist/components/Organisms/DynamicGallery/_Lightbox.style.js +7 -11
  11. package/dist/components/Organisms/DynamicGallery/__snapshots__/DynamicGallery.test.js.snap +254 -216
  12. package/package.json +1 -1
  13. package/playwright/components/organisms/dynamicGallery.spec.js +222 -1
  14. package/src/components/Atoms/Picture/Picture.js +1 -0
  15. package/src/components/Molecules/CTA/CTAMultiCard/__snapshots__/CTAMultiCard.test.js.snap +48 -24
  16. package/src/components/Molecules/CTA/CTASingleCard/__snapshots__/CTASingleCard.test.js.snap +128 -96
  17. package/src/components/Molecules/CTA/shared/CTACard.js +2 -1
  18. package/src/components/Organisms/DynamicGallery/DynamicGallery.js +48 -25
  19. package/src/components/Organisms/DynamicGallery/DynamicGallery.md +1 -1
  20. package/src/components/Organisms/DynamicGallery/DynamicGallery.style.js +23 -1
  21. package/src/components/Organisms/DynamicGallery/_DynamicGalleryColumn.js +8 -3
  22. package/src/components/Organisms/DynamicGallery/_Lightbox.js +36 -19
  23. package/src/components/Organisms/DynamicGallery/_Lightbox.style.js +16 -29
  24. package/src/components/Organisms/DynamicGallery/__snapshots__/DynamicGallery.test.js.snap +254 -216
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@comicrelief/component-library",
3
3
  "author": "Comic Relief Engineering Team",
4
- "version": "8.53.1",
4
+ "version": "8.53.3",
5
5
  "main": "dist/index.js",
6
6
  "license": "ISC",
7
7
  "jest": {
@@ -1,9 +1,230 @@
1
1
  const { test, expect } = require('@playwright/test');
2
2
 
3
+ function hexToRgb(hex) {
4
+ // Remove the '#' if it's included in the input
5
+ const hexValue = hex.replace(/^#/, '');
6
+
7
+ // Parse the hex values into separate R, G, and B values
8
+ const red = parseInt(hexValue.substring(0, 2), 16);
9
+ const green = parseInt(hexValue.substring(2, 4), 16);
10
+ const blue = parseInt(hexValue.substring(4, 6), 16);
11
+
12
+ return `rgb(${red}, ${green}, ${blue})`;
13
+ }
14
+
3
15
  test.describe('dynamic gallery component', () => {
4
- test('dynamic gallery', async ({ page }) => {
16
+ test('smoke test', async ({ page }) => {
5
17
  await page.goto('/#dynamicgallery');
6
18
 
7
19
  await page.close();
8
20
  });
21
+
22
+ test('gallery column props', async ({ page }) => {
23
+ await page.goto('/#!/DynamicGallery/5');
24
+
25
+ // expect three gallery columns
26
+ await expect(page.locator('.gallery-column')).toHaveCount(4);
27
+
28
+ await page.close();
29
+ });
30
+
31
+ test('responsive gallery columns', async ({ page }) => {
32
+ await page.goto('/#!/DynamicGallery/3');
33
+
34
+ // expect three gallery columns
35
+ await expect(page.locator('.gallery-column')).toHaveCount(3);
36
+
37
+ // resize the page to a small width
38
+ await page.setViewportSize({ width: 700, height: 1000 });
39
+
40
+ // expect one gallery column
41
+ await expect(page.locator('.gallery-column')).toHaveCount(2);
42
+
43
+ // resize the page to a medium width
44
+ await page.setViewportSize({ width: 320, height: 1000 });
45
+
46
+ // expect one gallery column
47
+ await expect(page.locator('.gallery-column')).toHaveCount(1);
48
+
49
+ await page.close();
50
+ });
51
+
52
+ test('chunk mode test', async ({ page }) => {
53
+ await page.goto('/#!/DynamicGallery/3');
54
+
55
+ // expect 25 images to be visible
56
+ await expect(page.locator('.gallery-node')).toHaveCount(25);
57
+
58
+ // find the "load more" button and click it
59
+ await page.locator('button:has-text("Show more")').click();
60
+
61
+ // expect 50 images to be visible
62
+ await expect(page.locator('.gallery-node')).toHaveCount(50);
63
+
64
+ // expect the "load more" button to be hidden
65
+ await expect(page.locator('button:has-text("Show more")')).toBeHidden();
66
+
67
+ await page.close();
68
+ });
69
+
70
+ test('non-chunk mode test', async ({ page }) => {
71
+ await page.goto('/#!/DynamicGallery/5');
72
+
73
+ // expect all 30 images to be visible
74
+ await expect(page.locator('.gallery-node')).toHaveCount(30);
75
+
76
+ // expect the "load more" button to be hidden
77
+ await expect(page.locator('button:has-text("Show more")')).toBeHidden();
78
+
79
+ await page.close();
80
+ });
81
+
82
+ test('gallery tabbing', async ({ page }) => {
83
+ await page.goto('/#!/DynamicGallery/3');
84
+
85
+ // focus the first gallery node
86
+ await page.locator('.gallery-node').first().focus();
87
+
88
+ await page.waitForTimeout(3000);
89
+
90
+ // first tab should focus the first node in the first column
91
+ const firstNode = page.locator('.gallery-column').first().locator('.gallery-node').first();
92
+ await firstNode.focus();
93
+ await expect(firstNode).toBeFocused();
94
+
95
+ // tab to the first node in the second column
96
+ await page.keyboard.press('Tab');
97
+ const secondNode = page.locator('.gallery-column').nth(1).locator('.gallery-node').first();
98
+ await expect(secondNode).toBeFocused();
99
+
100
+ // tab back to the first node in the first column
101
+ await page.keyboard.press('Shift+Tab');
102
+ await expect(firstNode).toBeFocused();
103
+
104
+ await page.close();
105
+ });
106
+
107
+ test('gallery tabbing should allow tabbing out of the gallery', async ({ page }) => {
108
+ await page.goto('/#!/DynamicGallery/5');
109
+
110
+ await page.waitForTimeout(3000);
111
+
112
+ // focus the first gallery node
113
+ const galleryNodes = await page.locator('.gallery-node').all();
114
+ await page.locator(`[data-node-index="${galleryNodes.length - 1}"]`).focus();
115
+
116
+ // press tab
117
+ await page.keyboard.press('Tab');
118
+ const galleryContainer = page.locator('.gallery-container');
119
+
120
+ // asset that the focus has moved outside the gallery
121
+ expect(
122
+ await galleryContainer.evaluate(
123
+ el => !el.contains(document.activeElement)
124
+ )
125
+ ).toBe(true);
126
+ await page.close();
127
+ });
128
+
129
+ test('custom page background and text colour', async ({ page }) => {
130
+ await page.goto('/#!/DynamicGallery/5');
131
+
132
+ const galleryContainer = page.locator('.gallery-container');
133
+
134
+ const backgroundColor = await galleryContainer.evaluate(el => window.getComputedStyle(el).getPropertyValue('background-color'));
135
+ expect(backgroundColor).toBe(hexToRgb('#0565D1'));
136
+
137
+ const textColor = await galleryContainer.evaluate(el => window.getComputedStyle(el).getPropertyValue('color'));
138
+ expect(textColor).toBe(hexToRgb('#FFFFFF'));
139
+
140
+ await page.close();
141
+ });
142
+
143
+ test('check lightbox mode', async ({ page }) => {
144
+ await page.goto('/#!/DynamicGallery/3');
145
+
146
+ // find the first gallery node
147
+ const galleryNode = page.locator('.gallery-node').first();
148
+
149
+ // click it
150
+ await galleryNode.click();
151
+
152
+ // expect the lightbox to be visible
153
+ await expect(page.locator('dialog')).toBeVisible();
154
+
155
+ await page.waitForTimeout(1000);
156
+ await page.keyboard.press('Escape');
157
+ await expect(page.locator('dialog')).toBeHidden();
158
+
159
+ // focus the gallery node and press enter
160
+ await galleryNode.focus();
161
+ await page.keyboard.press('Enter');
162
+
163
+ // expect the lightbox to be visible
164
+ await expect(page.locator('dialog')).toBeVisible();
165
+
166
+ await page.close();
167
+ });
168
+
169
+ test('lightbox navigation', async ({ page }) => {
170
+ await page.goto('/#!/DynamicGallery/3');
171
+
172
+ // find the first gallery node
173
+ const galleryNode = page.locator('.gallery-node').first();
174
+
175
+ // click it
176
+ await galleryNode.click();
177
+
178
+ // expect the lightbox and caption to be visible
179
+ await expect(page.locator('dialog')).toBeVisible();
180
+ await expect(page.getByText('Lightbox: This is the body for image 0')).toBeVisible();
181
+
182
+ await page.waitForTimeout(1000);
183
+
184
+ // navigate to the next image
185
+ await page.keyboard.press('ArrowRight');
186
+ await expect(page.getByText('Lightbox: This is the body for image 1')).toBeVisible();
187
+
188
+ await page.close();
189
+ });
190
+
191
+ test('lightbox pointer close', async ({ page }) => {
192
+ await page.goto('/#!/DynamicGallery/3');
193
+
194
+ // find the first gallery node
195
+ const galleryNode = page.locator('.gallery-node').first();
196
+
197
+ // click it
198
+ await galleryNode.click();
199
+
200
+ // click the close button
201
+ await page.locator('.close-button').click();
202
+
203
+ // expect the lightbox to be hidden
204
+ await expect(page.locator('dialog')).toBeHidden();
205
+
206
+ await page.close();
207
+ });
208
+
209
+ test('check non-lightbox mode', async ({ page }) => {
210
+ await page.goto('/#!/DynamicGallery/5');
211
+
212
+ // find the first gallery node
213
+ const galleryNode = page.locator('.gallery-node').first();
214
+
215
+ // click it
216
+ await galleryNode.click();
217
+
218
+ // expect the lightbox to be hidden
219
+ await expect(page.locator('dialog')).toBeHidden();
220
+
221
+ // focus the gallery node and press enter
222
+ await galleryNode.focus();
223
+ await page.keyboard.press('Enter');
224
+
225
+ // expect the lightbox to be hidden
226
+ await expect(page.locator('dialog')).toBeHidden();
227
+
228
+ await page.close();
229
+ });
9
230
  });
@@ -109,6 +109,7 @@ const Picture = ({
109
109
  {...rest}
110
110
  >
111
111
  <Image
112
+ key={image}
112
113
  alt={alt}
113
114
  height={height}
114
115
  width={width}
@@ -17,10 +17,12 @@ exports[`handles data structure correctly 1`] = `
17
17
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 iSFtcX"
18
18
  >
19
19
  <a
20
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
20
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
21
+ color="red"
21
22
  href="/test"
22
23
  rel={null}
23
- target="self"
24
+ target="_self"
25
+ type="standard"
24
26
  >
25
27
  <div
26
28
  className="CTACardstyle__ImageWrapper-sc-si8xx1-0 etphrL"
@@ -148,10 +150,12 @@ exports[`handles data structure correctly 1`] = `
148
150
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 iSFtcX"
149
151
  >
150
152
  <a
151
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
153
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
154
+ color="red"
152
155
  href="/test"
153
156
  rel={null}
154
- target="self"
157
+ target="_self"
158
+ type="standard"
155
159
  >
156
160
  <div
157
161
  className="CTACardstyle__ImageWrapper-sc-si8xx1-0 etphrL"
@@ -233,10 +237,12 @@ exports[`handles data structure correctly 1`] = `
233
237
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 iSFtcX"
234
238
  >
235
239
  <a
236
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
240
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
241
+ color="red"
237
242
  href="/test-no-image"
238
243
  rel={null}
239
- target="self"
244
+ target="_self"
245
+ type="standard"
240
246
  >
241
247
  <div
242
248
  className="CTACardstyle__CopyAndLinkSection-sc-si8xx1-7 cCIYkv"
@@ -312,10 +318,12 @@ exports[`renders 2 columns layout correctly 1`] = `
312
318
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 gBbrVV"
313
319
  >
314
320
  <a
315
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
321
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
322
+ color="red"
316
323
  href="/test"
317
324
  rel={null}
318
- target="self"
325
+ target="_self"
326
+ type="standard"
319
327
  >
320
328
  <div
321
329
  className="CTACardstyle__ImageWrapper-sc-si8xx1-0 etphrL"
@@ -443,10 +451,12 @@ exports[`renders 2 columns layout correctly 1`] = `
443
451
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 gBbrVV"
444
452
  >
445
453
  <a
446
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
454
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
455
+ color="red"
447
456
  href="/test"
448
457
  rel={null}
449
- target="self"
458
+ target="_self"
459
+ type="standard"
450
460
  >
451
461
  <div
452
462
  className="CTACardstyle__ImageWrapper-sc-si8xx1-0 etphrL"
@@ -528,10 +538,12 @@ exports[`renders 2 columns layout correctly 1`] = `
528
538
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 gBbrVV"
529
539
  >
530
540
  <a
531
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
541
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
542
+ color="red"
532
543
  href="/test-no-image"
533
544
  rel={null}
534
- target="self"
545
+ target="_self"
546
+ type="standard"
535
547
  >
536
548
  <div
537
549
  className="CTACardstyle__CopyAndLinkSection-sc-si8xx1-7 cCIYkv"
@@ -607,10 +619,12 @@ exports[`renders carousel mode correctly 1`] = `
607
619
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 kNLFm"
608
620
  >
609
621
  <a
610
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
622
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
623
+ color="red"
611
624
  href="/test"
612
625
  rel={null}
613
- target="self"
626
+ target="_self"
627
+ type="standard"
614
628
  >
615
629
  <div
616
630
  className="CTACardstyle__ImageWrapper-sc-si8xx1-0 etphrL"
@@ -738,10 +752,12 @@ exports[`renders carousel mode correctly 1`] = `
738
752
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 kNLFm"
739
753
  >
740
754
  <a
741
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
755
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
756
+ color="red"
742
757
  href="/test"
743
758
  rel={null}
744
- target="self"
759
+ target="_self"
760
+ type="standard"
745
761
  >
746
762
  <div
747
763
  className="CTACardstyle__ImageWrapper-sc-si8xx1-0 etphrL"
@@ -823,10 +839,12 @@ exports[`renders carousel mode correctly 1`] = `
823
839
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 kNLFm"
824
840
  >
825
841
  <a
826
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
842
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
843
+ color="red"
827
844
  href="/test-no-image"
828
845
  rel={null}
829
- target="self"
846
+ target="_self"
847
+ type="standard"
830
848
  >
831
849
  <div
832
850
  className="CTACardstyle__CopyAndLinkSection-sc-si8xx1-7 cCIYkv"
@@ -902,10 +920,12 @@ exports[`renders correctly with data prop 1`] = `
902
920
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 kNLFm"
903
921
  >
904
922
  <a
905
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
923
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
924
+ color="red"
906
925
  href="/test"
907
926
  rel={null}
908
- target="self"
927
+ target="_self"
928
+ type="standard"
909
929
  >
910
930
  <div
911
931
  className="CTACardstyle__ImageWrapper-sc-si8xx1-0 etphrL"
@@ -1033,10 +1053,12 @@ exports[`renders correctly with data prop 1`] = `
1033
1053
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 kNLFm"
1034
1054
  >
1035
1055
  <a
1036
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
1056
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
1057
+ color="red"
1037
1058
  href="/test"
1038
1059
  rel={null}
1039
- target="self"
1060
+ target="_self"
1061
+ type="standard"
1040
1062
  >
1041
1063
  <div
1042
1064
  className="CTACardstyle__ImageWrapper-sc-si8xx1-0 etphrL"
@@ -1118,10 +1140,12 @@ exports[`renders correctly with data prop 1`] = `
1118
1140
  className="CTACardstyle__CardWrapper-sc-si8xx1-6 kNLFm"
1119
1141
  >
1120
1142
  <a
1121
- className="CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
1143
+ className="Linkstyle__StyledLink-sc-t360tr-1 iydhqO CTACardstyle__CardLink-sc-si8xx1-5 jlRIUG"
1144
+ color="red"
1122
1145
  href="/test-no-image"
1123
1146
  rel={null}
1124
- target="self"
1147
+ target="_self"
1148
+ type="standard"
1125
1149
  >
1126
1150
  <div
1127
1151
  className="CTACardstyle__CopyAndLinkSection-sc-si8xx1-7 cCIYkv"