@applicaster/zapp-react-native-utils 14.0.0-rc.9 → 15.0.0-alpha.2239032089

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 (138) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +60 -84
  2. package/actionsExecutor/ScreenActions.ts +164 -0
  3. package/actionsExecutor/StorageActions.ts +110 -0
  4. package/actionsExecutor/feedDecorator.ts +171 -0
  5. package/actionsExecutor/screenResolver.ts +11 -0
  6. package/analyticsUtils/AnalyticsEvents/helper.ts +81 -0
  7. package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
  8. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
  9. package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
  10. package/analyticsUtils/__tests__/analyticsUtils.test.js +3 -0
  11. package/analyticsUtils/events.ts +8 -0
  12. package/analyticsUtils/index.tsx +3 -4
  13. package/analyticsUtils/manager.ts +1 -1
  14. package/analyticsUtils/playerAnalyticsTracker.ts +2 -1
  15. package/appUtils/HooksManager/Hook.ts +4 -4
  16. package/appUtils/HooksManager/index.ts +11 -1
  17. package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
  18. package/appUtils/accessibilityManager/const.ts +13 -0
  19. package/appUtils/accessibilityManager/hooks.ts +35 -1
  20. package/appUtils/accessibilityManager/index.ts +154 -30
  21. package/appUtils/accessibilityManager/utils.ts +24 -0
  22. package/appUtils/contextKeysManager/contextResolver.ts +42 -1
  23. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +10 -0
  24. package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
  25. package/appUtils/focusManager/events.ts +2 -0
  26. package/appUtils/focusManager/index.ios.ts +46 -1
  27. package/appUtils/focusManager/index.ts +86 -11
  28. package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
  29. package/appUtils/focusManagerAux/utils/index.ios.ts +104 -0
  30. package/appUtils/focusManagerAux/utils/index.ts +94 -3
  31. package/appUtils/focusManagerAux/utils/utils.ios.ts +63 -0
  32. package/appUtils/platform/platformUtils.ts +31 -1
  33. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +0 -15
  34. package/appUtils/playerManager/useChapterMarker.tsx +0 -1
  35. package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
  36. package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
  37. package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
  38. package/arrayUtils/index.ts +8 -3
  39. package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +144 -0
  40. package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +72 -0
  41. package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +110 -0
  42. package/audioPlayerUtils/assets/index.ts +2 -0
  43. package/audioPlayerUtils/index.ts +242 -0
  44. package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
  45. package/componentsUtils/index.ts +4 -1
  46. package/conf/player/__tests__/selectors.test.ts +34 -0
  47. package/conf/player/selectors.ts +10 -0
  48. package/configurationUtils/__tests__/configurationUtils.test.js +0 -31
  49. package/configurationUtils/__tests__/getMediaItems.test.ts +65 -0
  50. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +34 -0
  51. package/configurationUtils/__tests__/manifestKeyParser.test.ts +546 -0
  52. package/configurationUtils/index.ts +64 -35
  53. package/configurationUtils/manifestKeyParser.ts +57 -32
  54. package/focusManager/FocusManager.ts +104 -20
  55. package/focusManager/Tree.ts +25 -21
  56. package/focusManager/__tests__/FocusManager.test.ts +50 -8
  57. package/focusManager/aux/index.ts +98 -0
  58. package/focusManager/utils.ts +12 -6
  59. package/index.d.ts +1 -10
  60. package/manifestUtils/_internals/getDefaultConfiguration.js +28 -0
  61. package/manifestUtils/{_internals.js → _internals/index.js} +2 -25
  62. package/manifestUtils/createConfig.js +4 -1
  63. package/manifestUtils/defaultManifestConfigurations/player.js +2764 -1539
  64. package/manifestUtils/index.js +4 -0
  65. package/manifestUtils/keys.js +12 -0
  66. package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
  67. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +6 -0
  68. package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
  69. package/navigationUtils/index.ts +7 -5
  70. package/package.json +2 -3
  71. package/playerUtils/PlayerTTS/PlayerTTS.ts +359 -0
  72. package/playerUtils/PlayerTTS/index.ts +1 -0
  73. package/playerUtils/__tests__/configurationUtils.test.ts +1 -65
  74. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +54 -0
  75. package/playerUtils/_internals/__tests__/utils.test.ts +71 -0
  76. package/playerUtils/_internals/index.ts +1 -0
  77. package/playerUtils/_internals/utils.ts +31 -0
  78. package/playerUtils/configurationUtils.ts +0 -44
  79. package/playerUtils/getPlayerActionButtons.ts +17 -0
  80. package/playerUtils/index.ts +53 -0
  81. package/playerUtils/usePlayerTTS.ts +21 -0
  82. package/playerUtils/useValidatePlayerConfig.tsx +22 -19
  83. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
  84. package/reactHooks/cell-click/__tests__/index.test.js +3 -0
  85. package/reactHooks/cell-click/index.ts +8 -1
  86. package/reactHooks/debugging/__tests__/index.test.js +0 -1
  87. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +47 -90
  88. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +71 -31
  89. package/reactHooks/feed/index.ts +2 -0
  90. package/reactHooks/feed/useBatchLoading.ts +17 -10
  91. package/reactHooks/feed/useFeedLoader.tsx +36 -34
  92. package/reactHooks/feed/useLoadPipesDataDispatch.ts +63 -0
  93. package/reactHooks/feed/usePipesCacheReset.ts +3 -3
  94. package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
  95. package/reactHooks/layout/__tests__/index.test.tsx +3 -1
  96. package/reactHooks/layout/isTablet/index.ts +12 -5
  97. package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
  98. package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
  99. package/reactHooks/layout/useLayoutVersion.ts +5 -5
  100. package/reactHooks/navigation/index.ts +7 -5
  101. package/reactHooks/navigation/useIsScreenActive.ts +9 -5
  102. package/reactHooks/navigation/useRoute.ts +7 -2
  103. package/reactHooks/navigation/useScreenStateStore.ts +8 -0
  104. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
  105. package/reactHooks/screen/useScreenContext.ts +1 -1
  106. package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
  107. package/reactHooks/state/index.ts +1 -1
  108. package/reactHooks/state/useHomeRiver.ts +4 -2
  109. package/reactHooks/state/useRivers.ts +7 -8
  110. package/riverComponetsMeasurementProvider/index.tsx +1 -1
  111. package/screenPickerUtils/index.ts +13 -0
  112. package/services/js2native.ts +1 -0
  113. package/storage/ScreenSingleValueProvider.ts +204 -0
  114. package/storage/ScreenStateMultiSelectProvider.ts +293 -0
  115. package/storage/StorageMultiSelectProvider.ts +192 -0
  116. package/storage/StorageSingleSelectProvider.ts +108 -0
  117. package/testUtils/index.tsx +7 -8
  118. package/time/BackgroundTimer.ts +6 -4
  119. package/utils/__tests__/endsWith.test.ts +30 -0
  120. package/utils/__tests__/find.test.ts +36 -0
  121. package/utils/__tests__/omit.test.ts +19 -0
  122. package/utils/__tests__/path.test.ts +33 -0
  123. package/utils/__tests__/pathOr.test.ts +37 -0
  124. package/utils/__tests__/startsWith.test.ts +30 -0
  125. package/utils/__tests__/take.test.ts +40 -0
  126. package/utils/endsWith.ts +9 -0
  127. package/utils/find.ts +3 -0
  128. package/utils/index.ts +34 -1
  129. package/utils/omit.ts +5 -0
  130. package/utils/path.ts +5 -0
  131. package/utils/pathOr.ts +5 -0
  132. package/utils/startsWith.ts +9 -0
  133. package/utils/take.ts +5 -0
  134. package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +164 -0
  135. package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +60 -0
  136. package/zappFrameworkUtils/HookCallback/useCallbackActions.ts +22 -0
  137. package/zappFrameworkUtils/loginPluginUtils.ts +1 -1
  138. package/playerUtils/configurationGenerator.ts +0 -2572
