@applicaster/zapp-react-native-utils 15.0.0-alpha.3752284136 → 15.0.0-alpha.3842304615

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 (130) hide show
  1. package/README.md +0 -6
  2. package/actionUtils/index.ts +7 -0
  3. package/actionsExecutor/ActionExecutorContext.tsx +83 -6
  4. package/adsUtils/__tests__/createVMAP.test.ts +419 -0
  5. package/analyticsUtils/analyticsMapper.ts +10 -2
  6. package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
  7. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
  8. package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
  9. package/appUtils/HooksManager/index.ts +35 -0
  10. package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
  11. package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
  12. package/appUtils/contextKeysManager/contextResolver.ts +51 -22
  13. package/appUtils/contextKeysManager/index.ts +65 -10
  14. package/appUtils/focusManager/treeDataStructure/Tree/__tests__/Tree.test.js +46 -0
  15. package/appUtils/focusManager/treeDataStructure/Tree/index.js +18 -18
  16. package/appUtils/focusManagerAux/utils/index.ts +12 -6
  17. package/appUtils/focusManagerAux/utils/utils.ios.ts +6 -3
  18. package/appUtils/localizationsHelper.ts +4 -0
  19. package/appUtils/playerManager/index.ts +9 -0
  20. package/appUtils/playerManager/player.ts +1 -1
  21. package/appUtils/playerManager/playerNative.ts +2 -1
  22. package/appUtils/playerManager/usePlayer.tsx +5 -3
  23. package/cellUtils/__tests__/cellUtils.test.ts +39 -0
  24. package/cellUtils/index.ts +11 -1
  25. package/cloudEventsUtils/__tests__/index.test.ts +529 -0
  26. package/cloudEventsUtils/index.ts +65 -1
  27. package/componentsUtils/index.ts +8 -0
  28. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
  29. package/configurationUtils/index.ts +17 -11
  30. package/dateUtils/__tests__/dayjs.test.ts +327 -0
  31. package/dateUtils/index.ts +2 -0
  32. package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
  33. package/errorUtils/__tests__/GeneralError.test.ts +97 -0
  34. package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
  35. package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
  36. package/errorUtils/__tests__/NetworkError.test.ts +202 -0
  37. package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
  38. package/errorUtils/__tests__/invariant.test.ts +112 -0
  39. package/headersUtils/__tests__/headersUtils.test.js +11 -1
  40. package/headersUtils/index.ts +2 -1
  41. package/manifestUtils/_internals/__tests__/index.test.js +41 -0
  42. package/manifestUtils/_internals/index.js +33 -0
  43. package/manifestUtils/defaultManifestConfigurations/player.js +35 -16
  44. package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +49 -0
  45. package/manifestUtils/fieldUtils/index.js +54 -0
  46. package/manifestUtils/index.js +2 -0
  47. package/manifestUtils/keys.js +228 -0
  48. package/manifestUtils/mobileAction/button/__tests__/mobileActionButton.test.js +168 -0
  49. package/manifestUtils/mobileAction/button/index.js +140 -0
  50. package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +102 -0
  51. package/manifestUtils/mobileAction/container/index.js +73 -0
  52. package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +127 -0
  53. package/manifestUtils/mobileAction/groups/defaults.js +76 -0
  54. package/manifestUtils/mobileAction/groups/index.js +80 -0
  55. package/manifestUtils/platformIsTV.js +13 -0
  56. package/navigationUtils/index.ts +15 -5
  57. package/numberUtils/__tests__/toNumber.test.ts +27 -0
  58. package/numberUtils/__tests__/toPositiveNumber.test.ts +193 -0
  59. package/numberUtils/index.ts +23 -1
  60. package/package.json +3 -3
  61. package/pluginUtils/index.ts +4 -5
  62. package/reactHooks/analytics/__tests__/useSendAnalyticsOnPress.test.ts +537 -0
  63. package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
  64. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  65. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
  66. package/reactHooks/casting/index.ts +1 -0
  67. package/reactHooks/casting/useIsCasting.tsx +57 -0
  68. package/reactHooks/cell-click/__tests__/index.test.js +1 -3
  69. package/reactHooks/cell-click/index.ts +2 -1
  70. package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
  71. package/reactHooks/connection/__tests__/index.test.js +1 -1
  72. package/reactHooks/dev/__tests__/useReRenderLog.test.ts +188 -0
  73. package/reactHooks/device/useIsTablet.tsx +14 -19
  74. package/reactHooks/events/index.ts +20 -0
  75. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
  76. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
  77. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +1 -1
  78. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
  79. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +1 -1
  80. package/reactHooks/feed/index.ts +0 -2
  81. package/reactHooks/feed/useInflatedUrl.ts +1 -1
  82. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
  83. package/reactHooks/index.ts +2 -0
  84. package/reactHooks/layout/__tests__/index.test.tsx +1 -1
  85. package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
  86. package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
  87. package/reactHooks/navigation/index.ts +15 -4
  88. package/reactHooks/navigation/useRoute.ts +3 -1
  89. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
  90. package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
  91. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
  92. package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
  93. package/reactHooks/resolvers/useComponentResolver.ts +13 -3
  94. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +1 -1
  95. package/reactHooks/screen/__tests__/useCurrentScreenIsHook.test.ts +103 -0
  96. package/reactHooks/screen/__tests__/useCurrentScreenIsStartupHook.test.ts +94 -0
  97. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
  98. package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
  99. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +1 -1
  100. package/reactHooks/screen/index.ts +4 -0
  101. package/reactHooks/screen/useCurrentScreenIsHook.ts +9 -0
  102. package/reactHooks/screen/useCurrentScreenIsStartupHook.ts +8 -0
  103. package/reactHooks/state/__tests__/useComponentScreenState.test.ts +246 -0
  104. package/reactHooks/state/index.ts +2 -0
  105. package/reactHooks/state/useComponentScreenState.ts +45 -0
  106. package/reactHooks/state/useRefWithInitialValue.ts +10 -0
  107. package/reactHooks/ui/__tests__/useFadeOutWhenBlurred.test.ts +580 -0
  108. package/reactHooks/utils/__tests__/index.test.js +1 -1
  109. package/rectUtils/__tests__/index.test.ts +549 -0
  110. package/rectUtils/index.ts +2 -2
  111. package/refreshUtils/RefreshCoordinator/__tests__/refreshCoordinator.test.ts +206 -0
  112. package/refreshUtils/RefreshCoordinator/index.ts +245 -0
  113. package/refreshUtils/RefreshCoordinator/utils/__tests__/getDataRefreshConfig.test.ts +104 -0
  114. package/refreshUtils/RefreshCoordinator/utils/index.ts +29 -0
  115. package/screenPickerUtils/__tests__/index.test.ts +333 -0
  116. package/screenPickerUtils/index.ts +5 -0
  117. package/screenState/__tests__/index.test.ts +1 -1
  118. package/screenUtils/index.ts +3 -0
  119. package/services/storageServiceSync.web.ts +1 -1
  120. package/time/__tests__/BackgroundTimer.test.ts +156 -0
  121. package/time/__tests__/Timer.test.ts +236 -0
  122. package/typeGuards/__tests__/isString.test.ts +21 -0
  123. package/typeGuards/index.ts +4 -0
  124. package/utils/__tests__/clone.test.ts +158 -0
  125. package/utils/__tests__/path.test.ts +7 -0
  126. package/utils/clone.ts +7 -0
  127. package/utils/index.ts +2 -1
  128. package/reactHooks/componentsMap/index.ts +0 -55
  129. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +0 -75
  130. package/reactHooks/feed/useFeedRefresh.tsx +0 -65
