@applicaster/zapp-react-native-utils 15.0.0-alpha.3564377339 → 15.0.0-alpha.3642255793

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 (71) hide show
  1. package/adsUtils/__tests__/createVMAP.test.ts +419 -0
  2. package/analyticsUtils/analyticsMapper.ts +10 -2
  3. package/appDataUtils/__tests__/urlScheme.test.ts +678 -0
  4. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -188
  5. package/appUtils/HooksManager/__tests__/hooksManager.test.js +16 -2
  6. package/appUtils/RiverFocusManager/{index.js → index.ts} +25 -18
  7. package/appUtils/contextKeysManager/__tests__/getKeys/failure.test.ts +7 -2
  8. package/appUtils/contextKeysManager/__tests__/getKeys/success.test.ts +48 -0
  9. package/appUtils/contextKeysManager/contextResolver.ts +51 -22
  10. package/appUtils/contextKeysManager/index.ts +65 -10
  11. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +3 -0
  12. package/appUtils/focusManager/index.ios.ts +37 -4
  13. package/appUtils/focusManagerAux/utils/index.ios.ts +122 -0
  14. package/appUtils/focusManagerAux/utils/utils.ios.ts +150 -11
  15. package/cloudEventsUtils/__tests__/index.test.ts +529 -0
  16. package/cloudEventsUtils/index.ts +65 -1
  17. package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +38 -0
  18. package/configurationUtils/index.ts +17 -11
  19. package/dateUtils/__tests__/dayjs.test.ts +330 -0
  20. package/enumUtils/__tests__/getEnumKeyByEnumValue.test.ts +207 -0
  21. package/errorUtils/__tests__/GeneralError.test.ts +97 -0
  22. package/errorUtils/__tests__/HttpStatusCode.test.ts +344 -0
  23. package/errorUtils/__tests__/MissingPluginError.test.ts +113 -0
  24. package/errorUtils/__tests__/NetworkError.test.ts +202 -0
  25. package/errorUtils/__tests__/getParsedResponse.test.ts +188 -0
  26. package/errorUtils/__tests__/invariant.test.ts +112 -0
  27. package/headersUtils/__tests__/headersUtils.test.js +11 -1
  28. package/headersUtils/index.ts +2 -1
  29. package/manifestUtils/defaultManifestConfigurations/player.js +50 -10
  30. package/navigationUtils/index.ts +15 -5
  31. package/numberUtils/__tests__/toNumber.test.ts +12 -0
  32. package/numberUtils/__tests__/toPositiveNumber.test.ts +165 -0
  33. package/numberUtils/index.ts +19 -1
  34. package/package.json +4 -4
  35. package/reactHooks/app/__tests__/useAppState.test.ts +1 -1
  36. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  37. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +1 -2
  38. package/reactHooks/cell-click/__tests__/index.test.js +1 -3
  39. package/reactHooks/configuration/__tests__/index.test.tsx +1 -1
  40. package/reactHooks/connection/__tests__/index.test.js +1 -1
  41. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +32 -23
  42. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +19 -19
  43. package/reactHooks/feed/__tests__/useEntryScreenId.test.tsx +1 -1
  44. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +42 -30
  45. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +1 -1
  46. package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +1 -1
  47. package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +12 -8
  48. package/reactHooks/layout/__tests__/index.test.tsx +1 -1
  49. package/reactHooks/layout/__tests__/useLayoutVersion.test.tsx +1 -1
  50. package/reactHooks/navigation/__tests__/index.test.tsx +40 -9
  51. package/reactHooks/navigation/index.ts +19 -4
  52. package/reactHooks/navigation/useRoute.ts +3 -1
  53. package/reactHooks/player/__tests__/useAutoSeek._test.tsx +1 -1
  54. package/reactHooks/player/__tests__/useTapSeek._test.ts +1 -1
  55. package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +1 -1
  56. package/reactHooks/resolvers/__tests__/useComponentResolver.test.tsx +1 -1
  57. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +2 -2
  58. package/reactHooks/screen/__tests__/useScreenBackgroundColor.test.tsx +1 -1
  59. package/reactHooks/screen/__tests__/useScreenData.test.tsx +1 -1
  60. package/reactHooks/screen/__tests__/useTargetScreenData.test.tsx +2 -2
  61. package/reactHooks/state/useRefWithInitialValue.ts +10 -0
  62. package/reactHooks/utils/__tests__/index.test.js +1 -1
  63. package/screenState/__tests__/index.test.ts +1 -1
  64. package/searchUtils/const.ts +7 -0
  65. package/searchUtils/index.ts +3 -0
  66. package/services/storageServiceSync.web.ts +1 -1
  67. package/stringUtils/index.ts +1 -1
  68. package/testUtils/index.tsx +1 -1
  69. package/utils/__tests__/mergeRight.test.ts +48 -0
  70. package/utils/index.ts +3 -0
  71. package/utils/mergeRight.ts +5 -0
