@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.
Files changed (137) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/__mocks__/isomorphic-unfetch.d.ts +3 -0
  3. package/dist/__mocks__/isomorphic-unfetch.js +4 -0
  4. package/dist/components/article-flag/LiveArticleFlag.js +5 -5
  5. package/dist/components/article-flag/styles.d.ts +4 -3
  6. package/dist/components/article-flag/styles.js +30 -26
  7. package/dist/components/article-header/ArticleHeader.js +11 -2
  8. package/dist/components/common-styles.d.ts +13 -0
  9. package/dist/components/common-styles.js +54 -10
  10. package/dist/components/in-article-big-numbers/BigNumbers.js +4 -4
  11. package/dist/components/in-article-big-numbers/styles.d.ts +1 -13
  12. package/dist/components/in-article-big-numbers/styles.js +3 -52
  13. package/dist/components/in-article-timelines/Timelines.d.ts +4 -0
  14. package/dist/components/in-article-timelines/Timelines.js +70 -0
  15. package/dist/components/in-article-timelines/Timelines.stories.d.ts +1 -0
  16. package/dist/components/in-article-timelines/Timelines.stories.js +21 -0
  17. package/dist/components/in-article-timelines/__tests__/Timelines.test.d.ts +2 -0
  18. package/dist/components/in-article-timelines/__tests__/Timelines.test.js +256 -0
  19. package/dist/components/in-article-timelines/styles.d.ts +15 -0
  20. package/dist/components/in-article-timelines/styles.js +115 -0
  21. package/dist/components/opta/football/fixtures/OptaFootballFixtures.js +5 -4
  22. package/dist/components/opta/football/fixtures/__tests__/OptaFootballFixtures.test.d.ts +2 -0
  23. package/dist/components/opta/football/fixtures/__tests__/OptaFootballFixtures.test.js +41 -0
  24. package/dist/components/opta/football/match-stats/OptaFootballMatchStats.js +4 -3
  25. package/dist/components/opta/football/match-stats/__tests__/OptaFootballMatchStats.test.d.ts +2 -0
  26. package/dist/components/opta/football/match-stats/__tests__/OptaFootballMatchStats.test.js +40 -0
  27. package/dist/components/opta/football/standings/OptaFootballStandings.js +4 -3
  28. package/dist/components/opta/football/standings/__tests__/OptaFootballStandings.test.d.ts +2 -0
  29. package/dist/components/opta/football/standings/__tests__/OptaFootballStandings.test.js +39 -0
  30. package/dist/components/opta/football/summary/OptaFootballSummary.js +4 -3
  31. package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.d.ts +2 -0
  32. package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.js +40 -0
  33. package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.d.ts +8 -0
  34. package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.js +54 -0
  35. package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.stories.d.ts +1 -0
  36. package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.stories.js +26 -0
  37. package/dist/components/opta/rugby/fixtures/__tests__/OptaRugbyFixtures.test.d.ts +2 -0
  38. package/dist/components/opta/rugby/fixtures/__tests__/OptaRugbyFixtures.test.js +41 -0
  39. package/dist/components/opta/rugby/fixtures/styles.d.ts +2 -0
  40. package/dist/components/opta/rugby/fixtures/styles.js +255 -0
  41. package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.d.ts +7 -0
  42. package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.js +43 -0
  43. package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.stories.d.ts +1 -0
  44. package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.stories.js +26 -0
  45. package/dist/components/opta/rugby/match-stats/__tests__/OptaRugbyMatchStats.test.d.ts +2 -0
  46. package/dist/components/opta/rugby/match-stats/__tests__/OptaRugbyMatchStats.test.js +40 -0
  47. package/dist/components/opta/rugby/match-stats/styles.d.ts +1 -0
  48. package/dist/components/opta/rugby/match-stats/styles.js +153 -0
  49. package/dist/components/opta/rugby/shared-styles.d.ts +6 -0
  50. package/dist/components/opta/rugby/shared-styles.js +72 -0
  51. package/dist/components/opta/rugby/standings/OptaRugbyStandings.d.ts +8 -0
  52. package/dist/components/opta/rugby/standings/OptaRugbyStandings.js +36 -0
  53. package/dist/components/opta/rugby/standings/OptaRugbyStandings.stories.d.ts +1 -0
  54. package/dist/components/opta/rugby/standings/OptaRugbyStandings.stories.js +36 -0
  55. package/dist/components/opta/rugby/standings/__tests__/OptaRugbyStandings.test.d.ts +2 -0
  56. package/dist/components/opta/rugby/standings/__tests__/OptaRugbyStandings.test.js +39 -0
  57. package/dist/components/opta/rugby/standings/styles.d.ts +1 -0
  58. package/dist/components/opta/rugby/standings/styles.js +247 -0
  59. package/dist/components/opta/rugby/summary/OptaRugbySummary.d.ts +7 -0
  60. package/dist/components/opta/rugby/summary/OptaRugbySummary.js +44 -0
  61. package/dist/components/opta/rugby/summary/OptaRugbySummary.stories.d.ts +1 -0
  62. package/dist/components/opta/rugby/summary/OptaRugbySummary.stories.js +26 -0
  63. package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.d.ts +2 -0
  64. package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.js +40 -0
  65. package/dist/components/opta/rugby/summary/styles.d.ts +1 -0
  66. package/dist/components/opta/rugby/summary/styles.js +152 -0
  67. package/dist/components/opta/utils/__tests__/config.test.d.ts +1 -0
  68. package/dist/components/opta/utils/__tests__/config.test.js +24 -0
  69. package/dist/components/opta/utils/config.d.ts +1 -1
  70. package/dist/components/opta/utils/config.js +12 -3
  71. package/dist/helpers/fetch/FetchProvider.js +3 -3
  72. package/dist/helpers/fetch/__tests__/FetchProvider.test.d.ts +0 -1
  73. package/dist/helpers/fetch/__tests__/FetchProvider.test.js +17 -23
  74. package/dist/index.d.ts +1 -0
  75. package/dist/index.js +2 -1
  76. package/jest.config.js +4 -4
  77. package/package.json +6 -5
  78. package/rnw.js +1 -1
  79. package/src/__mocks__/isomorphic-unfetch.ts +3 -0
  80. package/src/components/article-flag/LiveArticleFlag.tsx +7 -6
  81. package/src/components/article-flag/__tests__/__snapshots__/ArticleFlag.test.tsx.snap +100 -100
  82. package/src/components/article-flag/__tests__/__snapshots__/LiveArticleFlag.test.tsx.snap +33 -33
  83. package/src/components/article-flag/styles.ts +32 -27
  84. package/src/components/article-header/ArticleHeader.tsx +10 -2
  85. package/src/components/article-header/__tests__/__snapshots__/ArticleHeader.test.tsx.snap +14 -11
  86. package/src/components/carousel/__tests__/__snapshots__/GalleryCarousel.test.tsx.snap +3 -3
  87. package/src/components/common-styles.ts +66 -7
  88. package/src/components/in-article-big-numbers/BigNumbers.tsx +11 -8
  89. package/src/components/in-article-big-numbers/__tests__/__snapshots__/BigNumbers.test.tsx.snap +67 -67
  90. package/src/components/in-article-big-numbers/styles.ts +2 -65
  91. package/src/components/in-article-info-card/__tests__/__snapshots__/InfoCard.test.tsx.snap +8 -8
  92. package/src/components/in-article-info-card-bulletpoints/__tests__/__snapshots__/InfoCardBulletPoints.test.tsx.snap +2 -2
  93. package/src/components/in-article-puff/__tests__/__snapshots__/InArticlePuff.test.tsx.snap +10 -10
  94. package/src/components/in-article-timelines/Timelines.stories.tsx +33 -0
  95. package/src/components/in-article-timelines/Timelines.tsx +160 -0
  96. package/src/components/in-article-timelines/__tests__/Timelines.test.tsx +309 -0
  97. package/src/components/in-article-timelines/__tests__/__snapshots__/Timelines.test.tsx.snap +727 -0
  98. package/src/components/in-article-timelines/styles.ts +127 -0
  99. package/src/components/opta/football/fixtures/OptaFootballFixtures.tsx +5 -3
  100. package/src/components/opta/football/fixtures/__tests__/OptaFootballFixtures.test.tsx +53 -0
  101. package/src/components/opta/football/fixtures/__tests__/__snapshots__/OptaFootballFixtures.test.tsx.snap +34 -0
  102. package/src/components/opta/football/match-stats/OptaFootballMatchStats.tsx +4 -2
  103. package/src/components/opta/football/match-stats/__tests__/OptaFootballMatchStats.test.tsx +52 -0
  104. package/src/components/opta/football/match-stats/__tests__/__snapshots__/OptaFootballMatchStats.test.tsx.snap +34 -0
  105. package/src/components/opta/football/standings/OptaFootballStandings.tsx +4 -2
  106. package/src/components/opta/football/standings/__tests__/OptaFootballStandings.test.tsx +51 -0
  107. package/src/components/opta/football/standings/__tests__/__snapshots__/OptaFootballStandings.test.tsx.snap +34 -0
  108. package/src/components/opta/football/summary/OptaFootballSummary.tsx +4 -2
  109. package/src/components/opta/football/summary/__tests__/OptaFootballSummary.test.tsx +52 -0
  110. package/src/components/opta/football/summary/__tests__/__snapshots__/OptaFootballSummary.test.tsx.snap +34 -0
  111. package/src/components/opta/rugby/fixtures/OptaRugbyFixtures.stories.tsx +44 -0
  112. package/src/components/opta/rugby/fixtures/OptaRugbyFixtures.tsx +86 -0
  113. package/src/components/opta/rugby/fixtures/__tests__/OptaRugbyFixtures.test.tsx +53 -0
  114. package/src/components/opta/rugby/fixtures/__tests__/__snapshots__/OptaRugbyFixtures.test.tsx.snap +34 -0
  115. package/src/components/opta/rugby/fixtures/styles.ts +257 -0
  116. package/src/components/opta/rugby/match-stats/OptaRugbyMatchStats.stories.tsx +34 -0
  117. package/src/components/opta/rugby/match-stats/OptaRugbyMatchStats.tsx +71 -0
  118. package/src/components/opta/rugby/match-stats/__tests__/OptaRugbyMatchStats.test.tsx +52 -0
  119. package/src/components/opta/rugby/match-stats/__tests__/__snapshots__/OptaRugbyMatchStats.test.tsx.snap +34 -0
  120. package/src/components/opta/rugby/match-stats/styles.ts +154 -0
  121. package/src/components/opta/rugby/shared-styles.ts +75 -0
  122. package/src/components/opta/rugby/standings/OptaRugbyStandings.stories.tsx +49 -0
  123. package/src/components/opta/rugby/standings/OptaRugbyStandings.tsx +66 -0
  124. package/src/components/opta/rugby/standings/__tests__/OptaRugbyStandings.test.tsx +51 -0
  125. package/src/components/opta/rugby/standings/__tests__/__snapshots__/OptaRugbyStandings.test.tsx.snap +34 -0
  126. package/src/components/opta/rugby/standings/styles.ts +248 -0
  127. package/src/components/opta/rugby/summary/OptaRugbySummary.stories.tsx +34 -0
  128. package/src/components/opta/rugby/summary/OptaRugbySummary.tsx +71 -0
  129. package/src/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.tsx +52 -0
  130. package/src/components/opta/rugby/summary/__tests__/__snapshots__/OptaRugbySummary.test.tsx.snap +34 -0
  131. package/src/components/opta/rugby/summary/styles.ts +153 -0
  132. package/src/components/opta/utils/__tests__/config.test.tsx +38 -0
  133. package/src/components/opta/utils/config.ts +13 -3
  134. package/src/helpers/fetch/FetchProvider.tsx +2 -2
  135. package/src/helpers/fetch/__tests__/FetchProvider.test.tsx +21 -31
  136. package/src/helpers/fetch/__tests__/__snapshots__/FetchProvider.test.tsx.snap +10 -2
  137. 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
+ });