@times-components/ts-components 1.24.0 → 1.26.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/CHANGELOG.md +35 -0
- package/dist/__mocks__/isomorphic-unfetch.d.ts +3 -0
- package/dist/__mocks__/isomorphic-unfetch.js +4 -0
- package/dist/components/article-flag/LiveArticleFlag.js +5 -5
- package/dist/components/article-flag/styles.d.ts +4 -3
- package/dist/components/article-flag/styles.js +30 -26
- package/dist/components/article-header/ArticleHeader.js +11 -2
- package/dist/components/common-styles.d.ts +13 -0
- package/dist/components/common-styles.js +54 -10
- package/dist/components/in-article-big-numbers/BigNumbers.js +4 -4
- package/dist/components/in-article-big-numbers/styles.d.ts +1 -13
- package/dist/components/in-article-big-numbers/styles.js +3 -52
- package/dist/components/in-article-timelines/Timelines.d.ts +4 -0
- package/dist/components/in-article-timelines/Timelines.js +70 -0
- package/dist/components/in-article-timelines/Timelines.stories.d.ts +1 -0
- package/dist/components/in-article-timelines/Timelines.stories.js +21 -0
- package/dist/components/in-article-timelines/__tests__/Timelines.test.d.ts +2 -0
- package/dist/components/in-article-timelines/__tests__/Timelines.test.js +256 -0
- package/dist/components/in-article-timelines/styles.d.ts +15 -0
- package/dist/components/in-article-timelines/styles.js +115 -0
- package/dist/components/opta/football/fixtures/OptaFootballFixtures.js +5 -4
- package/dist/components/opta/football/fixtures/__tests__/OptaFootballFixtures.test.d.ts +2 -0
- package/dist/components/opta/football/fixtures/__tests__/OptaFootballFixtures.test.js +41 -0
- package/dist/components/opta/football/match-stats/OptaFootballMatchStats.js +4 -3
- package/dist/components/opta/football/match-stats/__tests__/OptaFootballMatchStats.test.d.ts +2 -0
- package/dist/components/opta/football/match-stats/__tests__/OptaFootballMatchStats.test.js +40 -0
- package/dist/components/opta/football/standings/OptaFootballStandings.js +4 -3
- package/dist/components/opta/football/standings/__tests__/OptaFootballStandings.test.d.ts +2 -0
- package/dist/components/opta/football/standings/__tests__/OptaFootballStandings.test.js +39 -0
- package/dist/components/opta/football/summary/OptaFootballSummary.js +4 -3
- package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.d.ts +2 -0
- package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.js +40 -0
- package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.d.ts +8 -0
- package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.js +54 -0
- package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.stories.d.ts +1 -0
- package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.stories.js +26 -0
- package/dist/components/opta/rugby/fixtures/__tests__/OptaRugbyFixtures.test.d.ts +2 -0
- package/dist/components/opta/rugby/fixtures/__tests__/OptaRugbyFixtures.test.js +41 -0
- package/dist/components/opta/rugby/fixtures/styles.d.ts +2 -0
- package/dist/components/opta/rugby/fixtures/styles.js +255 -0
- package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.d.ts +7 -0
- package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.js +43 -0
- package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.stories.d.ts +1 -0
- package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.stories.js +26 -0
- package/dist/components/opta/rugby/match-stats/__tests__/OptaRugbyMatchStats.test.d.ts +2 -0
- package/dist/components/opta/rugby/match-stats/__tests__/OptaRugbyMatchStats.test.js +40 -0
- package/dist/components/opta/rugby/match-stats/styles.d.ts +1 -0
- package/dist/components/opta/rugby/match-stats/styles.js +153 -0
- package/dist/components/opta/rugby/shared-styles.d.ts +6 -0
- package/dist/components/opta/rugby/shared-styles.js +72 -0
- package/dist/components/opta/rugby/standings/OptaRugbyStandings.d.ts +8 -0
- package/dist/components/opta/rugby/standings/OptaRugbyStandings.js +36 -0
- package/dist/components/opta/rugby/standings/OptaRugbyStandings.stories.d.ts +1 -0
- package/dist/components/opta/rugby/standings/OptaRugbyStandings.stories.js +36 -0
- package/dist/components/opta/rugby/standings/__tests__/OptaRugbyStandings.test.d.ts +2 -0
- package/dist/components/opta/rugby/standings/__tests__/OptaRugbyStandings.test.js +39 -0
- package/dist/components/opta/rugby/standings/styles.d.ts +1 -0
- package/dist/components/opta/rugby/standings/styles.js +247 -0
- package/dist/components/opta/rugby/summary/OptaRugbySummary.d.ts +7 -0
- package/dist/components/opta/rugby/summary/OptaRugbySummary.js +44 -0
- package/dist/components/opta/rugby/summary/OptaRugbySummary.stories.d.ts +1 -0
- package/dist/components/opta/rugby/summary/OptaRugbySummary.stories.js +26 -0
- package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.d.ts +2 -0
- package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.js +40 -0
- package/dist/components/opta/rugby/summary/styles.d.ts +1 -0
- package/dist/components/opta/rugby/summary/styles.js +152 -0
- package/dist/components/opta/utils/__tests__/config.test.d.ts +1 -0
- package/dist/components/opta/utils/__tests__/config.test.js +24 -0
- package/dist/components/opta/utils/config.d.ts +1 -1
- package/dist/components/opta/utils/config.js +12 -3
- package/dist/helpers/fetch/FetchProvider.js +3 -3
- package/dist/helpers/fetch/__tests__/FetchProvider.test.d.ts +0 -1
- package/dist/helpers/fetch/__tests__/FetchProvider.test.js +17 -23
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/jest.config.js +4 -4
- package/package.json +6 -5
- package/rnw.js +1 -1
- package/src/__mocks__/isomorphic-unfetch.ts +3 -0
- package/src/components/article-flag/LiveArticleFlag.tsx +7 -6
- package/src/components/article-flag/__tests__/__snapshots__/ArticleFlag.test.tsx.snap +100 -100
- package/src/components/article-flag/__tests__/__snapshots__/LiveArticleFlag.test.tsx.snap +33 -33
- package/src/components/article-flag/styles.ts +32 -27
- package/src/components/article-header/ArticleHeader.tsx +10 -2
- package/src/components/article-header/__tests__/__snapshots__/ArticleHeader.test.tsx.snap +14 -11
- package/src/components/carousel/__tests__/__snapshots__/GalleryCarousel.test.tsx.snap +3 -3
- package/src/components/common-styles.ts +66 -7
- package/src/components/in-article-big-numbers/BigNumbers.tsx +11 -8
- package/src/components/in-article-big-numbers/__tests__/__snapshots__/BigNumbers.test.tsx.snap +67 -67
- package/src/components/in-article-big-numbers/styles.ts +2 -65
- package/src/components/in-article-info-card/__tests__/__snapshots__/InfoCard.test.tsx.snap +8 -8
- package/src/components/in-article-info-card-bulletpoints/__tests__/__snapshots__/InfoCardBulletPoints.test.tsx.snap +2 -2
- package/src/components/in-article-puff/__tests__/__snapshots__/InArticlePuff.test.tsx.snap +10 -10
- package/src/components/in-article-timelines/Timelines.stories.tsx +33 -0
- package/src/components/in-article-timelines/Timelines.tsx +160 -0
- package/src/components/in-article-timelines/__tests__/Timelines.test.tsx +309 -0
- package/src/components/in-article-timelines/__tests__/__snapshots__/Timelines.test.tsx.snap +727 -0
- package/src/components/in-article-timelines/styles.ts +127 -0
- package/src/components/opta/football/fixtures/OptaFootballFixtures.tsx +5 -3
- package/src/components/opta/football/fixtures/__tests__/OptaFootballFixtures.test.tsx +53 -0
- package/src/components/opta/football/fixtures/__tests__/__snapshots__/OptaFootballFixtures.test.tsx.snap +34 -0
- package/src/components/opta/football/match-stats/OptaFootballMatchStats.tsx +4 -2
- package/src/components/opta/football/match-stats/__tests__/OptaFootballMatchStats.test.tsx +52 -0
- package/src/components/opta/football/match-stats/__tests__/__snapshots__/OptaFootballMatchStats.test.tsx.snap +34 -0
- package/src/components/opta/football/standings/OptaFootballStandings.tsx +4 -2
- package/src/components/opta/football/standings/__tests__/OptaFootballStandings.test.tsx +51 -0
- package/src/components/opta/football/standings/__tests__/__snapshots__/OptaFootballStandings.test.tsx.snap +34 -0
- package/src/components/opta/football/summary/OptaFootballSummary.tsx +4 -2
- package/src/components/opta/football/summary/__tests__/OptaFootballSummary.test.tsx +52 -0
- package/src/components/opta/football/summary/__tests__/__snapshots__/OptaFootballSummary.test.tsx.snap +34 -0
- package/src/components/opta/rugby/fixtures/OptaRugbyFixtures.stories.tsx +44 -0
- package/src/components/opta/rugby/fixtures/OptaRugbyFixtures.tsx +86 -0
- package/src/components/opta/rugby/fixtures/__tests__/OptaRugbyFixtures.test.tsx +53 -0
- package/src/components/opta/rugby/fixtures/__tests__/__snapshots__/OptaRugbyFixtures.test.tsx.snap +34 -0
- package/src/components/opta/rugby/fixtures/styles.ts +257 -0
- package/src/components/opta/rugby/match-stats/OptaRugbyMatchStats.stories.tsx +34 -0
- package/src/components/opta/rugby/match-stats/OptaRugbyMatchStats.tsx +71 -0
- package/src/components/opta/rugby/match-stats/__tests__/OptaRugbyMatchStats.test.tsx +52 -0
- package/src/components/opta/rugby/match-stats/__tests__/__snapshots__/OptaRugbyMatchStats.test.tsx.snap +34 -0
- package/src/components/opta/rugby/match-stats/styles.ts +154 -0
- package/src/components/opta/rugby/shared-styles.ts +75 -0
- package/src/components/opta/rugby/standings/OptaRugbyStandings.stories.tsx +49 -0
- package/src/components/opta/rugby/standings/OptaRugbyStandings.tsx +66 -0
- package/src/components/opta/rugby/standings/__tests__/OptaRugbyStandings.test.tsx +51 -0
- package/src/components/opta/rugby/standings/__tests__/__snapshots__/OptaRugbyStandings.test.tsx.snap +34 -0
- package/src/components/opta/rugby/standings/styles.ts +248 -0
- package/src/components/opta/rugby/summary/OptaRugbySummary.stories.tsx +34 -0
- package/src/components/opta/rugby/summary/OptaRugbySummary.tsx +71 -0
- package/src/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.tsx +52 -0
- package/src/components/opta/rugby/summary/__tests__/__snapshots__/OptaRugbySummary.test.tsx.snap +34 -0
- package/src/components/opta/rugby/summary/styles.ts +153 -0
- package/src/components/opta/utils/__tests__/config.test.tsx +38 -0
- package/src/components/opta/utils/config.ts +13 -3
- package/src/helpers/fetch/FetchProvider.tsx +2 -2
- package/src/helpers/fetch/__tests__/FetchProvider.test.tsx +21 -31
- package/src/helpers/fetch/__tests__/__snapshots__/FetchProvider.test.tsx.snap +10 -2
- package/src/index.ts +1 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import React, { useRef, useState, useEffect } from 'react';
|
|
2
|
+
import { Placeholder } from '@times-components/image';
|
|
3
|
+
import { useFetch } from '../../helpers/fetch/FetchProvider';
|
|
4
|
+
import {
|
|
5
|
+
TrackingContext,
|
|
6
|
+
TrackingContextProvider
|
|
7
|
+
} from '../../helpers/tracking/TrackingContextProvider';
|
|
8
|
+
import { sanitiseCopy } from '../../helpers/text-formatting/SanitiseCopy';
|
|
9
|
+
import {
|
|
10
|
+
Container,
|
|
11
|
+
ContentContainer,
|
|
12
|
+
ListItem,
|
|
13
|
+
LeftPanel,
|
|
14
|
+
RightPanel,
|
|
15
|
+
Date,
|
|
16
|
+
SubHeading,
|
|
17
|
+
StyledShowAllButton
|
|
18
|
+
} from './styles';
|
|
19
|
+
import {
|
|
20
|
+
PlaceholderContainer,
|
|
21
|
+
Label,
|
|
22
|
+
Headline,
|
|
23
|
+
ListContainer,
|
|
24
|
+
List,
|
|
25
|
+
Copy,
|
|
26
|
+
ShowAllContainer
|
|
27
|
+
} from '../common-styles';
|
|
28
|
+
import { DeckData } from '../../helpers/fetch/types';
|
|
29
|
+
|
|
30
|
+
type TimelinesData = {
|
|
31
|
+
type: string;
|
|
32
|
+
data: {
|
|
33
|
+
date: string;
|
|
34
|
+
eventHeading: string;
|
|
35
|
+
image: string;
|
|
36
|
+
copy: string;
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
type TimelinesDeckData = DeckData<never, TimelinesData>;
|
|
41
|
+
|
|
42
|
+
const scrollEvent = {
|
|
43
|
+
attrs: {
|
|
44
|
+
event_navigation_name: 'in-article component displayed : timelines',
|
|
45
|
+
event_navigation_browsing_method: 'scroll'
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const clickEvent = (buttonLabel: string) => ({
|
|
50
|
+
action: 'Clicked',
|
|
51
|
+
attrs: {
|
|
52
|
+
event_navigation_name: `button : ${buttonLabel}`,
|
|
53
|
+
event_navigation_browsing_method: 'click'
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
export const Timelines: React.FC<{
|
|
58
|
+
sectionColour: string;
|
|
59
|
+
}> = ({ sectionColour }) => {
|
|
60
|
+
const { loading, error, data } = useFetch<TimelinesDeckData>();
|
|
61
|
+
|
|
62
|
+
if (loading) {
|
|
63
|
+
return (
|
|
64
|
+
<PlaceholderContainer>
|
|
65
|
+
<Placeholder />
|
|
66
|
+
</PlaceholderContainer>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (error || data === undefined) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const { headline, label } = data.fields;
|
|
75
|
+
const timelinesData = data.body.data;
|
|
76
|
+
const [showAll, setShowAll] = useState(false);
|
|
77
|
+
|
|
78
|
+
const handleShowAll = (
|
|
79
|
+
fireAnalyticsEvent: (evt: TrackingContext) => void,
|
|
80
|
+
buttonLabel: string
|
|
81
|
+
) => {
|
|
82
|
+
fireAnalyticsEvent && fireAnalyticsEvent(clickEvent(buttonLabel));
|
|
83
|
+
setShowAll(!showAll);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const showAllRef = useRef<HTMLDivElement>(null);
|
|
87
|
+
const [displayShowAll, setShowShowAll] = useState(false);
|
|
88
|
+
const maxHeight = 375;
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
const listContainer = showAllRef.current;
|
|
91
|
+
if (listContainer) {
|
|
92
|
+
setShowShowAll(listContainer.clientHeight > maxHeight);
|
|
93
|
+
}
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<TrackingContextProvider
|
|
98
|
+
context={{
|
|
99
|
+
object: 'InArticleTimelines',
|
|
100
|
+
attrs: {
|
|
101
|
+
component_type:
|
|
102
|
+
'in-article component : timelines: ' +
|
|
103
|
+
(displayShowAll ? 'interactive' : 'static'),
|
|
104
|
+
event_navigation_action: 'navigation',
|
|
105
|
+
component_name: `${headline}`
|
|
106
|
+
}
|
|
107
|
+
}}
|
|
108
|
+
scrolledEvent={scrollEvent}
|
|
109
|
+
>
|
|
110
|
+
{({ fireAnalyticsEvent, intersectObserverRef }) => (
|
|
111
|
+
<Container ref={intersectObserverRef} sectionColour={sectionColour}>
|
|
112
|
+
<ContentContainer>
|
|
113
|
+
<Label sectionColour={sectionColour}>{label}</Label>
|
|
114
|
+
{headline && <Headline>{headline}</Headline>}
|
|
115
|
+
<ListContainer
|
|
116
|
+
ref={showAllRef}
|
|
117
|
+
showAll={showAll}
|
|
118
|
+
maxHeight={maxHeight}
|
|
119
|
+
displayShowAll={displayShowAll}
|
|
120
|
+
>
|
|
121
|
+
<List>
|
|
122
|
+
{timelinesData.map((row: TimelinesData, index: number) => (
|
|
123
|
+
<ListItem key={index}>
|
|
124
|
+
<LeftPanel
|
|
125
|
+
sectionColour={sectionColour}
|
|
126
|
+
circularImage={row.data.image}
|
|
127
|
+
>
|
|
128
|
+
{row.data.image && <img src={row.data.image} />}
|
|
129
|
+
</LeftPanel>
|
|
130
|
+
<RightPanel>
|
|
131
|
+
<Date sectionColour={sectionColour}>{row.data.date}</Date>
|
|
132
|
+
<SubHeading>{row.data.eventHeading}</SubHeading>
|
|
133
|
+
<Copy
|
|
134
|
+
dangerouslySetInnerHTML={{
|
|
135
|
+
__html: sanitiseCopy(row.data.copy, ['br', 'b', 'i'])
|
|
136
|
+
}}
|
|
137
|
+
/>
|
|
138
|
+
</RightPanel>
|
|
139
|
+
</ListItem>
|
|
140
|
+
))}
|
|
141
|
+
</List>
|
|
142
|
+
</ListContainer>
|
|
143
|
+
</ContentContainer>
|
|
144
|
+
<ShowAllContainer showAll={showAll} displayShowAll={displayShowAll}>
|
|
145
|
+
<StyledShowAllButton
|
|
146
|
+
onClick={() =>
|
|
147
|
+
handleShowAll(
|
|
148
|
+
fireAnalyticsEvent,
|
|
149
|
+
showAll ? 'Collapse' : 'Show all'
|
|
150
|
+
)
|
|
151
|
+
}
|
|
152
|
+
>
|
|
153
|
+
{showAll ? 'Collapse' : 'Show all'}
|
|
154
|
+
</StyledShowAllButton>
|
|
155
|
+
</ShowAllContainer>
|
|
156
|
+
</Container>
|
|
157
|
+
)}
|
|
158
|
+
</TrackingContextProvider>
|
|
159
|
+
);
|
|
160
|
+
};
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import mockDate from 'mockdate';
|
|
3
|
+
import { cleanup, fireEvent, render } from '@testing-library/react';
|
|
4
|
+
import { Timelines } from '../Timelines';
|
|
5
|
+
import { useFetch } from '../../../helpers/fetch/FetchProvider';
|
|
6
|
+
import { TrackingContextProvider } from '../../../helpers/tracking/TrackingContextProvider';
|
|
7
|
+
import FakeIntersectionObserver from '../../../test-utils/FakeIntersectionObserver';
|
|
8
|
+
import '@testing-library/jest-dom';
|
|
9
|
+
import 'regenerator-runtime';
|
|
10
|
+
|
|
11
|
+
jest.mock('@times-components/image', () => ({
|
|
12
|
+
Placeholder: () => <div>Placeholder</div>
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
jest.mock('../../../helpers/fetch/FetchProvider', () => ({
|
|
16
|
+
useFetch: jest.fn()
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
const deckApiPayloadWrapper = () => ({
|
|
20
|
+
data: testDataBullet
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const deckApiPayloadWrapperCircle = () => ({
|
|
24
|
+
data: testDataCircle
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
const testDataBullet = {
|
|
28
|
+
deck_id: 45060,
|
|
29
|
+
deck_name: '[TEST] Timeline with Bullet Points - 25/08/2021 11:04:10',
|
|
30
|
+
deck_type: 'Timeline with Bullet Points',
|
|
31
|
+
version: 2,
|
|
32
|
+
updated_at: {
|
|
33
|
+
date: '2021-08-16 12:48:43.000000',
|
|
34
|
+
timezone_type: 3,
|
|
35
|
+
timezone: 'UTC'
|
|
36
|
+
},
|
|
37
|
+
fields: {
|
|
38
|
+
label: 'Venezuelan Politics',
|
|
39
|
+
headline: 'A history of injury troubles'
|
|
40
|
+
},
|
|
41
|
+
body: {
|
|
42
|
+
data: [
|
|
43
|
+
{
|
|
44
|
+
type: 'event',
|
|
45
|
+
data: {
|
|
46
|
+
date: '9 June 2018',
|
|
47
|
+
eventHeading: 'Event Heading 1',
|
|
48
|
+
copy:
|
|
49
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'event',
|
|
54
|
+
data: {
|
|
55
|
+
date: '10 June 2018',
|
|
56
|
+
eventHeading: 'Event Heading 2',
|
|
57
|
+
copy:
|
|
58
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: 'event',
|
|
63
|
+
data: {
|
|
64
|
+
date: '11 June 2018',
|
|
65
|
+
eventHeading: 'Event Heading 3',
|
|
66
|
+
copy:
|
|
67
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
type: 'event',
|
|
72
|
+
data: {
|
|
73
|
+
date: '12 June 2018',
|
|
74
|
+
eventHeading: 'Event Heading 4',
|
|
75
|
+
copy:
|
|
76
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: 'event',
|
|
81
|
+
data: {
|
|
82
|
+
date: '13 June 2018',
|
|
83
|
+
eventHeading: 'Event Heading 5',
|
|
84
|
+
copy:
|
|
85
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
type: 'event',
|
|
90
|
+
data: {
|
|
91
|
+
date: '14 June 2018',
|
|
92
|
+
eventHeading: 'Event Heading 6',
|
|
93
|
+
copy:
|
|
94
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: 'event',
|
|
99
|
+
data: {
|
|
100
|
+
date: '15 June 2018',
|
|
101
|
+
eventHeading: 'Event Heading 7',
|
|
102
|
+
copy:
|
|
103
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
html:
|
|
109
|
+
'<!DOCTYPE html><html><head><title>The Times - In Article Timeline with Bullet Points</title></head><body></body></html>'
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const testDataCircle = {
|
|
113
|
+
deck_id: 45061,
|
|
114
|
+
deck_name: '[TEST] Timeline with Images - 25/08/2021 11:11:38',
|
|
115
|
+
deck_type: 'Timeline with Circle Images',
|
|
116
|
+
version: 2,
|
|
117
|
+
updated_at: {
|
|
118
|
+
date: '2021-08-16 12:48:43.000000',
|
|
119
|
+
timezone_type: 3,
|
|
120
|
+
timezone: 'UTC'
|
|
121
|
+
},
|
|
122
|
+
fields: {
|
|
123
|
+
label: 'Venezuelan Politics',
|
|
124
|
+
headline: 'A history of injury troubles'
|
|
125
|
+
},
|
|
126
|
+
body: {
|
|
127
|
+
data: [
|
|
128
|
+
{
|
|
129
|
+
type: 'event',
|
|
130
|
+
data: {
|
|
131
|
+
date: '9 June 2018',
|
|
132
|
+
eventHeading: 'Event Heading 1',
|
|
133
|
+
image:
|
|
134
|
+
'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2Ffee23bf0-04d7-11ec-89b3-29a9a04e8645.jpg?crop=1500%2C844%2C0%2C78&resize=1200',
|
|
135
|
+
copy:
|
|
136
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
type: 'event',
|
|
141
|
+
data: {
|
|
142
|
+
date: '10 June 2018',
|
|
143
|
+
eventHeading: 'Event Heading 2',
|
|
144
|
+
image:
|
|
145
|
+
'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2Ffee23bf0-04d7-11ec-89b3-29a9a04e8645.jpg?crop=1500%2C844%2C0%2C78&resize=1200',
|
|
146
|
+
copy:
|
|
147
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
type: 'event',
|
|
152
|
+
data: {
|
|
153
|
+
date: '11 June 2018',
|
|
154
|
+
eventHeading: 'Event Heading 3',
|
|
155
|
+
image:
|
|
156
|
+
'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2Ffee23bf0-04d7-11ec-89b3-29a9a04e8645.jpg?crop=1500%2C844%2C0%2C78&resize=1200',
|
|
157
|
+
copy:
|
|
158
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
type: 'event',
|
|
163
|
+
data: {
|
|
164
|
+
date: '12 June 2018',
|
|
165
|
+
eventHeading: 'Event Heading 4',
|
|
166
|
+
image:
|
|
167
|
+
'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2Ffee23bf0-04d7-11ec-89b3-29a9a04e8645.jpg?crop=1500%2C844%2C0%2C78&resize=1200',
|
|
168
|
+
copy:
|
|
169
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
type: 'event',
|
|
174
|
+
data: {
|
|
175
|
+
date: '13 June 2018',
|
|
176
|
+
eventHeading: 'Event Heading 5',
|
|
177
|
+
image:
|
|
178
|
+
'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2Ffee23bf0-04d7-11ec-89b3-29a9a04e8645.jpg?crop=1500%2C844%2C0%2C78&resize=1200',
|
|
179
|
+
copy:
|
|
180
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
type: 'event',
|
|
185
|
+
data: {
|
|
186
|
+
date: '14 June 2018',
|
|
187
|
+
eventHeading: 'Event Heading 6',
|
|
188
|
+
copy:
|
|
189
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
type: 'event',
|
|
194
|
+
data: {
|
|
195
|
+
date: '15 June 2018',
|
|
196
|
+
eventHeading: 'Event Heading 7',
|
|
197
|
+
image:
|
|
198
|
+
'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2Ffee23bf0-04d7-11ec-89b3-29a9a04e8645.jpg?crop=1500%2C844%2C0%2C78&resize=1200',
|
|
199
|
+
copy:
|
|
200
|
+
'Parturient mi dictumst suspendisse torquent primis potenti donec in parturient aliquam adipiscing bibendum bibendum magna nisi bibendum dignissim in dis a. Scelerisque a ullamcorper id maecenas tempor convallis ac cras. 1'
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
]
|
|
204
|
+
},
|
|
205
|
+
html:
|
|
206
|
+
'<!DOCTYPE html><html><head><title>The Times - In Article Timeline with Circle Images</title></head><body></body></html>'
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const renderTimelines = () => render(<Timelines sectionColour="#636C17" />);
|
|
210
|
+
|
|
211
|
+
describe('Timelines', () => {
|
|
212
|
+
beforeEach(() => {
|
|
213
|
+
mockDate.set(1620000000000);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
afterEach(() => {
|
|
217
|
+
mockDate.reset();
|
|
218
|
+
jest.clearAllMocks();
|
|
219
|
+
cleanup();
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('should render the initial loading state correctly', async () => {
|
|
223
|
+
(useFetch as jest.Mock).mockReturnValue({ loading: true });
|
|
224
|
+
const { asFragment, findByText } = render(
|
|
225
|
+
<Timelines sectionColour="#636C17" />
|
|
226
|
+
);
|
|
227
|
+
await findByText('Placeholder');
|
|
228
|
+
expect(asFragment()).toMatchSnapshot();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should render the bullet points component', () => {
|
|
232
|
+
(useFetch as jest.Mock).mockReturnValue(deckApiPayloadWrapper());
|
|
233
|
+
const { asFragment } = renderTimelines();
|
|
234
|
+
expect(asFragment()).toMatchSnapshot();
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('should render the circle images component', () => {
|
|
238
|
+
(useFetch as jest.Mock).mockReturnValue(deckApiPayloadWrapperCircle());
|
|
239
|
+
const { asFragment, getAllByRole } = renderTimelines();
|
|
240
|
+
expect(getAllByRole('img')[0]).toHaveAttribute(
|
|
241
|
+
'src',
|
|
242
|
+
'https://www.thetimes.co.uk/imageserver/image/%2Fmethode%2Ftimes%2Fprod%2Fweb%2Fbin%2Ffee23bf0-04d7-11ec-89b3-29a9a04e8645.jpg?crop=1500%2C844%2C0%2C78&resize=1200'
|
|
243
|
+
);
|
|
244
|
+
expect(asFragment()).toMatchSnapshot();
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
it('click show all', async () => {
|
|
248
|
+
const { asFragment, getByText, findByText } = render(
|
|
249
|
+
<Timelines sectionColour="#636C17" />
|
|
250
|
+
);
|
|
251
|
+
fireEvent.click(getByText('Show all'));
|
|
252
|
+
await findByText('Collapse');
|
|
253
|
+
expect(asFragment()).toMatchSnapshot();
|
|
254
|
+
});
|
|
255
|
+
describe('tracking', () => {
|
|
256
|
+
(useFetch as jest.Mock).mockReturnValue(deckApiPayloadWrapper());
|
|
257
|
+
let oldIntersectionObserver: typeof IntersectionObserver;
|
|
258
|
+
const analyticsStream = jest.fn();
|
|
259
|
+
|
|
260
|
+
beforeEach(() => {
|
|
261
|
+
oldIntersectionObserver = window.IntersectionObserver;
|
|
262
|
+
// @ts-ignore
|
|
263
|
+
window.IntersectionObserver = FakeIntersectionObserver;
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
afterEach(() => {
|
|
267
|
+
window.IntersectionObserver = oldIntersectionObserver;
|
|
268
|
+
jest.resetAllMocks();
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('fires scroll event when viewed', () => {
|
|
272
|
+
(useFetch as jest.Mock).mockReturnValue(deckApiPayloadWrapper());
|
|
273
|
+
|
|
274
|
+
render(
|
|
275
|
+
<TrackingContextProvider
|
|
276
|
+
context={{
|
|
277
|
+
component: 'ArticleSkeleton',
|
|
278
|
+
attrs: {
|
|
279
|
+
articleHeadline: 'articleHeadline',
|
|
280
|
+
section: 'section'
|
|
281
|
+
}
|
|
282
|
+
}}
|
|
283
|
+
analyticsStream={analyticsStream}
|
|
284
|
+
>
|
|
285
|
+
<Timelines sectionColour="#636C17" />
|
|
286
|
+
</TrackingContextProvider>
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
FakeIntersectionObserver.intersect();
|
|
290
|
+
|
|
291
|
+
expect(analyticsStream).toHaveBeenCalledTimes(1);
|
|
292
|
+
expect(analyticsStream).toHaveBeenCalledWith({
|
|
293
|
+
action: 'Scrolled',
|
|
294
|
+
component: 'ArticleSkeleton',
|
|
295
|
+
object: 'InArticleTimelines',
|
|
296
|
+
attrs: {
|
|
297
|
+
articleHeadline: 'articleHeadline',
|
|
298
|
+
component_name: 'A history of injury troubles',
|
|
299
|
+
component_type: 'in-article component : timelines: static',
|
|
300
|
+
eventTime: '2021-05-03T00:00:00.000Z',
|
|
301
|
+
event_navigation_action: 'navigation',
|
|
302
|
+
event_navigation_browsing_method: 'scroll',
|
|
303
|
+
event_navigation_name: 'in-article component displayed : timelines',
|
|
304
|
+
section: 'section'
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
});
|