@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,127 @@
1
+ import styled from 'styled-components';
2
+ import { breakpoints, colours, fonts } from '@times-components/styleguide';
3
+ import { ShowAllButton } from '../common-styles';
4
+
5
+ export const Container = styled.div<{
6
+ sectionColour: string;
7
+ }>`
8
+ margin: 0 auto 20px auto;
9
+ padding: 20px 0 0;
10
+ background-color: ${colours.functional.backgroundPrimary};
11
+ border-top: ${({ sectionColour }) => `2px solid ${sectionColour}`};
12
+ width: 100%;
13
+
14
+ @media (min-width: ${breakpoints.medium}px) {
15
+ width: 80.8%;
16
+ }
17
+
18
+ @media (min-width: ${breakpoints.wide}px) {
19
+ width: 56.2%;
20
+ }
21
+
22
+ a {
23
+ text-decoration: none;
24
+ }
25
+ `;
26
+
27
+ export const ContentContainer = styled.div`
28
+ display: flex;
29
+ flex-direction: column;
30
+ justify-content: space-between;
31
+ padding: 0 16px;
32
+ `;
33
+
34
+ export const StyledShowAllButton = styled(ShowAllButton)`
35
+ font-size: 14px;
36
+ margin: 11px 0;
37
+ padding: 12px 15px 10px;
38
+ `;
39
+
40
+ export const ListItem = styled.li`
41
+ padding: 12px 0 13px;
42
+ width: 100%;
43
+ position: relative;
44
+ `;
45
+
46
+ export const LeftPanel = styled.div<{
47
+ sectionColour: string;
48
+ circularImage: string;
49
+ }>`
50
+ display: table;
51
+ float: left;
52
+ width: ${({ circularImage }) => (circularImage ? '80px' : '40px')};
53
+ text-align: center;
54
+ padding-right: ${({ circularImage }) => (circularImage ? '16px' : '24px')};
55
+ height: 100%;
56
+
57
+ & img {
58
+ border-radius: 100%;
59
+ height: 50px;
60
+ width: 50px;
61
+ position: relative;
62
+ margin-left: 16px;
63
+ z-index: 2;
64
+ }
65
+
66
+ & :before {
67
+ content: '';
68
+ background: ${({ sectionColour }) => `${sectionColour}`};
69
+ position: relative;
70
+ top: 0px;
71
+ left: 15px;
72
+ width: 8px;
73
+ height: 8px;
74
+ border-radius: 100%;
75
+ z-index: 1;
76
+ display: ${({ circularImage }) => (circularImage ? 'none' : 'block')};
77
+ }
78
+
79
+ & :after {
80
+ content: '';
81
+ border-right: 1px solid #ccc;
82
+ height: 100%;
83
+ display: block;
84
+ position: absolute;
85
+ top: ${({ circularImage }) => (circularImage ? '60px' : '20px')};
86
+ left: ${({ circularImage }) => (circularImage ? '42px' : '19px')};
87
+ z-index: 1;
88
+ }
89
+
90
+ @media (min-width: ${breakpoints.medium}px) {
91
+ width: ${({ circularImage }) => (circularImage ? '100px' : '39px')};
92
+ padding-right: ${({ circularImage }) => (circularImage ? '16px' : '24px')};
93
+ & img {
94
+ height: 76px;
95
+ width: 76px;
96
+ }
97
+ & :after {
98
+ top: ${({ circularImage }) => (circularImage ? '74px' : '20px')};
99
+ left: ${({ circularImage }) => (circularImage ? '52px' : '19px')};
100
+ }
101
+ }
102
+ `;
103
+
104
+ export const RightPanel = styled.div`
105
+ display: grid;
106
+ `;
107
+
108
+ export const Date = styled.div<{ sectionColour: string }>`
109
+ font-family: ${fonts.supporting};
110
+ text-transform: uppercase;
111
+ font-size: 12px;
112
+ line-height: 16px;
113
+ margin-bottom: 8px;
114
+ color: ${({ sectionColour }) => `${sectionColour}`};
115
+ `;
116
+
117
+ export const SubHeading = styled.div`
118
+ font-size: 20px;
119
+ line-height: 20px;
120
+ color: ${colours.functional.brandColour};
121
+ font-family: ${fonts.headline};
122
+ margin-bottom: 6px;
123
+ @media (min-width: ${breakpoints.medium}px) {
124
+ font-size: 24px;
125
+ line-height: 24px;
126
+ }
127
+ `;
@@ -25,15 +25,17 @@ export const OptaFootballFixtures: React.FC<{
25
25
  const [isReady, setIsReady] = useState<boolean>(false);
26
26
 
27
27
  useEffect(() => {
28
+ const sport = 'football';
29
+
28
30
  initSettings();
29
- initStyleSheet();
31
+ initStyleSheet(sport);
30
32
 
31
33
  initScript().then(() => {
32
34
  if (ref.current) {
33
35
  ref.current.innerHTML = initElement(
34
36
  'opta-widget',
35
37
  {
36
- sport: 'football',
38
+ sport,
37
39
  widget: 'fixtures',
38
40
  season,
39
41
  competition,
@@ -47,7 +49,7 @@ export const OptaFootballFixtures: React.FC<{
47
49
  breakpoints: 520
48
50
  },
49
51
  initElement('opta-widget', {
50
- sport: 'football',
52
+ sport,
51
53
  widget: 'match_summary',
52
54
  season: '',
53
55
  competition: '',
@@ -0,0 +1,53 @@
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 { OptaFootballFixtures } from '../OptaFootballFixtures';
30
+
31
+ const requiredProps = {
32
+ season: '2020',
33
+ competition: '3',
34
+ date_from: '2021-06-20',
35
+ date_to: '2021-07-11'
36
+ };
37
+
38
+ describe('OptaFootballFixtures', () => {
39
+ it('should render correctly', async () => {
40
+ const { asFragment, getByText } = render(
41
+ <OptaFootballFixtures {...requiredProps} />
42
+ );
43
+ expect(asFragment()).toMatchSnapshot();
44
+
45
+ await waitForElementToBeRemoved(getByText('Placeholder'));
46
+
47
+ expect(mockInitSettings).toHaveBeenCalledTimes(1);
48
+ expect(mockInitStyleSheet).toHaveBeenCalledTimes(1);
49
+ expect(mockInitComponent).toHaveBeenCalledTimes(1);
50
+
51
+ expect(asFragment()).toMatchSnapshot();
52
+ });
53
+ });
@@ -0,0 +1,34 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`OptaFootballFixtures should render correctly 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="sc-bdVaJa giUBsz"
7
+ >
8
+ <div
9
+ class="sc-htpNat sc-ifAKCX ceXVkP"
10
+ />
11
+ <div
12
+ class="sc-bwzfXH kVYHKf"
13
+ >
14
+ Placeholder
15
+ </div>
16
+ </div>
17
+ </DocumentFragment>
18
+ `;
19
+
20
+ exports[`OptaFootballFixtures should render correctly 2`] = `
21
+ <DocumentFragment>
22
+ <div
23
+ class="sc-bdVaJa hGXeaj"
24
+ >
25
+ <div
26
+ class="sc-htpNat sc-ifAKCX ceXVkP"
27
+ >
28
+ <div>
29
+ Widget
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </DocumentFragment>
34
+ `;
@@ -24,13 +24,15 @@ export const OptaFootballMatchStats: React.FC<{
24
24
  const [isReady, setIsReady] = useState<boolean>(false);
25
25
 
26
26
  useEffect(() => {
27
+ const sport = 'football';
28
+
27
29
  initSettings();
28
- initStyleSheet();
30
+ initStyleSheet(sport);
29
31
 
30
32
  initScript().then(() => {
31
33
  if (ref.current) {
32
34
  ref.current.innerHTML = initElement('opta-widget', {
33
- sport: 'football',
35
+ sport,
34
36
  widget: 'matchstats',
35
37
  season,
36
38
  competition,
@@ -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 { OptaFootballMatchStats } from '../OptaFootballMatchStats';
30
+
31
+ const requiredProps = {
32
+ season: '2020',
33
+ competition: '3',
34
+ match: '2041900'
35
+ };
36
+
37
+ describe('OptaFootballMatchStats', () => {
38
+ it('should render correctly', async () => {
39
+ const { asFragment, getByText } = render(
40
+ <OptaFootballMatchStats {...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[`OptaFootballMatchStats should render correctly 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="sc-bdVaJa giUBsz"
7
+ >
8
+ <div
9
+ class="sc-htpNat sc-bxivhb ljTAFU"
10
+ />
11
+ <div
12
+ class="sc-bwzfXH kVYHKf"
13
+ >
14
+ Placeholder
15
+ </div>
16
+ </div>
17
+ </DocumentFragment>
18
+ `;
19
+
20
+ exports[`OptaFootballMatchStats should render correctly 2`] = `
21
+ <DocumentFragment>
22
+ <div
23
+ class="sc-bdVaJa hGXeaj"
24
+ >
25
+ <div
26
+ class="sc-htpNat sc-bxivhb ljTAFU"
27
+ >
28
+ <div>
29
+ Widget
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </DocumentFragment>
34
+ `;
@@ -26,13 +26,15 @@ export const OptaFootballStandings: React.FC<{
26
26
  const [isReady, setIsReady] = useState<boolean>(false);
27
27
 
28
28
  useEffect(() => {
29
+ const sport = 'football';
30
+
29
31
  initSettings();
30
- initStyleSheet();
32
+ initStyleSheet(sport);
31
33
 
32
34
  initScript().then(() => {
33
35
  if (ref.current) {
34
36
  ref.current.innerHTML = initElement('opta-widget', {
35
- sport: 'football',
37
+ sport,
36
38
  widget: 'standings',
37
39
  season,
38
40
  competition,
@@ -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 { OptaFootballStandings } from '../OptaFootballStandings';
30
+
31
+ const requiredProps = {
32
+ season: '2020',
33
+ competition: '3'
34
+ };
35
+
36
+ describe('OptaFootballStandings', () => {
37
+ it('should render correctly', async () => {
38
+ const { asFragment, getByText } = render(
39
+ <OptaFootballStandings {...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[`OptaFootballStandings should render correctly 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="sc-bdVaJa giUBsz"
7
+ >
8
+ <div
9
+ class="sc-htpNat sc-bxivhb cPAtKK"
10
+ />
11
+ <div
12
+ class="sc-bwzfXH kVYHKf"
13
+ >
14
+ Placeholder
15
+ </div>
16
+ </div>
17
+ </DocumentFragment>
18
+ `;
19
+
20
+ exports[`OptaFootballStandings should render correctly 2`] = `
21
+ <DocumentFragment>
22
+ <div
23
+ class="sc-bdVaJa hGXeaj"
24
+ >
25
+ <div
26
+ class="sc-htpNat sc-bxivhb cPAtKK"
27
+ >
28
+ <div>
29
+ Widget
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </DocumentFragment>
34
+ `;
@@ -24,13 +24,15 @@ export const OptaFootballSummary: React.FC<{
24
24
  const [isReady, setIsReady] = useState<boolean>(false);
25
25
 
26
26
  useEffect(() => {
27
+ const sport = 'football';
28
+
27
29
  initSettings();
28
- initStyleSheet();
30
+ initStyleSheet(sport);
29
31
 
30
32
  initScript().then(() => {
31
33
  if (ref.current) {
32
34
  ref.current.innerHTML = initElement('opta-widget', {
33
- sport: 'football',
35
+ sport,
34
36
  widget: 'match_summary',
35
37
  season,
36
38
  competition,
@@ -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 { OptaFootballSummary } from '../OptaFootballSummary';
30
+
31
+ const requiredProps = {
32
+ season: '2020',
33
+ competition: '3',
34
+ match: '2041900'
35
+ };
36
+
37
+ describe('OptaFootballSummary', () => {
38
+ it('should render correctly', async () => {
39
+ const { asFragment, getByText } = render(
40
+ <OptaFootballSummary {...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[`OptaFootballSummary should render correctly 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="sc-bdVaJa giUBsz"
7
+ >
8
+ <div
9
+ class="sc-htpNat sc-bxivhb hHhneA"
10
+ />
11
+ <div
12
+ class="sc-bwzfXH kVYHKf"
13
+ >
14
+ Placeholder
15
+ </div>
16
+ </div>
17
+ </DocumentFragment>
18
+ `;
19
+
20
+ exports[`OptaFootballSummary should render correctly 2`] = `
21
+ <DocumentFragment>
22
+ <div
23
+ class="sc-bdVaJa hGXeaj"
24
+ >
25
+ <div
26
+ class="sc-htpNat sc-bxivhb hHhneA"
27
+ >
28
+ <div>
29
+ Widget
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </DocumentFragment>
34
+ `;
@@ -0,0 +1,44 @@
1
+ import React from 'react';
2
+ import { showcaseConverter } from '@times-components/storybook';
3
+
4
+ import { ArticleHarness } from '../../../../fixtures/article-harness/ArticleHarness';
5
+ import { OptaRugbyFixtures } from './OptaRugbyFixtures';
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
+ <OptaRugbyFixtures
18
+ season="2022"
19
+ competition="209"
20
+ date_from="2022-01-01"
21
+ date_to="2022-12-01"
22
+ />
23
+ ),
24
+ name: 'Fixtures',
25
+ type: 'story'
26
+ },
27
+ {
28
+ component: () => (
29
+ <OptaRugbyFixtures
30
+ season="2022"
31
+ competition="209"
32
+ date_from="2022-01-01"
33
+ date_to="2022-12-01"
34
+ />
35
+ ),
36
+ name: 'Fixtures (results)',
37
+ type: 'story'
38
+ }
39
+ ],
40
+ name: 'Typescript Component/In Article/Rugby/Fixtures'
41
+ };
42
+
43
+ // @ts-ignore
44
+ showcaseConverter(module, showcase);
@@ -0,0 +1,86 @@
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 OptaRugbyFixtures: React.FC<{
17
+ season: string;
18
+ competition: string;
19
+ date_from: string;
20
+ date_to: string;
21
+ full_width?: boolean;
22
+ }> = React.memo(({ season, competition, date_from, date_to, full_width }) => {
23
+ const ref = React.createRef<HTMLDivElement>();
24
+
25
+ const [isReady, setIsReady] = useState<boolean>(false);
26
+
27
+ useEffect(() => {
28
+ const sport = 'rugby';
29
+
30
+ initSettings();
31
+ initStyleSheet(sport);
32
+
33
+ initScript().then(() => {
34
+ if (ref.current) {
35
+ ref.current.innerHTML = initElement(
36
+ 'opta-widget',
37
+ {
38
+ sport,
39
+ widget: 'fixtures',
40
+ season,
41
+ competition,
42
+ date_from,
43
+ date_to,
44
+ live: true,
45
+ grouping: 'date',
46
+ show_grouping: true,
47
+ show_subgrouping: false,
48
+ show_crests: true,
49
+ date_format: 'dddd MMMM D YYYY',
50
+ breakpoints: 520
51
+ },
52
+ initElement('opta-widget', {
53
+ sport,
54
+ widget: 'match_summary',
55
+ season: '',
56
+ competition: '',
57
+ match: '',
58
+ live: true,
59
+ show_crests: true,
60
+ show_tries: true,
61
+ show_conversions: true,
62
+ show_penalties: true,
63
+ show_drop_goals: 'scored',
64
+ show_cards: 'all',
65
+ breakpoints: '520'
66
+ })
67
+ ).outerHTML;
68
+
69
+ initComponent();
70
+ setIsReady(true);
71
+ }
72
+ });
73
+ }, []);
74
+
75
+ return (
76
+ <Container border={isReady} fullWidth={full_width}>
77
+ <WidgetContainer ref={ref} />
78
+
79
+ {!isReady && (
80
+ <PlaceholderContainer>
81
+ <Placeholder />
82
+ </PlaceholderContainer>
83
+ )}
84
+ </Container>
85
+ );
86
+ });