@applicaster/zapp-react-native-utils 16.0.0-alpha.1042942411 → 16.0.0-alpha.1054344748

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 (139) hide show
  1. package/actionsExecutor/ActionExecutor.ts +50 -3
  2. package/actionsExecutor/ActionExecutorContext.tsx +99 -17
  3. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  4. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  5. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
  6. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  7. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  8. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  9. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
  10. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
  11. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +300 -0
  12. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  13. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  14. package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
  15. package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
  16. package/actionsExecutor/actions/goBack.ts +60 -0
  17. package/actionsExecutor/actions/goHome.ts +31 -0
  18. package/actionsExecutor/actions/index.ts +12 -0
  19. package/actionsExecutor/actions/navigateToScreen.ts +18 -4
  20. package/actionsExecutor/actions/openBottomSheet.ts +338 -0
  21. package/actionsExecutor/actions/presentScreen.ts +78 -0
  22. package/actionsExecutor/actions/refreshComponent.ts +6 -0
  23. package/actionsExecutor/actions/sendCloudEvent.ts +6 -1
  24. package/actionsExecutor/actions/showAlert.ts +51 -0
  25. package/actionsExecutor/actions/showToast.ts +64 -8
  26. package/actionsExecutor/consts.ts +27 -0
  27. package/actionsExecutor/feedDecorator.ts +6 -6
  28. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  29. package/appUtils/HooksManager/index.ts +9 -0
  30. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
  31. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  32. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  33. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  34. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  35. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  36. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  37. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  38. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  39. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  40. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  41. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  42. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  43. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +97 -0
  44. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  45. package/appUtils/playerManager/{conts.ts → const.ts} +33 -0
  46. package/appUtils/playerManager/index.ts +3 -1
  47. package/appUtils/playerManager/player.ts +125 -3
  48. package/appUtils/playerManager/playerFactory.ts +1 -1
  49. package/appUtils/playerManager/playerNative.ts +28 -4
  50. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  51. package/appUtils/playerManager/playerToolbox.ts +192 -0
  52. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  53. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  54. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  55. package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
  56. package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
  57. package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
  58. package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
  59. package/arrayUtils/__tests__/isFirst.test.ts +17 -0
  60. package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
  61. package/arrayUtils/__tests__/isLast.test.ts +31 -0
  62. package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
  63. package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
  64. package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
  65. package/arrayUtils/__tests__/sample.test.ts +61 -0
  66. package/arrayUtils/index.ts +119 -20
  67. package/cellUtils/index.ts +30 -3
  68. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  69. package/configurationUtils/__tests__/modalBlocksParser.test.ts +269 -0
  70. package/configurationUtils/manifestKeyParser.ts +50 -10
  71. package/configurationUtils/modalBlocksParser.ts +214 -0
  72. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  73. package/entryActions/aliasPresentation.ts +108 -0
  74. package/entryActions/buildEntryActions.ts +167 -0
  75. package/entryActions/index.ts +15 -0
  76. package/entryActions/types.ts +39 -0
  77. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  78. package/manifestUtils/_internals/index.js +8 -3
  79. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  80. package/manifestUtils/defaultManifestConfigurations/player.js +330 -1
  81. package/manifestUtils/index.js +3 -0
  82. package/manifestUtils/modalBlocks.js +304 -0
  83. package/modalState/ContentViewModel.ts +113 -0
  84. package/modalState/EditableCollection.ts +17 -0
  85. package/modalState/EditableCollectionRegistry.ts +51 -0
  86. package/modalState/ModalOrchestrator.ts +212 -0
  87. package/modalState/RemoteEditableCollection.ts +235 -0
  88. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  89. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  90. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  91. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +63 -0
  92. package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
  93. package/modalState/__tests__/index.test.ts +30 -1
  94. package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
  95. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  96. package/modalState/index.ts +35 -83
  97. package/modalState/store.ts +109 -0
  98. package/modalState/types.ts +162 -0
  99. package/modalState/useBottomSheetContent.ts +109 -0
  100. package/package.json +2 -2
  101. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  102. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  103. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  104. package/playerUtils/contentDataKeys.ts +134 -0
  105. package/playerUtils/index.ts +37 -16
  106. package/playerUtils/isAudioItem.ts +26 -0
  107. package/playerUtils/resolvePlayerActions.ts +71 -0
  108. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  109. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  110. package/pluginUtils/index.ts +29 -0
  111. package/reactHooks/actions/index.ts +67 -2
  112. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  113. package/reactHooks/cell-click/index.ts +21 -14
  114. package/reactHooks/connection/index.tsx +8 -5
  115. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  116. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  117. package/reactHooks/index.ts +2 -0
  118. package/reactHooks/layout/index.ts +1 -1
  119. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  120. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  121. package/reactHooks/navigation/index.ts +2 -0
  122. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  123. package/reactHooks/navigation/useRoute.ts +22 -5
  124. package/reactHooks/usePluginConfiguration.ts +4 -1
  125. package/reactHooks/utils/__tests__/index.test.js +22 -2
  126. package/reactHooks/utils/index.ts +11 -1
  127. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  128. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  129. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  130. package/uiActionsRegistrator/index.ts +25 -203
  131. package/uiActionsRegistrator/registry.ts +351 -0
  132. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  133. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  134. package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
  135. package/zappFrameworkUtils/localStorageHelper.ts +19 -15
  136. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  137. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  138. package/playerUtils/getPlayerActionButtons.ts +0 -17
  139. /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