@@ -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
  };
@@ -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";
@@ -88,6 +89,10 @@ export function isNavBarVisible(
88
89
  if (route.startsWith("/hooks/")) {
89
90
  const module = screenData?.module;
90
91
 
92
+ if (module === undefined) {
93
+ return showNavBar;
94
+ }
95
+
91
96
  if (module?.presentFullScreen) {
92
97
  return false;
93
98
  }
@@ -164,7 +169,17 @@ export const useZappHooksForEntry = (
164
169
  setIsHooksExecutionInProgress,
165
170
  setIsPresentingFullScreen,
166
171
  setIsRunningInBackground,
167
- }: 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
+ );
168
183
 
169
184
  const plugins = usePlugins();
170
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,8 +1,8 @@
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
- import thunk from "redux-thunk";
5
+ import { thunk } from "redux-thunk";
6
6
 
7
7
  const mockStore = configureStore([thunk]);
8
8
 
@@ -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,8 +1,8 @@
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
- import thunk from "redux-thunk";
5
+ import { thunk } from "redux-thunk";
6
6
 
7
7
  const mockStore = configureStore([thunk]);
8
8
 
@@ -1,5 +1,9 @@
1
1
  import React from "react";
2
2
 
3
+ type WithOptionalCleanup = {
4
+ cleanup?: () => void;
5
+ };
6
+
3
7
  /**
4
8
  * returns a ref with an initial value that is lazily evaluated once
5
9
  * */
@@ -10,5 +14,11 @@ export const useRefWithInitialValue = <T>(initialValueGetter: () => T) => {
10
14
  ref.current = initialValueGetter();
11
15
  }
12
16
 
17
+ React.useEffect(() => {
18
+ return () => {
19
+ (ref.current as unknown as WithOptionalCleanup)?.cleanup?.();
20
+ };
21
+ }, []);
22
+
13
23
  return ref;
14
24
  };
@@ -1,5 +1,5 @@
1
1
  import { usePrevious, useIsInitialRender } from "../";
2
- import { renderHook, cleanup } from "@testing-library/react-hooks";
2
+ import { renderHook, cleanup } from "@testing-library/react-native";
3
3
 
