@times-components/ts-components 1.25.1 → 1.26.2

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 (101) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/__mocks__/isomorphic-unfetch.d.ts +3 -0
  3. package/dist/__mocks__/isomorphic-unfetch.js +4 -0
  4. package/dist/components/opta/football/fixtures/OptaFootballFixtures.js +5 -4
  5. package/dist/components/opta/football/fixtures/__tests__/OptaFootballFixtures.test.d.ts +2 -0
  6. package/dist/components/opta/football/fixtures/__tests__/OptaFootballFixtures.test.js +41 -0
  7. package/dist/components/opta/football/match-stats/OptaFootballMatchStats.js +4 -3
  8. package/dist/components/opta/football/match-stats/__tests__/OptaFootballMatchStats.test.d.ts +2 -0
  9. package/dist/components/opta/football/match-stats/__tests__/OptaFootballMatchStats.test.js +40 -0
  10. package/dist/components/opta/football/standings/OptaFootballStandings.js +4 -3
  11. package/dist/components/opta/football/standings/__tests__/OptaFootballStandings.test.d.ts +2 -0
  12. package/dist/components/opta/football/standings/__tests__/OptaFootballStandings.test.js +39 -0
  13. package/dist/components/opta/football/summary/OptaFootballSummary.js +4 -3
  14. package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.d.ts +2 -0
  15. package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.js +40 -0
  16. package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.d.ts +8 -0
  17. package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.js +54 -0
  18. package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.stories.d.ts +1 -0
  19. package/dist/components/opta/rugby/fixtures/OptaRugbyFixtures.stories.js +26 -0
  20. package/dist/components/opta/rugby/fixtures/__tests__/OptaRugbyFixtures.test.d.ts +2 -0
  21. package/dist/components/opta/rugby/fixtures/__tests__/OptaRugbyFixtures.test.js +41 -0
  22. package/dist/components/opta/rugby/fixtures/styles.d.ts +2 -0
  23. package/dist/components/opta/rugby/fixtures/styles.js +255 -0
  24. package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.d.ts +7 -0
  25. package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.js +43 -0
  26. package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.stories.d.ts +1 -0
  27. package/dist/components/opta/rugby/match-stats/OptaRugbyMatchStats.stories.js +26 -0
  28. package/dist/components/opta/rugby/match-stats/__tests__/OptaRugbyMatchStats.test.d.ts +2 -0
  29. package/dist/components/opta/rugby/match-stats/__tests__/OptaRugbyMatchStats.test.js +40 -0
  30. package/dist/components/opta/rugby/match-stats/styles.d.ts +1 -0
  31. package/dist/components/opta/rugby/match-stats/styles.js +153 -0
  32. package/dist/components/opta/rugby/shared-styles.d.ts +6 -0
  33. package/dist/components/opta/rugby/shared-styles.js +72 -0
  34. package/dist/components/opta/rugby/standings/OptaRugbyStandings.d.ts +8 -0
  35. package/dist/components/opta/rugby/standings/OptaRugbyStandings.js +36 -0
  36. package/dist/components/opta/rugby/standings/OptaRugbyStandings.stories.d.ts +1 -0
  37. package/dist/components/opta/rugby/standings/OptaRugbyStandings.stories.js +36 -0
  38. package/dist/components/opta/rugby/standings/__tests__/OptaRugbyStandings.test.d.ts +2 -0
  39. package/dist/components/opta/rugby/standings/__tests__/OptaRugbyStandings.test.js +39 -0
  40. package/dist/components/opta/rugby/standings/styles.d.ts +1 -0
  41. package/dist/components/opta/rugby/standings/styles.js +247 -0
  42. package/dist/components/opta/rugby/summary/OptaRugbySummary.d.ts +7 -0
  43. package/dist/components/opta/rugby/summary/OptaRugbySummary.js +44 -0
  44. package/dist/components/opta/rugby/summary/OptaRugbySummary.stories.d.ts +1 -0
  45. package/dist/components/opta/rugby/summary/OptaRugbySummary.stories.js +26 -0
  46. package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.d.ts +2 -0
  47. package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.js +40 -0
  48. package/dist/components/opta/rugby/summary/styles.d.ts +1 -0
  49. package/dist/components/opta/rugby/summary/styles.js +152 -0
  50. package/dist/components/opta/utils/__tests__/config.test.d.ts +1 -0
  51. package/dist/components/opta/utils/__tests__/config.test.js +24 -0
  52. package/dist/components/opta/utils/config.d.ts +1 -1
  53. package/dist/components/opta/utils/config.js +12 -3
  54. package/dist/helpers/fetch/FetchProvider.js +3 -3
  55. package/dist/helpers/fetch/__tests__/FetchProvider.test.d.ts +0 -1
  56. package/dist/helpers/fetch/__tests__/FetchProvider.test.js +17 -23
  57. package/dist/index.d.ts +4 -0
  58. package/dist/index.js +5 -1
  59. package/jest.config.js +4 -4
  60. package/package.json +6 -5
  61. package/rnw.js +1 -1
  62. package/src/__mocks__/isomorphic-unfetch.ts +3 -0
  63. package/src/components/opta/football/fixtures/OptaFootballFixtures.tsx +5 -3
  64. package/src/components/opta/football/fixtures/__tests__/OptaFootballFixtures.test.tsx +53 -0
  65. package/src/components/opta/football/fixtures/__tests__/__snapshots__/OptaFootballFixtures.test.tsx.snap +34 -0
  66. package/src/components/opta/football/match-stats/OptaFootballMatchStats.tsx +4 -2
  67. package/src/components/opta/football/match-stats/__tests__/OptaFootballMatchStats.test.tsx +52 -0
  68. package/src/components/opta/football/match-stats/__tests__/__snapshots__/OptaFootballMatchStats.test.tsx.snap +34 -0
  69. package/src/components/opta/football/standings/OptaFootballStandings.tsx +4 -2
  70. package/src/components/opta/football/standings/__tests__/OptaFootballStandings.test.tsx +51 -0
  71. package/src/components/opta/football/standings/__tests__/__snapshots__/OptaFootballStandings.test.tsx.snap +34 -0
  72. package/src/components/opta/football/summary/OptaFootballSummary.tsx +4 -2
  73. package/src/components/opta/football/summary/__tests__/OptaFootballSummary.test.tsx +52 -0
  74. package/src/components/opta/football/summary/__tests__/__snapshots__/OptaFootballSummary.test.tsx.snap +34 -0
  75. package/src/components/opta/rugby/fixtures/OptaRugbyFixtures.stories.tsx +44 -0
  76. package/src/components/opta/rugby/fixtures/OptaRugbyFixtures.tsx +86 -0
  77. package/src/components/opta/rugby/fixtures/__tests__/OptaRugbyFixtures.test.tsx +53 -0
  78. package/src/components/opta/rugby/fixtures/__tests__/__snapshots__/OptaRugbyFixtures.test.tsx.snap +34 -0
  79. package/src/components/opta/rugby/fixtures/styles.ts +257 -0
  80. package/src/components/opta/rugby/match-stats/OptaRugbyMatchStats.stories.tsx +34 -0
  81. package/src/components/opta/rugby/match-stats/OptaRugbyMatchStats.tsx +71 -0
  82. package/src/components/opta/rugby/match-stats/__tests__/OptaRugbyMatchStats.test.tsx +52 -0
  83. package/src/components/opta/rugby/match-stats/__tests__/__snapshots__/OptaRugbyMatchStats.test.tsx.snap +34 -0
  84. package/src/components/opta/rugby/match-stats/styles.ts +154 -0
  85. package/src/components/opta/rugby/shared-styles.ts +75 -0
  86. package/src/components/opta/rugby/standings/OptaRugbyStandings.stories.tsx +49 -0
  87. package/src/components/opta/rugby/standings/OptaRugbyStandings.tsx +66 -0
  88. package/src/components/opta/rugby/standings/__tests__/OptaRugbyStandings.test.tsx +51 -0
  89. package/src/components/opta/rugby/standings/__tests__/__snapshots__/OptaRugbyStandings.test.tsx.snap +34 -0
  90. package/src/components/opta/rugby/standings/styles.ts +248 -0
  91. package/src/components/opta/rugby/summary/OptaRugbySummary.stories.tsx +34 -0
  92. package/src/components/opta/rugby/summary/OptaRugbySummary.tsx +71 -0
  93. package/src/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.tsx +52 -0
  94. package/src/components/opta/rugby/summary/__tests__/__snapshots__/OptaRugbySummary.test.tsx.snap +34 -0
  95. package/src/components/opta/rugby/summary/styles.ts +153 -0
  96. package/src/components/opta/utils/__tests__/config.test.tsx +38 -0
  97. package/src/components/opta/utils/config.ts +13 -3
  98. package/src/helpers/fetch/FetchProvider.tsx +2 -2
  99. package/src/helpers/fetch/__tests__/FetchProvider.test.tsx +21 -31
  100. package/src/helpers/fetch/__tests__/__snapshots__/FetchProvider.test.tsx.snap +10 -2
  101. package/src/index.ts +14 -0