@@ -0,0 +1,104 @@
1
+ import { isNil, startsWith } from "@applicaster/zapp-react-native-utils/utils";
2
+
3
+ import {
4
+ QUICK_BRICK_CONTENT,
5
+ QUICK_BRICK_NAVBAR,
6
+ } from "@applicaster/quick-brick-core/const";
7
+
8
+ const isNavBar = (node) => startsWith(QUICK_BRICK_NAVBAR, node?.id);
9
+ const isContent = (node) => startsWith(QUICK_BRICK_CONTENT, node?.id);
10
+ const isRoot = (node) => node?.id === "root";
11
+
12
+ export const isPartOfTabsScreenContent = (
13
+ focusableTree,
14
+ screenPickerContentContainerId,
15
+ id
16
+ ) => {
17
+ const node = focusableTree.findInTree(id);
18
+
19
+ if (isNil(node)) {
20
+ return false;
21
+ }
22
+
23
+ if (isRoot(node)) {
24
+ return false;
25
+ }
26
+
27
+ if (isNavBar(node)) {
28
+ return false;
29
+ }
30
+
31
+ if (isContent(node)) {
32
+ return false;
33
+ }
34
+
35
+ if (node?.id === screenPickerContentContainerId) {
36
+ return true;
37
+ }
38
+
39
+ return isPartOfTabsScreenContent(
40
+ focusableTree,
41
+ screenPickerContentContainerId,
42
+ node.parent?.id
43
+ );
44
+ };
45
+
46
+ export const isPartOfMenu = (focusableTree, id): boolean => {
47
+ const node = focusableTree.findInTree(id);
48
+
49
+ if (isNil(node)) {
50
+ return false;
51
+ }
52
+
53
+ if (isRoot(node)) {
54
+ return false;
55
+ }
56
+
57
+ if (isNavBar(node)) {
58
+ return true;
59
+ }
60
+
61
+ if (isContent(node)) {
62
+ return false;
63
+ }
64
+
65
+ return isPartOfMenu(focusableTree, node.parent.id);
66
+ };
67
+
68
+ export const isPartOfContent = (focusableTree, id) => {
69
+ const node = focusableTree.findInTree(id);
70
+
71
+ if (isNil(node)) {
72
+ return false;
73
+ }
74
+
75
+ if (isRoot(node)) {
76
+ return false;
77
+ }
78
+
79
+ if (isNavBar(node)) {
80
+ return false;
81
+ }
82
+
83
+ if (isContent(node)) {
84
+ return true;
85
+ }
86
+
87
+ return isPartOfContent(focusableTree, node.parent?.id);
88
+ };
89
+
90
+ export const isCurrentFocusOn = (id, node) => {
91
+ if (!node) {
92
+ return false;
93
+ }
94
+
95
+ if (isRoot(node)) {
96
+ return false;
97
+ }
98
+
99
+ if (node?.id === id) {
100
+ return true;
101
+ }
102
+
103
+ return isCurrentFocusOn(id, node.parent);
104
+ };
@@ -1,14 +1,31 @@
1
- import { isNotNil } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
2
- import { find, last, pathOr, startsWith } from "ramda";
1
+ import {
2
+ isNil,
3
+ last,
4
+ startsWith,
5
+ find,
6
+ pathOr,
7
+ } from "@applicaster/zapp-react-native-utils/utils";
8
+
3
9
  import {
4
10
  QUICK_BRICK_CONTENT,
5
11
  QUICK_BRICK_NAVBAR,
6
12
  } from "@applicaster/quick-brick-core/const";
