Skip to content

Commit d6897ec

Browse files
committed
Add DateTime context to tests where required
1 parent 55326a5 commit d6897ec

5 files changed

Lines changed: 133 additions & 96 deletions

File tree

dotcom-rendering/src/components/ArticleMeta.web.test.tsx

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { interactiveLegacyClasses } from '../layouts/lib/interactiveLegacyStylin
33
import { ArticleDesign, ArticleDisplay, Pillar } from '../lib/articleFormat';
44
import { ArticleMeta, shouldShowContributor } from './ArticleMeta.web';
55
import { ConfigProvider } from './ConfigContext';
6+
import { DateTimeProvider } from './DateTimeContext';
67

78
jest.mock('../lib/bridgetApi', () => jest.fn());
89
jest.mock('../lib/useMatchMedia', () => ({
@@ -25,24 +26,26 @@ describe('ArticleMeta', () => {
2526
editionId: 'UK',
2627
}}
2728
>
28-
<ArticleMeta
29-
format={format}
30-
pageId="1234"
31-
webTitle="A title"
32-
byline="Observer writers"
33-
tags={[
34-
{
35-
id: 'lifeandstyle/series/observer-design',
36-
type: 'Series',
37-
title: 'Observer Design',
38-
},
39-
]}
40-
primaryDateline="primary date line"
41-
secondaryDateline="secondary date line"
42-
isCommentable={false}
43-
discussionApiUrl=""
44-
shortUrlId=""
45-
/>
29+
<DateTimeProvider value={Date.now()}>
30+
<ArticleMeta
31+
format={format}
32+
pageId="1234"
33+
webTitle="A title"
34+
byline="Observer writers"
35+
tags={[
36+
{
37+
id: 'lifeandstyle/series/observer-design',
38+
type: 'Series',
39+
title: 'Observer Design',
40+
},
41+
]}
42+
primaryDateline="primary date line"
43+
secondaryDateline="secondary date line"
44+
isCommentable={false}
45+
discussionApiUrl=""
46+
shortUrlId=""
47+
/>
48+
</DateTimeProvider>
4649
</ConfigProvider>,
4750
);
4851

@@ -72,24 +75,26 @@ describe('ArticleMeta', () => {
7275
editionId: 'UK',
7376
}}
7477
>
75-
<ArticleMeta
76-
format={format}
77-
pageId="1234"
78-
webTitle="A title"
79-
byline="Observer writers"
80-
tags={[
81-
{
82-
id: 'lifeandstyle/series/observer-design',
83-
type: 'Series',
84-
title: 'Observer Design',
85-
},
86-
]}
87-
primaryDateline="primary date line"
88-
secondaryDateline="secondary date line"
89-
isCommentable={false}
90-
discussionApiUrl=""
91-
shortUrlId=""
92-
/>
78+
<DateTimeProvider value={Date.now()}>
79+
<ArticleMeta
80+
format={format}
81+
pageId="1234"
82+
webTitle="A title"
83+
byline="Observer writers"
84+
tags={[
85+
{
86+
id: 'lifeandstyle/series/observer-design',
87+
type: 'Series',
88+
title: 'Observer Design',
89+
},
90+
]}
91+
primaryDateline="primary date line"
92+
secondaryDateline="secondary date line"
93+
isCommentable={false}
94+
discussionApiUrl=""
95+
shortUrlId=""
96+
/>
97+
</DateTimeProvider>
9398
</ConfigProvider>,
9499
);
95100

dotcom-rendering/src/components/Island.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { BrazeMessaging } from './BrazeMessaging.importable';
1212
import { CardCommentCount } from './CardCommentCount.importable';
1313
import { CommentCount } from './CommentCount.importable';
1414
import { ConfigProvider } from './ConfigContext';
15+
import { DateTimeProvider } from './DateTimeContext';
1516
import { DiscussionLayout } from './DiscussionLayout';
1617
import { DiscussionMeta } from './DiscussionMeta.importable';
1718
import { EnhanceAffiliateLinks } from './EnhanceAffiliateLinks.importable';
@@ -102,7 +103,7 @@ describe('Island: server-side rendering', () => {
102103
editionId: 'UK',
103104
}}
104105
>
105-
{children}
106+
<DateTimeProvider value={Date.now()}>{children}</DateTimeProvider>
106107
</ConfigProvider>
107108
);
108109

