@applicaster/zapp-react-native-utils 14.0.0-alpha.3881160800 → 14.0.0-alpha.3890252181

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 (50) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +60 -83
  2. package/actionsExecutor/ScreenActions.ts +163 -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 +1 -2
  9. package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
  10. package/analyticsUtils/__tests__/analyticsUtils.test.js +14 -0
  11. package/analyticsUtils/events.ts +8 -0
  12. package/analyticsUtils/index.tsx +4 -3
  13. package/analyticsUtils/manager.ts +1 -1
  14. package/appUtils/accessibilityManager/index.ts +3 -3
  15. package/appUtils/contextKeysManager/contextResolver.ts +14 -1
  16. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +0 -15
  17. package/appUtils/playerManager/useChapterMarker.tsx +0 -1
  18. package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
  19. package/configurationUtils/__tests__/manifestKeyParser.test.ts +547 -0
  20. package/configurationUtils/manifestKeyParser.ts +57 -32
  21. package/focusManager/FocusManager.ts +26 -16
  22. package/focusManager/Tree.ts +25 -21
  23. package/focusManager/__tests__/FocusManager.test.ts +50 -8
  24. package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
  25. package/package.json +2 -2
  26. package/playerUtils/getPlayerActionButtons.ts +1 -1
  27. package/playerUtils/index.ts +51 -0
  28. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +13 -12
  29. package/reactHooks/cell-click/index.ts +8 -1
  30. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +88 -39
  31. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +20 -0
  32. package/reactHooks/feed/useBatchLoading.ts +1 -1
  33. package/reactHooks/feed/useFeedLoader.tsx +12 -5
  34. package/reactHooks/feed/usePipesCacheReset.ts +1 -1
  35. package/reactHooks/layout/isTablet/index.ts +12 -5
  36. package/reactHooks/navigation/index.ts +7 -3
  37. package/reactHooks/navigation/useIsScreenActive.ts +9 -5
  38. package/reactHooks/navigation/useRoute.ts +7 -2
  39. package/reactHooks/navigation/useScreenStateStore.ts +8 -0
  40. package/reactHooks/screen/useScreenContext.ts +1 -1
  41. package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
  42. package/riverComponetsMeasurementProvider/index.tsx +1 -1
  43. package/services/js2native.ts +1 -0
  44. package/storage/ScreenSingleValueProvider.ts +201 -0
  45. package/storage/ScreenStateMultiSelectProvider.ts +290 -0
  46. package/storage/StorageMultiSelectProvider.ts +192 -0
  47. package/storage/StorageSingleSelectProvider.ts +108 -0
  48. package/testUtils/index.tsx +8 -7
  49. package/time/BackgroundTimer.ts +5 -3
  50. package/utils/index.ts +4 -0
@@ -176,18 +176,30 @@ class FocusManager {
176
176
  }
177
177
  }
178
178
 