7
13
 
14
+ import {
15
+ getFocusableId,
16
+ SCREEN_PICKER_CONTAINER,
17
+ } from "@applicaster/zapp-react-native-utils/screenPickerUtils";
18
+
8
19
  // run check each 300 ms
9
20
  // run this check too often could lead to performance penalty on low-end devices
10
21
  const HOW_OFTEN_TO_CHECK_CONDITION = 300; // ms
11
22
 
23
+ const isTopMenu = (node) => startsWith(QUICK_BRICK_NAVBAR, node?.id);
24
+ const isContent = (node) => startsWith(QUICK_BRICK_CONTENT, node?.id);
25
+ const isRoot = (node) => node?.id === "root";
26
+
27
+ const isScrenPicker = (node) => startsWith(SCREEN_PICKER_CONTAINER, node?.id);
28
+
12
29
  type Props = {
13
30
  maxTimeout: number;
14
31
  conditionFn: () => boolean;
@@ -49,7 +66,7 @@ export const waitForActiveScreen = (currentRoute: string, focusableTree) => {
49
66
 
50
67
  const route = find((route) => route.id === currentRoute, routes);
51
68
 
52
- return isNotNil(route);
69
+ return !isNil(route);
53
70
  };
54
71
 
55
72
  return waitUntil({
@@ -99,3 +116,77 @@ export const waitForContent = (focusableTree) => {
99
116
  conditionFn: contentHasAnyChildren,
100
117
  });
101
118
  };
119
+
120
+ export const findSelectedTabId = (item: ZappEntry): string => {
121
+ const selectedTabId = getFocusableId(item.id);
122
+
123
+ return selectedTabId;
124
+ };
125
+
126
+ export const isTabsScreenOnContentFocused = (node) => {
127
+ if (isRoot(node)) {
128
+ return false;
129
+ }
130
+
131
+ if (isTopMenu(node)) {
132
+ return false;
133
+ }
134
+
135
+ if (isContent(node)) {
136
+ return false;
137
+ }
138
+
139
+ if (isScrenPicker(node)) {
140
+ return true;
141
+ }
142
+
143
+ return isTabsScreenOnContentFocused(node.parent);
144
+ };
145
+
146
+ export const isCurrentFocusOnMenu = (node) => {
147
+ if (isRoot(node)) {
148
+ return false;
149
+ }
150
+
151
+ if (isTopMenu(node)) {
152
+ return true;
153
+ }
154
+
155
+ if (isContent(node)) {
156
+ return false;
157
+ }
158
+
159
+ return isCurrentFocusOnMenu(node.parent);
160
+ };
161
+
162
+ export const isCurrentFocusOnContent = (node) => {
163
+ if (isRoot(node)) {
164
+ return false;
165
+ }
166
+
167
+ if (isTopMenu(node)) {
168
+ return false;
169
+ }
170
+
171
+ if (isContent(node)) {
172
+ return true;
173
+ }
174
+
175
+ return isCurrentFocusOnContent(node.parent);
176
+ };
177
+
178
+ export const isCurrentFocusOn = (id, node) => {
179
+ if (!node) {
180
+ return false;
181
+ }
182
+
183
+ if (isRoot(node)) {
184
+ return false;
185
+ }
186
+
187
+ if (node?.id === id) {
188
+ return true;
189
+ }
190
+
191
+ return isCurrentFocusOn(id, node.parent);
192
+ };
@@ -0,0 +1,63 @@
1
+ import { Subject, ReplaySubject, withLatestFrom } from "rxjs";
2
+ import { filter } from "rxjs/operators";
3
+
4
+ import { isPartOfMenu, isPartOfContent } from "./index.ios";
5
+
6
+ import { focusManager } from "../../focusManager/index.ios";
7
+
8
+ type FocusableID = string;
9
+ const focusedSubject$ = new Subject<FocusableID>();
10
+
11
+ const focused$ = focusedSubject$.asObservable();
12
+
13
+ export const emitFocused = (id: FocusableID): void => {
14
+ focusedSubject$.next(id);
15
+ };
16
+
17
+ export const topMenuItemFocused$ = focused$.pipe(
18
+ filter((id) => id && isPartOfMenu(focusManager.focusableTree, id))
19
+ );
20
+
21
+ export const contentFocused$ = focused$.pipe(
22
+ filter((id) => {
23
+ const isContent = isPartOfContent(focusManager.focusableTree, id);
24
+
25
+ return id && isContent;
26
+ })
27
+ );
28
+
29
+ const registeredHomeTopMenuItemSubject$ = new ReplaySubject<FocusableID>(1);
30
+
31
+ export const registeredHomeTopMenuItem$ =
32
+ registeredHomeTopMenuItemSubject$.asObservable();
33
+
34
+ export const homeTopMenuItemFocused$ = topMenuItemFocused$.pipe(
35
+ withLatestFrom(registeredHomeTopMenuItem$),
36
+ filter(([id, homeId]) => id === homeId)
37
+ );
38
+
39
+ export const emitHomeTopMenuItemRegistered = (id) => {
40
+ // save homeId on registration
41
+ registeredHomeTopMenuItemSubject$.next(id);
42
+ };
43
+
44
+ export const emitHomeTopMenuItemUnregistered = () => {
45
+ // reset homeId on unregistration
46
+ registeredHomeTopMenuItemSubject$.next(undefined);
47
+ };
48
+
49
+ const registeredScreenPickerContentContainerSubject$ =
50
+ new ReplaySubject<FocusableID>(1);
51
+
52
+ export const registeredScreenPickerContentContainer$ =
53
+ registeredScreenPickerContentContainerSubject$.asObservable();
54
+
55
+ export const emitScreenPickerContentContainerRegistered = (id) => {
56
+ // save screenPickerContentContainerId on registration
57
+ registeredScreenPickerContentContainerSubject$.next(id);
58
+ };
59
+
60
+ export const emitScreenPickerContentContainerUnregistered = () => {
61
+ // reset screenPickerContentContainerId on unregistration
62
+ registeredScreenPickerContentContainerSubject$.next(undefined);
63
+ };
@@ -10,6 +10,7 @@ import { PLATFORM_KEYS, PLATFORMS, ZappPlatform } from "./const";
10
10
  import { createLogger, utilsLogger } from "../../logger";
11
11
  import { getPlatform } from "../../reactUtils";
12
12
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
13
+ import { calculateReadingTime } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager/utils";
13
14
 
14
15
  const { log_debug } = createLogger({
15
16
  category: "General",
@@ -212,9 +213,16 @@ export class TTSManager {
212
213
  }
213
214
 
214
215
  readText(text: string) {
216
+ this.ttsState$.next(true);
217
+
215
218
  if (isSamsungPlatform() && window.speechSynthesis) {
216
219
  const utterance = new SpeechSynthesisUtterance(text);
220
+
221
+ window.speechSynthesis.cancel(); // Cancel previous speech before speaking new text
217
222
  window.speechSynthesis.speak(utterance);
223
+
224
+ // Estimate reading time and set inactive when done
225
+ this.scheduleTTSComplete(text);
218
226
  }
219
227
 
220
228
  if (isLgPlatform() && window.webOS?.service) {
@@ -225,23 +233,45 @@ export class TTSManager {
225
233
  log_debug("There was a failure setting up webOS TTS service", {
226
234
  error,
227
235
  });
236
+
237
+ this.ttsState$.next(false);
228
238
  },
229
239
  onSuccess(response: any) {
230
240
  log_debug("webOS TTS service is configured successfully", {
231
241
  response,
232
242
  });
243
+
244
+ // Estimate reading time and set inactive when done
245
+ this.scheduleTTSComplete(text);
233
246
  },
234
247
  parameters: {
235
248
  text,
249
+ clear: true, // Clear any previous speech before speaking new text
236
250
  },
237
251
  });
238
252
  } catch (error) {
239
253
  log_debug("webOS TTS service error", { error });
254
+ this.ttsState$.next(false);
240
255
  }
241
256
  }
242
257
 
243
- if (!window.VIZIO?.Chromevox) return;
258
+ if (!window.VIZIO?.Chromevox) {
259
+ // For platforms without TTS, estimate reading time
260
+ this.scheduleTTSComplete(text);
261
+
262
+ return;
263
+ }
244
264
 
245
265
  window.VIZIO.Chromevox.play(text);
266
+ // Estimate reading time and set inactive when done
267
+ this.scheduleTTSComplete(text);
268
+ }
269
+
270
+ private scheduleTTSComplete(text: string) {
271
+ const readingTime = calculateReadingTime(text);
272
+
273
+ setTimeout(() => {
274
+ this.ttsState$.next(false);
275
+ }, readingTime);
246
276
  }