@@ -0,0 +1,403 @@
1
+ import { Player } from "../player";
2
+ import { isTV } from "../../../reactUtils";
3
+
4
+ jest.mock("../../../reactUtils", () => ({
5
+ ...jest.requireActual("../../../reactUtils"),
6
+ isTV: jest.fn(() => false),
7
+ }));
8
+
9
+ const mockIsTV = isTV as jest.Mock;
10
+
11
+ const ENTRY = {
12
+ title: "Entry Title",
13
+ summary: "Entry Summary",
14
+ extensions: { programme: "Programme Title" },
15
+ } as unknown as ZappEntry;
16
+
17
+ const LIVE_ENTRY = {
18
+ title: "Live Title",
19
+ summary: "Live Summary",
20
+ } as unknown as ZappEntry;
21
+
22
+ const makePlayer = (configuration: Record<string, any> | null = null) => {
23
+ const player = new Player({ playerId: "test-player" });
24
+
25
+ player.getPluginConfiguration = () => configuration;
26
+
27
+ return player;
28
+ };
29
+
30
+ describe("Player content channel", () => {
31
+ beforeEach(() => {
32
+ mockIsTV.mockReturnValue(false);
33
+ });
34
+
35
+ it("resolves the entry fields when nothing is configured", () => {
36
+ const player = makePlayer();
37
+
38
+ player.entry = ENTRY;
39
+
40
+ expect(player.getContent()).toEqual({
41
+ title: "Entry Title",
42
+ summary: "Entry Summary",
43
+ });
44
+ });
45
+
46
+ it("resolves a configured custom data key", () => {
47
+ const player = makePlayer({
48
+ title_data_key_source: "other",
49
+ title_custom_data_key: "extensions.programme",
50
+ });
51
+
52
+ player.entry = ENTRY;
53
+
54
+ expect(player.getContent().title).toBe("Programme Title");
55
+ });
56
+
57
+ it("falls back to the entry field when the configured key is unresolvable", () => {
58
+ const player = makePlayer({
59
+ title_data_key_source: "other",
60
+ title_custom_data_key: "extensions.nope",
61
+ });
62
+
63
+ player.entry = ENTRY;
64
+
65
+ expect(player.getContent().title).toBe("Entry Title");
66
+ });
67
+
68
+ it("emits the resolved content to subscribers when the entry changes", () => {
69
+ const player = makePlayer();
70
+ const received: any[] = [];
71
+
72
+ player
73
+ .getContentObservable()
74
+ .subscribe((content) => received.push(content));
75
+
76
+ player.entry = ENTRY;
77
+
78
+ expect(received[received.length - 1]).toEqual({
79
+ title: "Entry Title",
80
+ summary: "Entry Summary",
81
+ });
82
+ });
83
+
84
+ it("seeds subscribers with resolved content, never the raw entry", () => {
85
+ const player = makePlayer({
86
+ title_data_key_source: "other",
87
+ title_custom_data_key: "extensions.programme",
88
+ });
89
+
90
+ player.entry = ENTRY;
91
+
92
+ const received: any[] = [];
93
+
94
+ player
95
+ .getContentObservable()
96
+ .subscribe((content) => received.push(content));
97
+
98
+ expect(received[0].title).toBe("Programme Title");
99
+ });
100
+
101
+ // The live entry lives on `OverlaysObserver`, not on the player, so these
102
+ // stub the observer rather than constructing a real one (whose constructor
103
+ // pulls in chapter markers, play-next and the plugin store). What is under
104
+ // test here is only how `getContent` and the `entry` setter treat it; the
105
+ // observer's own side - loading the feed and storing the result - is
106
+ // covered in `OverlayObserver/__tests__/liveContent.test.ts`.
107
+ const withLiveEntry = (player: Player, liveEntry: ZappEntry | null) => {
108
+ (player as any).overlaysObserver = {
109
+ liveEntry,
110
+ clearLiveEntry() {
111
+ this.liveEntry = null;
112
+ },
113
+ };
114
+ };
115
+
116
+ it("prefers the observer's live entry over the player entry", () => {
117
+ const player = makePlayer();
118
+
119
+ player.entry = ENTRY;
120
+ withLiveEntry(player, LIVE_ENTRY);
121
+
122
+ expect(player.getContent()).toEqual({
123
+ title: "Live Title",
124
+ summary: "Live Summary",
125
+ });
126
+ });
127
+
128
+ it("clears the live entry when a new entry is set", () => {
129
+ const player = makePlayer();
130
+
131
+ player.entry = ENTRY;
132
+ withLiveEntry(player, LIVE_ENTRY);
133
+ player.entry = ENTRY;
134
+
135
+ expect(player.getContent().title).toBe("Entry Title");
136
+ });
137
+
138
+ it("falls through to the player entry when there is no observer at all", () => {
139
+ const player = makePlayer();
140
+
141
+ player.entry = ENTRY;
142
+
143
+ expect((player as any).overlaysObserver).toBeFalsy();
144
+ expect(player.getContent().title).toBe("Entry Title");
145
+ });
146
+
147
+ it("resolves the cover image from the entry's media group", () => {
148
+ const player = makePlayer();
149
+
150
+ player.entry = {
151
+ title: "Entry Title",
152
+ media_group: [
153
+ {
154
+ type: "image",
155
+ media_item: [
156
+ { key: "image_other", src: "https://img.test/other.jpg" },
157
+ { key: "image_base", src: "https://img.test/base.jpg" },
158
+ ],
159
+ },
160
+ ],
161
+ } as unknown as ZappEntry;
162
+
163
+ expect(player.getContent().imageUrl).toBe("https://img.test/base.jpg");
164
+ });
165
+
166
+ it("falls back to the first media item when there is no image_base", () => {
167
+ const player = makePlayer();
168
+
169
+ player.entry = {
170
+ title: "Entry Title",
171
+ media_group: [
172
+ {
173
+ type: "image",
174
+ media_item: [
175
+ { key: "image_other", src: "https://img.test/other.jpg" },
176
+ ],
177
+ },
178
+ ],
179
+ } as unknown as ZappEntry;
180
+
181
+ expect(player.getContent().imageUrl).toBe("https://img.test/other.jpg");
182
+ });
183
+
184
+ it("has no image when the entry carries no media group", () => {
185
+ const player = makePlayer();
186
+
187
+ player.entry = ENTRY;
188
+
189
+ expect(player.getContent().imageUrl).toBeUndefined();
190
+ });
191
+
192
+ it("takes the cover image from the live entry, not the channel", () => {
193
+ // The programme's own artwork has to travel with its title - otherwise the
194
+ // lock screen would keep showing the channel's cover all day.
195
+ const player = makePlayer();
196
+
197
+ player.entry = {
198
+ title: "Channel",
199
+ media_group: [
200
+ {
201
+ type: "image",
202
+ media_item: [
203
+ { key: "image_base", src: "https://img.test/channel.jpg" },
204
+ ],
205
+ },
206
+ ],
207
+ } as unknown as ZappEntry;
208
+
209
+ withLiveEntry(player, {
210
+ title: "Programme",
211
+ media_group: [
212
+ {
213
+ type: "image",
214
+ media_item: [
215
+ { key: "image_base", src: "https://img.test/programme.jpg" },
216
+ ],
217
+ },
218
+ ],
219
+ } as unknown as ZappEntry);
220
+
221
+ expect(player.getContent().imageUrl).toBe("https://img.test/programme.jpg");
222
+ });
223
+
224
+ it("publishes the observer's live entry to subscribers", () => {
225
+ const player = makePlayer();
226
+ const received: any[] = [];
227
+
228
+ player.entry = ENTRY;
229
+
230
+ player
231
+ .getContentObservable()
232
+ .subscribe((content) => received.push(content));
233
+
234
+ withLiveEntry(player, LIVE_ENTRY);
235
+ player.publishContent();
236
+
237
+ expect(received[received.length - 1].title).toBe("Live Title");
238
+ });
239
+
240
+ it("does not resolve while no subscriber exists", () => {
241
+ const player = makePlayer();
242
+ const getConfiguration = jest.fn(() => null);
243
+
244
+ player.getPluginConfiguration = getConfiguration;
245
+ player.entry = ENTRY;
246
+
247
+ expect(getConfiguration).not.toHaveBeenCalled();
248
+ });
249
+ });
250
+
251
+ /**
252
+ * Which Studio key set backs the resolution is decided inside `getContent()`
253
+ * (via `getPlayerContentDataKeys`). Getting it wrong would make one platform
254
+ * or content type read another's Studio configuration, so each combination is
255
+ * pinned here - including the negative cases that prove the sets never cross.
256
+ *
257
+ * These moved here from `PlayerContainer.test.tsx` when the resolution moved
258
+ * out of the React tree and into the player; the assertions are unchanged.
259
+ */
260
+ describe("Player content channel: key-set selection", () => {
261
+ const VIDEO_ENTRY = {
262
+ id: "video-entry",
263
+ title: "Entry Title",
264
+ summary: "Entry Summary",
265
+ content: { src: "https://example.com/video.m3u8" },
266
+ extensions: { customTitleKey: "Custom Title From Extensions" },
267
+ } as unknown as ZappEntry;
268
+
269
+ const AUDIO_ENTRY = {
270
+ id: "audio-entry",
271
+ title: "Entry Title",
272
+ summary: "Entry Summary",
273
+ content: { type: "audio", src: "https://example.com/audio.m3u8" },
274
+ extensions: { customTitleKey: "Custom Audio Title From Extensions" },
275
+ } as unknown as ZappEntry;
276
+
277
+ const contentFor = (
278
+ entry: ZappEntry,
279
+ configuration: Record<string, any> | null
280
+ ) => {
281
+ const player = makePlayer(configuration);
282
+
283
+ player.entry = entry;
284
+
285
+ return player.getContent();
286
+ };
287
+
288
+ describe("TV video", () => {
289
+ beforeEach(() => mockIsTV.mockReturnValue(true));
290
+
291
+ it("resolves the TV video override to the configured extensions key", () => {
292
+ const content = contentFor(VIDEO_ENTRY, {
293
+ video_player_title_data_key_source: "other",
294
+ video_player_title_custom_data_key: "extensions.customTitleKey",
295
+ });
296
+
297
+ expect(content.title).toBe("Custom Title From Extensions");
298
+ // summary was not overridden, so it keeps falling back to entry.summary.
299
+ expect(content.summary).toBe("Entry Summary");
300
+ });
301
+
302
+ it("falls back to the entry title when the configured key does not resolve", () => {
303
+ const content = contentFor(VIDEO_ENTRY, {
304
+ video_player_title_data_key_source: "other",
305
+ video_player_title_custom_data_key: "extensions.doesNotExist",
306
+ });
307
+
308
+ expect(content.title).toBe("Entry Title");
309
+ });
310
+
311
+ it("ignores mobile configuration", () => {
312
+ const content = contentFor(VIDEO_ENTRY, {
313
+ title_data_key_source: "other",
314
+ title_custom_data_key: "extensions.customTitleKey",
315
+ });
316
+
317
+ expect(content.title).toBe("Entry Title");
318
+ });
319
+
320
+ it("reads the TV video key set, not the mobile one, when both are configured", () => {
321
+ const content = contentFor(VIDEO_ENTRY, {
322
+ video_player_title_data_key_source: "other",
323
+ video_player_title_custom_data_key: "extensions.customTitleKey",
324
+ // A mobile key is also configured, to prove the TV branch ignores it.
325
+ title_data_key_source: "other",
326
+ title_custom_data_key: "extensions.doesNotExist",
327
+ });
328
+
329
+ expect(content.title).toBe("Custom Title From Extensions");
330
+ });
331
+
332
+ it("passes the entry fields through when nothing is configured", () => {
333
+ const content = contentFor(VIDEO_ENTRY, {});
334
+
335
+ expect(content.title).toBe("Entry Title");
336
+ expect(content.summary).toBe("Entry Summary");
337
+ });
338
+ });
339
+
340
+ describe("TV audio", () => {
341
+ beforeEach(() => mockIsTV.mockReturnValue(true));
342
+
343
+ it("reads the TV audio key set, not the TV video one", () => {
344
+ const content = contentFor(AUDIO_ENTRY, {
345
+ audio_player_title_data_key_source: "other",
346
+ audio_player_title_custom_data_key: "extensions.customTitleKey",
347
+ // Configuring the TV *video* key too, to prove TV audio content reads
348
+ // its own key family instead.
349
+ video_player_title_data_key_source: "other",
350
+ video_player_title_custom_data_key: "extensions.doesNotExist",
351
+ });
352
+
353
+ expect(content.title).toBe("Custom Audio Title From Extensions");
354
+ });
355
+
356
+ it("falls back to the entry fields when nothing is configured", () => {
357
+ const content = contentFor(AUDIO_ENTRY, {});
358
+
359
+ expect(content.title).toBe("Entry Title");
360
+ expect(content.summary).toBe("Entry Summary");
361
+ });
362
+ });
363
+
364
+ describe("mobile", () => {
365
+ beforeEach(() => mockIsTV.mockReturnValue(false));
366
+
367
+ it("resolves the default (mobile) key set", () => {
368
+ const content = contentFor(VIDEO_ENTRY, {
369
+ title_data_key_source: "other",
370
+ title_custom_data_key: "extensions.customTitleKey",
371
+ });
372
+
373
+ expect(content.title).toBe("Custom Title From Extensions");
374
+ });
375
+
376
+ it("ignores TV video configuration", () => {
377
+ const content = contentFor(VIDEO_ENTRY, {
378
+ video_player_title_data_key_source: "other",
379
+ video_player_title_custom_data_key: "extensions.customTitleKey",
380
+ });
381
+
382
+ expect(content.title).toBe("Entry Title");
383
+ });
384
+
385
+ it("shares one key set between video and audio", () => {
386
+ const content = contentFor(AUDIO_ENTRY, {
387
+ title_data_key_source: "other",
388
+ title_custom_data_key: "extensions.customTitleKey",
389
+ });
390
+
391
+ expect(content.title).toBe("Custom Audio Title From Extensions");
392
+ });
393
+
394
+ it("ignores TV audio configuration for mobile audio", () => {
395
+ const content = contentFor(AUDIO_ENTRY, {
396
+ audio_player_title_data_key_source: "other",
397
+ audio_player_title_custom_data_key: "extensions.customTitleKey",
398
+ });
399
+
400
+ expect(content.title).toBe("Entry Title");
401
+ });
402
+ });
403
+ });
@@ -10,7 +10,7 @@ jest.mock("@applicaster/zapp-react-native-utils/pluginUtils", () => ({
10
10
  mockFindPluginByIdentifier(id, plugins),
11
11
  }));
