@times-components/ts-components 1.145.1-82bc6796129e892c1eb22c6257c5e3809c159767.3 → 1.145.1-b32ea924749bafdf12e3e8515023538fa20e7808.3

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 (70) hide show
  1. package/dist/components/opta/cricket/scorecard/OptaCricketScorecard.js +10 -2
  2. package/dist/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.js +94 -17
  3. package/dist/components/opta/football/opta-match-stats/shared/styles.js +1 -8
  4. package/dist/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.js +2 -2
  5. package/dist/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.stories.js +1 -1
  6. package/dist/components/opta/football/opta-match-stats/summary/WidgetContainer.js +4 -13
  7. package/dist/components/opta/football/summary/OptaFootballSummary.js +10 -2
  8. package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.js +95 -18
  9. package/dist/components/opta/rugby/summary/OptaRugbySummary.js +10 -2
  10. package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.js +94 -17
  11. package/dist/components/opta/utils/__tests__/emitEvent.test.js +264 -0
  12. package/dist/components/opta/utils/emitEvent.d.ts +1 -0
  13. package/dist/components/opta/utils/emitEvent.js +9 -0
  14. package/dist/index.d.ts +0 -1
  15. package/dist/index.js +1 -2
  16. package/package.json +3 -3
  17. package/rnw.js +1 -1
  18. package/src/components/opta/cricket/scorecard/OptaCricketScorecard.tsx +13 -0
  19. package/src/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.tsx +126 -16
  20. package/src/components/opta/cricket/scorecard/__tests__/__snapshots__/OptaCricketScorecard.test.tsx.snap +5 -6
  21. package/src/components/opta/football/opta-match-stats/commentary/__tests__/__snapshots__/OptaMatchStatsCommentary.test.tsx.snap +1 -1
  22. package/src/components/opta/football/opta-match-stats/shared/styles.ts +0 -8
  23. package/src/components/opta/football/opta-match-stats/stats-graphs/__tests__/__snapshots__/OptaMatchStatsGraphs.test.tsx.snap +1 -1
  24. package/src/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.stories.tsx +1 -1
  25. package/src/components/opta/football/opta-match-stats/summary/OptaMatchStatsSummary.tsx +1 -1
  26. package/src/components/opta/football/opta-match-stats/summary/WidgetContainer.tsx +3 -12
  27. package/src/components/opta/football/opta-match-stats/summary/__tests__/__snapshots__/OptaMatchStatsSummary.test.tsx.snap +1 -1
  28. package/src/components/opta/football/summary/OptaFootballSummary.tsx +13 -0
  29. package/src/components/opta/football/summary/__tests__/OptaFootballSummary.test.tsx +127 -18
  30. package/src/components/opta/football/summary/__tests__/__snapshots__/OptaFootballSummary.test.tsx.snap +5 -6
  31. package/src/components/opta/rugby/summary/OptaRugbySummary.tsx +13 -0
  32. package/src/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.tsx +127 -17
  33. package/src/components/opta/rugby/summary/__tests__/__snapshots__/OptaRugbySummary.test.tsx.snap +5 -6
  34. package/src/components/opta/utils/__tests__/emitEvent.test.tsx +415 -0
  35. package/src/components/opta/utils/emitEvent.ts +11 -0
  36. package/src/index.ts +0 -3
  37. package/dist/components/opta/football/opta-match-stats/matchday-live/DesktopWidget.d.ts +0 -10
  38. package/dist/components/opta/football/opta-match-stats/matchday-live/DesktopWidget.js +0 -69
  39. package/dist/components/opta/football/opta-match-stats/matchday-live/MobileWidget.d.ts +0 -12
  40. package/dist/components/opta/football/opta-match-stats/matchday-live/MobileWidget.js +0 -90
  41. package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.d.ts +0 -12
  42. package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.js +0 -10
  43. package/dist/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.js +0 -24
  44. package/dist/components/opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.d.ts +0 -1
  45. package/dist/components/opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.js +0 -57
  46. package/dist/components/opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.d.ts +0 -2
  47. package/dist/components/opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.js +0 -48
  48. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.d.ts +0 -1
  49. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.js +0 -19
  50. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.d.ts +0 -12
  51. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.js +0 -67
  52. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.d.ts +0 -6
  53. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.js +0 -730
  54. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.d.ts +0 -1
  55. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.js +0 -33
  56. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.d.ts +0 -1
  57. package/dist/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.js +0 -36
  58. package/src/components/opta/football/opta-match-stats/matchday-live/DesktopWidget.tsx +0 -108
  59. package/src/components/opta/football/opta-match-stats/matchday-live/MobileWidget.tsx +0 -158
  60. package/src/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.tsx +0 -38
  61. package/src/components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.tsx +0 -23
  62. package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/MobileWidget.test.tsx +0 -69
  63. package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/OptaMatchStatsMatchdayLive.test.tsx +0 -61
  64. package/src/components/opta/football/opta-match-stats/matchday-live/__tests__/__snapshots__/OptaMatchStatsMatchdayLive.test.tsx.snap +0 -61
  65. package/src/components/opta/football/opta-match-stats/matchday-live/styles/MatchdayLiveController.tsx +0 -19
  66. package/src/components/opta/football/opta-match-stats/matchday-live/styles/NavigationWrapper.tsx +0 -81
  67. package/src/components/opta/football/opta-match-stats/matchday-live/styles/WidgetContainer.tsx +0 -761
  68. package/src/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/NavigationWrapper.test.tsx +0 -67
  69. package/src/components/opta/football/opta-match-stats/matchday-live/styles/__tests__/WidgetContainer.test.tsx +0 -64
  70. /package/dist/components/opta/{football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive.stories.d.ts → utils/__tests__/emitEvent.test.d.ts} +0 -0
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
- import { render, act, fireEvent } from '@testing-library/react';
3
-
2
+ import { render, act, fireEvent, waitFor } from '@testing-library/react';
4
3
  import 'regenerator-runtime';