179
- registerFocusable(
180
- component: FocusManager.TouchableReactRef,
181
- parentFocusable: FocusManager.TouchableReactRef,
182
- isFocusableCell: boolean
183
- ) {
184
- const focusableId = getFocusableId(component);
179
+ registerFocusable({
180
+ touchableRef,
181
+ parentFocusableRef,
182
+ isFocusableCell,
183
+ parentFocusableId,
184
+ }: {
185
+ touchableRef: FocusManager.TouchableReactRef;
186
+ parentFocusableRef: FocusManager.TouchableReactRef;
187
+ isFocusableCell: boolean;
188
+ parentFocusableId: string;
189
+ }) {
190
+ const focusableId = getFocusableId(touchableRef);
191
+
185
192
  const focusableComponent = FocusManager.findFocusable(focusableId);
186
193
 
187
- if (!focusableComponent && component) {
188
- this.focusableComponents.push(component);
194
+ if (!focusableComponent && touchableRef) {
195
+ this.focusableComponents.push(touchableRef);
189
196
 
190
- this.tree.add(component, parentFocusable, isFocusableCell);
197
+ this.tree.add(
198
+ touchableRef,
199
+ parentFocusableRef,
200
+ isFocusableCell,
201
+ parentFocusableId
202
+ );
191
203
  } else {
192
204
  logger.warning("Focusable component already registered", {
193
205
  id: focusableId,
@@ -243,12 +255,10 @@ class FocusManager {
243
255
  }
244
256
 
245
257
  blurPrevious(options?: FocusManager.Android.CallbackOptions) {
246
- if (options) {
247
- FocusManager.instance.prevFocused?.onBlur?.(
248
- FocusManager.instance.prevFocused,
249
- options
250
- );
251
- }
258
+ FocusManager.instance.prevFocused?.onBlur?.(
259
+ FocusManager.instance.prevFocused,
260
+ options ?? {} // Adding fallback to avoid potential regression caused by #7509
261
+ );
252
262
  }
253
263
 
254
264
  onDisableFocusChange = (id) => {
@@ -269,7 +279,7 @@ class FocusManager {
269
279
 
270
280
  if (nextFocus) {
271
281
  // HACK: hack to fix the hack below
272
- // HACK: putting call to the end of the event loop so the next component has a chane to be registered
282
+ // HACK: putting call to the end of the event loop so the next component has a chance to be registered
273
283
  setTimeout(() => {
274
284
  FocusManager.instance.setFocus(nextFocus, {
275
285
  direction: "down",
@@ -8,37 +8,41 @@ export class Tree {
8
8
  this.tree = focusManagerTree;
9
9
  }
10
10
 
11
- add(component, parentFocusable, isFocusableCell) {
12
- const focusableId = getFocusableId(component);
13
- const parentId = getFocusableId(parentFocusable);
11
+ add(
12
+ touchableRef: FocusManager.TouchableReactRef,
13
+ parentFocusableRef: FocusManager.TouchableReactRef,
14
+ isFocusableCell: boolean,
15
+ parentFocusableId: string
16
+ ) {
17
+ const focusableId = getFocusableId(touchableRef);
18
+ const parentId = getFocusableId(parentFocusableRef) || parentFocusableId;
14
19
  const focusableComponentInTree = this.find(focusableId);
15
20
 
16
21
  // update node if it already exists
17
22
  if (focusableComponentInTree) {
18
- focusableComponentInTree.updateNode(component);
23
+ focusableComponentInTree.updateNode(touchableRef);
19
24
  }
20
25
 
21
- if (parentFocusable?.current) {
22
- if (!this.find(parentId)) {
23
- this.tree.push(new TreeNode(null, parentId, null, isFocusableCell));
24
- }
26
+ if (!this.find(parentId)) {
27
+ // create temporary node to the root of the tree
28
+ this.tree.push(new TreeNode(null, parentId, null, isFocusableCell));
29
+ }
25
30
 
26
- const parentNode = this.find(parentId);
31
+ const parentNode = this.find(parentId);
27
32
 
28
- if (parentNode) {
29
- if (focusableComponentInTree) {
30
- focusableComponentInTree.isFocusableCell = isFocusableCell;
31
- focusableComponentInTree.parentId = parentNode.id;
33
+ if (parentNode) {
34
+ if (focusableComponentInTree) {
35
+ focusableComponentInTree.isFocusableCell = isFocusableCell;
36
+ focusableComponentInTree.parentId = parentNode.id;
32
37
 
33
- parentNode.addChild(focusableComponentInTree);
38
+ parentNode.addChild(focusableComponentInTree);
34
39
 
35
- // remove root object from the list
36
- this.tree = this.tree.filter(
37
- (node) => node !== focusableComponentInTree
38
- );
39
- } else {
40
- parentNode.addChild(component, focusableId, isFocusableCell);
41
- }
40
+ // remove root object from the list
41
+ this.tree = this.tree.filter(
42
+ (node) => node !== focusableComponentInTree
43
+ );
44
+ } else {
45
+ parentNode.addChild(touchableRef, focusableId, isFocusableCell);
42
46
  }
43
47
  }
44
48
  }
@@ -1,5 +1,8 @@
1
1
  import { focusManager } from "../FocusManager";
2
2
 
3
+ const isFocusableCell = true;
4
+ const parentFocusableId = "parentFocusableId";
5
+
3
6
  const group = {
4
7
  current: {
5
8
  props: {
@@ -62,13 +65,47 @@ jest.useFakeTimers();
62
65
 
63
66
  describe("FocusManager", () => {
64
67
  beforeAll(() => {
65
- focusManager.registerFocusable(group, { current: null });
66
- focusManager.registerFocusable(child1, group);
67
- focusManager.registerFocusable(child2, group);
68
- focusManager.registerFocusable(child3, child2);
69
-
70
- focusManager.registerFocusable(child4, child2);
71
- focusManager.registerFocusable(child5, child2);
68
+ focusManager.registerFocusable({
69
+ touchableRef: group,
70
+ parentFocusableRef: { current: null },
71
+ isFocusableCell,
72
+ parentFocusableId,
73
+ });
74
+
75
+ focusManager.registerFocusable({
76
+ touchableRef: child1,
77
+ parentFocusableRef: group,
78
+ isFocusableCell,
79
+ parentFocusableId,
80
+ });
81
+
82
+ focusManager.registerFocusable({
83
+ touchableRef: child2,
84
+ parentFocusableRef: group,
85
+ isFocusableCell,
86
+ parentFocusableId,
87
+ });
88
+
89
+ focusManager.registerFocusable({
90
+ touchableRef: child3,
91
+ parentFocusableRef: child2,
92
+ isFocusableCell,
93
+ parentFocusableId,
94
+ });
95
+
96
+ focusManager.registerFocusable({
97
+ touchableRef: child4,
98
+ parentFocusableRef: child2,
99
+ isFocusableCell,
100
+ parentFocusableId,
101
+ });
102
+
103
+ focusManager.registerFocusable({
104
+ touchableRef: child5,
105
+ parentFocusableRef: child2,
106
+ isFocusableCell,
107
+ parentFocusableId,
108
+ });
72
109
  });
73
110
 
74
111
  it("focusManager should be defined", () => {
@@ -199,7 +236,12 @@ describe("FocusManager", () => {
199
236
  });
200
237
 
201
238
  it("focusManager registerFocusable should register", () => {
202
- focusManager.registerFocusable(child5, child2);
239
+ focusManager.registerFocusable({
240
+ touchableRef: child5,
241
+ parentFocusableRef: child2,
242
+ isFocusableCell,
243
+ parentFocusableId,
244
+ });
203
245
 
204
246
  expect(
205
247
  focusManager.isFocusableChildOf(child5.current.props.id, child2)
@@ -2985,6 +2985,14 @@ function getPlayerConfiguration({ platform, version }) {
2985
2985
  type: "uploader",
2986
2986
  default: "",
2987
2987
  },
2988
+ {
2989
+ key: "audio_player_background_image_overlay",
2990
+ label: "Background Image Overlay",
2991
+ label_tooltip:
2992
+ "Add a semi-transparent color overlay to improve text readability over the background image.",
2993
+ type: "color_picker_rgba",
2994
+ initial_value: "rgba(17, 17, 17, 0.5)",
2995
+ },
2988
2996
  {
2989
2997
  type: "text_input",
2990
2998
  label: "Item Image Key",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-utils",
3
- "version": "14.0.0-alpha.3881160800",
3
+ "version": "14.0.0-alpha.3890252181",
4
4
  "description": "Applicaster Zapp React Native utilities package",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://github.com/applicaster/quickbrick#readme",
29
29
  "dependencies": {
30
- "@applicaster/applicaster-types": "14.0.0-alpha.3881160800",
30
+ "@applicaster/applicaster-types": "14.0.0-alpha.3890252181",
31
31
  "buffer": "^5.2.1",
32
32
  "camelize": "^1.0.0",
33
33
  "dayjs": "^1.11.10",
@@ -1,4 +1,4 @@
1
- import { take, map, trim } from "lodash";
1
+ import { map, take, trim } from "../utils";
2
2
  import { selectActionButtons } from "../conf/player/selectors";
3
3
 
4
4
  /**
@@ -5,6 +5,7 @@ import { isFilledArray } from "@applicaster/zapp-react-native-utils/arrayUtils";
5
5
  import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
6
6
 
7
7
  import { getBoolFromConfigValue } from "../configurationUtils";
8
+ import { Dimensions } from "react-native";
8
9
 
9
10
  export { getPlayerActionButtons } from "./getPlayerActionButtons";
10
11
 
@@ -97,3 +98,53 @@ export const isAudioItem = (item: Option<ZappEntry>) => {
97
98
  export const isInlineTV = (screenData) => {
98
99
  return isTV() && isFilledArray(screenData?.ui_components);
99
100
  };
101
+
102
+ const isPercentage = (value: string | number): boolean => {
103
+ if (typeof value === "string") {
104
+ return value.includes("%");
105
+ }
106
+
107
+ return false;
108
+ };
109
+
110
+ const getPercentageOf = (percent: string, value: number) => {
111
+ const percentageValue = parseFloat(percent.replace("%", ""));
112
+
113
+ if (isNaN(percentageValue)) {
114
+ return value;
115
+ }
116
+
117
+ return (value * percentageValue) / 100;
118
+ };
119
+
120
+ type DimensionsT = {
121
+ width: number | string;
122
+ height: number | string | undefined;
123
+ aspectRatio?: number;
124
+ };
125
+
126
+ export const getTabletWidth = (
127
+ tablet_landscape_sidebar_width,
128
+ dimensions: DimensionsT
129
+ ) => {
130
+ const { width: SCREEN_WIDTH } = Dimensions.get("screen");
131
+
132
+ const { width } = dimensions;
133
+ let widthValue = Number(width);
134
+
135
+ if (isPercentage(width)) {
136
+ widthValue = getPercentageOf(width.toString(), SCREEN_WIDTH);
137
+ }
138
+
139
+ const sidebarWidth = Number(tablet_landscape_sidebar_width?.replace("%", ""));
140
+
141
+ if (tablet_landscape_sidebar_width?.includes("%")) {
142
+ return widthValue * (1 - sidebarWidth / 100);
143
+ }
144
+
145
+ if (Number.isNaN(sidebarWidth)) {
146
+ return widthValue * 0.65;
147
+ }
148
+
149
+ return widthValue - sidebarWidth;
150
+ };
@@ -1,27 +1,25 @@
1
1
  import React from "react";
2
2
 
3
- import { renderHook } from "@testing-library/react-hooks";
4
- import { act, waitFor } from "@testing-library/react-native";
3
+ import { act, renderHook } from "@testing-library/react-hooks";
5
4
  import { Provider } from "react-redux";
6
5
  import configureStore from "redux-mock-store";
7
- import { useTrackedView } from "../useTrackedView";
8
6
 
9
7
  const mockUpdateComponentsPositions = jest.fn();
10
8
 
11
9
  jest.mock(
12
10
  "@applicaster/zapp-react-native-ui-components/Contexts/ScreenTrackedViewPositionsContext",
13
11
  () => ({
14
- useScreenTrackedViewPositionsContext: jest.fn(() => ({
12
+ useScreenTrackedViewPositionsContext: jest.fn().mockReturnValue({
15
13
  updateComponentsPositions: mockUpdateComponentsPositions,
16
14
  value: {
17
15
  "123": { componentId: "123", centerX: 0.4, centerY: 0.5 },
18
16
  "124": { componentId: "124", centerX: 0.2, centerY: 0.3 },
19
17
  },
20
- })),
18
+ }),
21
19
  })
22
20
  );
23
21
 
24
- jest.useFakeTimers();
22
+ jest.useFakeTimers({ legacyFakeTimers: true });
25
23
 
26
24
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
27
25
 
@@ -34,8 +32,10 @@ const Wrapper = ({ children }: { children: React.ReactChild }) => (
34
32
  <Provider store={store}>{children}</Provider>
35
33
  );
36
34
 
35
+ const { useTrackedView } = require("../useTrackedView");
36
+
37
37
  describe("useTrackCurrentAutoScrollingElement", () => {
38
- it("should update position for selected component - onViewportEnter", async () => {
38
+ it("should update position for selected component - onViewportEnter", () => {
39
39
  const { result } = renderHook(() => useTrackedView("123"), {
40
40
  wrapper: Wrapper,
41
41
  });
@@ -46,13 +46,14 @@ describe("useTrackCurrentAutoScrollingElement", () => {
46
46
  rect: { left: 1, right: 1, top: 1, bottom: 1 },
47
47
  };
48
48
 
49
- act(() => {
50
- result.current.onPositionUpdated(mockRect);
49
+ act(async () => {
50
+ await result.current.onPositionUpdated(mockRect);
51
51
  });
52
52
 
53
- await waitFor(() => {
54
- expect(result.current.inViewPort).toBe(true);
55
- });
53
+ // Fast-forward until all timers have been executed
54
+ jest.runAllTimers();
55
+
56
+ expect(result.current.inViewPort).toBe(true);
56
57
 
57
58
  expect(mockUpdateComponentsPositions).toHaveBeenCalledWith(
58
59
  "123",
@@ -16,7 +16,8 @@ import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/acti
16
16
  import { isFunction, noop } from "../../functionUtils";
17
17
  import { useSendAnalyticsOnPress } from "../analytics";
18
18
  import { logOnPress, warnEmptyContentType } from "./helpers";
19
- import { useCurrentScreenData } from "../screen";
19
+ import { useCurrentScreenData, useScreenContext } from "../screen";
20
+ import { useScreenStateStore } from "../navigation/useScreenStateStore";
20
21
 
21
22
  /**
22
23
  * If onCellTap is defined execute the function and
@@ -42,10 +43,12 @@ export const useCellClick = ({
42
43
  }: Props): onPressReturnFn => {
43
44
  const { push, currentRoute } = useNavigation();
44
45
  const { pathname } = useRoute();
46
+ const screenStateStore = useScreenStateStore();
45
47
 
46
48
  const onCellTap: Option<Function> = React.useContext(CellTapContext);
47
49
  const actionExecutor = React.useContext(ActionExecutorContext);
48
50
  const screenData = useCurrentScreenData();
51
+ const screenState = useScreenContext()?.options;
49
52
 
50
53
  const cellSelectable = toBooleanWithDefaultTrue(
51
54
  component?.rules?.component_cells_selectable
@@ -83,6 +86,9 @@ export const useCellClick = ({
83
86
  await actionExecutor?.handleEntryActions(selectedItem, {
84
87
  component,
85
88
  screenData,
89
+ screenState,
90
+ screenRoute: pathname,
91
+ screenStateStore,
86
92
  });
87
93
  }
88
94
 
@@ -117,6 +123,7 @@ export const useCellClick = ({
117
123
  push,
118
124
  sendAnalyticsOnPress,
119
125
  screenData,
126
+ screenState,
120
127
  ]
121
128
  );
122
129
 
@@ -1,7 +1,8 @@
1
1
  import { renderHook } from "@testing-library/react-hooks";
2
- import { allFeedsIsReady, useBatchLoading } from "../useBatchLoading";
3
- import { WrappedWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
4
- import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
2
+ import * as reduxMockStore from "redux-mock-store";
3
+ import thunk from "redux-thunk";
4
+ import React from "react";
5
+ import * as ReactRedux from "react-redux";
5
6
 
6
7
  jest.mock("../../navigation");
7
8
 
@@ -12,18 +13,17 @@ jest.mock(
12
13
  })
13
14
  );
14
15
 
15
- const wrapper = WrappedWithProviders;
16
+ const useBatchLoading = require("../useBatchLoading").useBatchLoading;
17
+ const allFeedsIsReady = require("../useBatchLoading").allFeedsIsReady;
18
+
19
+ const mockStore = reduxMockStore.default([thunk]);
20
+
21
+ const wrapper: React.FC<any> = ({ children, store }) => (
22
+ <ReactRedux.Provider store={store}>{children}</ReactRedux.Provider>
23
+ );
16
24
 
17
25
  describe("useBatchLoading", () => {
18
- const data = [
19
- { data: { source: "url1" }, component_type: "any" },
20
- { data: { source: "url2" }, component_type: "any" },
21
- { data: { source: "url3" }, component_type: "any" },
22
- { data: { source: "url4" }, component_type: "any" },
23
- { data: { source: "url5" }, component_type: "any" },
24
- { data: { source: "url6" }, component_type: "any" },
25
- // ... more items
26
- ];
26
+ const useDispatchSpy = jest.spyOn(ReactRedux, "useDispatch");
27
27
 
28
28
  beforeAll(() => {
29
29
  jest.useFakeTimers();
@@ -34,7 +34,7 @@ describe("useBatchLoading", () => {
34
34
  });
35
35
 
36
36
  it("loadPipesData start loading not started requests", () => {
37
- const store = {
37
+ const store = mockStore({
38
38
  zappPipes: {
39
39
  url1: {
40
40
  loading: true,
@@ -53,17 +53,29 @@ describe("useBatchLoading", () => {
53
53
  },
54
54
  },
55
55
  test: "true",
56
- };
56
+ });
57
+
58
+ useDispatchSpy.mockReturnValue(store.dispatch);
57
59
 
58
60
  const initialBatchSize = 3;
59
61
  const riverId = "123";
60
62
 
63
+ const data = [
64
+ { data: { source: "url1" } },
65
+ { data: { source: "url2" } },
66
+ { data: { source: "url3" } },
67
+ { data: { source: "url4" } },
68
+ { data: { source: "url5" } },
69
+ { data: { source: "url6" } },
70
+ // ... more items
71
+ ];
72
+
61
73
  renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
62
74
  wrapper,
63
75
  initialProps: { store },
64
76
  });
65
77
 
66
- const actions = (appStore.getStore() as any).getActions();
78
+ const actions = store.getActions();
67
79
 
68
80
  expect(actions).toHaveLength(2);
69
81
 
@@ -79,7 +91,7 @@ describe("useBatchLoading", () => {
79
91
  });
80
92
 
81
93
  it("loadPipesData start loading new feed when 1 feed is done loading and 1 is in loading state", () => {
82
- const store = {
94
+ const store = mockStore({
83
95
  zappPipes: {
84
96
  url1: {
85
97
  loading: false,
@@ -98,17 +110,31 @@ describe("useBatchLoading", () => {
98
110
  },
99
111
  },
100
112
  test: "true",
101
- };
113
+ });
114
+
115
+ useDispatchSpy.mockReturnValue(store.dispatch);
102
116
 
103
117
  const initialBatchSize = 3;
104
118
  const riverId = "123";
105
119
 
120
+ const data = [
121
+ { data: { source: "url1" } },
122
+ { data: { source: "url2" } },
123
+ { data: { source: "url3" } },
124
+ { data: { source: "url4" } },
125
+ { data: { source: "url5" } },
126
+ { data: { source: "url6" } },
127
+ // ... more items
128
+ ];
129
+
130
+ expect(useDispatchSpy).toBeCalledTimes(0);
131
+
106
132
  renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
107
133
  wrapper,
108
134
  initialProps: { store },
109
135
  });
110
136
 
111
- const actions = (appStore.getStore() as any).getActions();
137
+ const actions = store.getActions();
112
138
 
113
139
  expect(actions).toHaveLength(1);
114
140
 
@@ -119,26 +145,38 @@ describe("useBatchLoading", () => {
119
145
  });
120
146
 
121
147
  it("loadPipesData has been called when no data cached", () => {
122
- const store = {
148
+ const store = mockStore({
123
149
  zappPipes: {},
124
150
  test: "true",
125
- };
151
+ });
152
+
153
+ useDispatchSpy.mockReturnValue(store.dispatch);
126
154
 
127
155
  const initialBatchSize = 3;
128
156
  const riverId = "123";
129
157
 
158
+ const data = [
159
+ { data: { source: "url1" } },
160
+ { data: { source: "url2" } },
161
+ { data: { source: "url3" } },
162
+ { data: { source: "url4" } },
163
+ { data: { source: "url5" } },
164
+ { data: { source: "url6" } },
165
+ // ... more items
166
+ ];
167
+
130
168
  renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
131
169
  wrapper,
132
170
  initialProps: { store },
133
171
  });
134
172
 
135
- const actions = (appStore.getStore() as any).getActions();
173
+ const actions = store.getActions();
136
174
 
137
175
  expect(actions).toHaveLength(3);
138
176
  });
139
177
 
140
178
  it("initial batch ready when all initial items loaded", () => {
141
- const store = {
179
+ const store = mockStore({
142
180
  zappPipes: {
143
181
  url1: {
144
182
  loading: false,
@@ -156,11 +194,19 @@ describe("useBatchLoading", () => {
156
194
  data: {},
157
195
  },
158
196
  },
159
- };
197
+ });
198
+
199
+ useDispatchSpy.mockReturnValue(store.dispatch);
160
200
 
161
201
  const initialBatchSize = 3;
162
202
  const riverId = "123";
163
203
 
204
+ const data: Partial<ZappUIComponent>[] = [
205
+ { data: { source: "url1" } },
206
+ { data: { source: "url2" } },
207
+ { data: { source: "url3" } },
208
+ ];
209
+
164
210
  const { result } = renderHook(
165
211
  () => useBatchLoading(data, { initialBatchSize, riverId }),
166
212
  { wrapper, initialProps: { store } }
@@ -170,10 +216,12 @@ describe("useBatchLoading", () => {
170
216
  });
171
217
 
172
218
  it("gallery-qb: loadPipesData should be called only once for first component in the gallery", () => {
173
- const store = {
219
+ const store = mockStore({
174
220
  zappPipes: {},
175
221
  test: "true",
176
- };
222
+ });
223
+
224
+ useDispatchSpy.mockReturnValue(store.dispatch);
177
225
 
178
226
  const initialBatchSize = 3;
179
227
  const riverId = "123";
@@ -183,11 +231,11 @@ describe("useBatchLoading", () => {
183
231
  component_type: "gallery-qb",
184
232
  ui_components: [{ data: { source: "url1" } }],
185
233
  },
186
- { data: { source: "url2" }, component_type: "any" },
187
- { data: { source: "url3" }, component_type: "any" },
188
- { data: { source: "url4" }, component_type: "any" },
189
- { data: { source: "url5" }, component_type: "any" },
190
- { data: { source: "url6" }, component_type: "any" },
234
+ { data: { source: "url2" } },
235
+ { data: { source: "url3" } },
236
+ { data: { source: "url4" } },
237
+ { data: { source: "url5" } },
238
+ { data: { source: "url6" } },
191
239
  // ... more items
192
240
  ];
193
241
 
@@ -196,13 +244,13 @@ describe("useBatchLoading", () => {
196
244
  initialProps: { store },
197
245
  });
198
246
 
199
- const actions = (appStore.getStore() as any).getActions();
247
+ const actions = store.getActions();
200
248
 
201
249
  expect(actions).toHaveLength(1);
202
250
  });
203
251
 
204
252
  it("gallery-qb: initial batch ready when all initial items loaded", () => {
205
- const store = {
253
+ const store = mockStore({
206
254
  zappPipes: {
207
255
  url1: {
208
256
  loading: false,
@@ -210,19 +258,20 @@ describe("useBatchLoading", () => {
210
258
  data: {},
211
259
  },
212
260
  },
213
- };
261
+ });
262
+
263
+ useDispatchSpy.mockReturnValue(store.dispatch);
214
264
 
215
265
  const initialBatchSize = 3;
216
266
  const riverId = "123";
217
267
 
218
- const data = [
268
+ const data: Partial<ZappUIComponent>[] = [
219
269
  {
220
270
  component_type: "gallery-qb",
221
- data: {},
222
- ui_components: [{ data: { source: "url1" } }] as any,
271
+ ui_components: [{ data: { source: "url1" } }],
223
272
  },
224
- { data: { source: "url2" }, component_type: "any" },
225
- { data: { source: "url3" }, component_type: "any" },
273
+ { data: { source: "url2" } },
274
+ { data: { source: "url3" } },
226
275
  ];
227
276
 
228
277
  const { result } = renderHook(