@applicaster/zapp-react-native-utils 15.0.0-rc.98 → 15.1.0-rc.1
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 +51 -5
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/adsUtils/index.ts +2 -2
- package/analyticsUtils/README.md +1 -1
- package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +188 -0
- package/appUtils/HooksManager/__tests__/hooksManager.test.js +2 -16
- package/appUtils/HooksManager/index.ts +45 -10
- package/appUtils/RiverFocusManager/{index.ts → index.js} +18 -25
- package/appUtils/accessibilityManager/const.ts +0 -4
- package/appUtils/accessibilityManager/utils.ts +1 -0
- package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +2 -7
- package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +0 -48
- package/appUtils/contextKeysManager/contextResolver.ts +22 -51
- package/appUtils/contextKeysManager/index.ts +10 -65
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +0 -3
- package/appUtils/focusManager/index.ios.ts +4 -43
- package/appUtils/focusManagerAux/utils/index.ts +3 -5
- package/appUtils/focusManagerAux/utils/utils.ios.ts +3 -199
- package/appUtils/keyCodes/keys/keys.web.ts +4 -1
- package/appUtils/localizationsHelper.ts +4 -0
- package/appUtils/orientationHelper.ts +4 -2
- package/appUtils/platform/platformUtils.ts +1 -1
- package/appUtils/playerManager/index.ts +9 -0
- package/appUtils/playerManager/player.ts +1 -5
- package/appUtils/playerManager/playerNative.ts +22 -30
- package/appUtils/playerManager/usePlayer.tsx +5 -3
- package/appUtils/playerManager/usePlayerState.tsx +2 -14
- package/cellUtils/__tests__/cellUtils.test.ts +39 -0
- package/cellUtils/index.ts +11 -1
- package/cloudEventsUtils/index.ts +1 -65
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +26 -26
- package/dateUtils/__tests__/dayjs.test.ts +0 -3
- package/dateUtils/index.ts +2 -0
- package/focusManager/aux/index.ts +1 -1
- package/headersUtils/__tests__/headersUtils.test.js +1 -11
- package/headersUtils/index.ts +1 -2
- package/manifestUtils/defaultManifestConfigurations/player.js +7 -75
- package/manifestUtils/platformIsTV.js +13 -0
- package/manifestUtils/tvAction/container/index.js +1 -1
- package/numberUtils/__tests__/toNumber.test.ts +0 -12
- package/numberUtils/index.ts +1 -19
- package/package.json +4 -4
- package/pluginUtils/index.ts +4 -9
- package/reactHooks/advertising/index.ts +2 -2
- package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +2 -1
- package/reactHooks/casting/index.ts +1 -0
- package/reactHooks/casting/useIsCasting.tsx +57 -0
- package/reactHooks/cell-click/__tests__/index.test.js +3 -1
- package/reactHooks/componentsMap/index.ts +55 -0
- package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
- package/reactHooks/connection/__tests__/index.test.js +1 -1
- package/reactHooks/debugging/__tests__/index.test.js +4 -4
- package/reactHooks/device/useIsTablet.tsx +19 -14
- package/reactHooks/device/useMemoizedIsTablet.ts +3 -3
- package/reactHooks/events/index.ts +20 -0
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +23 -32
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
- package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +1 -4
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +30 -42
- package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +1 -1
- package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +1 -1
- package/reactHooks/feed/useBatchLoading.ts +1 -7
- package/reactHooks/feed/useEntryScreenId.ts +2 -2
- package/reactHooks/feed/useInflatedUrl.ts +1 -1
- package/reactHooks/feed/usePipesCacheReset.ts +1 -3
- package/reactHooks/flatList/useLoadNextPageIfNeeded.ts +16 -13
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/__tests__/index.test.tsx +1 -1
- package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
- package/reactHooks/layout/useDimensions/__tests__/{useDimensions.test.tsx → useDimensions.test.ts} +25 -105
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -2
- package/reactHooks/navigation/__tests__/index.test.tsx +4 -2
- package/reactHooks/navigation/index.ts +6 -7
- package/reactHooks/navigation/useRoute.ts +6 -8
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +10 -27
- package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
- package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
- package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
- package/reactHooks/resolvers/useCellResolver.ts +2 -6
- package/reactHooks/resolvers/useComponentResolver.ts +13 -9
- package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
- package/reactHooks/screen/__tests__/useCurrentScreenIsHook.test.ts +103 -0
- package/reactHooks/screen/__tests__/useCurrentScreenIsStartupHook.test.ts +94 -0
- package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
- package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
- package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +4 -12
- package/reactHooks/screen/index.ts +6 -0
- package/reactHooks/screen/useCurrentScreenIsHook.ts +9 -0
- package/reactHooks/screen/useCurrentScreenIsStartupHook.ts +8 -0
- package/reactHooks/screen/useIsStandaloneFullscreen.ts +12 -0
- package/reactHooks/screen/useTargetScreenData.ts +2 -4
- package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
- package/reactHooks/state/index.ts +2 -0
- package/reactHooks/state/useComponentScreenState.ts +45 -0
- package/reactHooks/state/useRivers.ts +1 -1
- package/reactHooks/usePluginConfiguration.ts +2 -2
- package/reactHooks/utils/__tests__/index.test.js +1 -1
- package/rectUtils/index.ts +2 -2
- package/screenPickerUtils/index.ts +5 -0
- package/screenState/__tests__/index.test.ts +1 -1
- package/stringUtils/index.ts +1 -1
- package/testUtils/index.tsx +21 -30
- package/typeGuards/index.ts +0 -4
- package/utils/__tests__/clone.test.ts +158 -0
- package/utils/clone.ts +7 -0
- package/utils/index.ts +1 -13
- package/utils/path.ts +3 -6
- package/utils/pathOr.ts +1 -5
- package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +1 -1
- package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +1 -1
- package/zappFrameworkUtils/loginPluginUtils.ts +1 -1
- package/adsUtils/__tests__/createVMAP.test.ts +0 -419
- package/appDataUtils/__tests__/urlScheme.test.ts +0 -678
- package/appUtils/focusManagerAux/utils/index.ios.ts +0 -122
- package/cloudEventsUtils/__tests__/index.test.ts +0 -529
- package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +0 -207
- package/errorUtils/__tests__/GeneralError.test.ts +0 -97
- package/errorUtils/__tests__/HttpStatusCode.test.ts +0 -344
- package/errorUtils/__tests__/MissingPluginError.test.ts +0 -113
- package/errorUtils/__tests__/NetworkError.test.ts +0 -202
- package/errorUtils/__tests__/getParsedResponse.test.ts +0 -188
- package/errorUtils/__tests__/invariant.test.ts +0 -112
- package/numberUtils/__tests__/toPositiveNumber.test.ts +0 -165
- package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +0 -537
- package/reactHooks/dev/__tests__/useReRenderLog.test.ts +0 -188
- package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +0 -580
- package/rectUtils/__tests__/index.test.ts +0 -549
- package/screenPickerUtils/__tests__/index.test.ts +0 -333
- package/searchUtils/const.ts +0 -7
- package/searchUtils/index.ts +0 -3
- package/time/__tests__/BackgroundTimer.test.ts +0 -156
- package/time/__tests__/Timer.test.ts +0 -236
- package/typeGuards/__tests__/isString.test.ts +0 -21
- package/utils/__tests__/mergeRight.test.ts +0 -48
- package/utils/__tests__/selectors.test.ts +0 -124
- package/utils/mergeRight.ts +0 -5
- package/utils/selectors.ts +0 -46
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { renderHook
|
|
1
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
2
2
|
import { allFeedsIsReady, useBatchLoading } from "../useBatchLoading";
|
|
3
3
|
import { WrappedWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
|
|
4
4
|
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
5
|
+
import { waitFor } from "@testing-library/react-native";
|
|
5
6
|
|
|
6
7
|
jest.mock("../../navigation");
|
|
7
8
|
|
|
@@ -15,11 +16,7 @@ jest.mock(
|
|
|
15
16
|
})
|
|
16
17
|
);
|
|
17
18
|
|
|
18
|
-
const
|
|
19
|
-
(store) =>
|
|
20
|
-
({ children }) => (
|
|
21
|
-
<WrappedWithProviders store={store}>{children}</WrappedWithProviders>
|
|
22
|
-
);
|
|
19
|
+
const wrapper = WrappedWithProviders;
|
|
23
20
|
|
|
24
21
|
describe("useBatchLoading", () => {
|
|
25
22
|
const data = [
|
|
@@ -66,7 +63,8 @@ describe("useBatchLoading", () => {
|
|
|
66
63
|
const riverId = "123";
|
|
67
64
|
|
|
68
65
|
renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
|
|
69
|
-
wrapper
|
|
66
|
+
wrapper,
|
|
67
|
+
initialProps: { store },
|
|
70
68
|
});
|
|
71
69
|
|
|
72
70
|
const actions = (appStore.getStore() as any).getActions();
|
|
@@ -86,7 +84,7 @@ describe("useBatchLoading", () => {
|
|
|
86
84
|
});
|
|
87
85
|
});
|
|
88
86
|
|
|
89
|
-
it("loadPipesData start loading new feed when 1 feed is done loading and 1 is in loading state",
|
|
87
|
+
it("loadPipesData start loading new feed when 1 feed is done loading and 1 is in loading state", () => {
|
|
90
88
|
const store = {
|
|
91
89
|
zappPipes: {
|
|
92
90
|
url1: {
|
|
@@ -112,14 +110,13 @@ describe("useBatchLoading", () => {
|
|
|
112
110
|
const riverId = "123";
|
|
113
111
|
|
|
114
112
|
renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
|
|
115
|
-
wrapper
|
|
113
|
+
wrapper,
|
|
114
|
+
initialProps: { store },
|
|
116
115
|
});
|
|
117
116
|
|
|
118
117
|
const actions = (appStore.getStore() as any).getActions();
|
|
119
118
|
|
|
120
|
-
|
|
121
|
-
expect(actions).toHaveLength(1);
|
|
122
|
-
});
|
|
119
|
+
expect(actions).toHaveLength(1);
|
|
123
120
|
|
|
124
121
|
expect(actions[0]).toMatchObject({
|
|
125
122
|
type: "ZAPP_PIPES_REQUEST_START",
|
|
@@ -127,7 +124,7 @@ describe("useBatchLoading", () => {
|
|
|
127
124
|
});
|
|
128
125
|
});
|
|
129
126
|
|
|
130
|
-
it("loadPipesData has been called when no data cached",
|
|
127
|
+
it("loadPipesData has been called when no data cached", () => {
|
|
131
128
|
const store = {
|
|
132
129
|
zappPipes: {},
|
|
133
130
|
test: "true",
|
|
@@ -137,17 +134,16 @@ describe("useBatchLoading", () => {
|
|
|
137
134
|
const riverId = "123";
|
|
138
135
|
|
|
139
136
|
renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
|
|
140
|
-
wrapper
|
|
137
|
+
wrapper,
|
|
138
|
+
initialProps: { store },
|
|
141
139
|
});
|
|
142
140
|
|
|
143
141
|
const actions = (appStore.getStore() as any).getActions();
|
|
144
142
|
|
|
145
|
-
|
|
146
|
-
expect(actions).toHaveLength(3);
|
|
147
|
-
});
|
|
143
|
+
expect(actions).toHaveLength(3);
|
|
148
144
|
});
|
|
149
145
|
|
|
150
|
-
it("initial batch ready when all initial items loaded",
|
|
146
|
+
it("initial batch ready when all initial items loaded", () => {
|
|
151
147
|
const store = {
|
|
152
148
|
zappPipes: {
|
|
153
149
|
url1: {
|
|
@@ -173,15 +169,13 @@ describe("useBatchLoading", () => {
|
|
|
173
169
|
|
|
174
170
|
const { result } = renderHook(
|
|
175
171
|
() => useBatchLoading(data, { initialBatchSize, riverId }),
|
|
176
|
-
{ wrapper:
|
|
172
|
+
{ wrapper, initialProps: { store } }
|
|
177
173
|
);
|
|
178
174
|
|
|
179
|
-
|
|
180
|
-
expect(result.current).toBe(true);
|
|
181
|
-
});
|
|
175
|
+
expect(result.current).toBe(true);
|
|
182
176
|
});
|
|
183
177
|
|
|
184
|
-
it("gallery-qb: loadPipesData should be called only once for first component in the gallery",
|
|
178
|
+
it("gallery-qb: loadPipesData should be called only once for first component in the gallery", () => {
|
|
185
179
|
const store = {
|
|
186
180
|
zappPipes: {},
|
|
187
181
|
test: "true",
|
|
@@ -204,17 +198,16 @@ describe("useBatchLoading", () => {
|
|
|
204
198
|
];
|
|
205
199
|
|
|
206
200
|
renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
|
|
207
|
-
wrapper
|
|
201
|
+
wrapper,
|
|
202
|
+
initialProps: { store },
|
|
208
203
|
});
|
|
209
204
|
|
|
210
205
|
const actions = (appStore.getStore() as any).getActions();
|
|
211
206
|
|
|
212
|
-
|
|
213
|
-
expect(actions).toHaveLength(1);
|
|
214
|
-
});
|
|
207
|
+
expect(actions).toHaveLength(1);
|
|
215
208
|
});
|
|
216
209
|
|
|
217
|
-
it("gallery-qb: initial batch ready when all initial items loaded",
|
|
210
|
+
it("gallery-qb: initial batch ready when all initial items loaded", () => {
|
|
218
211
|
const store = {
|
|
219
212
|
zappPipes: {
|
|
220
213
|
url1: {
|
|
@@ -240,12 +233,10 @@ describe("useBatchLoading", () => {
|
|
|
240
233
|
|
|
241
234
|
const { result } = renderHook(
|
|
242
235
|
() => useBatchLoading(data, { initialBatchSize, riverId }),
|
|
243
|
-
{ wrapper:
|
|
236
|
+
{ wrapper, initialProps: { store } }
|
|
244
237
|
);
|
|
245
238
|
|
|
246
|
-
|
|
247
|
-
expect(result.current).toBe(true);
|
|
248
|
-
});
|
|
239
|
+
expect(result.current).toBe(true);
|
|
249
240
|
});
|
|
250
241
|
});
|
|
251
242
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { renderHook
|
|
1
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
2
2
|
import { encodeParams } from "@applicaster/zapp-pipes-v2-client/src/utils";
|
|
3
3
|
|
|
4
4
|
const appData = {
|
|
@@ -42,26 +42,26 @@ describe("useBuildPipesUrl", () => {
|
|
|
42
42
|
build: jest.fn(() => Promise.resolve(buildResult)),
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
const { result } = renderHook(() =>
|
|
45
|
+
const { result, waitForNextUpdate } = renderHook(() =>
|
|
46
46
|
useBuildPipesUrl({ url, mapping, requestBuilder: mockedRequestBuilder })
|
|
47
47
|
);
|
|
48
48
|
|
|
49
49
|
expect(result.current.url).toBe("http://foo.com/show/show-1");
|
|
50
50
|
expect(result.current.requestParams).toBeNull();
|
|
51
51
|
|
|
52
|
-
await
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
)
|
|
64
|
-
|
|
52
|
+
await waitForNextUpdate();
|
|
53
|
+
|
|
54
|
+
expect(result.current.requestParams).toEqual(
|
|
55
|
+
expect.objectContaining({
|
|
56
|
+
params: {
|
|
57
|
+
version: appData.version_name,
|
|
58
|
+
ctx: encodeParams({ platform: appData.platform }),
|
|
59
|
+
},
|
|
60
|
+
headers: {
|
|
61
|
+
SDK: appData.sdk_version,
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
);
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it("returns empty object if url is not in endpoints", async () => {
|
|
@@ -81,15 +81,15 @@ describe("useBuildPipesUrl", () => {
|
|
|
81
81
|
build: jest.fn(() => Promise.resolve(buildResult)),
|
|
82
82
|
};
|
|
83
83
|
|
|
84
|
-
const { result } = renderHook(() =>
|
|
84
|
+
const { result, waitForNextUpdate } = renderHook(() =>
|
|
85
85
|
useBuildPipesUrl({ url, mapping, requestBuilder: mockedRequestBuilder })
|
|
86
86
|
);
|
|
87
87
|
|
|
88
88
|
expect(result.current.url).toBe("http://foobar.com/show-1");
|
|
89
89
|
expect(result.current.requestParams).toBeNull();
|
|
90
90
|
|
|
91
|
-
await
|
|
92
|
-
|
|
93
|
-
});
|
|
91
|
+
await waitForNextUpdate();
|
|
92
|
+
|
|
93
|
+
expect(result.current.requestParams).toEqual({});
|
|
94
94
|
});
|
|
95
95
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import { renderHook } from "@testing-library/react-
|
|
3
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
4
4
|
import { Provider } from "react-redux";
|
|
5
5
|
import { createStore } from "redux";
|
|
6
6
|
|
|
@@ -10,9 +10,6 @@ describe("useEntryScreenId", () => {
|
|
|
10
10
|
const mappedScreenId = "mapped-id";
|
|
11
11
|
|
|
12
12
|
const initialState = {
|
|
13
|
-
rivers: {
|
|
14
|
-
[mappedScreenId]: { id: mappedScreenId, type: "any" },
|
|
15
|
-
},
|
|
16
13
|
contentTypes: { mappedEntry: { screen_id: mappedScreenId } },
|
|
17
14
|
};
|
|
18
15
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { renderHook } from "@testing-library/react-
|
|
1
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
import * as zappPipesModule from "@applicaster/zapp-react-native-redux/ZappPipes";
|
|
4
4
|
import * as reactReduxModules from "react-redux";
|
|
@@ -50,16 +50,6 @@ const mockZappPipesData = {
|
|
|
50
50
|
url: "test://testfakeurl",
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
const createWrapper = (
|
|
54
|
-
getStore: () => any
|
|
55
|
-
): React.FC<{ children: React.ReactNode }> => {
|
|
56
|
-
const Wrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => (
|
|
57
|
-
<WrappedWithProviders store={getStore()}>{children}</WrappedWithProviders>
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
return Wrapper;
|
|
61
|
-
};
|
|
62
|
-
|
|
63
53
|
describe("useFeedLoader", () => {
|
|
64
54
|
describe("with cached feed url", () => {
|
|
65
55
|
const store = {
|
|
@@ -67,7 +57,11 @@ describe("useFeedLoader", () => {
|
|
|
67
57
|
zappPipes: { "test://testfakeurl": mockZappPipesData },
|
|
68
58
|
};
|
|
69
59
|
|
|
70
|
-
const wrapper =
|
|
60
|
+
const wrapper: React.FC<any> = ({ children, ...props }) => (
|
|
61
|
+
<WrappedWithProviders store={props.store || store}>
|
|
62
|
+
{children}
|
|
63
|
+
</WrappedWithProviders>
|
|
64
|
+
);
|
|
71
65
|
|
|
72
66
|
it("returns cached feed", () => {
|
|
73
67
|
const { result } = renderHook(
|
|
@@ -115,6 +109,12 @@ describe("useFeedLoader", () => {
|
|
|
115
109
|
describe("without cached feeds", () => {
|
|
116
110
|
const feedUrl = "test://testfakeurl2";
|
|
117
111
|
|
|
112
|
+
const wrapper: React.FC<any> = ({ children, ...props }) => (
|
|
113
|
+
<WrappedWithProviders store={props.store}>
|
|
114
|
+
{children}
|
|
115
|
+
</WrappedWithProviders>
|
|
116
|
+
);
|
|
117
|
+
|
|
118
118
|
it("It loads data for new url and returns it", () => {
|
|
119
119
|
const useDispatchSpy = jest
|
|
120
120
|
.spyOn(reactReduxModules, "useDispatch")
|
|
@@ -129,12 +129,9 @@ describe("useFeedLoader", () => {
|
|
|
129
129
|
zappPipes: { "test://testfakeurl": "foobar" },
|
|
130
130
|
};
|
|
131
131
|
|
|
132
|
-
let store = initialStore;
|
|
133
|
-
const wrapper = createWrapper(() => store);
|
|
134
|
-
|
|
135
132
|
const { result, rerender } = renderHook(
|
|
136
|
-
(
|
|
137
|
-
{ wrapper, initialProps: {
|
|
133
|
+
() => useFeedLoader({ feedUrl: "test://testfakeurl2" }),
|
|
134
|
+
{ wrapper, initialProps: { store: initialStore } }
|
|
138
135
|
);
|
|
139
136
|
|
|
140
137
|
expect(result.current.data).toBeNull();
|
|
@@ -153,8 +150,7 @@ describe("useFeedLoader", () => {
|
|
|
153
150
|
zappPipes: { "test://testfakeurl2": mockZappPipesData },
|
|
154
151
|
};
|
|
155
152
|
|
|
156
|
-
store
|
|
157
|
-
rerender({ feedUrl });
|
|
153
|
+
rerender({ store: store2 });
|
|
158
154
|
|
|
159
155
|
expect(R.omit(["reloadData", "loadNext"], result.current)).toEqual(
|
|
160
156
|
mockZappPipesData
|
|
@@ -178,12 +174,9 @@ describe("useFeedLoader", () => {
|
|
|
178
174
|
zappPipes: { "test://testfakeurl": "foobar" },
|
|
179
175
|
};
|
|
180
176
|
|
|
181
|
-
let store = initialStore;
|
|
182
|
-
const wrapper = createWrapper(() => store);
|
|
183
|
-
|
|
184
177
|
const { result, rerender } = renderHook(
|
|
185
|
-
(
|
|
186
|
-
{ wrapper, initialProps: {
|
|
178
|
+
() => useFeedLoader({ feedUrl: "test://testfakeurl2" }),
|
|
179
|
+
{ wrapper, initialProps: { store: initialStore } }
|
|
187
180
|
);
|
|
188
181
|
|
|
189
182
|
expect(result.current.data).toBeNull();
|
|
@@ -205,8 +198,7 @@ describe("useFeedLoader", () => {
|
|
|
205
198
|
zappPipes: { "test://testfakeurl2": mockZappPipesData },
|
|
206
199
|
};
|
|
207
200
|
|
|
208
|
-
store
|
|
209
|
-
rerender({ feedUrl });
|
|
201
|
+
rerender({ store: store2 });
|
|
210
202
|
|
|
211
203
|
loadPipesDataSpy.mockRestore();
|
|
212
204
|
useDispatchSpy.mockRestore();
|
|
@@ -217,6 +209,12 @@ describe("useFeedLoader", () => {
|
|
|
217
209
|
const feedUrl = "test://testfakeurl";
|
|
218
210
|
const feedUrlWithNext = "test://withnexttestfakeurl";
|
|
219
211
|
|
|
212
|
+
const wrapper: React.FC<any> = ({ children, ...props }) => (
|
|
213
|
+
<WrappedWithProviders store={props.store || {}}>
|
|
214
|
+
{children}
|
|
215
|
+
</WrappedWithProviders>
|
|
216
|
+
);
|
|
217
|
+
|
|
220
218
|
describe("reloadData", () => {
|
|
221
219
|
it("Tries to reload data in the redux store", () => {
|
|
222
220
|
const loadPipesDataSpy = jest
|
|
@@ -232,17 +230,10 @@ describe("useFeedLoader", () => {
|
|
|
232
230
|
zappPipes: { [feedUrl]: "foobar" },
|
|
233
231
|
};
|
|
234
232
|
|
|
235
|
-
const
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const { result } = renderHook(
|
|
240
|
-
({ feedUrl: url }) => useFeedLoader({ feedUrl: url }),
|
|
241
|
-
{
|
|
242
|
-
wrapper,
|
|
243
|
-
initialProps: { feedUrl },
|
|
244
|
-
}
|
|
245
|
-
);
|
|
233
|
+
const { result } = renderHook(() => useFeedLoader({ feedUrl }), {
|
|
234
|
+
wrapper,
|
|
235
|
+
initialProps: { store: initialStore },
|
|
236
|
+
});
|
|
246
237
|
|
|
247
238
|
const { reloadData } = result.current;
|
|
248
239
|
|
|
@@ -288,14 +279,11 @@ describe("useFeedLoader", () => {
|
|
|
288
279
|
zappPipes: { [feedUrlWithNext]: { data: { next: nextUrl } } },
|
|
289
280
|
};
|
|
290
281
|
|
|
291
|
-
const store = initialStore;
|
|
292
|
-
const wrapper = createWrapper(() => store);
|
|
293
|
-
|
|
294
282
|
const { result } = renderHook(
|
|
295
|
-
(
|
|
283
|
+
() => useFeedLoader({ feedUrl: feedUrlWithNext }),
|
|
296
284
|
{
|
|
297
285
|
wrapper,
|
|
298
|
-
initialProps: {
|
|
286
|
+
initialProps: { store: initialStore },
|
|
299
287
|
}
|
|
300
288
|
);
|
|
301
289
|
|
|
@@ -214,7 +214,7 @@ describe("getSearchContext", () => {
|
|
|
214
214
|
});
|
|
215
215
|
|
|
216
216
|
describe("useGetUrlInflater", () => {
|
|
217
|
-
const { renderHook } = require("@testing-library/react-
|
|
217
|
+
const { renderHook } = require("@testing-library/react-hooks");
|
|
218
218
|
|
|
219
219
|
it("returns original url when mapping is not provided", () => {
|
|
220
220
|
const { result } = renderHook(() => useGetUrlInflater(), {
|
|
@@ -151,13 +151,7 @@ export const useBatchLoading = (
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
});
|
|
154
|
-
}, [
|
|
155
|
-
batchComponents,
|
|
156
|
-
feeds,
|
|
157
|
-
getUrl,
|
|
158
|
-
loadPipesDataDispatcher,
|
|
159
|
-
options.riverId,
|
|
160
|
-
]);
|
|
154
|
+
}, [feedUrls, feeds, loadPipesDataDispatcher]);
|
|
161
155
|
|
|
162
156
|
React.useEffect(() => {
|
|
163
157
|
runBatchLoading();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
2
2
|
|
|
3
3
|
export const useEntryScreenId = (entry?: ZappEntry): string | undefined => {
|
|
4
|
-
const contentTypes =
|
|
4
|
+
const { contentTypes } = usePickFromState("contentTypes");
|
|
5
5
|
|
|
6
6
|
if (!entry) {
|
|
7
7
|
return;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { noop } from "@applicaster/zapp-react-native-utils/functionUtils";
|
|
2
2
|
import React from "react";
|
|
3
3
|
|
|
4
|
+
type Return = (index: number) => void;
|
|
5
|
+
|
|
4
6
|
type Predicate = (
|
|
5
|
-
|
|
7
|
+
entry: ZappUIComponentProps["zappPipesData"]["data"]["entry"],
|
|
6
8
|
index: number,
|
|
7
9
|
numberOfColumns: number
|
|
8
10
|
) => boolean;
|
|
@@ -10,15 +12,19 @@ type Predicate = (
|
|
|
10
12
|
type Props = {
|
|
11
13
|
ifNeeded: Predicate;
|
|
12
14
|
loadNextData: () => void;
|
|
13
|
-
|
|
15
|
+
entry: ZappUIComponentProps["zappPipesData"]["data"]["entry"];
|
|
14
16
|
numberOfColumns?: number;
|
|
15
17
|
};
|
|
16
18
|
|
|
17
19
|
const handleLoadNextPage =
|
|
18
20
|
(
|
|
19
|
-
ifNeeded:
|
|
21
|
+
ifNeeded: (
|
|
22
|
+
entry: ZappEntry[],
|
|
23
|
+
index: number,
|
|
24
|
+
numberOfColumns?: number
|
|
25
|
+
) => boolean,
|
|
20
26
|
loadNextData: () => void,
|
|
21
|
-
|
|
27
|
+
entry: ZappEntry[],
|
|
22
28
|
numberOfColumns
|
|
23
29
|
) =>
|
|
24
30
|
(index: number) => {
|
|
@@ -26,7 +32,7 @@ const handleLoadNextPage =
|
|
|
26
32
|
* Lazy-Loading, invoke nextLoadData if we reach the end of the List
|
|
27
33
|
*/
|
|
28
34
|
|
|
29
|
-
if (ifNeeded(
|
|
35
|
+
if (ifNeeded(entry, index, numberOfColumns)) {
|
|
30
36
|
loadNextData();
|
|
31
37
|
}
|
|
32
38
|
};
|
|
@@ -34,14 +40,11 @@ const handleLoadNextPage =
|
|
|
34
40
|
export const useLoadNextPageIfNeeded = ({
|
|
35
41
|
ifNeeded,
|
|
36
42
|
loadNextData = noop,
|
|
37
|
-
|
|
43
|
+
entry,
|
|
38
44
|
numberOfColumns = 0,
|
|
39
|
-
}: Props) => {
|
|
40
|
-
|
|
41
|
-
()
|
|
42
|
-
|
|
43
|
-
[ifNeeded, loadNextData, entryLength, numberOfColumns]
|
|
45
|
+
}: Props): Return => {
|
|
46
|
+
return React.useCallback(
|
|
47
|
+
handleLoadNextPage(ifNeeded, loadNextData, entry, numberOfColumns),
|
|
48
|
+
[ifNeeded, loadNextData, entry, numberOfColumns]
|
|
44
49
|
);
|
|
45
|
-
|
|
46
|
-
return memoFn;
|
|
47
50
|
};
|
package/reactHooks/index.ts
CHANGED