@applicaster/zapp-react-native-ui-components 14.0.0-alpha.3140225604 → 14.0.0-alpha.3216572828

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 (79) hide show
  1. package/Components/AnimatedInOut/index.tsx +5 -3
  2. package/Components/AudioPlayer/mobile/Layout.tsx +1 -1
  3. package/Components/AudioPlayer/tv/helpers.tsx +10 -3
  4. package/Components/BaseFocusable/index.tsx +23 -12
  5. package/Components/Cell/Cell.tsx +3 -8
  6. package/Components/Cell/index.js +1 -1
  7. package/Components/ComponentResolver/index.ts +1 -1
  8. package/Components/FeedLoader/index.js +1 -1
  9. package/Components/Focusable/FocusableTvOS.tsx +3 -3
  10. package/Components/Focusable/FocusableiOS.tsx +2 -2
  11. package/Components/Focusable/index.tsx +1 -1
  12. package/Components/FocusableList/index.tsx +4 -0
  13. package/Components/FreezeWithCallback/__tests__/index.test.tsx +67 -43
  14. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +42 -59
  15. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +12 -8
  16. package/Components/HandlePlayable/HandlePlayable.tsx +14 -8
  17. package/Components/Layout/TV/LayoutBackground.tsx +1 -1
  18. package/Components/Layout/TV/__tests__/index.test.tsx +0 -1
  19. package/Components/MasterCell/DefaultComponents/Button.tsx +1 -1
  20. package/Components/MasterCell/DefaultComponents/Image/hoc/withDimensions.tsx +1 -1
  21. package/Components/MasterCell/DefaultComponents/ImageContainer/index.tsx +1 -1
  22. package/Components/MasterCell/DefaultComponents/__tests__/image.test.js +10 -10
  23. package/Components/MasterCell/DefaultComponents/__tests__/text.test.tsx +18 -18
  24. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/index.test.tsx +10 -10
  25. package/Components/MasterCell/elementMapper.tsx +1 -2
  26. package/Components/OfflineHandler/NotificationView/__tests__/index.test.tsx +13 -18
  27. package/Components/OfflineHandler/__tests__/__snapshots__/index.test.tsx.snap +9 -0
  28. package/Components/OfflineHandler/__tests__/index.test.tsx +26 -35
  29. package/Components/PlayerContainer/ErrorDisplay/index.ts +1 -1
  30. package/Components/PlayerContainer/PlayerContainer.tsx +26 -22
  31. package/Components/PlayerContainer/ProgramInfo/index.tsx +1 -1
  32. package/Components/PlayerContainer/index.ts +1 -1
  33. package/Components/River/ComponentsMap/ComponentsMap.tsx +0 -1
  34. package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +378 -0
  35. package/Components/River/ComponentsMap/hooks/useLoadingState.ts +2 -2
  36. package/Components/River/RefreshControl.tsx +6 -4
  37. package/Components/River/TV/River.tsx +2 -17
  38. package/Components/River/TV/index.tsx +3 -1
  39. package/Components/River/TV/withPipesV1DataLoader.tsx +43 -0
  40. package/Components/River/TV/withRiverDataLoader.tsx +17 -0
  41. package/Components/River/TV/withTVEventHandler.tsx +1 -1
  42. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +2 -0
  43. package/Components/River/index.tsx +1 -1
  44. package/Components/Screen/__tests__/Screen.test.tsx +28 -29
  45. package/Components/ScreenRevealManager/ScreenRevealManager.ts +76 -0
  46. package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +107 -0
  47. package/Components/ScreenRevealManager/__tests__/withScreenRevealManager.test.tsx +96 -0
  48. package/Components/ScreenRevealManager/index.ts +1 -0
  49. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +79 -0
  50. package/Components/Tabs/TV/Tabs.android.tsx +0 -2
  51. package/Components/Tabs/Tabs.tsx +2 -3
  52. package/Components/TextInputTv/__tests__/__snapshots__/TextInputTv.test.js.snap +0 -13
  53. package/Components/TextInputTv/index.tsx +0 -11
  54. package/Components/Touchable/__tests__/__snapshots__/touchable.test.tsx.snap +34 -0
  55. package/Components/Touchable/__tests__/touchable.test.tsx +12 -17
  56. package/Components/Transitioner/__tests__/__snapshots__/Scene.test.js.snap +15 -9
  57. package/Components/VideoLive/animationUtils.ts +3 -3
  58. package/Components/VideoModal/ModalAnimation/AnimatedScrollModal.tsx +3 -9
  59. package/Components/VideoModal/ModalAnimation/ModalAnimationContext.tsx +24 -8
  60. package/Components/VideoModal/__tests__/PlayerDetails.test.tsx +5 -5
  61. package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +12 -16
  62. package/Components/Viewport/ViewportTracker/__tests__/viewportTracker.test.js +84 -24
  63. package/Contexts/ConfigutaionContext/__tests__/ConfigurationProvider.test.tsx +3 -3
  64. package/Decorators/ConfigurationWrapper/__tests__/withConfigurationProvider.test.tsx +3 -3
  65. package/Decorators/ConfigurationWrapper/withConfigurationProvider.tsx +2 -2
  66. package/Decorators/RiverResolver/__tests__/riverResolver.test.tsx +3 -6
  67. package/Decorators/ZappPipesDataConnector/ResolverSelector.tsx +25 -0
  68. package/Decorators/ZappPipesDataConnector/__tests__/NullFeedResolver.test.tsx +78 -0
  69. package/Decorators/ZappPipesDataConnector/__tests__/ResolverSelector.test.tsx +205 -0
  70. package/Decorators/ZappPipesDataConnector/__tests__/StaticFeedResolver.test.tsx +251 -0
  71. package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +368 -0
  72. package/Decorators/ZappPipesDataConnector/__tests__/utils.test.ts +39 -0
  73. package/Decorators/ZappPipesDataConnector/index.tsx +26 -293
  74. package/Decorators/ZappPipesDataConnector/resolvers/NullFeedResolver.tsx +25 -0
  75. package/Decorators/ZappPipesDataConnector/resolvers/StaticFeedResolver.tsx +87 -0
  76. package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +241 -0
  77. package/Decorators/ZappPipesDataConnector/types.ts +29 -0
  78. package/events/index.ts +1 -0
  79. package/package.json +5 -7
