@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,3 @@
1
+ import fetchMock from 'fetch-mock';
2
+ const fetch = fetchMock.sandbox();
3
+ export default fetch;
@@ -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
+ });
@@ -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 { OptaRugbyFixtures } from '../OptaRugbyFixtures';
30
+
31
+ const requiredProps = {
32
+ season: '2022',
33
+ competition: '209',
34
+ date_from: '2022-01-01',
35
+ date_to: '2022-12-01'
36
+ };
37
+
38
+ describe('OptaRugbyFixtures', () => {
39
+ it('should render correctly', async () => {
40
+ const { asFragment, getByText } = render(
41
+ <OptaRugbyFixtures {...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[`OptaRugbyFixtures should render correctly 1`] = `
4
+ <DocumentFragment>
5
+ <div
6
+ class="sc-bdVaJa giUBsz"
7
+ >
8
+ <div
9
+ class="sc-htpNat sc-ifAKCX cyWAhZ"
10
+ />
11
+ <div
12
+ class="sc-bwzfXH kVYHKf"
13
+ >
14
+ Placeholder
15
+ </div>
16
+ </div>
17
+ </DocumentFragment>
18
+ `;
19
+
20
+ exports[`OptaRugbyFixtures should render correctly 2`] = `
21
+ <DocumentFragment>
22
+ <div
23
+ class="sc-bdVaJa hGXeaj"
24
+ >
25
+ <div
26
+ class="sc-htpNat sc-ifAKCX cyWAhZ"
27
+ >
28
+ <div>
29
+ Widget
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </DocumentFragment>
34
+ `;