@times-components/ts-components 1.145.1-d1253ed8e87e7cdf861fbf772a5f9026182434db.4 → 1.145.1-e871182934034874ea6a75e1e684090e5504df44.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 (47) hide show
  1. package/dist/components/opta/cricket/scorecard/OptaCricketScorecard.js +2 -10
  2. package/dist/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.js +17 -94
  3. package/dist/components/opta/football/summary/OptaFootballSummary.js +2 -10
  4. package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.js +18 -95
  5. package/dist/components/opta/rugby/summary/OptaRugbySummary.js +2 -10
  6. package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.js +17 -94
  7. package/dist/components/travel-mini-cta/index.d.ts +3 -0
  8. package/dist/components/travel-mini-cta/index.js +86 -0
  9. package/dist/components/travel-mini-cta/styles.d.ts +42 -0
  10. package/dist/components/travel-mini-cta/styles.js +273 -0
  11. package/dist/components/travel-mini-cta/travel-mini-cta.stories.d.ts +110 -0
  12. package/dist/components/travel-mini-cta/travel-mini-cta.stories.js +121 -0
  13. package/dist/components/travel-mini-cta/types.d.ts +10 -0
  14. package/dist/components/travel-mini-cta/types.js +2 -0
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.js +2 -1
  17. package/dist/utils/applyDarkMode.d.ts +1 -0
  18. package/dist/utils/applyDarkMode.js +12 -0
  19. package/dist/utils/getMediaQuery.d.ts +11 -0
  20. package/dist/utils/getMediaQuery.js +19 -0
  21. package/dist/utils/index.d.ts +2 -0
  22. package/dist/utils/index.js +3 -0
  23. package/package.json +3 -3
  24. package/rnw.js +1 -1
  25. package/src/components/opta/cricket/scorecard/OptaCricketScorecard.tsx +0 -13
  26. package/src/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.tsx +16 -126
  27. package/src/components/opta/cricket/scorecard/__tests__/__snapshots__/OptaCricketScorecard.test.tsx.snap +6 -5
  28. package/src/components/opta/football/summary/OptaFootballSummary.tsx +0 -13
  29. package/src/components/opta/football/summary/__tests__/OptaFootballSummary.test.tsx +18 -127
  30. package/src/components/opta/football/summary/__tests__/__snapshots__/OptaFootballSummary.test.tsx.snap +6 -5
  31. package/src/components/opta/rugby/summary/OptaRugbySummary.tsx +0 -13
  32. package/src/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.tsx +17 -127
  33. package/src/components/opta/rugby/summary/__tests__/__snapshots__/OptaRugbySummary.test.tsx.snap +6 -5
  34. package/src/components/travel-mini-cta/index.tsx +164 -0
  35. package/src/components/travel-mini-cta/styles.ts +336 -0
  36. package/src/components/travel-mini-cta/travel-mini-cta.stories.tsx +157 -0
  37. package/src/components/travel-mini-cta/types.ts +10 -0
  38. package/src/index.ts +1 -0
  39. package/src/utils/applyDarkMode.ts +12 -0
  40. package/src/utils/getMediaQuery.ts +25 -0
  41. package/src/utils/index.ts +2 -0
  42. package/dist/components/opta/utils/__tests__/emitEvent.test.d.ts +0 -1
  43. package/dist/components/opta/utils/__tests__/emitEvent.test.js +0 -264
  44. package/dist/components/opta/utils/emitEvent.d.ts +0 -1
  45. package/dist/components/opta/utils/emitEvent.js +0 -15
  46. package/src/components/opta/utils/__tests__/emitEvent.test.tsx +0 -415
  47. package/src/components/opta/utils/emitEvent.ts +0 -20