@@ -6,15 +6,21 @@ exports[`<Scene /> renders correctly 1`] = `
6
6
  collapsable={false}
7
7
  pointerEvents="auto"
8
8
  style={
9
- {
10
- "flex": 1,
11
- "fontScale": 2,
12
- "height": 1334,
13
- "paddingBottom": 49,
14
- "scale": 2,
15
- "statusBarHeight": null,
16
- "width": 750,
17
- }
9
+ [
10
+ {
11
+ "flex": 1,
12
+ },
13
+ {
14
+ "paddingBottom": 49,
15
+ },
16
+ {
17
+ "fontScale": 2,
18
+ "height": 1334,
19
+ "scale": 2,
20
+ "statusBarHeight": null,
21
+ "width": 750,
22
+ },
23
+ ]
18
24
  }
19
25
  />
20
26
  </View>
@@ -1,8 +1,8 @@
1
1
  import { Animated, Easing, EasingFunction, StyleProp } from "react-native";
2
2
 
3
3
  type AnimatedInterpolatedStyle =
4
- | Animated.AnimatedInterpolation
5
- | [{ [Key: string]: Animated.AnimatedInterpolation }];
4
+ | Animated.AnimatedInterpolation<number>
5
+ | [{ [Key: string]: Animated.AnimatedInterpolation<number> }];
6
6
 
7
7
  type AnimationConfig = {
8
8
  duration: number;
@@ -31,7 +31,7 @@ const interpolate = (
31
31
  animatedValue: Animated.Value,
32
32
  from: number = 0,
33
33
  to: number = 1
34
- ): Animated.AnimatedInterpolation =>
34
+ ): Animated.AnimatedInterpolation<number> =>
35
35
  animatedValue.interpolate({
36
36
  inputRange: [0, 1],
37
37
  outputRange: [from, to],
@@ -1,9 +1,8 @@
1
1
  import React from "react";
2
- import { Animated, Platform, StyleSheet, View } from "react-native";
2
+ import { Animated, StyleSheet, View } from "react-native";
3
3
 
4
4
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
5
5
  import {
6
- GestureHandlerRootView,
7
6
  NativeViewGestureHandler,
8
7
  PanGestureHandler,
9
8
  State,
@@ -357,15 +356,10 @@ export const AnimatedScrollModalComponent = ({ children }: Props) => {
357
356
  };
358
357
  }, [playerAnimationState, isAudioItem, isMinimizedModal]);
359
358
 
360
- const Wrapper = React.useMemo(
361
- () => (Platform.OS === "android" ? GestureHandlerRootView : View),
362
- []
363
- );
364
-
365
359
  const scrollEnabled = isMaximizedModal && isNotMinimizeMaximazeAnimation;
366
360
 
367
361
  return (
368
- <Wrapper style={generalStyles.container}>
362
+ <View style={generalStyles.container}>
369
363
  <TapGestureHandler
370
364
  maxDurationMs={100000}
371
365
  ref={tapHandlerRef}
@@ -405,7 +399,7 @@ export const AnimatedScrollModalComponent = ({ children }: Props) => {
405
399
  </PanGestureHandler>
406
400
  </View>
407
401
  </TapGestureHandler>
408
- </Wrapper>
402
+ </View>
409
403
  );
410
404
  };
411
405
 
@@ -11,6 +11,7 @@ import { isLive } from "@applicaster/zapp-react-native-utils/playerUtils";
11
11
 
12
12
  import { PROGRESS_BAR_HEIGHT } from "./utils";
13
13
  import { useConfiguration } from "../utils";
14
+ import { useIsTabletLandscape } from "@applicaster/zapp-react-native-utils/reactHooks/device/useMemoizedIsTablet";
14
15
 
15
16
  export enum PlayerAnimationStateEnum {
16
17
  minimize = "minimize",
@@ -102,14 +103,6 @@ const Provider = ({ children }: { children: React.ReactNode }) => {
102
103
  setStartComponentsAnimation(false);
103
104
  }, []);
104
105
 
105
- useEffect(() => {
106
- // Reset player animation state when video modal is closed
107
- if (!visible) {
108
- resetPlayerAnimationState();
109
- yTranslate.current?.setValue(Dimensions.get("window").height);
110
- }
111
- }, [visible, resetPlayerAnimationState]);
112
-
113
106
  // Animated values
114
107
  const lastScrollY = React.useRef(new Animated.Value(0)).current;
115
108
  const dragScrollY = React.useRef(new Animated.Value(0)).current;
@@ -122,6 +115,29 @@ const Provider = ({ children }: { children: React.ReactNode }) => {
122
115
  const { bottom: bottomSafeArea } = useSafeAreaInsets();
123
116
  const bottomTabBarHeight = useGetBottomTabBarHeight();
124
117
  const startComponentsAnimationDistance = Math.round((height * 60) / 100);
118
+ const isTabletLandscape = useIsTabletLandscape();
119
+ const windowDimensions = Dimensions.get("window");
120
+
121
+ useEffect(() => {
122
+ // Reset player animation state when video modal is closed
123
+ if (!visible) {
124
+ resetPlayerAnimationState();
125
+
126
+ if (!isTabletLandscape) {
127
+ // restore to portrait ( in portrait mode height is bigger)
128
+ if (windowDimensions.height > windowDimensions.width) {
129
+ yTranslate.current?.setValue(windowDimensions.height);
130
+ }
131
+ } else {
132
+ yTranslate.current?.setValue(windowDimensions.height);
133
+ }
134
+ }
135
+ }, [
136
+ visible,
137
+ resetPlayerAnimationState,
138
+ windowDimensions.height,
139
+ isTabletLandscape,
140
+ ]);
125
141
 
126
142
  React.useEffect(() => {
127
143
  if (visible && mode === "MAXIMIZED" && height !== safeAreaFrameHeight) {
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import renderer from "react-test-renderer";
2
+ import { render } from "@testing-library/react-native";
3
3
 
4
4
  const props = {
5
5
  entry: {},
@@ -42,16 +42,16 @@ const { PlayerDetails } = require("../PlayerDetails");
42
42
 
43
43
  describe("PlayerDetails", () => {
44
44
  it("renders properly", () => {
45
- const element = renderer.create(<PlayerDetails {...props} />);
45
+ const { toJSON } = render(<PlayerDetails {...props} />);
46
46
 
47
- expect(element).toMatchSnapshot();
47
+ expect(toJSON()).toMatchSnapshot();
48
48
  });
49
49
 
50
50
  it("renders properly on tablet in landscape orientation", () => {
51
- const element = renderer.create(
51
+ const { toJSON } = render(
52
52
  <PlayerDetails {...props} isTabletLandscape={true} />
53
53
  );
54
54
 
55
- expect(element).toMatchSnapshot();
55
+ expect(toJSON()).toMatchSnapshot();
56
56
  });
57
57
  });
@@ -2,7 +2,7 @@
2
2
 
3
3
  import * as React from "react";
4
4
 
5
- import { act, create as render } from "react-test-renderer";
5
+ import { act, render } from "@testing-library/react-native";
6
6
 
7
7
  import { ViewportAware } from "../";
8
8
  import { ViewportTracker } from "../../ViewportTracker";
@@ -12,21 +12,17 @@ import ReactNative from "react-native";
12
12
 
13
13
  jest.useFakeTimers();
14
14
 
15
- jest.mock("react-native/Libraries/ReactNative/UIManager", () => {
16
- return {
17
- ...jest.requireActual("react-native/Libraries/ReactNative/NativeUIManager"),
18
- measureLayout: (handle, parent, error, success) => {
19
- success(100, 100, 400, 400);
20
- },
21
- };
22
- });
15
+ const { ScrollView } = ReactNative;
23
16
 
24
- jest.mock("react-native/Libraries/Renderer/shims/ReactNative", () => ({
25
- ...jest.requireActual("react-native/Libraries/Renderer/shims/ReactNative"),
26
- findNodeHandle: () => 1234,
27
- }));
17
+ jest.spyOn(ReactNative, "findNodeHandle").mockImplementation(() => 1234);
28
18
 
29
- const { ScrollView } = ReactNative;
19
+ ReactNative.UIManager.measureLayout = jest.fn(
20
+ (handle, parent, error, success) => {
21
+ success(100, 100, 400, 400);
22
+ }
23
+ );
24
+
25
+ ReactNative.findNodeHandle = () => 1234;
30
26
 
31
27
  const viewportEventsManager = new ViewportEvents(true);
32
28
 
@@ -138,7 +134,7 @@ describe("<ViewportAware />", () => {
138
134
  expect(wrapper.toJSON()).toMatchSnapshot();
139
135
  expect(onViewportEnter).toHaveBeenCalled();
140
136
 
141
- const scrollviews = wrapper.root.findAllByType(ScrollView);
137
+ const scrollviews = wrapper.UNSAFE_getAllByType(ScrollView);
142
138
  expect(scrollviews).toBeArray();
143
139
  expect(scrollviews).toHaveProperty("length", 2);
144
140
 
@@ -179,7 +175,7 @@ describe("<ViewportAware />", () => {
179
175
 
180
176
  expect(wrapper.toJSON()).toMatchSnapshot();
181
177
 
182
- const scrollviews = wrapper.root.findAllByType(ScrollView);
178
+ const scrollviews = wrapper.UNSAFE_getAllByType(ScrollView);
183
179
  expect(scrollviews).toBeArray();
184
180
  expect(scrollviews).toHaveProperty("length", 2);
185
181
 
@@ -1,14 +1,19 @@
1
1
  import * as React from "react";
2
- import { ScrollView } from "react-native";
3
- import TestRenderer, { act } from "react-test-renderer";
2
+ import { act, render } from "@testing-library/react-native";
4
3
  import { ViewportEvents } from "../../ViewportEvents";
4
+ import ReactNative from "react-native";
5
+
6
+ const { ScrollView } = ReactNative;
5
7
 
6
8
  const TestComponent = () => <ScrollView />;
7
9
 
8
- jest.mock("react-native/Libraries/Renderer/shims/ReactNative", () => ({
9
- ...jest.requireActual("react-native/Libraries/Renderer/shims/ReactNative"),
10
- findNodeHandle: () => 1234,
11
- }));
10
+ jest.spyOn(ReactNative, "findNodeHandle").mockImplementation(() => 1234);
11
+
12
+ ReactNative.UIManager.measureLayout = jest.fn(
13
+ (handle, parent, error, success) => {
14
+ success(100, 100, 400, 400);
15
+ }
16
+ );
12
17
 
13
18
  const viewportEventsManager = new ViewportEvents(true);
14
19
 
@@ -23,32 +28,49 @@ const event = {
23
28
  };
24
29
 
25
30
  describe("<ViewportTracker />", () => {
26
- // eslint-disable-next-line react/prop-types
27
- const ReactWrapper = ({ children }) => (
28
- <ViewportTracker viewportEventsManager={viewportEventsManager}>
29
- <ScrollView>{children}</ScrollView>
30
- </ViewportTracker>
31
- );
32
-
33
- const wrapper = TestRenderer.create(
34
- <ReactWrapper>
35
- <TestComponent />
36
- </ReactWrapper>
37
- );
38
-
39
- const scrollView = wrapper.root.findByType(ScrollView);
40
-
41
31
  beforeEach(() => {
42
32
  viewportEventSpy.mockClear();
43
33
  });
44
34
 
45
35
  it("renders correctly", () => {
36
+ // eslint-disable-next-line react/prop-types
37
+ const ReactWrapper = ({ children }) => (
38
+ <ViewportTracker viewportEventsManager={viewportEventsManager}>
39
+ <ScrollView>{children}</ScrollView>
40
+ </ViewportTracker>
41
+ );
42
+
43
+ const wrapper = render(
44
+ <ReactWrapper>
45
+ <TestComponent />
46
+ </ReactWrapper>
47
+ );
48
+
49
+ const scrollView = wrapper.UNSAFE_getByType(ScrollView);
50
+
46
51
  expect(wrapper.toJSON()).toMatchSnapshot();
47
52
  expect(scrollView.props).toMatchSnapshot();
48
53
  });
49
54
 
50
55
  it("notifies viewport listeners when layout changes", () => {
51
- act(() => scrollView.props.onLayout(event));
56
+ // eslint-disable-next-line react/prop-types
57
+ const ReactWrapper = ({ children }) => (
58
+ <ViewportTracker viewportEventsManager={viewportEventsManager}>
59
+ <ScrollView>{children}</ScrollView>
60
+ </ViewportTracker>
61
+ );
62
+
63
+ const wrapper = render(
64
+ <ReactWrapper>
65
+ <TestComponent />
66
+ </ReactWrapper>
67
+ );
68
+
69
+ const scrollView = wrapper.UNSAFE_getByType(ScrollView);
70
+
71
+ act(() => {
72
+ scrollView.props.onLayout(event);
73
+ });
52
74
 
53
75
  expect(viewportEventSpy).toHaveBeenCalledWith(
54
76
  expect.objectContaining({
@@ -63,12 +85,50 @@ describe("<ViewportTracker />", () => {
63
85
  });
64
86
 
65
87
  it("notifies viewport listeners when content scrolls", () => {
66
- act(() => scrollView.props.onScroll(event));
88
+ // eslint-disable-next-line react/prop-types
89
+ const ReactWrapper = ({ children }) => (
90
+ <ViewportTracker viewportEventsManager={viewportEventsManager}>
91
+ <ScrollView>{children}</ScrollView>
92
+ </ViewportTracker>
93
+ );
94
+
95
+ const wrapper = render(
96
+ <ReactWrapper>
97
+ <TestComponent />
98
+ </ReactWrapper>
99
+ );
100
+
101
+ const scrollView = wrapper.UNSAFE_getByType(ScrollView);
102
+
103
+ act(() => {
104
+ scrollView.props.onLayout(event);
105
+ scrollView.props.onScroll(event);
106
+ });
107
+
67
108
  expect(viewportEventSpy).toHaveBeenCalled();
68
109
  });
69
110
 
70
111
  it("notifies viewport listeners when content size changes", () => {
71
- act(() => scrollView.props.onContentSizeChange(100, 100));
112
+ // eslint-disable-next-line react/prop-types
113
+ const ReactWrapper = ({ children }) => (
114
+ <ViewportTracker viewportEventsManager={viewportEventsManager}>
115
+ <ScrollView>{children}</ScrollView>
116
+ </ViewportTracker>
117
+ );
118
+
119
+ const wrapper = render(
120
+ <ReactWrapper>
121
+ <TestComponent />
122
+ </ReactWrapper>
123
+ );
124
+
125
+ const scrollView = wrapper.UNSAFE_getByType(ScrollView);
126
+
127
+ act(() => {
128
+ scrollView.props.onLayout(event);
129
+ scrollView.props.onContentSizeChange(100, 100);
130
+ });
131
+
72
132
  expect(viewportEventSpy).toHaveBeenCalled();
73
133
  });
74
134
  });
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import TestRenderer from "react-test-renderer";
2
+ import { render } from "@testing-library/react-native";
3
3
  import { View } from "react-native";
4
4
  import { useConfiguration } from "@applicaster/zapp-react-native-utils/reactHooks/configuration";
5
5
 
@@ -14,12 +14,12 @@ describe("withConfigurationProvider", () => {
14
14
  };
15
15
 
16
16
  it("provides configuration to children", () => {
17
- const wrapper = TestRenderer.create(
17
+ const { toJSON } = render(
18
18
  <ConfigurationProvider configuration={{ target: "foobar" }}>
19
19
  <TestComponent />
20
20
  </ConfigurationProvider>
21
21
  );
22
22
 
23
- expect(wrapper.toJSON()).toMatchSnapshot();
23
+ expect(toJSON()).toMatchSnapshot();
24
24
  });
25
25
  });
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import TestRenderer from "react-test-renderer";
2
+ import { render } from "@testing-library/react-native";
3
3
  import { useConfiguration } from "@applicaster/zapp-react-native-utils/reactHooks/configuration";
4
4
  import { View } from "react-native";
5
5
  import { withConfigurationProvider } from "@applicaster/zapp-react-native-ui-components/Decorators/ConfigurationWrapper";
@@ -15,12 +15,12 @@ describe("withConfigurationProvider", () => {
15
15
  it("correctly passes all the configuration keys child component", () => {
16
16
  const Component = withConfigurationProvider(TestComponent);
17
17
 
18
- const wrapper = TestRenderer.create(
18
+ const { toJSON } = render(
19
19
  <Component
20
20
  screenData={{ styles: {}, general: {}, data: { source: "test" } }}
21
21
  />
22
22
  );
23
23
 
24
- expect(wrapper.toJSON()).toMatchSnapshot();
24
+ expect(toJSON()).toMatchSnapshot();
25
25
  });
26
26
  });
@@ -21,13 +21,13 @@ const prepareConfiguration = (
21
21
  keys: [string]
22
22
  ) => R.compose(R.evolve(keysMap), R.pickAll(keys))(configuration);
23
23
 
24
+ const configurationKeys = R.keys(keysMap);
25
+
24
26
  export function withConfigurationProvider(Component: React.ComponentType<any>) {
25
27
  return function WithConfigurationProvider(props: Props) {
26
28
  const styles = props?.screenData?.styles;
27
29
  const general = props?.screenData?.general;
28
30
 
29
- const configurationKeys = React.useMemo(() => R.keys(keysMap), []);
30
-
31
31
  const configuration = React.useMemo(
32
32
  () => prepareConfiguration({ ...general, ...styles }, configurationKeys),
33
33
  []
@@ -13,12 +13,9 @@ const rivers = {
13
13
  },
14
14
  };
15
15
 
16
- jest.doMock(
17
- "@applicaster/zapp-react-native-redux/hooks/usePickFromState",
18
- () => ({
19
- usePickFromState: jest.fn(() => ({ rivers })),
20
- })
21
- );
16
+ jest.doMock("@applicaster/zapp-react-native-redux/hooks", () => ({
17
+ usePickFromState: jest.fn(() => ({ rivers })),
18
+ }));
22
19
 
23
20
  jest.doMock(
24
21
  "@applicaster/zapp-react-native-utils/reactHooks/navigation/usePathname",
@@ -0,0 +1,25 @@
1
+ // ResolverSelector.tsx
2
+ import React from "react";
3
+ import { ComponentDataSourceContext, ZappPipesDataProps } from "./types";
4
+ import { StaticFeedResolver } from "./resolvers/StaticFeedResolver";
5
+ import { UrlFeedResolver } from "./resolvers/UrlFeedResolver";
6
+ import { NullFeedResolver } from "./resolvers/NullFeedResolver";
7
+
8
+ type ResolverSelectorProps = ComponentDataSourceContext & {
9
+ children: (dataProps: ZappPipesDataProps) => React.ReactNode;
10
+ };
11
+
12
+ export function ResolverSelector(props: ResolverSelectorProps) {
13
+ const { getStaticComponentFeed, component, feedUrl, children } = props;
14
+
15
+ // Determine which resolver to use
16
+ if (getStaticComponentFeed) {
17
+ return <StaticFeedResolver {...props}>{children}</StaticFeedResolver>;
18
+ }
19
+
20
+ if (feedUrl || component?.data?.source) {
21
+ return <UrlFeedResolver {...props}>{children}</UrlFeedResolver>;
22
+ }
23
+
24
+ return <NullFeedResolver>{children}</NullFeedResolver>;
25
+ }
@@ -0,0 +1,78 @@
1
+ import React from "react";
2
+ import { View } from "react-native";
3
+ import { render } from "@testing-library/react-native";
4
+ import { NullFeedResolver } from "../resolvers/NullFeedResolver";
5
+ import { ReloadDataFunction } from "@applicaster/zapp-react-native-utils/reactHooks/feed/useFeedLoader";
6
+
7
+ type MockChildrenArgs = {
8
+ zappPipesData?: {
9
+ loading: boolean;
10
+ data?: any;
11
+ error?: Error | null;
12
+ };
13
+ reloadData?: ReloadDataFunction;
14
+ loadNextData?: () => void;
15
+ };
16
+
17
+ describe("NullFeedResolver", () => {
18
+ it("should render children with correct default props", () => {
19
+ const mockChildren = jest.fn((_args: MockChildrenArgs) => (
20
+ <View testID="mock-children" />
21
+ ));
22
+
23
+ render(<NullFeedResolver>{mockChildren}</NullFeedResolver>);
24
+
25
+ expect(mockChildren).toHaveBeenCalledWith(
26
+ expect.objectContaining({
27
+ zappPipesData: {
28
+ url: "",
29
+ loading: false,
30
+ data: null,
31
+ error: null,
32
+ },
33
+ reloadData: expect.any(Function),
34
+ loadNextData: undefined,
35
+ })
36
+ );
37
+ });
38
+
39
+ it("should render children component", () => {
40
+ const { getByTestId } = render(
41
+ <NullFeedResolver>{() => <View testID="test-child" />}</NullFeedResolver>
42
+ );
43
+
44
+ expect(getByTestId("test-child")).toBeTruthy();
45
+ });
46
+
47
+ it("should create a memoized data object that doesn't change on re-renders", () => {
48
+ const mockChildren = jest.fn(() => <View testID="mock-children" />);
49
+
50
+ const { rerender } = render(
51
+ <NullFeedResolver>{mockChildren}</NullFeedResolver>
52
+ );
53
+
54
+ expect(mockChildren).toHaveBeenCalled();
55
+ // @ts-ignore
56
+ const firstCallDataProps = mockChildren.mock.calls[0][0];
57
+
58
+ rerender(<NullFeedResolver>{mockChildren}</NullFeedResolver>);
59
+
60
+ // @ts-ignore
61
+ const secondCallDataProps = mockChildren.mock.calls[1][0];
62
+
63
+ expect(firstCallDataProps).toBe(secondCallDataProps);
64
+ });
65
+
66
+ it("should have reloadData function that returns null", () => {
67
+ const mockChildren = jest.fn(() => <View testID="mock-children" />);
68
+
69
+ render(<NullFeedResolver>{mockChildren}</NullFeedResolver>);
70
+
71
+ expect(mockChildren).toHaveBeenCalled();
72
+
73
+ // @ts-ignore
74
+ const { reloadData } = mockChildren.mock.calls[0][0];
75
+
76
+ expect(reloadData()).toBeNull();
77
+ });
78
+ });