@@ -1,20 +1,24 @@
1
1
  import { reactHooksLogger } from "../../logger";
2
- import { useZappHooksModalState } from "@applicaster/zapp-react-dom-ui-components/Components/ZappHooksModal/hooks/useZappHooksModalState";
2
+ import { useZappHookModalStore } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
3
3
 
4
4
  const logger = reactHooksLogger.addSubsystem("useHookModalScreenData");
5
5
 
6
6
  type VariousScreenData = LegacyNavigationScreenData | ZappRiver | ZappEntry;
7
7
 
8
- export const useHookModalScreenData = (): VariousScreenData | undefined => {
9
- const hookModalState = useZappHooksModalState();
8
+ export const useHookModalScreenData = (
9
+ skipSubscription: boolean
10
+ ): VariousScreenData | undefined => {
11
+ const hookModalState = useZappHookModalStore((state) =>
12
+ skipSubscription ? undefined : state.state
13
+ );
10
14
 
11
- if (!hookModalState.state?.screenData) {
15
+ if (!hookModalState?.screenData) {
12
16
  return;
13
17
  }
14
18
 
15
19
  try {
16
- const screenData = hookModalState.state.screenData?.payload;
17
- const hookPlugin = hookModalState.state.screenData.hookPlugin;
20
+ const screenData = hookModalState.screenData?.payload;
21
+ const hookPlugin = hookModalState.screenData.hookPlugin;
18
22
 
19
23
  if (hookPlugin?.screen_id) {
20
24
  return {
@@ -23,7 +27,7 @@ export const useHookModalScreenData = (): VariousScreenData | undefined => {
23
27
  };
24
28
  }
25
29
 
26
- return hookModalState.state.screenData?.payload;
30
+ return hookModalState.screenData?.payload;
27
31
  } catch (error) {
28
32
  logger.error({
29
33
  message: "Hook modal screen data creation failed",
@@ -34,6 +38,6 @@ export const useHookModalScreenData = (): VariousScreenData | undefined => {
34
38
  jsOnly: true,
35
39
  });
36
40
 
37
- return hookModalState.state.screenData?.payload;
41
+ return hookModalState.screenData?.payload;
38
42
  }
39
43
  };
@@ -15,3 +15,5 @@ export * from "./device";
15
15
  export * from "./screen";
16
16
 
17
17
  export * from "./state";
18
+
19
+ export * from "./events";
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
 
3
- import { cleanup, renderHook } from "@testing-library/react-hooks";
3
+ import { cleanup, renderHook } from "@testing-library/react-native";
4
4
  import { Provider } from "react-redux";
5
5
  import configureStore from "redux-mock-store";
6
6
 
@@ -1,4 +1,4 @@
1
- import { renderHook } from "@testing-library/react-hooks";
1
+ import { renderHook } from "@testing-library/react-native";
2
2
  import configureStore from "redux-mock-store";
3
3
 
4
4
  const mockStore = configureStore();
@@ -1,11 +1,10 @@
1
1
  import React from "react";
2
2
  import { PathnameContext } from "@applicaster/zapp-react-native-ui-components/Contexts/PathnameContext";
3
- import { renderHook } from "@testing-library/react-hooks";
3
+ import { renderHook } from "@testing-library/react-native";
4
4
  import { isNavBarVisible, useRoute } from "../";
5
5
  import { Provider } from "react-redux";
6
6
  import configureMockStore from "redux-mock-store";
7
7
  import { NavigationContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NavigationContext";
8
- import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
9
8
  import { ROUTE_TYPES } from "@applicaster/zapp-react-native-utils/navigationUtils/routeTypes";
10
9
  import { ScreenDataContext } from "@applicaster/zapp-react-native-ui-components/Contexts/ScreenDataContext";
11
10
 
@@ -83,10 +82,44 @@ const hookModalContextState = {
83
82
  },
84
83
  setState: jest.fn(),
85
84
  resetState: jest.fn(),
85
+ hookPresentationMode: null,
86
86
  };
87
87
 
88
88
  const hooksModalPathname = `${ROUTE_TYPES.HOOKS_MODAL}/${hookModalContextState.state.screenData.payload.id}`;
89
89
  const videoModalPathname = `${ROUTE_TYPES.VIDEO_MODAL}/${videoModalNavigator.videoModalState.item.id}`;
90
+
91
+ jest.mock(
92
+ "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext",
93
+ () => {
94
+ const mockState = {
95
+ isRunningInBackground: false,
96
+ setIsRunningInBackground: jest.fn(),
97
+ setIsPresentingFullScreen: jest.fn(),
98
+ isPresentationFullScreen: true,
99
+ isHooksExecutionInProgress: true,
100
+ setIsHooksExecutionInProgress: jest.fn(),
101
+ state: {
102
+ path: "/home",
103
+ screenData: { payload: { id: "hookExecutedInModal" } },
104
+ },
105
+ setState: jest.fn(),
106
+ resetState: jest.fn(),
107
+ hookPresentationMode: null,
108
+ };
109
+
110
+ const mockHook = jest.fn((selector) => {
111
+ return selector ? selector(mockState) : mockState;
112
+ }) as jest.MockedFunction<any> & { getState: () => typeof mockState };
113
+
114
+ mockHook.getState = jest.fn(() => mockState);
115
+
116
+ return {
117
+ useZappHookModalStore: mockHook,
118
+ zappHookModalStore: mockHook,
119
+ };
120
+ }
121
+ );
122
+
90
123
  const mockStore = configureMockStore();
91
124
 
92
125
  const store = mockStore({
@@ -125,13 +158,11 @@ const videoModalWrapper = ({ children }) => (
125
158
 
126
159
  const hookModalWrapper = ({ children }) => (
127
160
  <Provider store={store}>
128
- <ZappHookModalContext.ReactContext.Provider value={hookModalContextState}>
129
- <NavigationContext.Provider value={hookModalNavigator}>
130
- <PathnameContext.Provider value={hooksModalPathname}>
131
- {children}
132
- </PathnameContext.Provider>
133
- </NavigationContext.Provider>
134
- </ZappHookModalContext.ReactContext.Provider>
161
+ <NavigationContext.Provider value={hookModalNavigator}>
162
+ <PathnameContext.Provider value={hooksModalPathname}>
163
+ {children}
164
+ </PathnameContext.Provider>
165
+ </NavigationContext.Provider>
135
166
  </Provider>
136
167
  );
137
168
 
@@ -1,5 +1,6 @@
1
- import { useContext, useEffect, useMemo, useRef } from "react";
1
+ import { useEffect, useMemo, useRef } from "react";
2
2
  import { BackHandler } from "react-native";
3
+ import { shallow } from "zustand/shallow";
3
4
 
4
5
  import {
5
6
  useContentTypes,
@@ -8,13 +9,13 @@ import {
8
9
  import { HooksManager } from "@applicaster/zapp-react-native-utils/appUtils/HooksManager";
9
10
 
10
11
  import { LONG_KEY_PRESS_TIMEOUT } from "@applicaster/quick-brick-core/const";
11
- import { ZappHookModalContext } from "@applicaster/zapp-react-native-ui-components/Contexts";
12
- import { HookModalContextT } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
12
+ import { useZappHookModalStore } from "@applicaster/zapp-react-native-ui-components/Contexts/ZappHookModalContext";
13
13
  import { HOOKS_EVENTS } from "../../appUtils/HooksManager/constants";
14
14
  import { getRiverFromRoute, getTargetRoute } from "../../navigationUtils";
15
15
  import { useConnectionInfo } from "../connection";
16
16
 
17
17
  import { isTV, isWeb } from "@applicaster/zapp-react-native-utils/reactUtils";
18
+ import { pick } from "@applicaster/zapp-react-native-utils/utils";
18
19
  import { useNavbarState } from "../screen";
19
20
  import { useRivers } from "../state";
20
21
  import { useLayoutVersion } from "../layout";
@@ -168,7 +169,17 @@ export const useZappHooksForEntry = (
168
169
  setIsHooksExecutionInProgress,
169
170
  setIsPresentingFullScreen,
170
171
  setIsRunningInBackground,
171
- }: HookModalContextT = useContext(ZappHookModalContext.ReactContext);
172
+ } = useZappHookModalStore(
173
+ (state) =>
174
+ pick(state, [
175
+ "setState",
176
+ "resetState",
177
+ "setIsHooksExecutionInProgress",
178
+ "setIsPresentingFullScreen",
179
+ "setIsRunningInBackground",
180
+ ]),
181
+ shallow
182
+ );
172
183
 
173
184
  const plugins = usePlugins();
174
185
  const rivers = useRivers();
@@ -54,7 +54,9 @@ export const useRoute = (
54
54
 
55
55
  const modalScreenData = modalState.screen;
56
56
 
57
- const hookModalScreenData = useHookModalScreenData();
57
+ const hookModalScreenData = useHookModalScreenData(
58
+ !isHookModalPathname(pathname)
59
+ );
58
60
 
59
61
  const videoModalScreenData =
60
62
  navigator?.videoModalState?.item &&
@@ -1,4 +1,4 @@
1
- import { act, renderHook } from "@testing-library/react-hooks";
1
+ import { act, renderHook } from "@testing-library/react-native";
2
2
  import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
3
3
 
4
4
  import { ON_HOLD_INTERVAL, SEEK_TYPE, SKIP_TIME_BASE } from "../const";
@@ -1,4 +1,4 @@
1
- import { renderHook } from "@testing-library/react-hooks";
1
+ import { renderHook } from "@testing-library/react-native";
2
2
  import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils/playerManager";
3
3
  import { useTapSeek } from "../useTapSeek";
4
4
 
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { View } from "react-native";
3
- import { cleanup, renderHook } from "@testing-library/react-hooks";
3
+ import { cleanup, renderHook } from "@testing-library/react-native";
4
4
  import configureStore from "redux-mock-store";
5
5
  import { Provider } from "react-redux";
6
6
 
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { renderHook, cleanup } from "@testing-library/react-hooks";
2
+ import { renderHook, cleanup } from "@testing-library/react-native";
3
3
  import configureStore from "redux-mock-store";
4
4
  import { Provider } from "react-redux";
5
5
 
@@ -1,11 +1,13 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
2
  import * as React from "react";
3
3
 
4
+ import { coreLogger } from "@applicaster/zapp-react-native-utils/logger";
5
+
4
6
  import { findComponentByType } from "@applicaster/zapp-react-native-utils/pluginUtils";
5
7
  import {
6
- usePlugins,
7
- useAppSelector,
8
8
  selectComponents,
9
+ useAppSelector,
10
+ usePlugins,
9
11
  } from "@applicaster/zapp-react-native-redux";
10
12
 
11
13
  type Decorator = (component: React.Component<any>) => React.Component<any>;
@@ -23,7 +25,7 @@ export function useComponentResolver(
23
25
 
24
26
  const components = useAppSelector(selectComponents);
25
27
 
26
- return React.useMemo(
28
+ const component = React.useMemo(
27
29
  () =>
28
30
  findComponentByType({
29
31
  components,
@@ -33,4 +35,12 @@ export function useComponentResolver(
33
35
  }),
34
36
  watchers
35
37
  );
38
+
39
+ if (!component) {
40
+ coreLogger.warn({
41
+ message: `useComponentResolver: Component of type ${componentType} not found`,
42
+ });
43
+ }
44
+
45
+ return component;
36
46
  }
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { Provider } from "react-redux";
3
- import { renderHook } from "@testing-library/react-hooks";
3
+ import { renderHook } from "@testing-library/react-native";
4
4
  import configureStore from "redux-mock-store";
5
5
  import { thunk } from "redux-thunk";
6
6
 
@@ -0,0 +1,103 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+ import { useCurrentScreenIsHook } from "../useCurrentScreenIsHook";
3
+
4
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
5
+ import { last } from "@applicaster/zapp-react-native-utils/utils";
6
+ import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
7
+
8
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks");
9
+ jest.mock("@applicaster/zapp-react-native-utils/utils");
10
+ jest.mock("@applicaster/zapp-react-native-utils/booleanUtils");
11
+
12
+ const mockUseNavigation = useNavigation as jest.Mock;
13
+ const mockLast = last as jest.Mock;
14
+ const mockToBoolean = toBooleanWithDefaultFalse as jest.Mock;
15
+
16
+ describe("useCurrentScreenIsHook", () => {
17
+ beforeEach(() => {
18
+ jest.clearAllMocks();
19
+
20
+ // sensible defaults
21
+ mockUseNavigation.mockReturnValue({ mainStack: [] });
22
+ mockLast.mockReturnValue(undefined);
23
+ mockToBoolean.mockReturnValue(false);
24
+ });
25
+
26
+ it("returns true when last route includes 'hook'", () => {
27
+ const stack = [{ route: "some-hook-screen" }];
28
+
29
+ mockUseNavigation.mockReturnValue({ mainStack: stack });
30
+ mockLast.mockReturnValue(stack[0]);
31
+ mockToBoolean.mockReturnValue(true);
32
+
33
+ const { result } = renderHook(() => useCurrentScreenIsHook());
34
+
35
+ expect(mockLast).toHaveBeenCalledWith(stack);
36
+ expect(mockToBoolean).toHaveBeenCalledWith(true);
37
+ expect(result.current).toBe(true);
38
+ });
39
+
40
+ it("returns false when last route does not include 'hook'", () => {
41
+ const stack = [{ route: "home-screen" }];
42
+
43
+ mockUseNavigation.mockReturnValue({ mainStack: stack });
44
+ mockLast.mockReturnValue(stack[0]);
45
+ mockToBoolean.mockReturnValue(false);
46
+
47
+ const { result } = renderHook(() => useCurrentScreenIsHook());
48
+
49
+ expect(mockToBoolean).toHaveBeenCalledWith(false);
50
+ expect(result.current).toBe(false);
51
+ });
52
+
53
+ it("returns false when route is undefined", () => {
54
+ const stack = [{}];
55
+
56
+ mockUseNavigation.mockReturnValue({ mainStack: stack });
57
+ mockLast.mockReturnValue(stack[0]);
58
+ mockToBoolean.mockReturnValue(false);
59
+
60
+ const { result } = renderHook(() => useCurrentScreenIsHook());
61
+
62
+ expect(mockToBoolean).toHaveBeenCalledWith(undefined);
63
+ expect(result.current).toBe(false);
64
+ });
65
+
66
+ it("returns false when last(mainStack) is undefined (empty stack)", () => {
67
+ mockUseNavigation.mockReturnValue({ mainStack: [] });
68
+ mockLast.mockReturnValue(undefined);
69
+ mockToBoolean.mockReturnValue(false);
70
+
71
+ const { result } = renderHook(() => useCurrentScreenIsHook());
72
+
73
+ expect(mockLast).toHaveBeenCalledWith([]);
74
+ expect(mockToBoolean).toHaveBeenCalledWith(undefined);
75
+ expect(result.current).toBe(false);
76
+ });
77
+
78
+ it("uses default empty array when mainStack is undefined", () => {
79
+ mockUseNavigation.mockReturnValue({});
80
+ mockLast.mockReturnValue(undefined);
81
+ mockToBoolean.mockReturnValue(false);
82
+
83
+ const { result } = renderHook(() => useCurrentScreenIsHook());
84
+
85
+ expect(mockLast).toHaveBeenCalledWith([]);
86
+ expect(result.current).toBe(false);
87
+ });
88
+
89
+ it("passes correct boolean result from includes('hook')", () => {
90
+ const stack = [{ route: "hook" }];
91
+
92
+ mockUseNavigation.mockReturnValue({ mainStack: stack });
93
+ mockLast.mockReturnValue(stack[0]);
94
+
95
+ // simulate actual includes result flowing through
96
+ mockToBoolean.mockImplementation((val) => Boolean(val));
97
+
98
+ const { result } = renderHook(() => useCurrentScreenIsHook());
99
+
100
+ expect(mockToBoolean).toHaveBeenCalledWith(true);
101
+ expect(result.current).toBe(true);
102
+ });
103
+ });
@@ -0,0 +1,94 @@
1
+ import { renderHook } from "@testing-library/react-native";
2
+ import { useCurrentScreenIsStartupHook } from "../useCurrentScreenIsStartupHook";
3
+
4
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
5
+ import { isFilledArray } from "@applicaster/zapp-react-native-utils/arrayUtils";
6
+
7
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks");
8
+ jest.mock("@applicaster/zapp-react-native-utils/arrayUtils");
9
+
10
+ const mockUseNavigation = useNavigation as jest.Mock;
11
+ const mockIsFilledArray = isFilledArray as jest.Mock;
12
+
13
+ describe("useCurrentScreenIsStartupHook", () => {
14
+ beforeEach(() => {
15
+ jest.clearAllMocks();
16
+ });
17
+
18
+ it("returns true when startUpHooks is a filled array", () => {
19
+ mockUseNavigation.mockReturnValue({
20
+ startUpHooks: ["hook1"],
21
+ });
22
+
23
+ mockIsFilledArray.mockReturnValue(true);
24
+
25
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
26
+
27
+ expect(result.current).toBe(true);
28
+ expect(mockIsFilledArray).toHaveBeenCalledWith(["hook1"]);
29
+ });
30
+
31
+ it('returns true when startUpHooks is "in_process"', () => {
32
+ mockUseNavigation.mockReturnValue({
33
+ startUpHooks: "in_process",
34
+ });
35
+
36
+ mockIsFilledArray.mockReturnValue(false);
37
+
38
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
39
+
40
+ expect(result.current).toBe(true);
41
+ expect(mockIsFilledArray).toHaveBeenCalledWith("in_process");
42
+ });
43
+
44
+ it("returns false when startUpHooks is empty array", () => {
45
+ mockUseNavigation.mockReturnValue({
46
+ startUpHooks: [],
47
+ });
48
+
49
+ mockIsFilledArray.mockReturnValue(false);
50
+
51
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
52
+
53
+ expect(result.current).toBe(false);
54
+ expect(mockIsFilledArray).toHaveBeenCalledWith([]);
55
+ });
56
+
57
+ it("returns false when startUpHooks is undefined", () => {
58
+ mockUseNavigation.mockReturnValue({
59
+ startUpHooks: undefined,
60
+ });
61
+
62
+ mockIsFilledArray.mockReturnValue(false);
63
+
64
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
65
+
66
+ expect(result.current).toBe(false);
67
+ expect(mockIsFilledArray).toHaveBeenCalledWith(undefined);
68
+ });
69
+
70
+ it("returns false when startUpHooks is null", () => {
71
+ mockUseNavigation.mockReturnValue({
72
+ startUpHooks: null,
73
+ });
74
+
75
+ mockIsFilledArray.mockReturnValue(false);
76
+
77
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
78
+
79
+ expect(result.current).toBe(false);
80
+ expect(mockIsFilledArray).toHaveBeenCalledWith(null);
81
+ });
82
+
83
+ it("prioritizes filled array over string comparison", () => {
84
+ mockUseNavigation.mockReturnValue({
85
+ startUpHooks: ["hook1"],
86
+ });
87
+
88
+ mockIsFilledArray.mockReturnValue(true);
89
+
90
+ const { result } = renderHook(() => useCurrentScreenIsStartupHook());
91
+
92
+ expect(result.current).toBe(true);
93
+ });
94
+ });
@@ -1,4 +1,4 @@
1
- import { renderHook } from "@testing-library/react-hooks";
1
+ import { renderHook } from "@testing-library/react-native";
2
2
 
3
3
  jest.mock(
4
4
  "@applicaster/zapp-react-native-ui-components/Components/River/useScreenConfiguration",
@@ -1,4 +1,4 @@
1
- import { renderHook } from "@testing-library/react-hooks";
1
+ import { renderHook } from "@testing-library/react-native";
2
2
  import configureStore from "redux-mock-store";
3
3
 
4
4
  const mockStore = configureStore();
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { Provider } from "react-redux";
3
- import { renderHook } from "@testing-library/react-hooks";
3
+ import { renderHook } from "@testing-library/react-native";
4
4
  import configureStore from "redux-mock-store";
5
5
  import { thunk } from "redux-thunk";
6
6
 
@@ -12,3 +12,7 @@ export {
12
12
  } from "./useScreenContext";
13
13
 
14
14
  export { useScreenBackgroundColor } from "./useScreenBackgroundColor";
15
+
16
+ export { useCurrentScreenIsHook } from "./useCurrentScreenIsHook";
17
+
18
+ export { useCurrentScreenIsStartupHook } from "./useCurrentScreenIsStartupHook";
@@ -0,0 +1,9 @@
1
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
2
+ import { last } from "@applicaster/zapp-react-native-utils/utils";
3
+ import { toBooleanWithDefaultFalse } from "@applicaster/zapp-react-native-utils/booleanUtils";
4
+
5
+ export const useCurrentScreenIsHook = (): boolean => {
6
+ const { mainStack = [] } = useNavigation();
7
+
8
+ return toBooleanWithDefaultFalse(last(mainStack)?.route?.includes("hook"));
9
+ };
@@ -0,0 +1,8 @@
1
+ import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
2
+ import { isFilledArray } from "@applicaster/zapp-react-native-utils/arrayUtils";
3
+
4
+ export const useCurrentScreenIsStartupHook = (): boolean => {
5
+ const { startUpHooks } = useNavigation();
6
+
7
+ return isFilledArray(startUpHooks) || startUpHooks === "in_process";
8
+ };