@@ -12,7 +12,6 @@ import {
12
12
  import { Container, PlaceholderContainer } from '../../shared/shared-styles';
13
13
  import { WidgetContainer } from './styles';
14
14
  import Button from '../../shared/button/Button';
15
- import { emitEvent } from '../../utils/emitEvent';
16
15
 
17
16
  export const OptaCricketScorecard: React.FC<{
18
17
  competition: string;
@@ -31,7 +30,6 @@ export const OptaCricketScorecard: React.FC<{
31
30
  heightLg = 258
32
31
  }) => {
33
32
  const ref = React.createRef<HTMLDivElement>();
34
- const containerRef = React.createRef<HTMLDivElement>();
35
33
  const [isReady, setIsReady] = useState<boolean>(false);
36
34
  const [showDetails, setShowDetails] = useState<boolean>(false);
37
35
 
@@ -83,16 +81,6 @@ export const OptaCricketScorecard: React.FC<{
83
81
  });
84
82
  }, []);
85
83
 
86
- useEffect(
87
- () => {
88
- const height = containerRef.current
89
- ? containerRef.current.offsetHeight
90
- : 0;
91
- emitEvent('updateHeight', height);
92
- },
93
- [showDetails]
94
- );
95
-
96
84
  return (
97
85
  <Container
98
86
  fullWidth={full_width}
@@ -100,7 +88,6 @@ export const OptaCricketScorecard: React.FC<{
100
88
  heightMd={heightMd}
101
89
  heightLg={heightLg}
102
90
  hasPadding
103
- ref={containerRef}
104
91
  >
105
92
  <WidgetContainer ref={ref} showDetails={showDetails} />
106
93
 
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { render, act, fireEvent, waitFor } from '@testing-library/react';
2
+ import { render, act, fireEvent } from '@testing-library/react';
3
3
  import 'regenerator-runtime';
4
4
  import '@testing-library/jest-dom';
5
5
 
@@ -10,27 +10,22 @@ jest.mock('@times-components/image', () => ({
10
10
  const mockInitSettings = jest.fn();
11
11
  const mockInitStyleSheet = jest.fn();
12
12
  const mockInitComponent = jest.fn();
13
- const mockInitScript = jest.fn();
14
- const mockEmitEvent = jest.fn();
13
+ const mockHasMatchEvents = jest.fn();
15
14
 
16
- const mockInitElement = jest.fn(() => {
15
+ const mockInitElement = () => {
17
16
  const element = document.createElement('div');
18
17
  element.appendChild(document.createTextNode('Widget'));
19
18
  return element;
20
- });
19
+ };
21
20
 
22
21
  jest.mock('../../../utils/config', () => ({
23
22
  initSettings: mockInitSettings,
24
23
  initStyleSheet: mockInitStyleSheet,
25
- initScript: mockInitScript,
24
+ initScript: () => new Promise(resolve => resolve({})),
26
25
  initElement: mockInitElement,
27
26
  initComponent: mockInitComponent
28
27
  }));
29
28
 
30
- jest.mock('../../../utils/emitEvent', () => ({
31
- emitEvent: mockEmitEvent
32
- }));
33
-
34
29
  import { OptaCricketScorecard } from '../OptaCricketScorecard';
35
30
 
36
31
  const requiredProps = {
@@ -41,26 +36,19 @@ const requiredProps = {
41
36
  describe('OptaCricketScorecard', () => {
42
37
  beforeEach(() => {
43
38
  jest.clearAllMocks();
44
- mockInitScript.mockResolvedValue({});
45
- });
46
-
47
- afterEach(() => {
48
- jest.clearAllMocks();
49
- document.body.innerHTML = '';
50
39
  });
51
40
 
52
41
  it('should render correctly', async () => {
53
- const { asFragment, getByRole } = render(
54
- <OptaCricketScorecard {...requiredProps} />
55
- );
42
+ const { asFragment } = render(<OptaCricketScorecard {...requiredProps} />);
56
43
 
57
- await waitFor(() => {
58
- expect(mockInitSettings).toHaveBeenCalledTimes(1);
44
+ act(() => {
45
+ mockInitComponent();
46
+ mockHasMatchEvents();
59
47
  });
60
48
 
61
- expect(mockInitStyleSheet).toHaveBeenCalledWith('cricket');
49
+ expect(mockInitSettings).toHaveBeenCalledTimes(1);
50
+ expect(mockInitStyleSheet).toHaveBeenCalledTimes(1);
62
51
  expect(mockInitComponent).toHaveBeenCalledTimes(1);
63
- expect(getByRole('button')).toBeInTheDocument();
64
52
 
65
53
  expect(asFragment()).toMatchSnapshot();
66
54
  });
@@ -71,112 +59,14 @@ describe('OptaCricketScorecard', () => {
71
59
  expect(button).not.toBeDisabled();
72
60
  });
73
61
 
74
- it('should toggle details when button is clicked', async () => {
62
+ it('should toggle details when button is clicked', () => {
75
63
  const { getByRole } = render(<OptaCricketScorecard {...requiredProps} />);
76
64
  const button = getByRole('button');
77
65
 
78
66
  expect(button).toHaveTextContent('Show Details');
79
-
80
- act(() => {
81
- fireEvent.click(button);
82
- });
83
-
84
- await waitFor(() => {
85
- expect(button).toHaveTextContent('Hide Details');
86
- });
87
-
88
- act(() => {
89
- fireEvent.click(button);
90
- });
91
-
92
- await waitFor(() => {
93
- expect(button).toHaveTextContent('Show Details');
94
- });
95
- });
96
-
97
- describe('emitEvent', () => {
98
- it('should call emitEvent with updateHeight when details are toggled', async () => {
99
- const { getByRole } = render(<OptaCricketScorecard {...requiredProps} />);
100
- const button = getByRole('button');
101
-
102
- // Clear initial calls
103
- jest.clearAllMocks();
104
-
105
- act(() => {
106
- fireEvent.click(button);
107
- });
108
-
109
- await waitFor(() => {
110
- expect(mockEmitEvent).toHaveBeenCalledWith(
111
- 'updateHeight',
112
- expect.any(Number)
113
- );
114
- });
115
- });
116
-
117
- it('should emit updateHeight event on each toggle', async () => {
118
- const { getByRole } = render(<OptaCricketScorecard {...requiredProps} />);
119
- const button = getByRole('button');
120
-
121
- // Clear initial calls
122
- jest.clearAllMocks();
123
-
124
- // First toggle
125
- act(() => {
126
- fireEvent.click(button);
127
- });
128
-
129
- await waitFor(() => {
130
- expect(mockEmitEvent).toHaveBeenCalledTimes(1);
131
- });
132
-
133
- // Second toggle
134
- act(() => {
135
- fireEvent.click(button);
136
- });
137
-
138
- await waitFor(() => {
139
- expect(mockEmitEvent).toHaveBeenCalledTimes(2);
140
- });
141
-
142
- // Third toggle
143
- act(() => {
144
- fireEvent.click(button);
145
- });
146
-
147
- await waitFor(() => {
148
- expect(mockEmitEvent).toHaveBeenCalledTimes(3);
149
- });
150
- });
151
-
152
- it('should emit updateHeight with container offsetHeight', async () => {
153
- const { getByRole, container } = render(
154
- <OptaCricketScorecard {...requiredProps} />
155
- );
156
- const button = getByRole('button');
157
-
158
- // Clear initial calls
159
- jest.clearAllMocks();
160
-
161
- // Mock offsetHeight
162
- const containerElement = container.querySelector('[class*="Container"]');
163
- if (containerElement) {
164
- Object.defineProperty(containerElement, 'offsetHeight', {
165
- value: 300,
166
- configurable: true
167
- });
168
- }
169
-
170
- act(() => {
171
- fireEvent.click(button);
172
- });
173
-
174
- await waitFor(() => {
175
- expect(mockEmitEvent).toHaveBeenCalledWith(
176
- 'updateHeight',
177
- expect.any(Number)
178
- );
179
- });
180
- });
67
+ fireEvent.click(button);
68
+ expect(button).toHaveTextContent('Hide Details');
69
+ fireEvent.click(button);
70
+ expect(button).toHaveTextContent('Show Details');
181
71
  });
182
72
  });
@@ -7,16 +7,17 @@ exports[`OptaCricketScorecard should render correctly 1`] = `
7
7
  >
8
8
  <div
9
9
  class="sc-bxivhb sc-ifAKCX dNXXXn"
10
- >
11
- <div>
12
- Widget
13
- </div>
14
- </div>
10
+ />
15
11
  <button
16
12
  class="sc-EHOje dWKhuC"
17
13
  >
18
14
  Show Details
19
15
  </button>
16
+ <div
17
+ class="sc-bwzfXH eSqyJ"
18
+ >
19
+ Placeholder
20
+ </div>
20
21
  </div>
21
22
  </DocumentFragment>
22
23
  `;
@@ -13,7 +13,6 @@ import {
13
13
  import { Container, PlaceholderContainer } from '../../shared/shared-styles';
14
14
  import { WidgetContainer } from '../../shared/summary-styles';
15
15
  import Button from '../../shared/button/Button';
16
- import { emitEvent } from '../../utils/emitEvent';
17
16
 
18
17
  export const OptaFootballSummary: React.FC<{
19
18
  season: string;
@@ -34,7 +33,6 @@ export const OptaFootballSummary: React.FC<{
34
33
  heightLg = 197
35
34
  }) => {
36
35
  const ref = React.createRef<HTMLDivElement>();
37
- const containerRef = React.createRef<HTMLDivElement>();
38
36
  const [isReady, setIsReady] = useState<boolean>(false);
39
37
  const [showDetails, setShowDetails] = useState<boolean>(false);
40
38
 
@@ -73,16 +71,6 @@ export const OptaFootballSummary: React.FC<{
73
71
  });
74
72
  }, []);
75
73
 
76
- useEffect(
77
- () => {
78
- const height = containerRef.current
79
- ? containerRef.current.offsetHeight
80
- : 0;
81
- emitEvent('updateHeight', height);
82
- },
83
- [showDetails]
84
- );
85
-
86
74
  return (
87
75
  <Container
88
76
  fullWidth={full_width}
@@ -90,7 +78,6 @@ export const OptaFootballSummary: React.FC<{
90
78
  heightMd={heightMd}
91
79
  heightLg={heightLg}
92
80
  hasPadding
93
- ref={containerRef}
94
81
  >
95
82
  <WidgetContainer ref={ref} showDetails={showDetails} />
96
83
 
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
- import { render, act, fireEvent, waitFor } from '@testing-library/react';
2
+ import { render, act, fireEvent } from '@testing-library/react';
3
+
3
4
  import 'regenerator-runtime';
4
5
  import '@testing-library/jest-dom';
5
6
 
@@ -10,27 +11,22 @@ jest.mock('@times-components/image', () => ({
10
11
  const mockInitSettings = jest.fn();
11
12
  const mockInitStyleSheet = jest.fn();
12
13
  const mockInitComponent = jest.fn();
13
- const mockInitScript = jest.fn();
14
- const mockEmitEvent = jest.fn();
14
+ const mockHasMatchEvents = jest.fn();
15
15
 
16
- const mockInitElement = jest.fn(() => {
16
+ const mockInitElement = () => {
17
17
  const element = document.createElement('div');
18
18
  element.appendChild(document.createTextNode('Widget'));
19
19
  return element;
20
- });
20
+ };
21
21
 
22
22
  jest.mock('../../../utils/config', () => ({
23
23
  initSettings: mockInitSettings,
24
24
  initStyleSheet: mockInitStyleSheet,
25
- initScript: mockInitScript,
25
+ initScript: () => new Promise(resolve => resolve({})),
26
26
  initElement: mockInitElement,
27
27
  initComponent: mockInitComponent
28
28
  }));
29
29
 
30
- jest.mock('../../../utils/emitEvent', () => ({
31
- emitEvent: mockEmitEvent
32
- }));
33
-
34
30
  import { OptaFootballSummary } from '../OptaFootballSummary';
35
31
 
36
32
  const requiredProps = {
@@ -42,142 +38,37 @@ const requiredProps = {
42
38
  describe('OptaFootballSummary', () => {
43
39
  beforeEach(() => {
44
40
  jest.clearAllMocks();
45
- mockInitScript.mockResolvedValue({});
46
- });
47
-
48
- afterEach(() => {
49
- jest.clearAllMocks();
50
- document.body.innerHTML = '';
51
41
  });
52
42
 
53
43
  it('should render correctly', async () => {
54
- const { asFragment, getByRole } = render(
55
- <OptaFootballSummary {...requiredProps} />
56
- );
44
+ const { asFragment } = render(<OptaFootballSummary {...requiredProps} />);
57
45
 
58
- await waitFor(() => {
59
- expect(mockInitSettings).toHaveBeenCalledTimes(1);
46
+ act(() => {
47
+ mockInitComponent();
48
+ mockHasMatchEvents();
60
49
  });
61
50
 
62
- expect(mockInitStyleSheet).toHaveBeenCalledWith('football');
51
+ expect(mockInitSettings).toHaveBeenCalledTimes(1);
52
+ expect(mockInitStyleSheet).toHaveBeenCalledTimes(1);
63
53
  expect(mockInitComponent).toHaveBeenCalledTimes(1);
64
- expect(getByRole('button')).toBeInTheDocument();
65
54
 
66
55
  expect(asFragment()).toMatchSnapshot();
67
56
  });
68
57
 
69
- it('should enable the button initially', () => {
58
+ it('should disable the button initially', () => {
70
59
  const { getByRole } = render(<OptaFootballSummary {...requiredProps} />);
71
60
  const button = getByRole('button');
72
61
  expect(button).not.toBeDisabled();
73
62
  });
74
63
 
75
- it('should toggle details when button is clicked', async () => {
64
+ it('should toggle details when button is clicked', () => {
76
65
  const { getByRole } = render(<OptaFootballSummary {...requiredProps} />);
77
66
  const button = getByRole('button');
78
67
 
79
68
  expect(button).toHaveTextContent('Show Details');
80
-
81
- act(() => {
82
- fireEvent.click(button);
83
- });
84
-
85
- await waitFor(() => {
86
- expect(button).toHaveTextContent('Hide Details');
87
- });
88
-
89
- act(() => {
90
- fireEvent.click(button);
91
- });
92
-
93
- await waitFor(() => {
94
- expect(button).toHaveTextContent('Show Details');
95
- });
96
- });
97
-
98
- describe('emitEvent', () => {
99
- it('should call emitEvent with updateHeight when details are toggled', async () => {
100
- const { getByRole } = render(<OptaFootballSummary {...requiredProps} />);
101
- const button = getByRole('button');
102
-
103
- // Clear initial calls
104
- jest.clearAllMocks();
105
-
106
- act(() => {
107
- fireEvent.click(button);
108
- });
109
-
110
- await waitFor(() => {
111
- expect(mockEmitEvent).toHaveBeenCalledWith(
112
- 'updateHeight',
113
- expect.any(Number)
114
- );
115
- });
116
- });
117
-
118
- it('should emit updateHeight event on each toggle', async () => {
119
- const { getByRole } = render(<OptaFootballSummary {...requiredProps} />);
120
- const button = getByRole('button');
121
-
122
- // Clear initial calls
123
- jest.clearAllMocks();
124
-
125
- // First toggle
126
- act(() => {
127
- fireEvent.click(button);
128
- });
129
-
130
- await waitFor(() => {
131
- expect(mockEmitEvent).toHaveBeenCalledTimes(1);
132
- });
133
-
134
- // Second toggle
135
- act(() => {
136
- fireEvent.click(button);
137
- });
138
-
139
- await waitFor(() => {
140
- expect(mockEmitEvent).toHaveBeenCalledTimes(2);
141
- });
142
-
143
- // Third toggle
144
- act(() => {
145
- fireEvent.click(button);
146
- });
147
-
148
- await waitFor(() => {
149
- expect(mockEmitEvent).toHaveBeenCalledTimes(3);
150
- });
151
- });
152
-
153
- it('should emit updateHeight with container offsetHeight', async () => {
154
- const { getByRole, container } = render(
155
- <OptaFootballSummary {...requiredProps} />
156
- );
157
- const button = getByRole('button');
158
-
159
- // Clear initial calls
160
- jest.clearAllMocks();
161
-
162
- // Mock offsetHeight
163
- const containerElement = container.querySelector('[class*="Container"]');
164
- if (containerElement) {
165
- Object.defineProperty(containerElement, 'offsetHeight', {
166
- value: 250,
167
- configurable: true
168
- });
169
- }
170
-
171
- act(() => {
172
- fireEvent.click(button);
173
- });
174
-
175
- await waitFor(() => {
176
- expect(mockEmitEvent).toHaveBeenCalledWith(
177
- 'updateHeight',
178
- expect.any(Number)
179
- );
180
- });
181
- });
69
+ fireEvent.click(button);
70
+ expect(button).toHaveTextContent('Hide Details');
71
+ fireEvent.click(button);
72
+ expect(button).toHaveTextContent('Show Details');
182
73
  });
183
74
  });
@@ -7,16 +7,17 @@ exports[`OptaFootballSummary should render correctly 1`] = `
7
7
  >
8
8
  <div
9
9
  class="sc-htpNat sc-bxivhb hNtyxM"
10
- >
11
- <div>
12
- Widget
13
- </div>
14
- </div>
10
+ />
15
11
  <button
16
12
  class="sc-ifAKCX fvBTJK"
17
13
  >
18
14
  Show Details
19
15
  </button>
16
+ <div
17
+ class="sc-bwzfXH eSqyJ"
18
+ >
19
+ Placeholder
20
+ </div>
20
21
  </div>
21
22
  </DocumentFragment>
22
23
  `;
@@ -13,7 +13,6 @@ import {
13
13
  import { Container, PlaceholderContainer } from '../../shared/shared-styles';
14
14
  import { WidgetContainer } from '../../shared/summary-styles';
15
15
  import Button from '../../shared/button/Button';
16
- import { emitEvent } from '../../utils/emitEvent';
17
16
 
18
17
  export const OptaRugbySummary: React.FC<{
19
18
  season: string;
@@ -34,7 +33,6 @@ export const OptaRugbySummary: React.FC<{
34
33
  heightLg = 197
35
34
  }) => {
36
35
  const ref = React.createRef<HTMLDivElement>();
37
- const containerRef = React.createRef<HTMLDivElement>();
38
36
  const [isReady, setIsReady] = useState<boolean>(false);
39
37
  const [showDetails, setShowDetails] = useState<boolean>(false);
40
38
 
@@ -75,16 +73,6 @@ export const OptaRugbySummary: React.FC<{
75
73
  });
76
74
  }, []);
77
75
 
78
- useEffect(
79
- () => {
80
- const height = containerRef.current
81
- ? containerRef.current.offsetHeight
82
- : 0;
83
- emitEvent('updateHeight', height);
84
- },
85
- [showDetails]
86
- );
87
-
88
76
  return (
89
77
  <Container
90
78
  fullWidth={full_width}
@@ -92,7 +80,6 @@ export const OptaRugbySummary: React.FC<{
92
80
  heightMd={heightMd}
93
81
  heightLg={heightLg}
94
82
  hasPadding
95
- ref={containerRef}
96
83
  >
97
84
  <WidgetContainer ref={ref} showDetails={showDetails} />
98
85