12
12
 
13
- import { PlayerRole } from "../conts";
13
+ import { PlayerRole } from "../const";
14
14
  import { playerFactory } from "../playerFactory";
15
15
 
16
16
  const fakeComponent = () => null;
@@ -0,0 +1,114 @@
1
+ import { PlayerNative } from "../playerNative";
2
+
3
+ const playerWithEntry = (entry: any) =>
4
+ new PlayerNative({
5
+ entry,
6
+ player: null as any,
7
+ playerId: "test-player",
8
+ });
9
+
10
+ describe("PlayerNative.isAudioItem", () => {
11
+ it.each(["audio", "audio-player", "audio-detail", "audio-show", "audio-hub"])(
12
+ "treats the %s content type as audio",
13
+ (type) => {
14
+ expect(playerWithEntry({ type: { value: type } }).isAudioItem()).toBe(
15
+ true
16
+ );
17
+ }
18
+ );
19
+
20
+ it.each(["video", "video-detail", "comic-detail", "article-show"])(
21
+ "does not treat the %s content type as audio",
22
+ (type) => {
23
+ expect(playerWithEntry({ type: { value: type } }).isAudioItem()).toBe(
24
+ false
25
+ );
26
+ }
27
+ );
28
+
29
+ it("falls back to the media type when the content type says nothing", () => {
30
+ const entry = { content: { type: "audio/mpeg" }, type: { value: "link" } };
31
+
32
+ expect(playerWithEntry(entry).isAudioItem()).toBe(true);
33
+ });
34
+
35
+ it("returns false when there is no entry", () => {
36
+ expect(playerWithEntry(null).isAudioItem()).toBe(false);
37
+ });
38
+ });
39
+
40
+ describe("PlayerNative.command", () => {
41
+ it("invokes native function with playerId on iOS platform", () => {
42
+ const player = new PlayerNative({
43
+ entry: null,
44
+ player: { current: {} } as any,
45
+ playerId: "test-player",
46
+ playerPluginId: "QuickBrickPlayerPlugin",
47
+ });
48
+
49
+ const commandSpy = jest.fn();
50
+
51
+ jest.spyOn(player, "getPlayerModule").mockReturnValue({
52
+ command: commandSpy,
53
+ } as any);
54
+
55
+ player.command("setPlayerControls", { transport: ["play"] });
56
+
57
+ expect(commandSpy).toHaveBeenCalledWith(
58
+ "setPlayerControls",
59
+ "test-player",
60
+ {
61
+ transport: ["play"],
62
+ }
63
+ );
64
+ });
65
+
66
+ it("invokes native function with view tag on Android when method exists", () => {
67
+ const reactUtils = require("../../../reactUtils");
68
+ jest.spyOn(reactUtils, "isApplePlatform").mockReturnValue(false);
69
+
70
+ const player = new PlayerNative({
71
+ entry: null,
72
+ player: { current: {} } as any,
73
+ playerId: "test-player",
74
+ playerPluginId: "QuickBrickPlayerPlugin",
75
+ });
76
+
77
+ const commandSpy = jest.fn();
78
+
79
+ jest.spyOn(player, "getPlayerModule").mockReturnValue({
80
+ command: commandSpy,
81
+ } as any);
82
+
83
+ jest.spyOn(player, "getComponentNode").mockReturnValue(12345 as any);
84
+
85
+ player.command("setPlayerControls", { transport: ["play"] });
86
+
87
+ expect(commandSpy).toHaveBeenCalledWith(12345, "setPlayerControls", {
88
+ transport: ["play"],
89
+ });
90
+
91
+ (reactUtils.isApplePlatform as jest.Mock).mockRestore();
92
+ });
93
+
94
+ it("handles when native module does not have command method on Android", () => {
95
+ const reactUtils = require("../../../reactUtils");
96
+ jest.spyOn(reactUtils, "isApplePlatform").mockReturnValue(false);
97
+
98
+ const player = new PlayerNative({
99
+ entry: null,
100
+ player: { current: {} } as any,
101
+ playerId: "test-player",
102
+ playerPluginId: "KalturaPlayerPlugin",
103
+ });
104
+
105
+ jest.spyOn(player, "getPlayerModule").mockReturnValue({} as any);
106
+ jest.spyOn(player, "getComponentNode").mockReturnValue(12345 as any);
107
+
108
+ expect(() => {
109
+ player.command("setPlayerControls", { transport: ["play"] });
110
+ }).not.toThrow();
111
+
112
+ (reactUtils.isApplePlatform as jest.Mock).mockRestore();
113
+ });
114
+ });
@@ -0,0 +1,62 @@
1
+ import { NativeModules } from "react-native";
2
+ import {
3
+ PlayerNativeCommandTypes,
4
+ PlayerNativeSendCommand,
5
+ } from "../playerNativeCommand";
6
+
7
+ describe("PlayerNativeSendCommand", () => {
8
+ const reactUtils = require("../../../reactUtils");
9
+
10
+ afterEach(() => {
11
+ jest.restoreAllMocks();
12
+ });
13
+
14
+ it("calls NativeModules.PlayerModule.command on Apple platform with playerId", () => {
15
+ jest.spyOn(reactUtils, "isApplePlatform").mockReturnValue(true);
16
+
17
+ NativeModules.PlayerModule = {
18
+ command: jest.fn(),
19
+ };
20
+
21
+ PlayerNativeSendCommand(
22
+ PlayerNativeCommandTypes.setPlayerControls,
23
+ "player-123",
24
+ { transport: ["play"] }
25
+ );
26
+
27
+ expect(NativeModules.PlayerModule.command).toHaveBeenCalledWith(
28
+ "setPlayerControls",
29
+ "player-123",
30
+ { transport: ["play"] }
31
+ );
32
+ });
33
+
34
+ it("does not call NativeModules.PlayerModule.command on non-Apple platform", () => {
35
+ jest.spyOn(reactUtils, "isApplePlatform").mockReturnValue(false);
36
+
37
+ NativeModules.PlayerModule = {
38
+ command: jest.fn(),
39
+ };
40
+
41
+ PlayerNativeSendCommand(
42
+ PlayerNativeCommandTypes.setPlayerControls,
43
+ "player-123",
44
+ { transport: ["play"] }
45
+ );
46
+
47
+ expect(NativeModules.PlayerModule.command).not.toHaveBeenCalled();
48
+ });
49
+
50
+ it("does nothing when playerId or command is missing", () => {
51
+ jest.spyOn(reactUtils, "isApplePlatform").mockReturnValue(true);
52
+
53
+ NativeModules.PlayerModule = {
54
+ command: jest.fn(),
55
+ };
56
+
57
+ PlayerNativeSendCommand("", "player-123");
58
+ PlayerNativeSendCommand("setPlayerControls", "");
59
+
60
+ expect(NativeModules.PlayerModule.command).not.toHaveBeenCalled();
61
+ });
62
+ });
@@ -0,0 +1,97 @@
1
+ const mockRegister = jest.fn();
2
+ let mockXray: Record<string, unknown> | null = {};
3
+
4
+ jest.mock("../../../logger", () => ({
5
+ getXray: () => mockXray,
6
+ }));
7
+
8
+ const loadToolbox = () => {
9
+ let module;
10
+
11
+ jest.isolateModules(() => {
12
+ module = require("../playerToolbox");
13
+ });
14
+
15
+ return module as typeof import("../playerToolbox");
16
+ };
17
+
18
+ const player = (overrides = {}) => ({
19
+ getSeekableDuration: () => 100,
20
+ getContentPosition: () => 40,
21
+ seekTo: jest.fn(),
22
+ ...overrides,
23
+ });
24
+
25
+ const manager = (active) =>
26
+ ({ getActivePlayer: () => active, isCasting: () => false }) as any;
27
+
28
+ const registeredTools = async (active) => {
29
+ mockRegister.mockResolvedValue(undefined);
30
+ mockXray = { registerReactToolbox: mockRegister };
31
+ await loadToolbox().registerPlayerToolbox(manager(active));
32
+
33
+ const { tools } = mockRegister.mock.calls[0][0];
34
+
35
+ return Object.fromEntries(tools.map((tool) => [tool.name, tool.handler]));
36
+ };
37
+
38
+ describe("playerToolbox", () => {
39
+ beforeEach(() => {
40
+ mockRegister.mockReset();
41
+ });
42
+
43
+ it("does nothing when X-Ray has no React toolbox API", async () => {
44
+ mockXray = {};
45
+
46
+ await expect(
47
+ loadToolbox().registerPlayerToolbox(manager(null))
48
+ ).resolves.toBeUndefined();
49
+ });
50
+
51
+ it("does nothing when getXray returns null", async () => {
52
+ mockXray = null;
53
+
54
+ await expect(
55
+ loadToolbox().registerPlayerToolbox(manager(null))
56
+ ).resolves.toBeUndefined();
57
+ });
58
+
59
+ it("swallows a failed registration", async () => {
60
+ mockRegister.mockRejectedValue(new Error("no native bridge"));
61
+ mockXray = { registerReactToolbox: mockRegister };
62
+
63
+ await expect(
64
+ loadToolbox().registerPlayerToolbox(manager(null))
65
+ ).resolves.toBeUndefined();
66
+ });
67
+
68
+ it("seeks to an absolute position, from the end when negative, clamped", async () => {
69
+ const active = player();
70
+ const tools = await registeredTools(active);
71
+
72
+ expect(tools.seek({ position: 30 })).toEqual({ position: 30 });
73
+ expect(tools.seek({ position: -10 })).toEqual({ position: 90 });
74
+ expect(tools.seek({ position: 500 })).toEqual({ position: 100 });
75
+ expect(tools.seek({ position: -500 })).toEqual({ position: 0 });
76
+ expect(active.seekTo.mock.calls).toEqual([[30], [90], [100], [0]]);
77
+ });
78
+
79
+ it("offsets from the current position and refuses zero", async () => {
80
+ const tools = await registeredTools(player());
81
+
82
+ expect(tools.offset({ seconds: 15 })).toEqual({ from: 40, position: 55 });
83
+ expect(tools.offset({ seconds: -60 })).toEqual({ from: 40, position: 0 });
84
+
85
+ expect(() => tools.offset({ seconds: 0 })).toThrow(
86
+ "Ignored zero relative seek"
87
+ );
88
+ });
89
+
90
+ it("refuses to seek a stream that is not seekable", async () => {
91
+ const tools = await registeredTools(
92
+ player({ getSeekableDuration: () => 0 })
93
+ );
94
+
95
+ expect(() => tools.seek({ position: 10 })).toThrow("Seek is not supported");
96
+ });
97
+ });