dotcom-rendering/src/components/IslandContext.test.tsx

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,74 @@
11
import { render } from '@testing-library/react';
2+
import { DateTimeProvider } from './DateTimeContext';
23
import { Island } from './Island';
34

45
describe('IslandContext tracks nesting of islands', () => {
56
test('Single island', () => {
67
const { container } = render(
7-
<Island priority="feature" defer={{ until: 'visible' }}>
8-
<span>🏝️</span>
9-
</Island>,
8+
<DateTimeProvider value={Date.now()}>
9+
<Island priority="feature" defer={{ until: 'visible' }}>
10+
<span>🏝️</span>
11+
</Island>
12+
,
13+
</DateTimeProvider>,
1014
);
1115
const islands = container.querySelectorAll('gu-island');
1216
expect(islands.length).toBe(1);
1317
});
1418

1519
test('Nested island', () => {
1620
const { container } = render(
17-
<Island priority="feature" defer={{ until: 'visible' }}>
18-
<div>
19-
<Island priority="feature" defer={{ until: 'visible' }}>
20-
<span>🏝️</span>
21-
</Island>
22-
</div>
23-
</Island>,
21+
<DateTimeProvider value={Date.now()}>
22+
<Island priority="feature" defer={{ until: 'visible' }}>
23+
<div>
24+
<Island priority="feature" defer={{ until: 'visible' }}>
25+
<span>🏝️</span>
26+
</Island>
27+
</div>
28+
</Island>
29+
,
30+
</DateTimeProvider>,
2431
);
2532
const islands = container.querySelectorAll('gu-island');
2633
expect(islands.length).toBe(1);
2734
});
2835

2936
test('Multiple nested islands', () => {
3037
const { container } = render(
31-
<Island priority="critical">
32-
<div>
33-
<Island priority="critical">
34-
<div>
35-
<Island priority="critical">
36-
<span>🏝️</span>
37-
</Island>
38-
<Island priority="critical">
39-
<span>🏝️</span>
40-
</Island>
41-
</div>
42-
</Island>
43-
</div>
44-
</Island>,
38+
<DateTimeProvider value={Date.now()}>
39+
<Island priority="critical">
40+
<div>
41+
<Island priority="critical">
42+
<div>
43+
<Island priority="critical">
44+
<span>🏝️</span>
45+
</Island>
46+
<Island priority="critical">
47+
<span>🏝️</span>
48+
</Island>
49+
</div>
50+
</Island>
51+
</div>
52+
</Island>
53+
,
54+
</DateTimeProvider>,
4555
);
4656
const islands = container.querySelectorAll('gu-island');
4757
expect(islands.length).toBe(1);
4858
});
4959

5060
test('Parent island includes props for child islands', () => {
5161
const { container } = render(
52-
<Island priority="feature" defer={{ until: 'visible' }}>
53-
<div>
54-
<Island priority="feature" defer={{ until: 'visible' }}>
55-
<span className="archipelago">🏝️</span>
56-
</Island>
57-
</div>
58-
</Island>,
62+
<DateTimeProvider value={Date.now()}>
63+
<Island priority="feature" defer={{ until: 'visible' }}>
64+
<div>
65+
<Island priority="feature" defer={{ until: 'visible' }}>
66+
<span className="archipelago">🏝️</span>
67+
</Island>
68+
</div>
69+
</Island>
70+
,
71+
</DateTimeProvider>,
5972
);
6073
const island = container.querySelector('gu-island');
6174
expect(island).toHaveAttribute(

dotcom-rendering/src/components/MostViewedFooter.test.tsx

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { fireEvent, render } from '@testing-library/react';
22
import { useApi as useApi_ } from '../lib/useApi';
33
import { ConfigProvider } from './ConfigContext';
4+
import { DateTimeProvider } from './DateTimeContext';
45
import { responseWithTwoTabs } from './MostViewed.mocks';
56
import { MostViewedFooterData } from './MostViewedFooterData.importable';
67

@@ -30,11 +31,13 @@ describe('MostViewedFooterData', () => {
3031
editionId: 'UK',
3132
}}
3233
>
33-
<MostViewedFooterData
34-
sectionId="Section Name"
35-
ajaxUrl="https://api.nextgen.guardianapps.co.uk"
36-
edition="UK"
37-
/>
34+
<DateTimeProvider value={Date.now()}>
35+
<MostViewedFooterData
36+
sectionId="Section Name"
37+
ajaxUrl="https://api.nextgen.guardianapps.co.uk"
38+
edition="UK"
39+
/>
40+
</DateTimeProvider>
3841
</ConfigProvider>,
3942
);
4043

@@ -73,11 +76,13 @@ describe('MostViewedFooterData', () => {
7376
editionId: 'UK',
7477
}}
7578
>
76-
<MostViewedFooterData
77-
sectionId="Section Name"
78-
ajaxUrl="https://api.nextgen.guardianapps.co.uk"
79-
edition="UK"
80-
/>
79+
<DateTimeProvider value={Date.now()}>
80+
<MostViewedFooterData
81+
sectionId="Section Name"
82+
ajaxUrl="https://api.nextgen.guardianapps.co.uk"
83+
edition="UK"
84+
/>
85+
</DateTimeProvider>
8186
</ConfigProvider>,
8287
);
8388

@@ -135,11 +140,13 @@ describe('MostViewedFooterData', () => {
135140
editionId: 'UK',
136141
}}
137142
>
138-
<MostViewedFooterData
139-
sectionId="Section Name"
140-
ajaxUrl="https://api.nextgen.guardianapps.co.uk"
141-
edition="UK"
142-
/>
143+
<DateTimeProvider value={Date.now()}>
144+
<MostViewedFooterData
145+
sectionId="Section Name"
146+
ajaxUrl="https://api.nextgen.guardianapps.co.uk"
147+
edition="UK"
148+
/>
149+
</DateTimeProvider>
143150
</ConfigProvider>,
144151
);
145152

@@ -182,11 +189,13 @@ describe('MostViewedFooterData', () => {
182189
editionId: 'UK',
183190
}}
184191
>
185-
<MostViewedFooterData
186-
sectionId="Section Name"
187-
ajaxUrl="https://api.nextgen.guardianapps.co.uk"
188-
edition="UK"
189-
/>
192+
<DateTimeProvider value={Date.now()}>
193+
<MostViewedFooterData
194+
sectionId="Section Name"
195+
ajaxUrl="https://api.nextgen.guardianapps.co.uk"
196+
edition="UK"
197+
/>
198+
</DateTimeProvider>
190199
</ConfigProvider>,
191200
);
192201

@@ -205,11 +214,13 @@ describe('MostViewedFooterData', () => {
205214
editionId: 'UK',
206215
}}
207216
>
208-
<MostViewedFooterData
209-
sectionId="Section Name"
210-
ajaxUrl="https://api.nextgen.guardianapps.co.uk"
211-
edition="UK"
212-
/>
217+
<DateTimeProvider value={Date.now()}>
218+
<MostViewedFooterData
219+
sectionId="Section Name"
220+
ajaxUrl="https://api.nextgen.guardianapps.co.uk"
221+
edition="UK"
222+
/>
223+
</DateTimeProvider>
213224
</ConfigProvider>,
214225
);
215226

