@applicaster/zapp-react-native-utils 14.0.0-rc.9 → 14.0.0-rc.91
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/actionsExecutor/ActionExecutorContext.tsx +60 -84
- package/actionsExecutor/ScreenActions.ts +164 -0
- package/actionsExecutor/StorageActions.ts +110 -0
- package/actionsExecutor/feedDecorator.ts +171 -0
- package/actionsExecutor/screenResolver.ts +11 -0
- package/analyticsUtils/AnalyticPlayerListener.ts +5 -2
- package/analyticsUtils/AnalyticsEvents/helper.ts +81 -0
- package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
- package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
- package/analyticsUtils/__tests__/analyticsUtils.test.js +3 -0
- package/analyticsUtils/events.ts +8 -0
- package/analyticsUtils/index.tsx +3 -4
- package/analyticsUtils/manager.ts +1 -1
- package/analyticsUtils/playerAnalyticsTracker.ts +2 -1
- package/appUtils/HooksManager/Hook.ts +4 -4
- package/appUtils/HooksManager/index.ts +11 -1
- package/appUtils/accessibilityManager/const.ts +13 -0
- package/appUtils/accessibilityManager/hooks.ts +35 -1
- package/appUtils/accessibilityManager/index.ts +154 -30
- package/appUtils/accessibilityManager/utils.ts +24 -0
- package/appUtils/contextKeysManager/contextResolver.ts +42 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +8 -0
- package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
- package/appUtils/focusManager/events.ts +2 -0
- package/appUtils/focusManager/index.ios.ts +27 -0
- package/appUtils/focusManager/index.ts +86 -11
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
- package/appUtils/focusManagerAux/utils/index.ts +112 -3
- package/appUtils/focusManagerAux/utils/utils.ios.ts +35 -0
- package/appUtils/platform/platformUtils.ts +33 -3
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +91 -16
- package/appUtils/playerManager/OverlayObserver/utils.ts +32 -20
- package/appUtils/playerManager/conts.ts +21 -0
- package/appUtils/playerManager/useChapterMarker.tsx +0 -1
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
- package/arrayUtils/__tests__/allTruthy.test.ts +24 -0
- package/arrayUtils/__tests__/anyThruthy.test.ts +24 -0
- package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
- package/arrayUtils/index.ts +13 -3
- package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +144 -0
- package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +72 -0
- package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +110 -0
- package/audioPlayerUtils/assets/index.ts +2 -0
- package/audioPlayerUtils/index.ts +242 -0
- package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
- package/componentsUtils/index.ts +4 -1
- package/conf/player/__tests__/selectors.test.ts +34 -0
- package/conf/player/selectors.ts +10 -0
- package/configurationUtils/__tests__/configurationUtils.test.js +0 -31
- package/configurationUtils/__tests__/getMediaItems.test.ts +65 -0
- package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +34 -0
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +546 -0
- package/configurationUtils/index.ts +64 -35
- package/configurationUtils/manifestKeyParser.ts +57 -32
- package/focusManager/FocusManager.ts +104 -20
- package/focusManager/Tree.ts +25 -21
- package/focusManager/__tests__/FocusManager.test.ts +50 -8
- package/focusManager/aux/index.ts +98 -0
- package/focusManager/utils.ts +12 -6
- package/index.d.ts +1 -10
- package/manifestUtils/_internals/getDefaultConfiguration.js +28 -0
- package/manifestUtils/{_internals.js → _internals/index.js} +2 -25
- package/manifestUtils/createConfig.js +4 -1
- package/manifestUtils/defaultManifestConfigurations/player.js +2764 -1539
- package/manifestUtils/index.js +4 -0
- package/manifestUtils/keys.js +33 -0
- package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +6 -0
- package/manifestUtils/sharedConfiguration/screenPicker/utils.js +1 -0
- package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
- package/navigationUtils/index.ts +26 -21
- package/package.json +2 -3
- package/playerUtils/PlayerTTS/PlayerTTS.ts +359 -0
- package/playerUtils/PlayerTTS/index.ts +1 -0
- package/playerUtils/__tests__/configurationUtils.test.ts +1 -65
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +54 -0
- package/playerUtils/_internals/__tests__/utils.test.ts +71 -0
- package/playerUtils/_internals/index.ts +1 -0
- package/playerUtils/_internals/utils.ts +31 -0
- package/playerUtils/configurationUtils.ts +0 -44
- package/playerUtils/getPlayerActionButtons.ts +17 -0
- package/playerUtils/index.ts +53 -0
- package/playerUtils/usePlayerTTS.ts +21 -0
- package/playerUtils/useValidatePlayerConfig.tsx +22 -19
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
- package/reactHooks/cell-click/__tests__/index.test.js +3 -0
- package/reactHooks/cell-click/index.ts +8 -1
- package/reactHooks/debugging/__tests__/index.test.js +0 -1
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +47 -90
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +71 -31
- package/reactHooks/feed/index.ts +2 -0
- package/reactHooks/feed/useBatchLoading.ts +17 -10
- package/reactHooks/feed/useFeedLoader.tsx +36 -43
- package/reactHooks/feed/useInflatedUrl.ts +23 -29
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +63 -0
- package/reactHooks/feed/usePipesCacheReset.ts +3 -3
- package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
- package/reactHooks/layout/__tests__/index.test.tsx +3 -1
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/layout/isTablet/index.ts +12 -5
- package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
- package/reactHooks/layout/useLayoutVersion.ts +5 -5
- package/reactHooks/navigation/index.ts +7 -5
- package/reactHooks/navigation/useIsScreenActive.ts +9 -5
- package/reactHooks/navigation/useRoute.ts +7 -2
- package/reactHooks/navigation/useScreenStateStore.ts +8 -0
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
- package/reactHooks/screen/useScreenContext.ts +1 -1
- package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
- package/reactHooks/state/index.ts +1 -1
- package/reactHooks/state/useHomeRiver.ts +4 -2
- package/reactHooks/state/useRivers.ts +7 -8
- package/riverComponetsMeasurementProvider/index.tsx +1 -1
- package/screenPickerUtils/index.ts +13 -0
- package/services/js2native.ts +1 -0
- package/storage/ScreenSingleValueProvider.ts +204 -0
- package/storage/ScreenStateMultiSelectProvider.ts +293 -0
- package/storage/StorageMultiSelectProvider.ts +192 -0
- package/storage/StorageSingleSelectProvider.ts +108 -0
- package/testUtils/index.tsx +7 -8
- package/time/BackgroundTimer.ts +6 -4
- package/utils/__tests__/endsWith.test.ts +30 -0
- package/utils/__tests__/find.test.ts +36 -0
- package/utils/__tests__/mapAccum.test.ts +73 -0
- package/utils/__tests__/omit.test.ts +19 -0
- package/utils/__tests__/path.test.ts +33 -0
- package/utils/__tests__/pathOr.test.ts +37 -0
- package/utils/__tests__/startsWith.test.ts +30 -0
- package/utils/__tests__/take.test.ts +40 -0
- package/utils/endsWith.ts +9 -0
- package/utils/find.ts +3 -0
- package/utils/index.ts +38 -1
- package/utils/mapAccum.ts +23 -0
- package/utils/omit.ts +5 -0
- package/utils/path.ts +5 -0
- package/utils/pathOr.ts +5 -0
- package/utils/startsWith.ts +9 -0
- package/utils/take.ts +5 -0
- package/playerUtils/configurationGenerator.ts +0 -2572
package/playerUtils/index.ts
CHANGED
|
@@ -5,6 +5,9 @@ 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";
|
|
9
|
+
|
|
10
|
+
export { getPlayerActionButtons } from "./getPlayerActionButtons";
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Gets duration value from player manager, and from extensions
|
|
@@ -95,3 +98,53 @@ export const isAudioItem = (item: Option<ZappEntry>) => {
|
|
|
95
98
|
export const isInlineTV = (screenData) => {
|
|
96
99
|
return isTV() && isFilledArray(screenData?.ui_components);
|
|
97
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
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { usePlayer } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer";
|
|
3
|
+
import { useAccessibilityManager } from "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager/hooks";
|
|
4
|
+
import { PlayerTTS } from "@applicaster/zapp-react-native-utils/playerUtils/PlayerTTS";
|
|
5
|
+
|
|
6
|
+
export const usePlayerTTS = () => {
|
|
7
|
+
const player = usePlayer();
|
|
8
|
+
const accessibilityManager = useAccessibilityManager({});
|
|
9
|
+
|
|
10
|
+
React.useEffect(() => {
|
|
11
|
+
if (player && accessibilityManager) {
|
|
12
|
+
const playerTTS = new PlayerTTS(player, accessibilityManager);
|
|
13
|
+
const unsubscribe = playerTTS.init();
|
|
14
|
+
|
|
15
|
+
return () => {
|
|
16
|
+
unsubscribe();
|
|
17
|
+
playerTTS.destroy();
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}, [player, accessibilityManager]);
|
|
21
|
+
};
|
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import * as R from "ramda";
|
|
3
|
-
import generateConfiguration from "./configurationGenerator";
|
|
4
2
|
import { createLogger } from "../logger";
|
|
3
|
+
import { createConfig } from "../manifestUtils/createConfig";
|
|
4
|
+
import { getAllFields, getConfigurationDiff } from "./_internals";
|
|
5
5
|
|
|
6
6
|
export const logger = createLogger({
|
|
7
7
|
category: "useValidatePlayerConfig",
|
|
8
8
|
subsystem: "useValidatePlayerConfig",
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
/** Default Player Configuration */
|
|
12
|
+
const {
|
|
13
|
+
styles,
|
|
14
|
+
general,
|
|
15
|
+
localizations,
|
|
16
|
+
custom_configuration_fields,
|
|
17
|
+
}: DefaultConfiguration = createConfig(
|
|
18
|
+
() => {
|
|
19
|
+
return {};
|
|
20
|
+
},
|
|
21
|
+
{ extend: "player" }
|
|
22
|
+
) as any;
|
|
23
|
+
|
|
24
|
+
const QBPlayerConfigFields = getAllFields(
|
|
25
|
+
styles,
|
|
26
|
+
general,
|
|
27
|
+
localizations,
|
|
28
|
+
custom_configuration_fields
|
|
29
|
+
);
|
|
12
30
|
|
|
13
31
|
export const useValidatePlayerConfig = (config) => {
|
|
14
32
|
React.useEffect(() => {
|
|
15
33
|
try {
|
|
16
|
-
const
|
|
17
|
-
R.map(R.prop("key")),
|
|
18
|
-
R.flatten,
|
|
19
|
-
R.map(R.compose(R.when(R.propEq("group", true), R.prop("fields")))),
|
|
20
|
-
R.concat
|
|
21
|
-
)(
|
|
22
|
-
configuration.styles.fields,
|
|
23
|
-
configuration.general.fields,
|
|
24
|
-
configuration.localizations.fields,
|
|
25
|
-
configuration.custom_configuration_fields
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
const diff = R.compose(
|
|
29
|
-
R.difference(QBPlayerConfigFields),
|
|
30
|
-
R.keys
|
|
31
|
-
)(config);
|
|
34
|
+
const diff = getConfigurationDiff(QBPlayerConfigFields, config);
|
|
32
35
|
|
|
33
36
|
logger.log_info(
|
|
34
37
|
"Missing following configuration properties. Some elements of the player may not work correctly. Check QuickBrickPlayerPlugin for the configuration reference https://github.com/applicaster/QuickBrick/tree/main/plugins/zapp-react-native-default-player/manifests",
|
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
4
|
+
import { act, waitFor } from "@testing-library/react-native";
|
|
4
5
|
import { Provider } from "react-redux";
|
|
5
6
|
import configureStore from "redux-mock-store";
|
|
7
|
+
import { useTrackedView } from "../useTrackedView";
|
|
6
8
|
|
|
7
9
|
const mockUpdateComponentsPositions = jest.fn();
|
|
8
10
|
|
|
9
11
|
jest.mock(
|
|
10
12
|
"@applicaster/zapp-react-native-ui-components/Contexts/ScreenTrackedViewPositionsContext",
|
|
11
13
|
() => ({
|
|
12
|
-
useScreenTrackedViewPositionsContext: jest.fn()
|
|
14
|
+
useScreenTrackedViewPositionsContext: jest.fn(() => ({
|
|
13
15
|
updateComponentsPositions: mockUpdateComponentsPositions,
|
|
14
16
|
value: {
|
|
15
17
|
"123": { componentId: "123", centerX: 0.4, centerY: 0.5 },
|
|
16
18
|
"124": { componentId: "124", centerX: 0.2, centerY: 0.3 },
|
|
17
19
|
},
|
|
18
|
-
}),
|
|
20
|
+
})),
|
|
19
21
|
})
|
|
20
22
|
);
|
|
21
23
|
|
|
22
|
-
jest.useFakeTimers(
|
|
24
|
+
jest.useFakeTimers();
|
|
23
25
|
|
|
24
|
-
jest.mock(
|
|
26
|
+
jest.mock(
|
|
27
|
+
"@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation"
|
|
28
|
+
);
|
|
25
29
|
|
|
26
30
|
const mockStore = configureStore();
|
|
27
31
|
|
|
@@ -32,10 +36,8 @@ const Wrapper = ({ children }: { children: React.ReactChild }) => (
|
|
|
32
36
|
<Provider store={store}>{children}</Provider>
|
|
33
37
|
);
|
|
34
38
|
|
|
35
|
-
const { useTrackedView } = require("../useTrackedView");
|
|
36
|
-
|
|
37
39
|
describe("useTrackCurrentAutoScrollingElement", () => {
|
|
38
|
-
it("should update position for selected component - onViewportEnter", () => {
|
|
40
|
+
it("should update position for selected component - onViewportEnter", async () => {
|
|
39
41
|
const { result } = renderHook(() => useTrackedView("123"), {
|
|
40
42
|
wrapper: Wrapper,
|
|
41
43
|
});
|
|
@@ -46,14 +48,13 @@ describe("useTrackCurrentAutoScrollingElement", () => {
|
|
|
46
48
|
rect: { left: 1, right: 1, top: 1, bottom: 1 },
|
|
47
49
|
};
|
|
48
50
|
|
|
49
|
-
act(
|
|
50
|
-
|
|
51
|
+
act(() => {
|
|
52
|
+
result.current.onPositionUpdated(mockRect);
|
|
51
53
|
});
|
|
52
54
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
expect(result.current.inViewPort).toBe(true);
|
|
55
|
+
await waitFor(() => {
|
|
56
|
+
expect(result.current.inViewPort).toBe(true);
|
|
57
|
+
});
|
|
57
58
|
|
|
58
59
|
expect(mockUpdateComponentsPositions).toHaveBeenCalledWith(
|
|
59
60
|
"123",
|
|
@@ -26,6 +26,9 @@ jest.mock("@applicaster/zapp-react-native-utils/analyticsUtils/", () => ({
|
|
|
26
26
|
}));
|
|
27
27
|
|
|
28
28
|
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/screen", () => ({
|
|
29
|
+
...jest.requireActual(
|
|
30
|
+
"@applicaster/zapp-react-native-utils/reactHooks/screen"
|
|
31
|
+
),
|
|
29
32
|
useTargetScreenData: jest.fn(() => ({})),
|
|
30
33
|
useCurrentScreenData: jest.fn(() => ({})),
|
|
31
34
|
}));
|
|
@@ -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
|
|
|
@@ -12,7 +12,6 @@ describe("Debug utils", () => {
|
|
|
12
12
|
// Clear the timers object
|
|
13
13
|
Object.keys(timers).forEach((key) => delete timers[key]);
|
|
14
14
|
|
|
15
|
-
// Mock performance.now()
|
|
16
15
|
// eslint-disable-next-line no-undef
|
|
17
16
|
performanceNowMock = jest.spyOn(performance, "now");
|
|
18
17
|
performanceNowMock.mockReturnValue(0); // Initial value
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
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";
|
|
5
|
+
import { waitFor } from "@testing-library/react-native";
|
|
6
6
|
|
|
7
7
|
jest.mock("../../navigation");
|
|
8
8
|
|
|
9
9
|
jest.mock(
|
|
10
10
|
"@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext",
|
|
11
11
|
() => ({
|
|
12
|
+
...jest.requireActual(
|
|
13
|
+
"@applicaster/zapp-react-native-utils/reactHooks/screen/useScreenContext"
|
|
14
|
+
),
|
|
12
15
|
useScreenContext: jest.fn().mockReturnValue({ screen: {}, entry: {} }),
|
|
13
16
|
})
|
|
14
17
|
);
|
|
15
18
|
|
|
16
|
-
const
|
|
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
|
-
);
|
|
19
|
+
const wrapper = WrappedWithProviders;
|
|
24
20
|
|
|
25
21
|
describe("useBatchLoading", () => {
|
|
26
|
-
const
|
|
22
|
+
const data = [
|
|
23
|
+
{ data: { source: "url1" }, component_type: "any" },
|
|
24
|
+
{ data: { source: "url2" }, component_type: "any" },
|
|
25
|
+
{ data: { source: "url3" }, component_type: "any" },
|
|
26
|
+
{ data: { source: "url4" }, component_type: "any" },
|
|
27
|
+
{ data: { source: "url5" }, component_type: "any" },
|
|
28
|
+
{ data: { source: "url6" }, component_type: "any" },
|
|
29
|
+
// ... more items
|
|
30
|
+
];
|
|
27
31
|
|
|
28
32
|
beforeAll(() => {
|
|
29
33
|
jest.useFakeTimers();
|
|
@@ -33,8 +37,8 @@ describe("useBatchLoading", () => {
|
|
|
33
37
|
jest.clearAllMocks();
|
|
34
38
|
});
|
|
35
39
|
|
|
36
|
-
it("loadPipesData start loading not started requests", () => {
|
|
37
|
-
const store =
|
|
40
|
+
it("loadPipesData start loading not started requests", async () => {
|
|
41
|
+
const store = {
|
|
38
42
|
zappPipes: {
|
|
39
43
|
url1: {
|
|
40
44
|
loading: true,
|
|
@@ -53,31 +57,21 @@ describe("useBatchLoading", () => {
|
|
|
53
57
|
},
|
|
54
58
|
},
|
|
55
59
|
test: "true",
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
useDispatchSpy.mockReturnValue(store.dispatch);
|
|
60
|
+
};
|
|
59
61
|
|
|
60
62
|
const initialBatchSize = 3;
|
|
61
63
|
const riverId = "123";
|
|
62
64
|
|
|
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
|
-
|
|
73
65
|
renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
|
|
74
66
|
wrapper,
|
|
75
67
|
initialProps: { store },
|
|
76
68
|
});
|
|
77
69
|
|
|
78
|
-
const actions =
|
|
70
|
+
const actions = (appStore.getStore() as any).getActions();
|
|
79
71
|
|
|
80
|
-
|
|
72
|
+
await waitFor(() => {
|
|
73
|
+
expect(actions).toHaveLength(2);
|
|
74
|
+
});
|
|
81
75
|
|
|
82
76
|
expect(actions[0]).toMatchObject({
|
|
83
77
|
type: "ZAPP_PIPES_REQUEST_START",
|
|
@@ -91,7 +85,7 @@ describe("useBatchLoading", () => {
|
|
|
91
85
|
});
|
|
92
86
|
|
|
93
87
|
it("loadPipesData start loading new feed when 1 feed is done loading and 1 is in loading state", () => {
|
|
94
|
-
const store =
|
|
88
|
+
const store = {
|
|
95
89
|
zappPipes: {
|
|
96
90
|
url1: {
|
|
97
91
|
loading: false,
|
|
@@ -110,31 +104,17 @@ describe("useBatchLoading", () => {
|
|
|
110
104
|
},
|
|
111
105
|
},
|
|
112
106
|
test: "true",
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
useDispatchSpy.mockReturnValue(store.dispatch);
|
|
107
|
+
};
|
|
116
108
|
|
|
117
109
|
const initialBatchSize = 3;
|
|
118
110
|
const riverId = "123";
|
|
119
111
|
|
|
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
|
-
|
|
132
112
|
renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
|
|
133
113
|
wrapper,
|
|
134
114
|
initialProps: { store },
|
|
135
115
|
});
|
|
136
116
|
|
|
137
|
-
const actions =
|
|
117
|
+
const actions = (appStore.getStore() as any).getActions();
|
|
138
118
|
|
|
139
119
|
expect(actions).toHaveLength(1);
|
|
140
120
|
|
|
@@ -145,38 +125,26 @@ describe("useBatchLoading", () => {
|
|
|
145
125
|
});
|
|
146
126
|
|
|
147
127
|
it("loadPipesData has been called when no data cached", () => {
|
|
148
|
-
const store =
|
|
128
|
+
const store = {
|
|
149
129
|
zappPipes: {},
|
|
150
130
|
test: "true",
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
useDispatchSpy.mockReturnValue(store.dispatch);
|
|
131
|
+
};
|
|
154
132
|
|
|
155
133
|
const initialBatchSize = 3;
|
|
156
134
|
const riverId = "123";
|
|
157
135
|
|
|
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
|
-
|
|
168
136
|
renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
|
|
169
137
|
wrapper,
|
|
170
138
|
initialProps: { store },
|
|
171
139
|
});
|
|
172
140
|
|
|
173
|
-
const actions =
|
|
141
|
+
const actions = (appStore.getStore() as any).getActions();
|
|
174
142
|
|
|
175
143
|
expect(actions).toHaveLength(3);
|
|
176
144
|
});
|
|
177
145
|
|
|
178
146
|
it("initial batch ready when all initial items loaded", () => {
|
|
179
|
-
const store =
|
|
147
|
+
const store = {
|
|
180
148
|
zappPipes: {
|
|
181
149
|
url1: {
|
|
182
150
|
loading: false,
|
|
@@ -194,19 +162,11 @@ describe("useBatchLoading", () => {
|
|
|
194
162
|
data: {},
|
|
195
163
|
},
|
|
196
164
|
},
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
useDispatchSpy.mockReturnValue(store.dispatch);
|
|
165
|
+
};
|
|
200
166
|
|
|
201
167
|
const initialBatchSize = 3;
|
|
202
168
|
const riverId = "123";
|
|
203
169
|
|
|
204
|
-
const data: Partial<ZappUIComponent>[] = [
|
|
205
|
-
{ data: { source: "url1" } },
|
|
206
|
-
{ data: { source: "url2" } },
|
|
207
|
-
{ data: { source: "url3" } },
|
|
208
|
-
];
|
|
209
|
-
|
|
210
170
|
const { result } = renderHook(
|
|
211
171
|
() => useBatchLoading(data, { initialBatchSize, riverId }),
|
|
212
172
|
{ wrapper, initialProps: { store } }
|
|
@@ -216,12 +176,10 @@ describe("useBatchLoading", () => {
|
|
|
216
176
|
});
|
|
217
177
|
|
|
218
178
|
it("gallery-qb: loadPipesData should be called only once for first component in the gallery", () => {
|
|
219
|
-
const store =
|
|
179
|
+
const store = {
|
|
220
180
|
zappPipes: {},
|
|
221
181
|
test: "true",
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
useDispatchSpy.mockReturnValue(store.dispatch);
|
|
182
|
+
};
|
|
225
183
|
|
|
226
184
|
const initialBatchSize = 3;
|
|
227
185
|
const riverId = "123";
|
|
@@ -231,11 +189,11 @@ describe("useBatchLoading", () => {
|
|
|
231
189
|
component_type: "gallery-qb",
|
|
232
190
|
ui_components: [{ data: { source: "url1" } }],
|
|
233
191
|
},
|
|
234
|
-
{ data: { source: "url2" } },
|
|
235
|
-
{ data: { source: "url3" } },
|
|
236
|
-
{ data: { source: "url4" } },
|
|
237
|
-
{ data: { source: "url5" } },
|
|
238
|
-
{ data: { source: "url6" } },
|
|
192
|
+
{ data: { source: "url2" }, component_type: "any" },
|
|
193
|
+
{ data: { source: "url3" }, component_type: "any" },
|
|
194
|
+
{ data: { source: "url4" }, component_type: "any" },
|
|
195
|
+
{ data: { source: "url5" }, component_type: "any" },
|
|
196
|
+
{ data: { source: "url6" }, component_type: "any" },
|
|
239
197
|
// ... more items
|
|
240
198
|
];
|
|
241
199
|
|
|
@@ -244,13 +202,13 @@ describe("useBatchLoading", () => {
|
|
|
244
202
|
initialProps: { store },
|
|
245
203
|
});
|
|
246
204
|
|
|
247
|
-
const actions =
|
|
205
|
+
const actions = (appStore.getStore() as any).getActions();
|
|
248
206
|
|
|
249
207
|
expect(actions).toHaveLength(1);
|
|
250
208
|
});
|
|
251
209
|
|
|
252
210
|
it("gallery-qb: initial batch ready when all initial items loaded", () => {
|
|
253
|
-
const store =
|
|
211
|
+
const store = {
|
|
254
212
|
zappPipes: {
|
|
255
213
|
url1: {
|
|
256
214
|
loading: false,
|
|
@@ -258,20 +216,19 @@ describe("useBatchLoading", () => {
|
|
|
258
216
|
data: {},
|
|
259
217
|
},
|
|
260
218
|
},
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
useDispatchSpy.mockReturnValue(store.dispatch);
|
|
219
|
+
};
|
|
264
220
|
|
|
265
221
|
const initialBatchSize = 3;
|
|
266
222
|
const riverId = "123";
|
|
267
223
|
|
|
268
|
-
const data
|
|
224
|
+
const data = [
|
|
269
225
|
{
|
|
270
226
|
component_type: "gallery-qb",
|
|
271
|
-
|
|
227
|
+
data: {},
|
|
228
|
+
ui_components: [{ data: { source: "url1" } }] as any,
|
|
272
229
|
},
|
|
273
|
-
{ data: { source: "url2" } },
|
|
274
|
-
{ data: { source: "url3" } },
|
|
230
|
+
{ data: { source: "url2" }, component_type: "any" },
|
|
231
|
+
{ data: { source: "url3" }, component_type: "any" },
|
|
275
232
|
];
|
|
276
233
|
|
|
277
234
|
const { result } = renderHook(
|