5
4
  import '@testing-library/jest-dom';
6
5
 
@@ -11,22 +10,27 @@ jest.mock('@times-components/image', () => ({
11
10
  const mockInitSettings = jest.fn();
12
11
  const mockInitStyleSheet = jest.fn();
13
12
  const mockInitComponent = jest.fn();
14
- const mockHasMatchEvents = jest.fn();
13
+ const mockInitScript = jest.fn();
14
+ const mockEmitEvent = jest.fn();
15
15
 
16
- const mockInitElement = () => {
16
+ const mockInitElement = jest.fn(() => {
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: () => new Promise(resolve => resolve({})),
25
+ initScript: mockInitScript,
26
26
  initElement: mockInitElement,
27
27
  initComponent: mockInitComponent
28
28
  }));
29
29
 
30
+ jest.mock('../../../utils/emitEvent', () => ({
31
+ emitEvent: mockEmitEvent
32
+ }));
33
+
30
34
  import { OptaRugbySummary } from '../OptaRugbySummary';
31
35
 
32
36
  const requiredProps = {
@@ -34,22 +38,30 @@ const requiredProps = {
34
38
  competition: '209',
35
39
  match: '921100'
36
40
  };
41
+
37
42
  describe('OptaRugbySummary', () => {
38
43
  beforeEach(() => {
39
44
  jest.clearAllMocks();
45
+ mockInitScript.mockResolvedValue({});
46
+ });
47
+
48
+ afterEach(() => {
49
+ jest.clearAllMocks();
50
+ document.body.innerHTML = '';
40
51
  });
41
52
 
42
53
  it('should render correctly', async () => {
43
- const { asFragment } = render(<OptaRugbySummary {...requiredProps} />);
54
+ const { asFragment, getByRole } = render(
55
+ <OptaRugbySummary {...requiredProps} />
56
+ );
44
57
 
45
- act(() => {
46
- mockInitComponent();
47
- mockHasMatchEvents();
58
+ await waitFor(() => {
59
+ expect(mockInitSettings).toHaveBeenCalledTimes(1);
48
60
  });
49
61
 
50
- expect(mockInitSettings).toHaveBeenCalledTimes(1);
51
- expect(mockInitStyleSheet).toHaveBeenCalledTimes(1);
62
+ expect(mockInitStyleSheet).toHaveBeenCalledWith('rugby');
52
63
  expect(mockInitComponent).toHaveBeenCalledTimes(1);
64
+ expect(getByRole('button')).toBeInTheDocument();
53
65
 
54
66
  expect(asFragment()).toMatchSnapshot();
55
67
  });
@@ -60,14 +72,112 @@ describe('OptaRugbySummary', () => {
60
72
  expect(button).not.toBeDisabled();
61
73
  });
62
74
 
63
- it('should toggle details when button is clicked', () => {
75
+ it('should toggle details when button is clicked', async () => {
64
76
  const { getByRole } = render(<OptaRugbySummary {...requiredProps} />);
65
77
  const button = getByRole('button');
66
78
 
67
79
  expect(button).toHaveTextContent('Show Details');
68
- fireEvent.click(button);
69
- expect(button).toHaveTextContent('Hide Details');
70
- fireEvent.click(button);
71
- 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(<OptaRugbySummary {...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(<OptaRugbySummary {...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
+ <OptaRugbySummary {...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
+ });
72
182
  });
73
183
  });
@@ -7,17 +7,16 @@ exports[`OptaRugbySummary should render correctly 1`] = `
7
7
  >
8
8
  <div
9
9
  class="sc-htpNat sc-bxivhb hNtyxM"
10
- />
10
+ >
11
+ <div>
12
+ Widget
13
+ </div>
14
+ </div>
11
15
  <button
12
16
  class="sc-ifAKCX fvBTJK"
13
17
  >
14
18
  Show Details
15
19
  </button>
16
- <div
17
- class="sc-bwzfXH eSqyJ"
18
- >
19
- Placeholder
20
- </div>
21
20
  </div>
22
21
  </DocumentFragment>
23
22
  `;
@@ -0,0 +1,415 @@
1
+ import { emitEvent } from '../emitEvent';
2
+
3
+ describe('emitEvent', () => {
4
+ let mockPostMessage: jest.Mock;
5
+
6
+ beforeEach(() => {
7
+ mockPostMessage = jest.fn();
8
+
9
+ // Mock window.parent with postMessage
10
+ Object.defineProperty(window, 'parent', {
11
+ value: {
12
+ postMessage: mockPostMessage
13
+ },
14
+ writable: true,
15
+ configurable: true
16
+ });
17
+ });
18
+
19
+ afterEach(() => {
20
+ jest.clearAllMocks();
21
+ jest.restoreAllMocks();
22
+ });
23
+
24
+ describe('basic functionality', () => {
25
+ it('should call window.parent.postMessage with event name', () => {
26
+ emitEvent('updateHeight');
27
+
28
+ expect(mockPostMessage).toHaveBeenCalledTimes(1);
29
+ expect(mockPostMessage).toHaveBeenCalledWith(
30
+ {
31
+ type: 'updateHeight',
32
+ payload: null
33
+ },
34
+ '*'
35
+ );
36
+ });
37
+
38
+ it('should send event name as type property', () => {
39
+ emitEvent('customEvent');
40
+
41
+ expect(mockPostMessage).toHaveBeenCalledWith(
42
+ expect.objectContaining({
43
+ type: 'customEvent'
44
+ }),
45
+ '*'
46
+ );
47
+ });
48
+
49
+ it('should send wildcard origin for cross-origin communication', () => {
50
+ emitEvent('testEvent');
51
+
52
+ const callArgs = mockPostMessage.mock.calls[0];
53
+ expect(callArgs[1]).toBe('*');
54
+ });
55
+ });
56
+
57
+ describe('data handling', () => {
58
+ it('should append px to numeric data', () => {
59
+ emitEvent('updateHeight', 500);
60
+
61
+ expect(mockPostMessage).toHaveBeenCalledWith(
62
+ {
63
+ type: 'updateHeight',
64
+ payload: '500px'
65
+ },
66
+ '*'
67
+ );
68
+ });
69
+
70
+ it('should handle string data', () => {
71
+ emitEvent('updateContent', 'test-data');
72
+
73
+ expect(mockPostMessage).toHaveBeenCalledWith(
74
+ {
75
+ type: 'updateContent',
76
+ payload: 'test-datapx'
77
+ },
78
+ '*'
79
+ );
80
+ });
81
+
82
+ it('should handle boolean data', () => {
83
+ emitEvent('toggleState', true);
84
+
85
+ expect(mockPostMessage).toHaveBeenCalledWith(
86
+ {
87
+ type: 'toggleState',
88
+ payload: 'truepx'
89
+ },
90
+ '*'
91
+ );
92
+ });
93
+
94
+ it('should handle object data', () => {
95
+ const data = { width: 100, height: 200 };
96
+ emitEvent('updateDimensions', data);
97
+
98
+ expect(mockPostMessage).toHaveBeenCalledWith(
99
+ {
100
+ type: 'updateDimensions',
101
+ payload: '[object Object]px'
102
+ },
103
+ '*'
104
+ );
105
+ });
106
+
107
+ it('should handle array data', () => {
108
+ const data = [1, 2, 3];
109
+ emitEvent('updateArray', data);
110
+
111
+ expect(mockPostMessage).toHaveBeenCalledWith(
112
+ {
113
+ type: 'updateArray',
114
+ payload: '1,2,3px'
115
+ },
116
+ '*'
117
+ );
118
+ });
119
+
120
+ it('should set payload to null when data is undefined', () => {
121
+ emitEvent('testEvent', undefined);
122
+
123
+ expect(mockPostMessage).toHaveBeenCalledWith(
124
+ {
125
+ type: 'testEvent',
126
+ payload: null
127
+ },
128
+ '*'
129
+ );
130
+ });
131
+
132
+ it('should set payload to null when no data is provided', () => {
133
+ emitEvent('testEvent');
134
+
135
+ expect(mockPostMessage).toHaveBeenCalledWith(
136
+ {
137
+ type: 'testEvent',
138
+ payload: null
139
+ },
140
+ '*'
141
+ );
142
+ });
143
+ });
144
+
145
+ describe('window safety', () => {
146
+ it('should not throw error when window.parent is undefined', () => {
147
+ Object.defineProperty(window, 'parent', {
148
+ value: undefined,
149
+ writable: true,
150
+ configurable: true
151
+ });
152
+
153
+ expect(() => {
154
+ emitEvent('testEvent');
155
+ }).not.toThrow();
156
+ });
157
+
158
+ it('should not call postMessage when window.parent is null', () => {
159
+ Object.defineProperty(window, 'parent', {
160
+ value: null,
161
+ writable: true,
162
+ configurable: true
163
+ });
164
+
165
+ emitEvent('testEvent');
166
+
167
+ expect(mockPostMessage).not.toHaveBeenCalled();
168
+ });
169
+
170
+ it('should not call postMessage when window.parent does not exist', () => {
171
+ const newMockPostMessage = jest.fn();
172
+
173
+ Object.defineProperty(window, 'parent', {
174
+ value: {
175
+ postMessage: newMockPostMessage
176
+ },
177
+ writable: true,
178
+ configurable: true
179
+ });
180
+
181
+ // Create a scenario where window.parent is falsy
182
+ Object.defineProperty(window, 'parent', {
183
+ value: false,
184
+ writable: true,
185
+ configurable: true
186
+ });
187
+
188
+ emitEvent('testEvent');
189
+
190
+ expect(newMockPostMessage).not.toHaveBeenCalled();
191
+ });
192
+ });
193
+
194
+ describe('event name variations', () => {
195
+ it('should handle event names with underscores', () => {
196
+ emitEvent('update_height');
197
+
198
+ expect(mockPostMessage).toHaveBeenCalledWith(
199
+ expect.objectContaining({
200
+ type: 'update_height'
201
+ }),
202
+ '*'
203
+ );
204
+ });
205
+
206
+ it('should handle event names with camelCase', () => {
207
+ emitEvent('updateHeight');
208
+
209
+ expect(mockPostMessage).toHaveBeenCalledWith(
210
+ expect.objectContaining({
211
+ type: 'updateHeight'
212
+ }),
213
+ '*'
214
+ );
215
+ });
216
+
217
+ it('should handle event names with hyphens', () => {
218
+ emitEvent('update-height');
219
+
220
+ expect(mockPostMessage).toHaveBeenCalledWith(
221
+ expect.objectContaining({
222
+ type: 'update-height'
223
+ }),
224
+ '*'
225
+ );
226
+ });
227
+
228
+ it('should handle event names in uppercase', () => {
229
+ emitEvent('UPDATE_HEIGHT');
230
+
231
+ expect(mockPostMessage).toHaveBeenCalledWith(
232
+ expect.objectContaining({
233
+ type: 'UPDATE_HEIGHT'
234
+ }),
235
+ '*'
236
+ );
237
+ });
238
+
239
+ it('should handle empty string as event name', () => {
240
+ emitEvent('');
241
+
242
+ expect(mockPostMessage).toHaveBeenCalledWith(
243
+ expect.objectContaining({
244
+ type: ''
245
+ }),
246
+ '*'
247
+ );
248
+ });
249
+
250
+ it('should handle very long event names', () => {
251
+ const longEventName = 'a'.repeat(1000);
252
+ emitEvent(longEventName);
253
+
254
+ expect(mockPostMessage).toHaveBeenCalledWith(
255
+ expect.objectContaining({
256
+ type: longEventName
257
+ }),
258
+ '*'
259
+ );
260
+ });
261
+ });
262
+
263
+ describe('multiple calls', () => {
264
+ it('should handle multiple sequential events', () => {
265
+ emitEvent('event1');
266
+ emitEvent('event2', 100);
267
+ emitEvent('event3');
268
+
269
+ expect(mockPostMessage).toHaveBeenCalledTimes(3);
270
+
271
+ expect(mockPostMessage).toHaveBeenNthCalledWith(
272
+ 1,
273
+ {
274
+ type: 'event1',
275
+ payload: null
276
+ },
277
+ '*'
278
+ );
279
+
280
+ expect(mockPostMessage).toHaveBeenNthCalledWith(
281
+ 2,
282
+ {
283
+ type: 'event2',
284
+ payload: '100px'
285
+ },
286
+ '*'
287
+ );
288
+
289
+ expect(mockPostMessage).toHaveBeenNthCalledWith(
290
+ 3,
291
+ {
292
+ type: 'event3',
293
+ payload: null
294
+ },
295
+ '*'
296
+ );
297
+ });
298
+
299
+ it('should handle rapid successive calls', () => {
300
+ for (let i = 0; i < 10; i++) {
301
+ emitEvent(`event${i}`, i * 100);
302
+ }
303
+
304
+ expect(mockPostMessage).toHaveBeenCalledTimes(10);
305
+ });
306
+ });
307
+
308
+ describe('real-world use cases', () => {
309
+ it('should emit updateHeight event for cricket scorecard', () => {
310
+ emitEvent('updateHeight', 500);
311
+
312
+ expect(mockPostMessage).toHaveBeenCalledWith(
313
+ {
314
+ type: 'updateHeight',
315
+ payload: '500px'
316
+ },
317
+ '*'
318
+ );
319
+ });
320
+
321
+ it('should emit enableButton event for match events', () => {
322
+ emitEvent('enableButton');
323
+
324
+ expect(mockPostMessage).toHaveBeenCalledWith(
325
+ {
326
+ type: 'enableButton',
327
+ payload: null
328
+ },
329
+ '*'
330
+ );
331
+ });
332
+
333
+ it('should emit custom widget ready event', () => {
334
+ emitEvent('widgetReady', 200);
335
+
336
+ expect(mockPostMessage).toHaveBeenCalledWith(
337
+ {
338
+ type: 'widgetReady',
339
+ payload: '200px'
340
+ },
341
+ '*'
342
+ );
343
+ });
344
+
345
+ it('should emit multiple events in sequence for complex workflows', () => {
346
+ emitEvent('initStart');
347
+ emitEvent('updateHeight', 400);
348
+ emitEvent('contentLoaded');
349
+ emitEvent('updateHeight', 600);
350
+
351
+ expect(mockPostMessage).toHaveBeenCalledTimes(4);
352
+ });
353
+ });
354
+
355
+ describe('edge cases', () => {
356
+ it('should handle negative numbers', () => {
357
+ emitEvent('updateHeight', -100);
358
+
359
+ expect(mockPostMessage).toHaveBeenCalledWith(
360
+ {
361
+ type: 'updateHeight',
362
+ payload: '-100px'
363
+ },
364
+ '*'
365
+ );
366
+ });
367
+
368
+ it('should handle very large numbers', () => {
369
+ emitEvent('updateHeight', 999999999);
370
+
371
+ expect(mockPostMessage).toHaveBeenCalledWith(
372
+ {
373
+ type: 'updateHeight',
374
+ payload: '999999999px'
375
+ },
376
+ '*'
377
+ );
378
+ });
379
+
380
+ it('should handle float numbers', () => {
381
+ emitEvent('updateHeight', 100.5);
382
+
383
+ expect(mockPostMessage).toHaveBeenCalledWith(
384
+ {
385
+ type: 'updateHeight',
386
+ payload: '100.5px'
387
+ },
388
+ '*'
389
+ );
390
+ });
391
+
392
+ it('should handle null data (falsy)', () => {
393
+ emitEvent('testEvent', null as unknown);
394
+
395
+ expect(mockPostMessage).toHaveBeenCalledWith(
396
+ {
397
+ type: 'testEvent',
398
+ payload: null
399
+ },
400
+ '*'
401
+ );
402
+ });
403
+
404
+ it('should handle special characters in event name', () => {
405
+ emitEvent('event@#$%');
406
+
407
+ expect(mockPostMessage).toHaveBeenCalledWith(
408
+ expect.objectContaining({
409
+ type: 'event@#$%'
410
+ }),
411
+ '*'
412
+ );
413
+ });
414
+ });
415
+ });
@@ -0,0 +1,11 @@
1
+ export function emitEvent(eventName: string, data?: unknown): void {
2
+ if (typeof window !== 'undefined' && window.parent) {
3
+ window.parent.postMessage(
4
+ {
5
+ type: eventName,
6
+ payload: data ? data + 'px' : null
7
+ },
8
+ '*'
9
+ );
10
+ }
11
+ }
package/src/index.ts CHANGED
@@ -152,6 +152,3 @@ export {
152
152
  export {
153
153
  OptaMatchStatsCommentary
154
154
  } from './components/opta/football/opta-match-stats/commentary/OptaMatchStatsCommentary';
155
- export {
156
- OptaMatchStatsMatchdayLive
157
- } from './components/opta/football/opta-match-stats/matchday-live/OptaMatchStatsMatchdayLive';
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- import { TeamColor } from '../shared/types';
3
- export declare const DesktopWidget: React.FC<{
4
- season: string;
5
- competition: string;
6
- match: string;
7
- isApp?: boolean;
8
- homeTeamColor?: TeamColor;
9
- awayTeamColor?: TeamColor;
10
- }>;