dotcom-rendering/src/components/MostViewedRight.test.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { render } from '@testing-library/react';
22
import { useApi as useApi_ } from '../lib/useApi';
33
import { ConfigProvider } from './ConfigContext';
4+
import { DateTimeProvider } from './DateTimeContext';
45
import { responseWithTwoTabs } from './MostViewed.mocks';
56
import { MostViewedRight } from './MostViewedRight';
67

@@ -27,7 +28,9 @@ describe('MostViewedList', () => {
2728
editionId: 'UK',
2829
}}
2930
>
30-
<MostViewedRight />
31+
<DateTimeProvider value={Date.now()}>
32+
<MostViewedRight />
33+
</DateTimeProvider>
3134
</ConfigProvider>,
3235
);
3336

@@ -77,7 +80,9 @@ describe('MostViewedList', () => {
7780
editionId: 'UK',
7881
}}
7982
>
80-
<MostViewedRight limitItems={3} />
83+
<DateTimeProvider value={Date.now()}>
84+
<MostViewedRight limitItems={3} />
85+
</DateTimeProvider>
8186
</ConfigProvider>,
8287
);
8388

@@ -106,7 +111,9 @@ describe('MostViewedList', () => {
106111
editionId: 'UK',
107112
}}
108113
>
109-
<MostViewedRight />
114+
<DateTimeProvider value={Date.now()}>
115+
<MostViewedRight />
116+
</DateTimeProvider>
110117
</ConfigProvider>,
111118
);
112119

0 commit comments

Comments
 (0)