@times-components/ts-components 1.145.1-cfea81c4084e6f91221ea00fec9fc730d5b933cb.4 → 1.145.1-d1253ed8e87e7cdf861fbf772a5f9026182434db.4

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 (136) 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/summary/OptaFootballSummary.js +10 -2
  4. package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.js +95 -18
  5. package/dist/components/opta/rugby/summary/OptaRugbySummary.js +10 -2
  6. package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.js +94 -17
  7. package/dist/components/opta/utils/__tests__/emitEvent.test.js +264 -0
  8. package/dist/components/opta/utils/emitEvent.d.ts +1 -0
  9. package/dist/components/opta/utils/emitEvent.js +15 -0
  10. package/dist/index.d.ts +0 -1
  11. package/dist/index.js +1 -2
  12. package/package.json +3 -3
  13. package/rnw.js +1 -1
  14. package/src/components/opta/cricket/scorecard/OptaCricketScorecard.tsx +13 -0
  15. package/src/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.tsx +126 -16
  16. package/src/components/opta/cricket/scorecard/__tests__/__snapshots__/OptaCricketScorecard.test.tsx.snap +5 -6
  17. package/src/components/opta/football/summary/OptaFootballSummary.tsx +13 -0
  18. package/src/components/opta/football/summary/__tests__/OptaFootballSummary.test.tsx +127 -18
  19. package/src/components/opta/football/summary/__tests__/__snapshots__/OptaFootballSummary.test.tsx.snap +5 -6
  20. package/src/components/opta/rugby/summary/OptaRugbySummary.tsx +13 -0
  21. package/src/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.tsx +127 -17
  22. package/src/components/opta/rugby/summary/__tests__/__snapshots__/OptaRugbySummary.test.tsx.snap +5 -6
  23. package/src/components/opta/utils/__tests__/emitEvent.test.tsx +415 -0
  24. package/src/components/opta/utils/emitEvent.ts +20 -0
  25. package/src/index.ts +0 -2
  26. package/dist/components/carousel-component/CarouselComponent.stories.js +0 -146
  27. package/dist/components/carousel-component/CarouselItem.d.ts +0 -3
  28. package/dist/components/carousel-component/CarouselItem.js +0 -11
  29. package/dist/components/carousel-component/DefaultNavigationArrow.d.ts +0 -8
  30. package/dist/components/carousel-component/DefaultNavigationArrow.js +0 -6
  31. package/dist/components/carousel-component/DefaultPageDot.d.ts +0 -8
  32. package/dist/components/carousel-component/DefaultPageDot.js +0 -4
  33. package/dist/components/carousel-component/__tests__/CarouselComponent.test.d.ts +0 -1
  34. package/dist/components/carousel-component/__tests__/CarouselComponent.test.js +0 -163
  35. package/dist/components/carousel-component/__tests__/CarouselItem.test.d.ts +0 -1
  36. package/dist/components/carousel-component/__tests__/CarouselItem.test.js +0 -80
  37. package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.d.ts +0 -1
  38. package/dist/components/carousel-component/__tests__/DefaultNavigationArrow.test.js +0 -62
  39. package/dist/components/carousel-component/__tests__/DefaultPageDot.test.d.ts +0 -1
  40. package/dist/components/carousel-component/__tests__/DefaultPageDot.test.js +0 -68
  41. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.d.ts +0 -1
  42. package/dist/components/carousel-component/hooks/__tests__/useCarousel.test.js +0 -314
  43. package/dist/components/carousel-component/hooks/useCarousel.d.ts +0 -2
  44. package/dist/components/carousel-component/hooks/useCarousel.js +0 -140
  45. package/dist/components/carousel-component/index.d.ts +0 -4
  46. package/dist/components/carousel-component/index.js +0 -20
  47. package/dist/components/carousel-component/styles.d.ts +0 -30
  48. package/dist/components/carousel-component/styles.js +0 -120
  49. package/dist/components/carousel-component/types.d.ts +0 -46
  50. package/dist/components/carousel-component/types.js +0 -2
  51. package/dist/components/trip-cards/SkeletonCard.d.ts +0 -2
  52. package/dist/components/trip-cards/SkeletonCard.js +0 -21
  53. package/dist/components/trip-cards/TripCard.d.ts +0 -3
  54. package/dist/components/trip-cards/TripCard.js +0 -47
  55. package/dist/components/trip-cards/TripCards.stories.d.ts +0 -1
  56. package/dist/components/trip-cards/TripCards.stories.js +0 -40
  57. package/dist/components/trip-cards/TripCardsLayout.d.ts +0 -3
  58. package/dist/components/trip-cards/TripCardsLayout.js +0 -26
  59. package/dist/components/trip-cards/__tests__/SkeletonCard.test.d.ts +0 -1
  60. package/dist/components/trip-cards/__tests__/SkeletonCard.test.js +0 -139
  61. package/dist/components/trip-cards/__tests__/TripCard.test.d.ts +0 -1
  62. package/dist/components/trip-cards/__tests__/TripCard.test.js +0 -95
  63. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.d.ts +0 -1
  64. package/dist/components/trip-cards/__tests__/TripCardsLayout.test.js +0 -277
  65. package/dist/components/trip-cards/__tests__/assets.test.d.ts +0 -1
  66. package/dist/components/trip-cards/__tests__/assets.test.js +0 -165
  67. package/dist/components/trip-cards/__tests__/helpers.test.d.ts +0 -1
  68. package/dist/components/trip-cards/__tests__/helpers.test.js +0 -135
  69. package/dist/components/trip-cards/__tests__/index.test.d.ts +0 -1
  70. package/dist/components/trip-cards/__tests__/index.test.js +0 -437
  71. package/dist/components/trip-cards/__tests__/mockData.test.d.ts +0 -1
  72. package/dist/components/trip-cards/__tests__/mockData.test.js +0 -57
  73. package/dist/components/trip-cards/__tests__/skeletonStyles.test.d.ts +0 -1
  74. package/dist/components/trip-cards/__tests__/skeletonStyles.test.js +0 -194
  75. package/dist/components/trip-cards/assets/BoatIcon.d.ts +0 -1
  76. package/dist/components/trip-cards/assets/BoatIcon.js +0 -4
  77. package/dist/components/trip-cards/assets/CalendarIcon.d.ts +0 -1
  78. package/dist/components/trip-cards/assets/CalendarIcon.js +0 -4
  79. package/dist/components/trip-cards/assets/ChevronRightIcon.d.ts +0 -1
  80. package/dist/components/trip-cards/assets/ChevronRightIcon.js +0 -4
  81. package/dist/components/trip-cards/assets/LocationIcon.d.ts +0 -1
  82. package/dist/components/trip-cards/assets/LocationIcon.js +0 -4
  83. package/dist/components/trip-cards/assets/MoonIcon.d.ts +0 -1
  84. package/dist/components/trip-cards/assets/MoonIcon.js +0 -4
  85. package/dist/components/trip-cards/assets/index.d.ts +0 -6
  86. package/dist/components/trip-cards/assets/index.js +0 -7
  87. package/dist/components/trip-cards/helpers.d.ts +0 -4
  88. package/dist/components/trip-cards/helpers.js +0 -74
  89. package/dist/components/trip-cards/index.d.ts +0 -4
  90. package/dist/components/trip-cards/index.js +0 -70
  91. package/dist/components/trip-cards/mockData.d.ts +0 -3
  92. package/dist/components/trip-cards/mockData.js +0 -323
  93. package/dist/components/trip-cards/skeletonStyles.d.ts +0 -9
  94. package/dist/components/trip-cards/skeletonStyles.js +0 -37
  95. package/dist/components/trip-cards/styles.d.ts +0 -39
  96. package/dist/components/trip-cards/styles.js +0 -387
  97. package/dist/components/trip-cards/types.d.ts +0 -87
  98. package/dist/components/trip-cards/types.js +0 -2
  99. package/src/components/carousel-component/CarouselComponent.stories.tsx +0 -220
  100. package/src/components/carousel-component/CarouselItem.tsx +0 -20
  101. package/src/components/carousel-component/DefaultNavigationArrow.tsx +0 -37
  102. package/src/components/carousel-component/DefaultPageDot.tsx +0 -20
  103. package/src/components/carousel-component/__tests__/CarouselComponent.test.tsx +0 -259
  104. package/src/components/carousel-component/__tests__/CarouselItem.test.tsx +0 -140
  105. package/src/components/carousel-component/__tests__/DefaultNavigationArrow.test.tsx +0 -153
  106. package/src/components/carousel-component/__tests__/DefaultPageDot.test.tsx +0 -105
  107. package/src/components/carousel-component/hooks/__tests__/useCarousel.test.ts +0 -438
  108. package/src/components/carousel-component/hooks/useCarousel.ts +0 -187
  109. package/src/components/carousel-component/index.tsx +0 -88
  110. package/src/components/carousel-component/styles.ts +0 -140
  111. package/src/components/carousel-component/types.ts +0 -51
  112. package/src/components/trip-cards/SkeletonCard.tsx +0 -54
  113. package/src/components/trip-cards/TripCard.tsx +0 -135
  114. package/src/components/trip-cards/TripCards.stories.tsx +0 -67
  115. package/src/components/trip-cards/TripCardsLayout.tsx +0 -75
  116. package/src/components/trip-cards/__tests__/SkeletonCard.test.tsx +0 -169
  117. package/src/components/trip-cards/__tests__/TripCard.test.tsx +0 -120
  118. package/src/components/trip-cards/__tests__/TripCardsLayout.test.tsx +0 -532
  119. package/src/components/trip-cards/__tests__/assets.test.tsx +0 -206
  120. package/src/components/trip-cards/__tests__/helpers.test.ts +0 -165
  121. package/src/components/trip-cards/__tests__/index.test.tsx +0 -499
  122. package/src/components/trip-cards/__tests__/mockData.test.ts +0 -67
  123. package/src/components/trip-cards/__tests__/skeletonStyles.test.tsx +0 -256
  124. package/src/components/trip-cards/assets/BoatIcon.tsx +0 -17
  125. package/src/components/trip-cards/assets/CalendarIcon.tsx +0 -17
  126. package/src/components/trip-cards/assets/ChevronRightIcon.tsx +0 -20
  127. package/src/components/trip-cards/assets/LocationIcon.tsx +0 -17
  128. package/src/components/trip-cards/assets/MoonIcon.tsx +0 -17
  129. package/src/components/trip-cards/assets/index.ts +0 -7
  130. package/src/components/trip-cards/helpers.ts +0 -99
  131. package/src/components/trip-cards/index.tsx +0 -104
  132. package/src/components/trip-cards/mockData.ts +0 -351
  133. package/src/components/trip-cards/skeletonStyles.ts +0 -46
  134. package/src/components/trip-cards/styles.ts +0 -426
  135. package/src/components/trip-cards/types.ts +0 -91
  136. /package/dist/components/{carousel-component/CarouselComponent.stories.d.ts → opta/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,20 @@
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
+ if (typeof window !== 'undefined' && (window as any).ReactNativeWebView) {
12
+ (window as any).ReactNativeWebView.postMessage(
13
+ {
14
+ type: eventName,
15
+ payload: data ? data + 'px' : null
16
+ },
17
+ '*'
18
+ );
19
+ }
20
+ }
package/src/index.ts CHANGED
@@ -104,8 +104,6 @@ export {
104
104
  default as ArticleHeader
105
105
  } from './components/article-header/ArticleHeader';
106
106
 
107
- export { TripCards } from './components/trip-cards';
108
-
109
107
  export {
110
108
  UpdatedTimestamp
111
109
  } from './components/updated-timestamp/UpdatedTimestamp';