@applicaster/zapp-react-native-utils 12.0.0-alpha.3977160850 → 12.0.0-alpha.4201443043
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/analyticsUtils/AnalyticsEvents/index.ts +6 -0
- package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
- package/analyticsUtils/analyticsPlugins.ts +25 -0
- package/analyticsUtils/events.ts +6 -0
- package/analyticsUtils/index.tsx +6 -0
- package/appUtils/HooksManager/index.js +3 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -3
- package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
- package/appUtils/focusManager/__tests__/index.test.ts +2 -3
- package/appUtils/focusManager/index.ts +76 -56
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +74 -34
- package/appUtils/focusManager/utils/index.ts +100 -0
- package/appUtils/focusManagerAux/index.ts +76 -0
- package/appUtils/focusManagerAux/utils/index.ts +100 -0
- package/appUtils/playerManager/conts.ts +5 -0
- package/appUtils/playerManager/player.ts +35 -0
- package/appUtils/playerManager/playerFactory.ts +12 -10
- package/appUtils/playerManager/playerNative.ts +9 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -1
- package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
- package/arrayUtils/index.ts +5 -0
- package/cellUtils/__tests__/cellUtils.test.ts +9 -20
- package/cellUtils/index.ts +10 -14
- package/dateUtils/index.ts +11 -0
- package/headersUtils/index.ts +1 -0
- package/inflatedUrlUtils/index.ts +4 -4
- package/localizationUtils/__tests__/localizationUtils.test.ts +72 -53
- package/localizationUtils/index.ts +13 -22
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +2 -1
- package/manifestUtils/index.js +5 -1
- package/manifestUtils/secondaryImage/index.js +18 -15
- package/navigationUtils/index.ts +8 -4
- package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
- package/numberUtils/index.ts +9 -18
- package/package.json +2 -2
- package/playerUtils/configurationGenerator.ts +3 -1
- package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +2 -0
- package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +18 -1
- package/reactHooks/cell-click/__tests__/index.test.js +10 -1
- package/reactHooks/cell-click/index.ts +12 -12
- package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
- package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
- package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
- package/reactHooks/feed/useInflatedUrl.ts +44 -15
- package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +44 -29
- package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
- package/reactHooks/layout/types/index.ts +2 -0
- package/reactHooks/layout/useDimensions/useDimensions.ts +13 -7
- package/reactHooks/navigation/__mocks__/index.ts +15 -0
- package/reactHooks/navigation/__mocks__/useNavigation.ts +7 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +26 -8
- package/reactHooks/navigation/index.ts +57 -20
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +3 -1
- package/reactHooks/screen/__mocks__/useScreenContext.ts +3 -1
- package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
- package/reactHooks/screen/index.ts +2 -0
- package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
- package/reactHooks/screen/useScreenContext.ts +4 -4
- package/reactHooks/screen/useScreenData.ts +1 -1
- package/reactHooks/screen/useTargetScreenData.ts +7 -0
- package/reactHooks/useListenEventBusEvent.ts +1 -4
- package/reactHooks/videoModal/index.ts +0 -3
- package/screenState/index.ts +0 -8
- package/stringUtils/index.ts +5 -0
- package/testUtils/getByTestId.ts +14 -0
- package/testUtils/index.tsx +38 -23
- package/types.ts +4 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
2
2
|
/* eslint max-len: off */
|
|
3
3
|
|
|
4
|
-
import React, { useEffect, useMemo } from "react";
|
|
4
|
+
import React, { useContext, useEffect, useMemo } from "react";
|
|
5
5
|
import { BackHandler, InteractionManager, NativeModules } from "react-native";
|
|
6
6
|
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
7
|
+
import { isEmpty } from "ramda";
|
|
7
8
|
|
|
8
9
|
import {
|
|
9
10
|
useContentTypes,
|
|
@@ -12,16 +13,20 @@ import {
|
|
|
12
13
|
import { HooksManager } from "@applicaster/zapp-react-native-utils/appUtils/HooksManager";
|
|
13
14
|
|
|
14
15
|
import { legacyScreenData } from "@applicaster/quick-brick-core/App/NavigationProvider/utils";
|
|
15
|
-
import {
|
|
16
|
+
import {
|
|
17
|
+
LONG_KEY_PRESS_TIMEOUT,
|
|
18
|
+
QUICK_BRICK_NAVBAR,
|
|
19
|
+
QUICK_BRICK_CONTENT,
|
|
20
|
+
} from "@applicaster/quick-brick-core/const";
|
|
16
21
|
import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/ZappHooksModal";
|
|
17
22
|
import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
|
|
18
23
|
import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
|
|
19
24
|
import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
|
|
20
25
|
import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
|
|
21
26
|
import {
|
|
27
|
+
getNavigationProps,
|
|
22
28
|
getRiverFromRoute,
|
|
23
29
|
getTargetRoute,
|
|
24
|
-
getNavigationProps,
|
|
25
30
|
} from "../../navigationUtils";
|
|
26
31
|
import { platformSelect } from "../../reactUtils";
|
|
27
32
|
import { useConnectionInfo } from "../connection";
|
|
@@ -31,6 +36,7 @@ import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
|
31
36
|
import { useNavbarState } from "../screen";
|
|
32
37
|
import { useNavigation } from "./useNavigation";
|
|
33
38
|
import { useModalStore } from "../../modalState";
|
|
39
|
+
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
34
40
|
|
|
35
41
|
export { useNavigation } from "./useNavigation";
|
|
36
42
|
|
|
@@ -147,6 +153,7 @@ export const useRoute = (): {
|
|
|
147
153
|
} => {
|
|
148
154
|
const pathname = usePathname() || "";
|
|
149
155
|
const navigator = useNavigation();
|
|
156
|
+
const screenDataContext = legacyScreenData(useContext(ScreenDataContext));
|
|
150
157
|
|
|
151
158
|
const { plugins, contentTypes, rivers } = usePickFromState([
|
|
152
159
|
"plugins",
|
|
@@ -154,7 +161,6 @@ export const useRoute = (): {
|
|
|
154
161
|
"contentTypes",
|
|
155
162
|
]);
|
|
156
163
|
|
|
157
|
-
const currentStack = navigator.getStackForPathname(pathname);
|
|
158
164
|
const { modalState } = useModalStore();
|
|
159
165
|
const hookModalState = useZappHooksModalState();
|
|
160
166
|
|
|
@@ -176,15 +182,6 @@ export const useRoute = (): {
|
|
|
176
182
|
plugins
|
|
177
183
|
);
|
|
178
184
|
|
|
179
|
-
const currentRouteScreenData = legacyScreenData(
|
|
180
|
-
{
|
|
181
|
-
screen: currentStack?.state?.screen ?? navigator.data?.screen ?? {},
|
|
182
|
-
entry: currentStack?.state?.entry ?? {},
|
|
183
|
-
} as NavigationScreenData,
|
|
184
|
-
|
|
185
|
-
plugins
|
|
186
|
-
);
|
|
187
|
-
|
|
188
185
|
// There are 4 route scenarios
|
|
189
186
|
// For regular screens take date from navigator stack.
|
|
190
187
|
// is path is model grab screenData from modal state
|
|
@@ -211,15 +208,13 @@ export const useRoute = (): {
|
|
|
211
208
|
}
|
|
212
209
|
|
|
213
210
|
if (isHookPathname(pathname)) {
|
|
214
|
-
|
|
215
|
-
"hookPlugin" in currentRouteScreenData
|
|
216
|
-
? currentRouteScreenData
|
|
217
|
-
: navigator.screenData;
|
|
218
|
-
|
|
219
|
-
return { screenData, pathname };
|
|
211
|
+
return { screenData: screenDataContext, pathname };
|
|
220
212
|
}
|
|
221
213
|
|
|
222
|
-
|
|
214
|
+
// Cover cases where screenContext is used before navigation is initialized
|
|
215
|
+
const screenData = isEmpty(screenDataContext)
|
|
216
|
+
? navigator.screenData
|
|
217
|
+
: screenDataContext;
|
|
223
218
|
|
|
224
219
|
return { screenData, pathname };
|
|
225
220
|
};
|
|
@@ -446,3 +441,45 @@ export const useGetBottomTabBarHeight = (): number => {
|
|
|
446
441
|
|
|
447
442
|
return !isBottomBarNavigation ? 0 : tabBarHeight + topBorderWidth;
|
|
448
443
|
};
|
|
444
|
+
|
|
445
|
+
// If current screen is active/focused (visible to the user)
|
|
446
|
+
export const useIsScreenActive = () => {
|
|
447
|
+
const pathname = usePathname();
|
|
448
|
+
const { currentRoute, videoModalState } = useNavigation();
|
|
449
|
+
|
|
450
|
+
if (
|
|
451
|
+
videoModalState.visible &&
|
|
452
|
+
["FULLSCREEN", "MAXIMIZED", "PIP"].includes(videoModalState.mode)
|
|
453
|
+
) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return pathname === currentRoute;
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
type Return = (prefix: string) => string;
|
|
461
|
+
|
|
462
|
+
export const useUniqueRouteSuffix = (): Return => {
|
|
463
|
+
const pathname = usePathname();
|
|
464
|
+
const { currentRoute } = useNavigation();
|
|
465
|
+
|
|
466
|
+
const suffix = `currentRoute:${currentRoute}_pathname:${pathname}`;
|
|
467
|
+
|
|
468
|
+
const withUniqueRouteSuffix = React.useCallback((prefix: string) => {
|
|
469
|
+
return `${prefix}___${suffix}`;
|
|
470
|
+
}, []);
|
|
471
|
+
|
|
472
|
+
return withUniqueRouteSuffix;
|
|
473
|
+
};
|
|
474
|
+
|
|
475
|
+
export const useNavbarId = () => {
|
|
476
|
+
const withUniqueRouteSuffix = useUniqueRouteSuffix();
|
|
477
|
+
|
|
478
|
+
return withUniqueRouteSuffix(QUICK_BRICK_NAVBAR);
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
export const useContentId = () => {
|
|
482
|
+
const withUniqueRouteSuffix = useUniqueRouteSuffix();
|
|
483
|
+
|
|
484
|
+
return withUniqueRouteSuffix(QUICK_BRICK_CONTENT);
|
|
485
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
|
-
import {
|
|
3
|
+
import { cleanup, renderHook } from "@testing-library/react-hooks";
|
|
4
4
|
import configureStore from "redux-mock-store";
|
|
5
5
|
import { Provider } from "react-redux";
|
|
6
6
|
|
|
@@ -12,6 +12,8 @@ jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
|
|
|
12
12
|
useIsRTL: jest.fn(() => mock_rtl_flag),
|
|
13
13
|
}));
|
|
14
14
|
|
|
15
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/navigation");
|
|
16
|
+
|
|
15
17
|
const { useCellResolver } = require("../useCellResolver");
|
|
16
18
|
|
|
17
19
|
describe("cellResolver", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import { View } from "react-native";
|
|
3
3
|
|
|
4
|
-
const mockData
|
|
4
|
+
const mockData = {
|
|
5
5
|
screen: {
|
|
6
6
|
id: "screen-id",
|
|
7
7
|
name: "screen",
|
|
@@ -40,3 +40,5 @@ const mockData: NavigationScreenData = {
|
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export const useScreenContext = jest.fn().mockReturnValue(mockData);
|
|
43
|
+
|
|
44
|
+
export const useNavbarState = () => ({ visible: true });
|
|
@@ -3,23 +3,28 @@ import { Provider } from "react-redux";
|
|
|
3
3
|
import { renderHook } from "@testing-library/react-hooks";
|
|
4
4
|
import configureStore from "redux-mock-store";
|
|
5
5
|
import thunk from "redux-thunk";
|
|
6
|
-
import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
|
|
7
6
|
|
|
8
7
|
const mockStore = configureStore([thunk]);
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
const river_id_2: ZappRiver = {
|
|
10
|
+
name: "River 2",
|
|
11
|
+
id: "A1234",
|
|
12
|
+
home: false,
|
|
13
|
+
home_offline: false,
|
|
14
|
+
supports_offline: false,
|
|
15
|
+
navigations: [],
|
|
16
|
+
hooks: { preload_plugins: [] },
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
jest.mock("../useScreenContext", () => ({
|
|
20
|
+
useScreenContext: () => ({
|
|
21
|
+
screen: river_id_2,
|
|
22
|
+
}),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
const { useCurrentScreenData } = require("../useCurrentScreenData");
|
|
26
|
+
|
|
27
|
+
describe("useScreenData", () => {
|
|
23
28
|
const river_id_1 = { id: "B5678" };
|
|
24
29
|
|
|
25
30
|
const store = mockStore({
|
|
@@ -27,17 +32,10 @@ describe("useScreenData", function () {
|
|
|
27
32
|
});
|
|
28
33
|
|
|
29
34
|
const wrapper: React.FC<any> = ({ children }) => (
|
|
30
|
-
<
|
|
31
|
-
value={{
|
|
32
|
-
currentRoute: "/river/river_id_1/river/river_id_2",
|
|
33
|
-
data: { screen: river_id_2 },
|
|
34
|
-
}}
|
|
35
|
-
>
|
|
36
|
-
<Provider store={store}>{children}</Provider>
|
|
37
|
-
</NavigationContext.Provider>
|
|
35
|
+
<Provider store={store}>{children}</Provider>
|
|
38
36
|
);
|
|
39
37
|
|
|
40
|
-
it("should return river data for the current screen/route",
|
|
38
|
+
it("should return river data for the current screen/route", () => {
|
|
41
39
|
const { result } = renderHook(() => useCurrentScreenData(), { wrapper });
|
|
42
40
|
|
|
43
41
|
expect(result.current).toBe(river_id_2);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useTheme } from "@applicaster/zapp-react-native-utils/theme";
|
|
3
|
+
import { useScreenConfiguration } from "@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration";
|
|
4
|
+
import { ifEmptyUseFallback } from "@applicaster/zapp-react-native-utils/cellUtils";
|
|
5
|
+
|
|
6
|
+
export const useScreenBackgroundColor = (screenId: string): string => {
|
|
7
|
+
const { backgroundColor: screenBackgroundColor } =
|
|
8
|
+
useScreenConfiguration(screenId);
|
|
9
|
+
|
|
10
|
+
const theme = useTheme();
|
|
11
|
+
|
|
12
|
+
const themeBackgroundColor = React.useMemo(
|
|
13
|
+
() => theme.app_background_color,
|
|
14
|
+
[theme.app_background_color]
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
const backgroundColor = ifEmptyUseFallback(
|
|
18
|
+
screenBackgroundColor,
|
|
19
|
+
themeBackgroundColor
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
return backgroundColor;
|
|
23
|
+
};
|
|
@@ -2,11 +2,12 @@ import { useContext, useMemo } from "react";
|
|
|
2
2
|
|
|
3
3
|
import { useModalNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ModalNavigationContext";
|
|
4
4
|
import { useNestedNavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NestedNavigationContext";
|
|
5
|
-
import { useNavigation } from "../navigation";
|
|
5
|
+
import { useNavigation } from "../navigation/useNavigation";
|
|
6
6
|
|
|
7
7
|
import { ScreenContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenContext";
|
|
8
|
+
import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
|
|
8
9
|
|
|
9
|
-
function useScreenContextV2() {
|
|
10
|
+
export function useScreenContextV2() {
|
|
10
11
|
return useContext(ScreenContext);
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -44,9 +45,8 @@ export function useSetNavbarState() {
|
|
|
44
45
|
|
|
45
46
|
export function useScreenContext(): NavigationScreenData {
|
|
46
47
|
const navigator = useNavigation();
|
|
48
|
+
const screenData = useContext(ScreenDataContext);
|
|
47
49
|
|
|
48
|
-
const screenKey = useMemo(() => navigator?.key, [navigator]);
|
|
49
|
-
const screenData = useMemo(() => navigator?.data, [screenKey]);
|
|
50
50
|
const modalScreenData = navigator?.modalData;
|
|
51
51
|
|
|
52
52
|
const isModal = useModalNavigationContext();
|
|
@@ -4,7 +4,7 @@ import { useRivers } from "../state";
|
|
|
4
4
|
|
|
5
5
|
const logger = utilsLogger.addSubsystem("useScreenData");
|
|
6
6
|
|
|
7
|
-
export const useScreenData = (screenId
|
|
7
|
+
export const useScreenData = (screenId: string): ZappRiver => {
|
|
8
8
|
const rivers = useRivers();
|
|
9
9
|
|
|
10
10
|
React.useEffect(() => {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
3
3
|
import * as R from "ramda";
|
|
4
|
+
import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
|
|
4
5
|
|
|
5
6
|
export function getTargetScreenData(
|
|
6
7
|
entry: ZappEntry,
|
|
@@ -35,6 +36,12 @@ export function getTargetScreenData(
|
|
|
35
36
|
return rivers?.[screenId];
|
|
36
37
|
}
|
|
37
38
|
|
|
39
|
+
export function getTargetScreenDataFromEntry(entry: ZappEntry): ZappRiver {
|
|
40
|
+
const { rivers, contentTypes } = appStore.get(["rivers", "contentTypes"]);
|
|
41
|
+
|
|
42
|
+
return getTargetScreenData(entry, rivers, contentTypes);
|
|
43
|
+
}
|
|
44
|
+
|
|
38
45
|
export const useTargetScreenData = (entry: ZappEntry) => {
|
|
39
46
|
const { rivers, contentTypes } = usePickFromState(["rivers", "contentTypes"]);
|
|
40
47
|
|
|
@@ -13,10 +13,7 @@ export const useListenEventBusEvent = (
|
|
|
13
13
|
// TODO: remove after implementing ReactNativeEventBusBridge on iOS
|
|
14
14
|
if (Platform.OS === "android") {
|
|
15
15
|
// subscribe to DeviceEventEmitter using subsciption ID
|
|
16
|
-
const sub = DeviceEventEmitter.addListener(
|
|
17
|
-
subscriptionID,
|
|
18
|
-
handler
|
|
19
|
-
);
|
|
16
|
+
const sub = DeviceEventEmitter.addListener(subscriptionID, handler);
|
|
20
17
|
|
|
21
18
|
// ask native to start routing these events to RN
|
|
22
19
|
ReactNativeEventBusBridge.subscribe(subscriptionID, { [source]: events });
|
|
@@ -2,9 +2,6 @@ import * as R from "ramda";
|
|
|
2
2
|
import { isTV } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
3
3
|
import { useMemoizedIsTablet } from "@applicaster/zapp-react-native-utils/reactHooks/device";
|
|
4
4
|
|
|
5
|
-
import { LogBox } from "react-native";
|
|
6
|
-
LogBox.ignoreAllLogs();
|
|
7
|
-
|
|
8
5
|
import { useMobileOrientationEffect } from "./useMobileOrientationEffect";
|
|
9
6
|
import { noop } from "./utils";
|
|
10
7
|
|
package/screenState/index.ts
CHANGED
|
@@ -49,11 +49,3 @@ export function useScreenState(
|
|
|
49
49
|
setSelectedEntry: (entryId) => setSelectedEntry(screenId, entryId),
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
export const useScreenScrollStore = create<{
|
|
54
|
-
scrollPosition: number;
|
|
55
|
-
scrollingVelocity: number;
|
|
56
|
-
}>(() => ({
|
|
57
|
-
scrollPosition: 0,
|
|
58
|
-
scrollingVelocity: 0,
|
|
59
|
-
}));
|
package/stringUtils/index.ts
CHANGED
|
@@ -152,3 +152,8 @@ export function objectToCamelCase(obj) {
|
|
|
152
152
|
export function isString(value: unknown): value is string {
|
|
153
153
|
return typeof value === "string" || value instanceof String;
|
|
154
154
|
}
|
|
155
|
+
|
|
156
|
+
/** Checks if a value is a non-empty string */
|
|
157
|
+
export function isNotEmptyString(value: unknown): value is string {
|
|
158
|
+
return isString(value) && value.length > 0;
|
|
159
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const getByTestId = (wrapper, testId) => {
|
|
2
|
+
try {
|
|
3
|
+
if (wrapper?.getByTestId) {
|
|
4
|
+
return wrapper?.queryAllByTestId(testId)?.[0] ?? undefined;
|
|
5
|
+
} else if (wrapper?.root?.findByProps) {
|
|
6
|
+
return wrapper.root.findAllByProps({ testID: testId })?.[0] ?? undefined;
|
|
7
|
+
}
|
|
8
|
+
} catch (e) {
|
|
9
|
+
// eslint-disable-next-line no-console
|
|
10
|
+
console.log("getByTestId E:", e);
|
|
11
|
+
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
};
|
package/testUtils/index.tsx
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
|
|
3
|
-
import React from "react";
|
|
3
|
+
import React, { PropsWithChildren } from "react";
|
|
4
4
|
import { View } from "react-native";
|
|
5
5
|
|
|
6
6
|
import { Provider } from "react-redux";
|
|
7
7
|
import thunk from "redux-thunk";
|
|
8
8
|
import configureStore from "redux-mock-store";
|
|
9
|
+
import { SafeAreaProvider } from "react-native-safe-area-context";
|
|
9
10
|
|
|
10
11
|
import { render } from "@testing-library/react-native";
|
|
12
|
+
import { AnalyticsProvider } from "../analyticsUtils";
|
|
13
|
+
|
|
14
|
+
export { getByTestId } from "./getByTestId";
|
|
11
15
|
|
|
12
16
|
/**
|
|
13
17
|
* Function to be used in tandem with enzyme findWhere(node => node.prop('testID') === 'yourID')
|
|
@@ -19,17 +23,6 @@ import { render } from "@testing-library/react-native";
|
|
|
19
23
|
export const testIDEquals = (testId: any): boolean =>
|
|
20
24
|
R.compose(R.equals(testId), R.invoker(1, "prop")("testID"));
|
|
21
25
|
|
|
22
|
-
export const getByTestId = (wrapper, testId) => {
|
|
23
|
-
try {
|
|
24
|
-
return wrapper?.queryAllByTestId(testId)?.[0] ?? undefined;
|
|
25
|
-
} catch (e) {
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
|
-
console.log("getByTestId E:", e);
|
|
28
|
-
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
26
|
/** Helper function for react-test-renderer, accepts type and renderer
|
|
34
27
|
* * @param {*} type React Component type instance or name of component
|
|
35
28
|
* * @param {*} renderer renderer instance
|
|
@@ -45,11 +38,11 @@ export const findByType = (type, renderer) => {
|
|
|
45
38
|
export function createComponentMock(mockName, hasChildren = false) {
|
|
46
39
|
return hasChildren
|
|
47
40
|
? jest.fn(({ children }) => (
|
|
48
|
-
<View
|
|
41
|
+
<View testID={mockName}>
|
|
49
42
|
{typeof children === "function" ? children() : children}
|
|
50
43
|
</View>
|
|
51
44
|
))
|
|
52
|
-
: jest.fn(() => <View
|
|
45
|
+
: jest.fn(() => <View testID={mockName} />);
|
|
53
46
|
}
|
|
54
47
|
|
|
55
48
|
const initialState = {
|
|
@@ -62,16 +55,34 @@ const initialState = {
|
|
|
62
55
|
AppContainer: createComponentMock("appContainer", true),
|
|
63
56
|
DisplayError: createComponentMock("displayError"),
|
|
64
57
|
},
|
|
65
|
-
rivers:
|
|
58
|
+
rivers: { id: "A1234", home: true },
|
|
66
59
|
appSettings: {},
|
|
67
60
|
plugins: [],
|
|
68
|
-
appState: { appReady: true },
|
|
61
|
+
appState: { appReady: true, appLaunched: true },
|
|
62
|
+
appData: { layoutVersion: "v1" },
|
|
63
|
+
contentTypes: null,
|
|
69
64
|
};
|
|
70
65
|
|
|
71
|
-
export const WrappedWithProviders = ({
|
|
72
|
-
|
|
66
|
+
export const WrappedWithProviders = ({
|
|
67
|
+
children,
|
|
68
|
+
store: storeObj = {},
|
|
69
|
+
}: any) => {
|
|
70
|
+
const _store = configureStore([thunk])(
|
|
71
|
+
R.mergeDeepWith(R.concat, { ...initialState }, storeObj)
|
|
72
|
+
);
|
|
73
73
|
|
|
74
|
-
return
|
|
74
|
+
return (
|
|
75
|
+
<SafeAreaProvider
|
|
76
|
+
initialMetrics={{
|
|
77
|
+
insets: { top: 0, left: 0, right: 0, bottom: 0 },
|
|
78
|
+
frame: { x: 0, y: 0, width: 0, height: 0 },
|
|
79
|
+
}}
|
|
80
|
+
>
|
|
81
|
+
<Provider store={_store}>
|
|
82
|
+
<AnalyticsProvider>{children}</AnalyticsProvider>
|
|
83
|
+
</Provider>
|
|
84
|
+
</SafeAreaProvider>
|
|
85
|
+
);
|
|
75
86
|
};
|
|
76
87
|
|
|
77
88
|
/**
|
|
@@ -80,8 +91,12 @@ export const WrappedWithProviders = ({ children, store = {} }: any) => {
|
|
|
80
91
|
* @param store optional store to pass to the provider
|
|
81
92
|
* @returns
|
|
82
93
|
*/
|
|
83
|
-
export const renderWithProviders = (component,
|
|
84
|
-
return render(
|
|
85
|
-
|
|
86
|
-
|
|
94
|
+
export const renderWithProviders = (component, storeObj?: unknown) => {
|
|
95
|
+
return render(component, {
|
|
96
|
+
wrapper: function TestWrapper({ children }: PropsWithChildren<any>) {
|
|
97
|
+
return (
|
|
98
|
+
<WrappedWithProviders store={storeObj}>{children}</WrappedWithProviders>
|
|
99
|
+
);
|
|
100
|
+
},
|
|
101
|
+
});
|
|
87
102
|
};
|