@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,153 @@
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
+ h2 {
9
+ margin: 20px 0 10px 0 !important;
10
+ }
11
+
12
+ .Opta-Cf {
13
+ padding: 0;
14
+ background-color: transparent;
15
+
16
+ table {
17
+ tbody {
18
+ tr {
19
+ td {
20
+ color: ${colours.functional.brandColour};
21
+ font-family: ${fonts.headline};
22
+ font-size: 18px;
23
+ line-height: 18px;
24
+ padding: 0;
25
+
26
+ &.Opta-Crest {
27
+ text-align: left;
28
+
29
+ &.Opta-Home {
30
+ text-align: right;
31
+ }
32
+
33
+ img {
34
+ width: 40px;
35
+ }
36
+ }
37
+
38
+ &.Opta-Team {
39
+ padding-left: 10px;
40
+ font-size: 18px;
41
+ line-height: 18px;
42
+
43
+ &.Opta-Home {
44
+ padding-right: 10px;
45
+ padding-left: 0;
46
+ text-align: right;
47
+ }
48
+ }
49
+
50
+ &.Opta-Score {
51
+ width: 20px;
52
+ font-size: 24px;
53
+ line-height: 24px;
54
+ text-align: left;
55
+
56
+ &.Opta-Home {
57
+ text-align: right;
58
+ }
59
+
60
+ span {
61
+ min-width: 0;
62
+ padding: 0;
63
+ color: inherit;
64
+ font-family: inherit;
65
+ font-size: inherit;
66
+ line-height: inherit;
67
+ text-align: inherit;
68
+ background-color: transparent !important;
69
+ }
70
+
71
+ @media (min-width: ${breakpoints.medium}px) {
72
+ width: 30px;
73
+ font-size: 32px;
74
+ line-height: 32px;
75
+ }
76
+ }
77
+
78
+ &.Opta-Divider {
79
+ width: 20px;
80
+ text-align: center;
81
+
82
+ abbr {
83
+ font-size: inherit;
84
+ line-height: inherit;
85
+ text-decoration: none;
86
+ }
87
+ }
88
+ }
89
+
90
+ &.Opta-Score-Extras {
91
+ td {
92
+ color: ${colours.functional.brandColour};
93
+ font-family: ${fonts.supporting};
94
+ font-size: 14px;
95
+ line-height: 28px;
96
+
97
+ span {
98
+ color: inherit;
99
+ font-size: inherit;
100
+ }
101
+ }
102
+ }
103
+
104
+ &.Opta-MatchHeader-Details {
105
+ div {
106
+ padding: 0;
107
+ color: ${colours.section.sport};
108
+ font-family: ${fonts.supporting};
109
+ font-size: 12px;
110
+ line-height: 12px;
111
+ letter-spacing: 1px;
112
+ text-transform: uppercase;
113
+ background-color: transparent;
114
+
115
+ span {
116
+ margin: 0 6px;
117
+ color: inherit;
118
+ font-size: inherit;
119
+ }
120
+ }
121
+ }
122
+ }
123
+ }
124
+ }
125
+
126
+ .Opta-Events {
127
+ padding: 10px 0 2px 0;
128
+
129
+ li {
130
+ padding: 0 0 8px 0;
131
+
132
+ .Opta-Event-Text {
133
+ color: ${colours.functional.brandColour};
134
+ font-family: ${fonts.supporting};
135
+ font-size: 14px;
136
+ line-height: 16px;
137
+
138
+ .Opta-Event-Player,
139
+ .Opta-Event-Time,
140
+ .Opta-Event-Text-Type {
141
+ font-size: inherit;
142
+ line-height: inherit;
143
+ }
144
+
145
+ .Opta-Event-Time {
146
+ color: ${colours.section.sport};
147
+ }
148
+ }
149
+ }
150
+ }
151
+ }
152
+ }
153
+ `;
@@ -0,0 +1,38 @@
1
+ import { initSettings, initStyleSheet, initElement } from '../config';
2
+
3
+ describe('Opta config', () => {
4
+ it('should initialise opta settings', async () => {
5
+ initSettings();
6
+ expect(window.opta_settings.subscription_id).toEqual(
7
+ 'db98cff9f9612c01bbf3435964748e95'
8
+ );
9
+ });
10
+
11
+ it('should initialise football stylesheet', async () => {
12
+ initStyleSheet('football');
13
+ const element = document.head.querySelector(
14
+ 'link[href="https://secure.widget.cloud.opta.net/v3/css/v3.football.opta-widgets.css"]'
15
+ );
16
+ expect(element).toBeTruthy();
17
+ });
18
+
19
+ it('should initialise rugby stylesheet', async () => {
20
+ initStyleSheet('rugby');
21
+ const element = document.head.querySelector(
22
+ 'link[href="https://secure.widget.cloud.opta.net/v3/css/v3.rugby.opta-widgets.css"]'
23
+ );
24
+ expect(element).toBeTruthy();
25
+ });
26
+
27
+ it('should create the correct element', async () => {
28
+ const element = initElement(
29
+ 'opta-widget',
30
+ { sport: 'football' },
31
+ initElement('opta-sub-widget')
32
+ );
33
+
34
+ expect(element.nodeName).toEqual('OPTA-WIDGET');
35
+ expect(element.getAttribute('sport')).toEqual('football');
36
+ expect(element.childNodes[0].nodeName).toEqual('OPTA-SUB-WIDGET');
37
+ });
38
+ });
@@ -25,10 +25,20 @@ export const initSettings = () => {
25
25
  }
26
26
  };
27
27
 
28
- const cssUrl =
29
- 'https://secure.widget.cloud.opta.net/v3/css/v3.football.opta-widgets.css';
28
+ const getStyleSheetUrl = (sport: string) => {
29
+ switch (sport) {
30
+ case 'rugby':
31
+ return 'https://secure.widget.cloud.opta.net/v3/css/v3.rugby.opta-widgets.css';
32
+
33
+ case 'football':
34
+ default:
35
+ return 'https://secure.widget.cloud.opta.net/v3/css/v3.football.opta-widgets.css';
36
+ }
37
+ };
38
+
39
+ export const initStyleSheet = (sport: string) => {
40
+ const cssUrl = getStyleSheetUrl(sport);
30
41
 
31
- export const initStyleSheet = () => {
32
42
  if (!document.head.querySelector(`link[href="${cssUrl}"]`)) {
33
43
  const link = document.createElement('link');
34
44
  link.setAttribute('rel', 'stylesheet');
@@ -40,8 +40,8 @@ export const FetchProvider: React.FC<FetchProviderProps> = ({
40
40
  } else {
41
41
  throw new Error('must provide a Fetch url');
42
42
  }
43
- } catch (error) {
44
- setError(error);
43
+ } catch (err) {
44
+ setError(err.message);
45
45
  setLoading(false);
46
46
  }
47
47
  };
@@ -2,12 +2,11 @@ import React, { FC } from 'react';
2
2
  import { render } from '@testing-library/react';
3
3
 
4
4
  import 'regenerator-runtime';
5
- import '@testing-library/jest-dom';
6
5
 
7
- import { FetchProvider, useFetch } from '../FetchProvider';
8
- import { enableFetchMocks } from 'jest-fetch-mock';
6
+ import _fetchMock from 'isomorphic-unfetch';
7
+ const fetchMock = _fetchMock as any;
9
8
 
10
- enableFetchMocks();
9
+ import { FetchProvider, useFetch } from '../FetchProvider';
11
10
 
12
11
  const TestComponent: FC<{}> = () => {
13
12
  try {
@@ -28,71 +27,62 @@ const TestComponent: FC<{}> = () => {
28
27
  };
29
28
 
30
29
  describe('<FetchProvider>', () => {
31
- beforeEach(() => {
32
- // if you have an existing `beforeEach` just add the following line to it
33
- fetchMock.doMock();
34
- });
35
-
36
30
  afterEach(() => {
37
- fetchMock.resetMocks();
31
+ fetchMock.restore();
32
+ fetchMock.reset();
38
33
  });
39
34
 
35
+ const endpoint = 'http://localhost:123';
36
+
40
37
  it('fetch', async () => {
41
- fetchMock.mockResponse(async () => ({ body: '{ "value" : "boo" }' }));
38
+ const value = 'Fetched';
39
+ fetchMock.mock(endpoint, { status: 200, body: { value } });
42
40
 
43
41
  const { asFragment, findByText } = render(
44
- <FetchProvider url="http://localhost:123">
42
+ <FetchProvider url={endpoint}>
45
43
  <TestComponent />
46
44
  </FetchProvider>
47
45
  );
48
- await findByText('boo');
49
46
 
47
+ findByText('loading');
50
48
  expect(asFragment()).toMatchSnapshot();
51
- });
52
-
53
- it('loading', async () => {
54
- fetchMock.mockResponse(async () => ({ body: '{ "value" : "boo" }' }));
55
49
 
56
- const { findByText } = render(
57
- <FetchProvider url="http://thetimes.co.uk">
58
- <TestComponent />
59
- </FetchProvider>
60
- );
61
- await findByText('Loading');
50
+ await findByText(value);
51
+ expect(asFragment()).toMatchSnapshot();
62
52
  });
63
53
 
64
54
  it('error', async () => {
65
- fetchMock.mockResponse(() => Promise.reject('error'));
55
+ fetchMock.mock(endpoint, { status: 500 });
66
56
 
67
57
  const { asFragment, findByText } = render(
68
- <FetchProvider url="http://thetimes.co.uk">
58
+ <FetchProvider url={endpoint}>
69
59
  <TestComponent>Children</TestComponent>
70
60
  </FetchProvider>
71
61
  );
72
- await findByText('Error');
73
62
 
63
+ await findByText('Error');
74
64
  expect(asFragment()).toMatchSnapshot();
75
65
  });
76
66
 
77
67
  it('Unprovided', async () => {
78
- fetchMock.mockResponse(async () => ({ body: '{ "value" : "boo" }' }));
79
-
80
68
  const { asFragment, findByText } = render(
81
69
  <TestComponent>Children</TestComponent>
82
70
  );
83
- await findByText('Error');
84
71
 
72
+ await findByText('Error');
85
73
  expect(asFragment()).toMatchSnapshot();
86
74
  });
87
75
 
88
76
  it('preview', () => {
77
+ const value = 'Preloaded';
78
+
89
79
  const { asFragment, getByText } = render(
90
- <FetchProvider previewData={{ value: 'boo' }}>
80
+ <FetchProvider previewData={{ value }}>
91
81
  <TestComponent />
92
82
  </FetchProvider>
93
83
  );
94
84
 
95
- expect(getByText('boo'));
85
+ expect(getByText(value));
96
86
  expect(asFragment()).toMatchSnapshot();
97
87
  });
98
88
  });
@@ -19,7 +19,15 @@ exports[`<FetchProvider> error 1`] = `
19
19
  exports[`<FetchProvider> fetch 1`] = `
20
20
  <DocumentFragment>
21
21
  <div>
22
- boo
22
+ Loading
23
+ </div>
24
+ </DocumentFragment>
25
+ `;
26
+
27
+ exports[`<FetchProvider> fetch 2`] = `
28
+ <DocumentFragment>
29
+ <div>
30
+ Fetched
23
31
  </div>
24
32
  </DocumentFragment>
25
33
  `;
@@ -27,7 +35,7 @@ exports[`<FetchProvider> fetch 1`] = `
27
35
  exports[`<FetchProvider> preview 1`] = `
28
36
  <DocumentFragment>
29
37
  <div>
30
- boo
38
+ Preloaded
31
39
  </div>
32
40
  </DocumentFragment>
33
41
  `;
package/src/index.ts CHANGED
@@ -45,6 +45,20 @@ export {
45
45
  export {
46
46
  OptaFootballMatchStats
47
47
  } from './components/opta/football/match-stats/OptaFootballMatchStats';
48
+
49
+ export {
50
+ OptaRugbyFixtures
51
+ } from './components/opta/rugby/fixtures/OptaRugbyFixtures';
52
+ export {
53
+ OptaRugbyStandings
54
+ } from './components/opta/rugby/standings/OptaRugbyStandings';
55
+ export {
56
+ OptaRugbySummary
57
+ } from './components/opta/rugby/summary/OptaRugbySummary';
58
+ export {
59
+ OptaRugbyMatchStats
60
+ } from './components/opta/rugby/match-stats/OptaRugbyMatchStats';
61
+
48
62
  export {
49
63
  OlympicsMedalTable
50
64
  } from './components/olympics/medal-table/OlympicsMedalTable';