@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.
- package/dist/components/opta/cricket/scorecard/OptaCricketScorecard.js +2 -10
- package/dist/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.js +17 -94
- package/dist/components/opta/football/summary/OptaFootballSummary.js +2 -10
- package/dist/components/opta/football/summary/__tests__/OptaFootballSummary.test.js +18 -95
- package/dist/components/opta/rugby/summary/OptaRugbySummary.js +2 -10
- package/dist/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.js +17 -94
- package/dist/components/travel-mini-cta/index.d.ts +3 -0
- package/dist/components/travel-mini-cta/index.js +86 -0
- package/dist/components/travel-mini-cta/styles.d.ts +42 -0
- package/dist/components/travel-mini-cta/styles.js +273 -0
- package/dist/components/travel-mini-cta/travel-mini-cta.stories.d.ts +110 -0
- package/dist/components/travel-mini-cta/travel-mini-cta.stories.js +121 -0
- package/dist/components/travel-mini-cta/types.d.ts +10 -0
- package/dist/components/travel-mini-cta/types.js +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/utils/applyDarkMode.d.ts +1 -0
- package/dist/utils/applyDarkMode.js +12 -0
- package/dist/utils/getMediaQuery.d.ts +11 -0
- package/dist/utils/getMediaQuery.js +19 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +3 -0
- package/package.json +3 -3
- package/rnw.js +1 -1
- package/src/components/opta/cricket/scorecard/OptaCricketScorecard.tsx +0 -13
- package/src/components/opta/cricket/scorecard/__tests__/OptaCricketScorecard.test.tsx +16 -126
- package/src/components/opta/cricket/scorecard/__tests__/__snapshots__/OptaCricketScorecard.test.tsx.snap +6 -5
- package/src/components/opta/football/summary/OptaFootballSummary.tsx +0 -13
- package/src/components/opta/football/summary/__tests__/OptaFootballSummary.test.tsx +18 -127
- package/src/components/opta/football/summary/__tests__/__snapshots__/OptaFootballSummary.test.tsx.snap +6 -5
- package/src/components/opta/rugby/summary/OptaRugbySummary.tsx +0 -13
- package/src/components/opta/rugby/summary/__tests__/OptaRugbySummary.test.tsx +17 -127
- package/src/components/opta/rugby/summary/__tests__/__snapshots__/OptaRugbySummary.test.tsx.snap +6 -5
- package/src/components/travel-mini-cta/index.tsx +164 -0
- package/src/components/travel-mini-cta/styles.ts +336 -0
- package/src/components/travel-mini-cta/travel-mini-cta.stories.tsx +157 -0
- package/src/components/travel-mini-cta/types.ts +10 -0
- package/src/index.ts +1 -0
- package/src/utils/applyDarkMode.ts +12 -0
- package/src/utils/getMediaQuery.ts +25 -0
- package/src/utils/index.ts +2 -0
- package/dist/components/opta/utils/__tests__/emitEvent.test.d.ts +0 -1
- package/dist/components/opta/utils/__tests__/emitEvent.test.js +0 -264
- package/dist/components/opta/utils/emitEvent.d.ts +0 -1
- package/dist/components/opta/utils/emitEvent.js +0 -15
- package/src/components/opta/utils/__tests__/emitEvent.test.tsx +0 -415
- package/src/components/opta/utils/emitEvent.ts +0 -20
|
@@ -1,415 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
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
|
-
}
|