247
277
  }
@@ -18,13 +18,6 @@ export const { log_verbose, log_debug, log_info, log_error } = createLogger({
18
18
  parent: utilsLogger,
19
19
  });
20
20
 
21
- type ActionChapter = {
22
- type: string;
23
- options?: {
24
- title: string;
25
- };
26
- };
27
-
28
21
  type ChapterMarkerOriginal = {
29
22
  id: string;
30
23
  title: string;
@@ -33,14 +26,6 @@ type ChapterMarkerOriginal = {
33
26
  actions: ActionChapter[];
34
27
  };
35
28
 
36
- export type ChapterMarkerEvent = {
37
- id: string;
38
- title: string;
39
- start_time: number;
40
- end_time: number;
41
- actions: ActionChapter[];
42
- };
43
-
44
29
  export type TitleSummaryEvent = {
45
30
  title: string | number;
46
31
  summary: string | number;
@@ -1,4 +1,3 @@
1
- import { ChapterMarkerEvent } from "./OverlayObserver/OverlaysObserver";
2
1
  import { usePlayer } from "./usePlayer";
3
2
  import * as React from "react";
4
3
 
@@ -5,6 +5,9 @@ import { playerManager } from "./index";
5
5
  import { useValidatePlayerConfig } from "../../playerUtils/useValidatePlayerConfig";
6
6
  import { PlayerRole } from "./conts";
7
7
  import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/Platform";
8
+ import { TVSeekController } from "../../reactHooks/player/TVSeekControlller/TVSeekController";
9
+ import { KeyInputHandler } from "../keyInputHandler/KeyInputHandler";
10
+ import { isTV } from "../../reactUtils";
8
11
 
9
12
  // TODO: Rename to ControllerType
10
13
  export const usePlayerControllerSetup = ({
@@ -76,5 +79,18 @@ export const usePlayerControllerSetup = ({
76
79
  };
77
80
  }, [playerId, playerController]);
78
81
 
82
+ useEffect(() => {
83
+ if (!isTV()) {
84
+ return;
85
+ }
86
+
87
+ if (playerController) {
88
+ const seekController = new TVSeekController(playerController);
89
+ playerController.seekController = seekController;
90
+
91
+ return KeyInputHandler.getInstance().addListener(seekController);
92
+ }
93
+ }, [playerController]);
94
+
79
95
  return playerController;
80
96
  };
@@ -0,0 +1,63 @@
1
+ import { isEmptyArray } from "..";
2
+
3
+ describe("isEmptyArray", () => {
4
+ it("non-empty array is not empty", () => {
5
+ const value = [1, 2, 3];
6
+
7
+ expect(isEmptyArray(value)).toBe(false);
8
+ });
9
+
10
+ it("empty array is empty", () => {
11
+ const value = [];
12
+
13
+ expect(isEmptyArray(value)).toBe(true);
14
+ });
15
+
16
+ it("number is not array", () => {
17
+ const value = 123;
18
+
19
+ expect(isEmptyArray(value)).toBe(false);
20
+ });
21
+
22
+ it("string is not array", () => {
23
+ const value = "vfnjdk";
24
+
25
+ expect(isEmptyArray(value)).toBe(false);
26
+ });
27
+
28
+ it("empty string is not array", () => {
29
+ const value = "";
30
+
31
+ expect(isEmptyArray(value)).toBe(false);
32
+ });
33
+
34
+ it("NaN is not array", () => {
35
+ const value = NaN;
36
+
37
+ expect(isEmptyArray(value)).toBe(false);
38
+ });
39
+
40
+ it("object is not array", () => {
41
+ const value = { test: 1 };
42
+
43
+ expect(isEmptyArray(value)).toBe(false);
44
+ });
45
+
46
+ it("empty object is not array", () => {
47
+ const value = {};
48
+
49
+ expect(isEmptyArray(value)).toBe(false);
50
+ });
51
+
52
+ it("undefined is not array", () => {
53
+ const value = undefined;
54
+
55
+ expect(isEmptyArray(value)).toBe(false);
56
+ });
57
+
58
+ it("null is not array", () => {
59
+ const value = null;
60
+
61
+ expect(isEmptyArray(value)).toBe(false);
62
+ });
63
+ });
@@ -32,7 +32,7 @@ describe("isFilledArray", () => {
32
32
  });
33
33
 
34
34
  it("NaN is not array", () => {
35
- const value = "";
35
+ const value = NaN;
36
36
 
37
37
  expect(isFilledArray(value)).toBe(false);
38
38
  });
@@ -93,18 +93,23 @@ export const isIndexInRange = (index: number, length: number): boolean => {
93
93
  export const makeListOfIndexes = (size: number): number[] =>
94
94
  Array.from({ length: size }, (_, index) => index);
95
95
 
96
- export const makeListOf = (value: unknown, size: number): number[] => {
96
+ export const makeListOf = <T>(value: T, size: number): T[] => {
97
97
  return Array(size).fill(value);
98
98
  };
99
99
 
100
100
  /** Checks if a value is a non-empty array */
101
101
  export function isFilledArray(value: unknown): boolean {
102
- return R.is(Array, value) && R.length(value) > 0;
102
+ return Array.isArray(value) && value.length > 0;
103
+ }
104
+
105
+ /** Checks if a value is a empty array */
106
+ export function isEmptyArray(value: unknown): boolean {
107
+ return Array.isArray(value) && value.length === 0;
103
108
  }
104
109
 
105
110
  // get random item from the list
106
111
  export const sample = (xs: unknown[]): unknown => {
107
- invariant(R.is(Array, xs), `input value is not a array: ${xs}`);
112
+ invariant(Array.isArray(xs), `input value is not an array: ${xs}`);
108
113
  invariant(isFilledArray(xs), `input array is empty: ${xs}`);
109
114
 
110
115
  const index = Math.floor(Math.random() * xs.length);
@@ -0,0 +1,144 @@
1
+ import { getArtworkImage } from "..";
2
+ import { DEFAULT_IMAGE } from "../assets";
3
+
4
+ describe("getArtworkImage", () => {
5
+ const entryWithImage = {
6
+ media_group: [
7
+ {
8
+ type: "image",
9
+ media_item: [
10
+ { key: "artwork_key", src: "image_from_entry" },
11
+ { key: "other_key", src: "other_image" },
12
+ ],
13
+ },
14
+ ],
15
+ extensions: {
16
+ artwork_key: "artwork_key",
17
+ },
18
+ };
19
+
20
+ const entryWithoutImage = {
21
+ media_group: [
22
+ {
23
+ type: "image",
24
+ media_item: [{ key: "other_key", src: "other_image" }],
25
+ },
26
+ ],
27
+ extensions: {
28
+ artwork_key: "artwork_key",
29
+ },
30
+ };
31
+
32
+ const pluginConfigWithImage = {
33
+ artwork_key: "plugin_artwork_key",
34
+ };
35
+
36
+ it("returns image from entry extensions key", () => {
37
+ const result = getArtworkImage({
38
+ key: "artwork_key",
39
+ entry: entryWithImage,
40
+ plugin_configuration: {},
41
+ });
42
+
43
+ expect(result).toBe("image_from_entry");
44
+ });
45
+
46
+ it("returns image from plugin configuration key if not in entry", () => {
47
+ const entryNoMatch = {
48
+ ...entryWithoutImage,
49
+ extensions: { artwork_key: "not_found_key" },
50
+ };
51
+
52
+ const pluginConfig = {
53
+ artwork_key: "plugin_artwork_key",
54
+ };
55
+
56
+ const entryWithPluginImage = {
57
+ ...entryNoMatch,
58
+ media_group: [
59
+ {
60
+ type: "image",
61
+ media_item: [{ key: "plugin_artwork_key", src: "image_from_plugin" }],
62
+ },
63
+ ],
64
+ };
65
+
66
+ const result = getArtworkImage({
67
+ key: "artwork_key",
68
+ entry: entryWithPluginImage,
69
+ plugin_configuration: pluginConfig,
70
+ });
71
+
72
+ expect(result).toBe("image_from_plugin");
73
+ });
74
+
75
+ it("returns DEFAULT_IMAGE if neither entry nor plugin configuration has image", () => {
76
+ const entryNoImage = {
77
+ media_group: [
78
+ {
79
+ type: "image",
80
+ media_item: [{ key: "other_key", src: "other_image" }],
81
+ },
82
+ ],
83
+ extensions: { artwork_key: "not_found_key" },
84
+ };
85
+
86
+ const pluginConfig = { artwork_key: "not_found_key" };
87
+
88
+ const result = getArtworkImage({
89
+ key: "artwork_key",
90
+ entry: entryNoImage,
91
+ plugin_configuration: pluginConfig,
92
+ });
93
+
94
+ expect(result).toBe(DEFAULT_IMAGE);
95
+ });
96
+
97
+ it("handles undefined key gracefully", () => {
98
+ const result = getArtworkImage({
99
+ key: undefined,
100
+ entry: entryWithImage,
101
+ plugin_configuration: pluginConfigWithImage,
102
+ });
103
+
104
+ expect(result).toBe(DEFAULT_IMAGE);
105
+ });
106
+
107
+ it("handles missing entry or plugin_configuration gracefully", () => {
108
+ const result = getArtworkImage({
109
+ key: "artwork_key",
110
+ entry: undefined,
111
+ plugin_configuration: undefined,
112
+ });
113
+
114
+ expect(result).toBe(DEFAULT_IMAGE);
115
+ });
116
+
117
+ it("handles empty media_group", () => {
118
+ const entryEmptyMedia = {
119
+ media_group: [],
120
+ extensions: { artwork_key: "artwork_key" },
121
+ };
122
+
123
+ const result = getArtworkImage({
124
+ key: "artwork_key",
125
+ entry: entryEmptyMedia,
126
+ plugin_configuration: pluginConfigWithImage,
127
+ });
128
+
129
+ expect(result).toBe(DEFAULT_IMAGE);
130
+ });
131
+
132
+ it("handles missing extensions/config keys", () => {
133
+ const entryNoExt = { media_group: [], extensions: {} };
134
+ const pluginConfig = {};
135
+
136
+ const result = getArtworkImage({
137
+ key: "artwork_key",
138
+ entry: entryNoExt,
139
+ plugin_configuration: pluginConfig,
140
+ });
141
+
142
+ expect(result).toBe(DEFAULT_IMAGE);
143
+ });
144
+ });