@@ -0,0 +1,49 @@
1
+ import React from 'react';
2
+ import { showcaseConverter } from '@times-components/storybook';
3
+
4
+ import { ArticleHarness } from '../../../../fixtures/article-harness/ArticleHarness';
5
+ import { OptaRugbyStandings } from './OptaRugbyStandings';
6
+
7
+ const showcase = {
8
+ children: [
9
+ {
10
+ decorator: (storyFn: () => React.ReactNode) => (
11
+ <ArticleHarness>{storyFn()}</ArticleHarness>
12
+ ),
13
+ type: 'decorator'
14
+ },
15
+ {
16
+ component: () => <OptaRugbyStandings season="2022" competition="209" />,
17
+ name: 'Standings',
18
+ type: 'story'
19
+ },
20
+ {
21
+ component: () => <OptaRugbyStandings season="2022" competition="242" />,
22
+ name: 'Standings (inline)',
23
+ type: 'story'
24
+ },
25
+ {
26
+ component: () => (
27
+ <OptaRugbyStandings season="2022" competition="242" navigation />
28
+ ),
29
+ name: 'Standings (dropdown)',
30
+ type: 'story'
31
+ },
32
+ {
33
+ component: () => (
34
+ <OptaRugbyStandings
35
+ season="2022"
36
+ competition="242"
37
+ default_nav="2"
38
+ navigation
39
+ />
40
+ ),
41
+ name: 'Standings (default)',
42
+ type: 'story'
43
+ }
44
+ ],
45
+ name: 'Typescript Component/In Article/Rugby/Standings'
46
+ };
47
+
48
+ // @ts-ignore
49
+ showcaseConverter(module, showcase);
@@ -0,0 +1,66 @@
1
+ import React, { useState, useEffect } from 'react';
2
+
3
+ import { Placeholder } from '@times-components/image';
4
+
5
+ import {
6
+ initSettings,
7
+ initStyleSheet,
8
+ initScript,
9
+ initElement,
10
+ initComponent
11
+ } from '../../utils/config';
12
+
13
+ import { Container, PlaceholderContainer } from '../shared-styles';
14
+ import { WidgetContainer } from './styles';
15
+
16
+ export const OptaRugbyStandings: React.FC<{
17
+ season: string;
18
+ competition: string;
19
+ default_nav?: string;
20
+ navigation?: boolean;
21
+ full_width?: boolean;
22
+ }> = React.memo(
23
+ ({ season, competition, default_nav = 1, navigation, full_width }) => {
24
+ const ref = React.createRef<HTMLDivElement>();
25
+
26
+ const [isReady, setIsReady] = useState<boolean>(false);
27
+
28
+ useEffect(() => {
29
+ const sport = 'rugby';
30
+
31
+ initSettings();
32
+ initStyleSheet(sport);
33
+
34
+ initScript().then(() => {
35
+ if (ref.current) {
36
+ ref.current.innerHTML = initElement('opta-widget', {
37
+ sport,
38
+ widget: 'standings',
39
+ season,
40
+ competition,
41
+ live: true,
42
+ navigation: navigation ? 'dropdown' : undefined,
43
+ default_nav,
44
+ show_crests: true,
45
+ breakpoints: 520
46
+ }).outerHTML;
47
+
48
+ initComponent();
49
+ setIsReady(true);
50
+ }
51
+ });
52
+ }, []);
53
+
54
+ return (
55
+ <Container border={isReady} fullWidth={full_width}>
56
+ <WidgetContainer ref={ref} />
57
+
58
+ {!isReady && (
59
+ <PlaceholderContainer>
60
+ <Placeholder />
61
+ </PlaceholderContainer>
62
+ )}
63
+ </Container>
64
+ );
65
+ }
66
+ );
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import { render, waitForElementToBeRemoved } from '@testing-library/react';
3
+
4
+ import 'regenerator-runtime';
5
+ import '@testing-library/jest-dom';
6
+
7
+ jest.mock('@times-components/image', () => ({
8
+ Placeholder: () => <>Placeholder</>
9
+ }));
10
+
11
+ const mockInitSettings = jest.fn();
12
+ const mockInitStyleSheet = jest.fn();
13
+ const mockInitComponent = jest.fn();
14
+
15
+ const mockInitElement = () => {
16
+ const element = document.createElement('div');
17
+ element.appendChild(document.createTextNode('Widget'));
18
+ return element;
19
+ };
20
+
21
+ jest.mock('../../../utils/config', () => ({
22
+ initSettings: mockInitSettings,
23
+ initStyleSheet: mockInitStyleSheet,
24
+ initScript: () => new Promise(resolve => resolve({})),
25
+ initElement: mockInitElement,
26
+ initComponent: mockInitComponent
27
+ }));
28
+
29
+ import { OptaRugbyStandings } from '../OptaRugbyStandings';
30
+
31
+ const requiredProps = {
32
+ season: '2022',
33
+ competition: '209'
34
+ };
35
+
36
+ describe('OptaRugbyStandings', () => {
37
+ it('should render correctly', async () => {
38
+ const { asFragment, getByText } = render(
39
+ <OptaRugbyStandings {...requiredProps} />
40
+ );
41
+ expect(asFragment()).toMatchSnapshot();
42
+
43
+ await waitForElementToBeRemoved(getByText('Placeholder'));
44
+
45
+ expect(mockInitSettings).toHaveBeenCalledTimes(1);
46
+ expect(mockInitStyleSheet).toHaveBeenCalledTimes(1);
47
+ expect(mockInitComponent).toHaveBeenCalledTimes(1);
48
+
49
+ expect(asFragment()).toMatchSnapshot();
50
+ });
51
+ });
@@ -0,0 +1,34 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`OptaRugbyStandings should render correctly 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="sc-bdVaJa giUBsz"
7
+ >
8
+ <div
9
+ class="sc-htpNat sc-bxivhb NeYJk"
10
+ />
11
+ <div
12
+ class="sc-bwzfXH kVYHKf"
13
+ >
14
+ Placeholder
15
+ </div>
16
+ </div>
17
+ </DocumentFragment>
18
+ `;
19
+
20
+ exports[`OptaRugbyStandings should render correctly 2`] = `
21
+ <DocumentFragment>
22
+ <div
23
+ class="sc-bdVaJa hGXeaj"
24
+ >
25
+ <div
26
+ class="sc-htpNat sc-bxivhb NeYJk"
27
+ >
28
+ <div>
29
+ Widget
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </DocumentFragment>
34
+ `;
@@ -0,0 +1,248 @@
1
+ import styled from 'styled-components';
2
+ import { breakpoints, colours, fonts } from '@times-components/styleguide';
3
+
4
+ import { WidgetContainerBase } from '../shared-styles';
5
+
6
+ export const WidgetContainer = styled(WidgetContainerBase)`
7
+ .Opta {
8
+ h3 {
9
+ height: 40px;
10
+ margin: 0;
11
+ padding-left: 10px;
12
+ color: ${colours.functional.primary};
13
+ font-family: ${fonts.supporting};
14
+ font-size: 14px;
15
+ line-height: 42px;
16
+ font-weight: normal;
17
+ background-color: ${colours.functional.keyline};
18
+ border: 0;
19
+
20
+ span {
21
+ float: none;
22
+ padding: 0;
23
+ }
24
+
25
+ @media (min-width: ${breakpoints.medium}px) {
26
+ padding-left: 14px;
27
+ }
28
+ }
29
+
30
+ .Opta-Cf {
31
+ float: none;
32
+ margin: 0;
33
+ padding: 0;
34
+ background-color: transparent;
35
+
36
+ &.Opta-Dropdown {
37
+ .Opta-Nav {
38
+ width: 110px;
39
+ margin: 20px auto;
40
+ background-color: transparent;
41
+ border: 1px solid ${colours.functional.brandColour};
42
+
43
+ h3 {
44
+ height: 38px;
45
+ color: ${colours.functional.brandColour};
46
+ font-family: ${fonts.supporting};
47
+ font-size: 14px;
48
+ line-height: 40px;
49
+ font-weight: normal;
50
+ text-align: center;
51
+ background-color: white;
52
+ border: 0;
53
+
54
+ .Opta-Icon {
55
+ height: 38px;
56
+ margin: 0 10px 0 0;
57
+
58
+ :after {
59
+ background-position: -180px -19px;
60
+ }
61
+ }
62
+
63
+ .Opta-Title {
64
+ height: 38px;
65
+ padding: 0 0 0 18px;
66
+ line-height: 40px;
67
+ }
68
+
69
+ &.Opta-Open {
70
+ .Opta-Icon {
71
+ :after {
72
+ background-position: -149px -20px;
73
+ }
74
+ }
75
+ }
76
+ }
77
+
78
+ ul {
79
+ display: none;
80
+ top: 0;
81
+ list-style-type: none;
82
+ background-color: ${colours.functional.backgroundPrimary};
83
+ border: 0;
84
+ border-top: 1px solid ${colours.functional.brandColour};
85
+
86
+ li {
87
+ margin: 0;
88
+ text-align: center;
89
+
90
+ a {
91
+ height: 28px;
92
+ padding: 0;
93
+ color: ${colours.functional.primary};
94
+ font-family: ${fonts.supporting};
95
+ font-size: 14px;
96
+ line-height: 30px;
97
+ background-color: transparent;
98
+
99
+ &:hover {
100
+ color: ${colours.functional.brandColour};
101
+ font-weight: bold;
102
+ background-color: white;
103
+ }
104
+ }
105
+
106
+ &:first-of-type {
107
+ a {
108
+ height: 32px;
109
+ padding-top: 4px;
110
+ }
111
+ }
112
+
113
+ &:last-of-type {
114
+ a {
115
+ height: 32px;
116
+ padding-bottom: 4px;
117
+ }
118
+ }
119
+ }
120
+ }
121
+ }
122
+ }
123
+
124
+ ul.Opta-TabbedContent {
125
+ margin: 0;
126
+ padding: 0;
127
+ list-style-type: none;
128
+
129
+ li {
130
+ display: none;
131
+
132
+ &.Opta-On {
133
+ display: block;
134
+ }
135
+
136
+ h3 {
137
+ display: none;
138
+ text-decoration: none !important;
139
+
140
+ .Opta-Icon {
141
+ display: none;
142
+ }
143
+ }
144
+ }
145
+ }
146
+
147
+ table {
148
+ thead {
149
+ background-color: ${colours.functional.backgroundSecondary};
150
+
151
+ tr {
152
+ height: 40px;
153
+
154
+ th {
155
+ padding: 0;
156
+ color: ${colours.functional.primary};
157
+ font-family: ${fonts.supporting};
158
+ font-size: 14px;
159
+ line-height: 14px;
160
+ font-weight: normal;
161
+ text-align: center;
162
+ background-color: transparent;
163
+
164
+ abbr {
165
+ font-size: inherit;
166
+ line-height: inherit;
167
+ text-decoration: none;
168
+ }
169
+
170
+ &.Opta-Team {
171
+ width: auto !important;
172
+ }
173
+
174
+ &:last-of-type {
175
+ padding: 0 10px 0 0;
176
+ }
177
+ }
178
+ }
179
+ }
180
+
181
+ tbody {
182
+ tr {
183
+ height: 40px;
184
+ border-bottom: 1px solid #e4e4e4;
185
+
186
+ th {
187
+ width: 42px;
188
+ padding: 6px 0 0 0;
189
+ color: ${colours.section.sport};
190
+ font-family: ${fonts.supporting};
191
+ font-size: 14px;
192
+ line-height: 14px;
193
+ font-weight: normal;
194
+ text-align: center;
195
+ background-color: transparent;
196
+
197
+ @media (min-width: ${breakpoints.medium}px) {
198
+ width: 50px;
199
+ font-size: 16px;
200
+ line-height: 16px;
201
+ }
202
+ }
203
+
204
+ td {
205
+ width: 30px;
206
+ padding: 3px 0 0 0;
207
+ color: ${colours.functional.brandColour};
208
+ font-family: ${fonts.headline};
209
+ font-size: 14px;
210
+ line-height: 14px;
211
+ text-align: center;
212
+ background-color: transparent;
213
+
214
+ &:last-of-type {
215
+ width: 40px;
216
+ padding: 3px 10px 0 0;
217
+ }
218
+
219
+ &.Opta-Team {
220
+ width: auto !important;
221
+ text-align: left;
222
+ }
223
+
224
+ .Opta-Image {
225
+ width: 20px;
226
+ margin-top: -3px;
227
+
228
+ img {
229
+ width: 20px;
230
+ }
231
+ }
232
+
233
+ @media (min-width: ${breakpoints.medium}px) {
234
+ width: 40px;
235
+ font-size: 16px;
236
+ line-height: 16px;
237
+
238
+ &:last-of-type {
239
+ width: 50px;
240
+ }
241
+ }
242
+ }
243
+ }
244
+ }
245
+ }
246
+ }
247
+ }
248
+ `;
@@ -0,0 +1,34 @@
1
+ import React from 'react';
2
+ import { showcaseConverter } from '@times-components/storybook';
3
+
4
+ import { ArticleHarness } from '../../../../fixtures/article-harness/ArticleHarness';
5
+ import { OptaRugbySummary } from './OptaRugbySummary';
6
+
7
+ const showcase = {
8
+ children: [
9
+ {
10
+ decorator: (storyFn: () => React.ReactNode) => (
11
+ <ArticleHarness>{storyFn()}</ArticleHarness>
12
+ ),
13
+ type: 'decorator'
14
+ },
15
+ {
16
+ component: () => (
17
+ <OptaRugbySummary season="2022" competition="209" match="921100" />
18
+ ),
19
+ name: 'Summary',
20
+ type: 'story'
21
+ },
22
+ {
23
+ component: () => (
24
+ <OptaRugbySummary season="2022" competition="209" match="921087" />
25
+ ),
26
+ name: 'Summary (results)',
27
+ type: 'story'
28
+ }
29
+ ],
30
+ name: 'Typescript Component/In Article/Rugby/Summary'
31
+ };
32
+
33
+ // @ts-ignore
34
+ showcaseConverter(module, showcase);
@@ -0,0 +1,71 @@
1
+ import React, { useState, useEffect } from 'react';
2
+
3
+ import { Placeholder } from '@times-components/image';
4
+
5
+ import {
6
+ initSettings,
7
+ initStyleSheet,
8
+ initScript,
9
+ initElement,
10
+ initComponent
11
+ } from '../../utils/config';
12
+
13
+ import { Container, PlaceholderContainer } from '../shared-styles';
14
+ import { WidgetContainer } from './styles';
15
+
16
+ export const OptaRugbySummary: React.FC<{
17
+ season: string;
18
+ competition: string;
19
+ match: string;
20
+ full_width?: boolean;
21
+ }> = React.memo(({ season, competition, match, full_width }) => {
22
+ const ref = React.createRef<HTMLDivElement>();
23
+
24
+ const [isReady, setIsReady] = useState<boolean>(false);
25
+
26
+ useEffect(() => {
27
+ const sport = 'rugby';
28
+
29
+ initSettings();
30
+ initStyleSheet(sport);
31
+
32
+ initScript().then(() => {
33
+ if (ref.current) {
34
+ ref.current.innerHTML = initElement('opta-widget', {
35
+ sport,
36
+ widget: 'match_summary',
37
+ season,
38
+ competition,
39
+ match,
40
+ live: true,
41
+ show_match_header: true,
42
+ show_halftime_score: true,
43
+ show_competition_name: true,
44
+ show_date: true,
45
+ show_crests: true,
46
+ show_tries: true,
47
+ show_conversions: true,
48
+ show_penalties: true,
49
+ show_drop_goals: 'scored',
50
+ date_format: 'DD/MM/YYYY',
51
+ breakpoints: '520'
52
+ }).outerHTML;
53
+
54
+ initComponent();
55
+ setIsReady(true);
56
+ }
57
+ });
58
+ }, []);
59
+
60
+ return (
61
+ <Container border={isReady} fullWidth={full_width}>
62
+ <WidgetContainer ref={ref} />
63
+
64
+ {!isReady && (
65
+ <PlaceholderContainer>
66
+ <Placeholder />
67
+ </PlaceholderContainer>
68
+ )}
69
+ </Container>
70
+ );
71
+ });
@@ -0,0 +1,52 @@
1
+ import React from 'react';
2
+ import { render, waitForElementToBeRemoved } from '@testing-library/react';
3
+
4
+ import 'regenerator-runtime';
5
+ import '@testing-library/jest-dom';
6
+
7
+ jest.mock('@times-components/image', () => ({
8
+ Placeholder: () => <>Placeholder</>
9
+ }));
10
+
11
+ const mockInitSettings = jest.fn();
12
+ const mockInitStyleSheet = jest.fn();
13
+ const mockInitComponent = jest.fn();
14
+
15
+ const mockInitElement = () => {
16
+ const element = document.createElement('div');
17
+ element.appendChild(document.createTextNode('Widget'));
18
+ return element;
19
+ };
20
+
21
+ jest.mock('../../../utils/config', () => ({
22
+ initSettings: mockInitSettings,
23
+ initStyleSheet: mockInitStyleSheet,
24
+ initScript: () => new Promise(resolve => resolve({})),
25
+ initElement: mockInitElement,
26
+ initComponent: mockInitComponent
27
+ }));
28
+
29
+ import { OptaRugbySummary } from '../OptaRugbySummary';
30
+
31
+ const requiredProps = {
32
+ season: '2022',
33
+ competition: '209',
34
+ match: '921100'
35
+ };
36
+
37
+ describe('OptaRugbySummary', () => {
38
+ it('should render correctly', async () => {
39
+ const { asFragment, getByText } = render(
40
+ <OptaRugbySummary {...requiredProps} />
41
+ );
42
+ expect(asFragment()).toMatchSnapshot();
43
+
44
+ await waitForElementToBeRemoved(getByText('Placeholder'));
45
+
46
+ expect(mockInitSettings).toHaveBeenCalledTimes(1);
47
+ expect(mockInitStyleSheet).toHaveBeenCalledTimes(1);
48
+ expect(mockInitComponent).toHaveBeenCalledTimes(1);
49
+
50
+ expect(asFragment()).toMatchSnapshot();
51
+ });
52
+ });
@@ -0,0 +1,34 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`OptaRugbySummary should render correctly 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="sc-bdVaJa giUBsz"
7
+ >
8
+ <div
9
+ class="sc-htpNat sc-bxivhb kCSvNb"
10
+ />
11
+ <div
12
+ class="sc-bwzfXH kVYHKf"
13
+ >
14
+ Placeholder
15
+ </div>
16
+ </div>
17
+ </DocumentFragment>
18
+ `;
19
+
20
+ exports[`OptaRugbySummary should render correctly 2`] = `
21
+ <DocumentFragment>
22
+ <div
23
+ class="sc-bdVaJa hGXeaj"
24
+ >
25
+ <div
26
+ class="sc-htpNat sc-bxivhb kCSvNb"
27
+ >
28
+ <div>
29
+ Widget
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </DocumentFragment>
34
+ `;