4
4
  describe("usePrevious", () => {
5
5
  it("renders", () => {
@@ -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 { useScreenState } from "../index";
3
3
 
4
4
  describe("useScreenState", () => {
@@ -0,0 +1,7 @@
1
+ export const FOCUSABLE_GROUP_ID = "search-screen";
2
+
3
+ export const FOCUSABLE_RESULTS_ID = "search-screen-results";
4
+
5
+ export const SEARCH_BOX_GROUP_ID = "search_box_group_id";
6
+
7
+ export const SEARCH_INPUT_FOCUSABLE_ID = "search_input_group_id";
@@ -0,0 +1,3 @@
1
+ import { SEARCH_INPUT_FOCUSABLE_ID } from "./const";
2
+
3
+ export const isSearchInputId = (id) => id === SEARCH_INPUT_FOCUSABLE_ID;
@@ -17,7 +17,7 @@ export const resolveStorageContextKey = (storageKey: string) => {
17
17
  const key = splitKey[1];
18
18
 
19
19
  if (!key) {
20
- return getFromSessionOrLocalStorage(key);
20
+ return getFromSessionOrLocalStorage(namespaceOrKey);
21
21
  } else {
22
22
  return getFromSessionOrLocalStorage(key, namespaceOrKey);
23
23
  }
@@ -4,7 +4,7 @@ declare const global;
4
4
  import * as R from "ramda";
5
5
  import camelize from "camelize";
6
6
  // @ts-ignore
7
- import Handlebars from "react-native-handlebars";
7
+ import Handlebars from "handlebars";
8
8
 
9
9
  global.Buffer = global.Buffer || require("buffer").Buffer;
10
10
 
@@ -4,7 +4,7 @@ import React, { PropsWithChildren } from "react";
4
4
  import configureStore from "redux-mock-store";
5
5
  import { Provider } from "react-redux";
6
6
  import { View } from "react-native";
7
- import thunk from "redux-thunk";
7
+ import { thunk } from "redux-thunk";
8
8
  import * as R from "ramda";
9
9
 
10
10
  import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
@@ -0,0 +1,48 @@
1
+ import { mergeRight } from "../mergeRight";
2
+
3
+ describe("mergeRight", () => {
4
+ test("merges two objects with no overlapping keys", () => {
5
+ const a = { x: 1, y: 2 };
6
+ const b = { z: 3 };
7
+
8
+ const result = mergeRight(a, b);
9
+
10
+ expect(result).toEqual({ x: 1, y: 2, z: 3 });
11
+ });
12
+
13
+ test("overwrites keys from the second object", () => {
14
+ const a = { x: 1, y: 2 };
15
+ const b = { y: 10, z: 3 };
16
+
17
+ const result = mergeRight(a, b);
18
+
19
+ expect(result).toEqual({ x: 1, y: 10, z: 3 });
20
+ });
21
+
22
+ test("does not mutate the original objects", () => {
23
+ const a = { x: 1 };
24
+ const b = { y: 2 };
25
+
26
+ const result = mergeRight(a, b);
27
+
28
+ expect(result).not.toBe(a);
29
+ expect(result).not.toBe(b);
30
+ expect(a).toEqual({ x: 1 });
31
+ expect(b).toEqual({ y: 2 });
32
+ });
33
+
34
+ test("works with empty objects", () => {
35
+ expect(mergeRight({}, { a: 1 })).toEqual({ a: 1 });
36
+ expect(mergeRight({ a: 1 }, {})).toEqual({ a: 1 });
37
+ expect(mergeRight({}, {})).toEqual({});
38
+ });
39
+
40
+ test("works with nested objects (shallow merge only)", () => {
41
+ const a = { x: { nested: 1 }, y: 2 };
42
+ const b = { x: { nested: 10 }, z: 3 };
43
+
44
+ const result = mergeRight(a, b);
45
+
46
+ expect(result).toEqual({ x: { nested: 10 }, y: 2, z: 3 });
47
+ });
48
+ });
package/utils/index.ts CHANGED
@@ -18,6 +18,8 @@ export { take } from "./take";
18
18
 
19
19
  export { mapAccum } from "./mapAccum";
20
20
 
21
+ export { mergeRight } from "./mergeRight";
22
+
21
23
  export {
22
24
  cloneDeep as clone,
23
25
  flatten,
@@ -51,4 +53,5 @@ export {
51
53
  findIndex,
52
54
  set,
53
55
  compact,
56
+ identity,
54
57
  } from "lodash";
@@ -0,0 +1,5 @@
1
+ import { assign } from "lodash";
2
+
3
+ export const mergeRight = (a, b) => {
4
+ return assign({}, a, b);
5
+ };