@applicaster/zapp-react-native-utils 13.0.0-alpha.9433330286 → 13.0.0-alpha.9524088075

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 (129) hide show
  1. package/README.md +0 -10
  2. package/actionsExecutor/ActionExecutor.ts +16 -9
  3. package/actionsExecutor/ActionExecutorContext.tsx +74 -9
  4. package/alertUtils/alert.ts +148 -0
  5. package/alertUtils/index.ts +1 -148
  6. package/analyticsUtils/AnalyticPlayerListener.ts +18 -1
  7. package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
  8. package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
  9. package/analyticsUtils/__tests__/__snapshots__/analyticsManagerNoModule.test.js.snap +9 -9
  10. package/analyticsUtils/currentScreenProperities.ts +6 -4
  11. package/analyticsUtils/helpers/hooks.ts +1 -1
  12. package/analyticsUtils/index.tsx +3 -4
  13. package/analyticsUtils/manager.ts +1 -1
  14. package/appUtils/HooksManager/Hook.ts +2 -2
  15. package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +7 -7
  16. package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +186 -186
  17. package/appUtils/HooksManager/index.ts +1 -1
  18. package/appUtils/HooksManager/types.ts +5 -2
  19. package/appUtils/accessibilityManager/index.ts +42 -1
  20. package/appUtils/contextKeysManager/contextResolver.ts +77 -0
  21. package/appUtils/contextKeysManager/index.ts +2 -2
  22. package/appUtils/contextKeysManager/utils/index.ts +2 -1
  23. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +7 -6
  24. package/appUtils/focusManager/index.ts +100 -74
  25. package/appUtils/focusManager/treeDataStructure/Tree/index.js +23 -0
  26. package/appUtils/focusManager/utils/enums.ts +4 -0
  27. package/appUtils/focusManagerAux/utils/index.ts +4 -3
  28. package/appUtils/keyCodes/__tests__/__snapshots__/keyCodes.test.js.snap +2 -2
  29. package/appUtils/keyCodes/__tests__/keyCodes.test.js +1 -1
  30. package/appUtils/keyCodes/index.ts +11 -7
  31. package/appUtils/keyCodes/keys/keysByPlatform.ts +4 -0
  32. package/appUtils/keyInputHandler/KeyInputHandler.ts +68 -0
  33. package/appUtils/orientationHelper.ts +1 -2
  34. package/appUtils/platform/const.ts +14 -0
  35. package/appUtils/platform/platformUtils.ts +47 -4
  36. package/appUtils/playerManager/index.ts +7 -3
  37. package/appUtils/playerManager/player.ts +19 -7
  38. package/appUtils/playerManager/playerNative.ts +3 -2
  39. package/appUtils/playerManager/usePlayerControllerSetup.tsx +3 -3
  40. package/arrayUtils/__tests__/__snapshots__/arrayUtils.test.ts.snap +4 -4
  41. package/equalUtils/__tests__/isEqual/combination.test.ts +263 -0
  42. package/equalUtils/index.ts +49 -30
  43. package/focusManager/FocusManager.ts +11 -1
  44. package/focusManager/index.ts +41 -4
  45. package/functionUtils/__tests__/__snapshots__/functionUtils.test.js.snap +4 -4
  46. package/functionUtils/index.ts +21 -8
  47. package/idleUtils/__tests__/withTimeout$.test.ts +37 -0
  48. package/idleUtils/index.ts +1 -1
  49. package/idleUtils/withTimeout.ts +15 -2
  50. package/logger/const.ts +9 -67
  51. package/manifestUtils/__tests__/createConfig.test.js +16 -16
  52. package/manifestUtils/fonts/index.js +5 -6
  53. package/manifestUtils/sharedConfiguration/screenPicker/__tests__/utils.test.js +304 -0
  54. package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +875 -0
  55. package/manifestUtils/sharedConfiguration/screenPicker/utils.js +130 -0
  56. package/navigationUtils/__tests__/__snapshots__/navigationUtils.test.js.snap +6 -6
  57. package/navigationUtils/__tests__/itemTypes.test.js +2 -2
  58. package/navigationUtils/__tests__/navigationUtils.test.js +2 -2
  59. package/navigationUtils/index.ts +3 -3
  60. package/numberUtils/index.ts +7 -5
  61. package/package.json +5 -9
  62. package/reactHooks/app/useAppState.ts +2 -2
  63. package/reactHooks/autoscrolling/__tests__/useTrackCurrentAutoScrollingElement.test.ts +1 -1
  64. package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +6 -8
  65. package/reactHooks/autoscrolling/useTrackedView.ts +12 -1
  66. package/reactHooks/cell-click/__tests__/index.test.js +10 -2
  67. package/reactHooks/cell-click/index.ts +7 -1
  68. package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +39 -88
  69. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +4 -4
  70. package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +10 -11
  71. package/reactHooks/feed/useFeedLoader.tsx +1 -1
  72. package/reactHooks/feed/usePipesCacheReset.ts +5 -5
  73. package/reactHooks/flatList/__tests__/index.test.tsx +30 -21
  74. package/reactHooks/layout/__tests__/index.test.tsx +10 -10
  75. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.native.test.js +14 -28
  76. package/reactHooks/layout/useDimensions/helpers/__tests__/getInitialDimensions.test.js +1 -1
  77. package/reactHooks/layout/useDimensions/useDimensions.ts +8 -0
  78. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  79. package/reactHooks/navigation/__tests__/index.test.tsx +6 -21
  80. package/reactHooks/navigation/index.ts +33 -237
  81. package/reactHooks/navigation/useGetBottomTabBarHeight.ts +12 -0
  82. package/reactHooks/navigation/useGetNavBarTopBorderWidth.ts +14 -0
  83. package/reactHooks/navigation/useGetTabBarHeight.ts +10 -0
  84. package/reactHooks/navigation/useIsScreenActive.ts +17 -0
  85. package/reactHooks/navigation/useNavigationPluginData.ts +15 -0
  86. package/reactHooks/navigation/useNavigationType.ts +15 -0
  87. package/reactHooks/navigation/usePathname.ts +4 -0
  88. package/reactHooks/navigation/useProfilerLogging.ts +15 -0
  89. package/reactHooks/navigation/useRoute.ts +100 -0
  90. package/reactHooks/navigation/useUniqueRouteSuffix.ts +41 -0
  91. package/reactHooks/player/TVSeekControlller/ISeekController.ts +32 -0
  92. package/reactHooks/player/TVSeekControlller/LongPressSeekController.ts +71 -0
  93. package/reactHooks/player/TVSeekControlller/TVSeekController.ts +258 -0
  94. package/reactHooks/player/TVSeekControlller/TapSeekController.ts +53 -0
  95. package/reactHooks/player/__tests__/{useAutoSeek.test.tsx → useAutoSeek._test.tsx} +2 -3
  96. package/reactHooks/player/const.ts +0 -4
  97. package/reactHooks/player/index.ts +0 -6
  98. package/reactHooks/state/useRefWithInitialValue.ts +14 -0
  99. package/reactHooks/state/useStateFromSubscribe.ts +23 -0
  100. package/reactHooks/usePluginConfiguration.ts +1 -1
  101. package/reactHooks/useSubscriberFor.ts +4 -3
  102. package/reactUtils/__tests__/__snapshots__/reactUtilsHelpers.test.js.snap +16 -4
  103. package/reactUtils/__tests__/reactUtils.test.js +1 -37
  104. package/reactUtils/__tests__/reactUtilsHelpers.test.js +72 -71
  105. package/reactUtils/createContext/__tests__/__snapshots__/helpers.test.js.snap +13 -79
  106. package/reactUtils/createContext/__tests__/__snapshots__/{index.test.js.snap → index.test.ts.snap} +2 -2
  107. package/reactUtils/createContext/__tests__/__snapshots__/provider.test.js.snap +3 -28
  108. package/reactUtils/createContext/__tests__/__snapshots__/withConsumer.test.js.snap +3 -4
  109. package/reactUtils/createContext/__tests__/__snapshots__/withProvider.test.js.snap +7 -3
  110. package/reactUtils/createContext/__tests__/helpers.test.js +107 -121
  111. package/reactUtils/createContext/__tests__/{index.test.js → index.test.ts} +2 -2
  112. package/reactUtils/createContext/__tests__/provider.test.js +4 -6
  113. package/reactUtils/createContext/__tests__/withConsumer.test.js +12 -12
  114. package/reactUtils/createContext/__tests__/withProvider.test.js +4 -4
  115. package/reactUtils/createContext/helpers.ts +6 -1
  116. package/reactUtils/createContext/index.ts +11 -25
  117. package/reactUtils/index.ts +0 -11
  118. package/screenState/index.ts +24 -10
  119. package/testUtils/index.tsx +7 -18
  120. package/theme/__mocks__/index.ts +4 -0
  121. package/theme/index.ts +1 -1
  122. package/time/Timer.ts +5 -2
  123. package/types.ts +1 -0
  124. package/zappFrameworkUtils/presentPluginOneTime.ts +2 -3
  125. package/reactHooks/player/useAutoSeek.tsx +0 -87
  126. package/reactHooks/player/useSeek.tsx +0 -66
  127. package/reactHooks/player/useTapSeek.tsx +0 -58
  128. package/reactUtils/createContext/__tests__/index-no-react.test.js +0 -27
  129. /package/reactHooks/player/__tests__/{useTapSeek.test.ts → useTapSeek._test.ts} +0 -0
@@ -1,8 +1,7 @@
1
1
  import { renderHook } from "@testing-library/react-hooks";
2
- import * as reduxMockStore from "redux-mock-store";
3
- import thunk from "redux-thunk";
4
- import React from "react";
5
- import * as ReactRedux from "react-redux";
2
+ import { allFeedsIsReady, useBatchLoading } from "../useBatchLoading";
3
+ import { WrappedWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
4
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
6
5
 
7
6
  jest.mock("../../navigation");
8
7
 
@@ -13,17 +12,18 @@ jest.mock(
13
12
  })
14
13
  );
15
14
 
16
- const useBatchLoading = require("../useBatchLoading").useBatchLoading;
17
- const allFeedsIsReady = require("../useBatchLoading").allFeedsIsReady;
18
-
19
- const mockStore = reduxMockStore.default([thunk]);
20
-
21
- const wrapper: React.FC<any> = ({ children, store }) => (
22
- <ReactRedux.Provider store={store}>{children}</ReactRedux.Provider>
23
- );
15
+ const wrapper = WrappedWithProviders;
24
16
 
25
17
  describe("useBatchLoading", () => {
26
- const useDispatchSpy = jest.spyOn(ReactRedux, "useDispatch");
18
+ const data = [
19
+ { data: { source: "url1" }, component_type: "any" },
20
+ { data: { source: "url2" }, component_type: "any" },
21
+ { data: { source: "url3" }, component_type: "any" },
22
+ { data: { source: "url4" }, component_type: "any" },
23
+ { data: { source: "url5" }, component_type: "any" },
24
+ { data: { source: "url6" }, component_type: "any" },
25
+ // ... more items
26
+ ];
27
27
 
28
28
  beforeAll(() => {
29
29
  jest.useFakeTimers();
@@ -34,7 +34,7 @@ describe("useBatchLoading", () => {
34
34
  });
35
35
 
36
36
  it("loadPipesData start loading not started requests", () => {
37
- const store = mockStore({
37
+ const store = {
38
38
  zappPipes: {
39
39
  url1: {
40
40
  loading: true,
@@ -53,29 +53,17 @@ describe("useBatchLoading", () => {
53
53
  },
54
54
  },
55
55
  test: "true",
56
- });
57
-
58
- useDispatchSpy.mockReturnValue(store.dispatch);
56
+ };
59
57
 
60
58
  const initialBatchSize = 3;
61
59
  const riverId = "123";
62
60
 
63
- const data = [
64
- { data: { source: "url1" } },
65
- { data: { source: "url2" } },
66
- { data: { source: "url3" } },
67
- { data: { source: "url4" } },
68
- { data: { source: "url5" } },
69
- { data: { source: "url6" } },
70
- // ... more items
71
- ];
72
-
73
61
  renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
74
62
  wrapper,
75
63
  initialProps: { store },
76
64
  });
77
65
 
78
- const actions = store.getActions();
66
+ const actions = (appStore.getStore() as any).getActions();
79
67
 
80
68
  expect(actions).toHaveLength(2);
81
69
 
@@ -91,7 +79,7 @@ describe("useBatchLoading", () => {
91
79
  });
92
80
 
93
81
  it("loadPipesData start loading new feed when 1 feed is done loading and 1 is in loading state", () => {
94
- const store = mockStore({
82
+ const store = {
95
83
  zappPipes: {
96
84
  url1: {
97
85
  loading: false,
@@ -110,31 +98,17 @@ describe("useBatchLoading", () => {
110
98
  },
111
99
  },
112
100
  test: "true",
113
- });
114
-
115
- useDispatchSpy.mockReturnValue(store.dispatch);
101
+ };
116
102
 
117
103
  const initialBatchSize = 3;
118
104
  const riverId = "123";
119
105
 
120
- const data = [
121
- { data: { source: "url1" } },
122
- { data: { source: "url2" } },
123
- { data: { source: "url3" } },
124
- { data: { source: "url4" } },
125
- { data: { source: "url5" } },
126
- { data: { source: "url6" } },
127
- // ... more items
128
- ];
129
-
130
- expect(useDispatchSpy).toBeCalledTimes(0);
131
-
132
106
  renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
133
107
  wrapper,
134
108
  initialProps: { store },
135
109
  });
136
110
 
137
- const actions = store.getActions();
111
+ const actions = (appStore.getStore() as any).getActions();
138
112
 
139
113
  expect(actions).toHaveLength(1);
140
114
 
@@ -145,38 +119,26 @@ describe("useBatchLoading", () => {
145
119
  });
146
120
 
147
121
  it("loadPipesData has been called when no data cached", () => {
148
- const store = mockStore({
122
+ const store = {
149
123
  zappPipes: {},
150
124
  test: "true",
151
- });
152
-
153
- useDispatchSpy.mockReturnValue(store.dispatch);
125
+ };
154
126
 
155
127
  const initialBatchSize = 3;
156
128
  const riverId = "123";
157
129
 
158
- const data = [
159
- { data: { source: "url1" } },
160
- { data: { source: "url2" } },
161
- { data: { source: "url3" } },
162
- { data: { source: "url4" } },
163
- { data: { source: "url5" } },
164
- { data: { source: "url6" } },
165
- // ... more items
166
- ];
167
-
168
130
  renderHook(() => useBatchLoading(data, { initialBatchSize, riverId }), {
169
131
  wrapper,
170
132
  initialProps: { store },
171
133
  });
172
134
 
173
- const actions = store.getActions();
135
+ const actions = (appStore.getStore() as any).getActions();
174
136
 
175
137
  expect(actions).toHaveLength(3);
176
138
  });
177
139
 
178
140
  it("initial batch ready when all initial items loaded", () => {
179
- const store = mockStore({
141
+ const store = {
180
142
  zappPipes: {
181
143
  url1: {
182
144
  loading: false,
@@ -194,19 +156,11 @@ describe("useBatchLoading", () => {
194
156
  data: {},
195
157
  },
196
158
  },
197
- });
198
-
199
- useDispatchSpy.mockReturnValue(store.dispatch);
159
+ };
200
160
 
201
161
  const initialBatchSize = 3;
202
162
  const riverId = "123";
203
163
 
204
- const data: Partial<ZappUIComponent>[] = [
205
- { data: { source: "url1" } },
206
- { data: { source: "url2" } },
207
- { data: { source: "url3" } },
208
- ];
209
-
210
164
  const { result } = renderHook(
211
165
  () => useBatchLoading(data, { initialBatchSize, riverId }),
212
166
  { wrapper, initialProps: { store } }
@@ -216,12 +170,10 @@ describe("useBatchLoading", () => {
216
170
  });
217
171
 
218
172
  it("gallery-qb: loadPipesData should be called only once for first component in the gallery", () => {
219
- const store = mockStore({
173
+ const store = {
220
174
  zappPipes: {},
221
175
  test: "true",
222
- });
223
-
224
- useDispatchSpy.mockReturnValue(store.dispatch);
176
+ };
225
177
 
226
178
  const initialBatchSize = 3;
227
179
  const riverId = "123";
@@ -231,11 +183,11 @@ describe("useBatchLoading", () => {
231
183
  component_type: "gallery-qb",
232
184
  ui_components: [{ data: { source: "url1" } }],
233
185
  },
234
- { data: { source: "url2" } },
235
- { data: { source: "url3" } },
236
- { data: { source: "url4" } },
237
- { data: { source: "url5" } },
238
- { data: { source: "url6" } },
186
+ { data: { source: "url2" }, component_type: "any" },
187
+ { data: { source: "url3" }, component_type: "any" },
188
+ { data: { source: "url4" }, component_type: "any" },
189
+ { data: { source: "url5" }, component_type: "any" },
190
+ { data: { source: "url6" }, component_type: "any" },
239
191
  // ... more items
240
192
  ];
241
193
 
@@ -244,13 +196,13 @@ describe("useBatchLoading", () => {
244
196
  initialProps: { store },
245
197
  });
246
198
 
247
- const actions = store.getActions();
199
+ const actions = (appStore.getStore() as any).getActions();
248
200
 
249
201
  expect(actions).toHaveLength(1);
250
202
  });
251
203
 
252
204
  it("gallery-qb: initial batch ready when all initial items loaded", () => {
253
- const store = mockStore({
205
+ const store = {
254
206
  zappPipes: {
255
207
  url1: {
256
208
  loading: false,
@@ -258,20 +210,19 @@ describe("useBatchLoading", () => {
258
210
  data: {},
259
211
  },
260
212
  },
261
- });
262
-
263
- useDispatchSpy.mockReturnValue(store.dispatch);
213
+ };
264
214
 
265
215
  const initialBatchSize = 3;
266
216
  const riverId = "123";
267
217
 
268
- const data: Partial<ZappUIComponent>[] = [
218
+ const data = [
269
219
  {
270
220
  component_type: "gallery-qb",
271
- ui_components: [{ data: { source: "url1" } }],
221
+ data: {},
222
+ ui_components: [{ data: { source: "url1" } }] as any,
272
223
  },
273
- { data: { source: "url2" } },
274
- { data: { source: "url3" } },
224
+ { data: { source: "url2" }, component_type: "any" },
225
+ { data: { source: "url3" }, component_type: "any" },
275
226
  ];
276
227
 
277
228
  const { result } = renderHook(
@@ -7,12 +7,12 @@ const appData = {
7
7
  sdk_version: "2.0.0",
8
8
  };
9
9
 
10
- let INFLATED_URL;
10
+ const mockUseInflatedUrl = jest.fn();
11
11
 
12
12
  jest.mock(
13
13
  "@applicaster/zapp-react-native-utils/reactHooks/feed/useInflatedUrl",
14
14
  () => ({
15
- useInflatedUrl: () => INFLATED_URL,
15
+ useInflatedUrl: mockUseInflatedUrl,
16
16
  })
17
17
  );
18
18
 
@@ -20,7 +20,7 @@ const { useBuildPipesUrl } = require("../useBuildPipesUrl");
20
20
 
21
21
  describe("useBuildPipesUrl", () => {
22
22
  it("returns the proper url", async () => {
23
- INFLATED_URL = "http://foo.com/show/show-1";
23
+ mockUseInflatedUrl.mockReturnValue("http://foo.com/show/show-1");
24
24
  const url = "http://foo.com/show/{{showId}}";
25
25
 
26
26
  const mapping = {
@@ -65,7 +65,7 @@ describe("useBuildPipesUrl", () => {
65
65
  });
66
66
 
67
67
  it("returns empty object if url is not in endpoints", async () => {
68
- INFLATED_URL = "http://foobar.com/show-1";
68
+ mockUseInflatedUrl.mockReturnValue("http://foobar.com/show-1");
69
69
  const url = "http://foobar.com/{{showId}}";
70
70
 
71
71
  const mapping = {
@@ -6,42 +6,41 @@ import { Provider } from "react-redux";
6
6
  import * as React from "react";
7
7
  import configureStore from "redux-mock-store";
8
8
  import thunk from "redux-thunk";
9
- import * as navigationHooks from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
9
+ import * as useRouteHook from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useRoute";
10
10
  import * as useNavigationHooks from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
11
+ import { useFeedLoader } from "../useFeedLoader";
11
12
 
12
13
  const mockStore = configureStore([thunk]);
13
14
 
14
- jest.useFakeTimers();
15
+ jest.useFakeTimers({ legacyFakeTimers: true });
15
16
 
16
- const logger = {
17
+ const mockLogger = {
17
18
  warning: jest.fn(),
18
19
  log: jest.fn(),
19
20
  info: jest.fn(),
20
21
  };
21
22
 
22
- const navigator = {
23
+ const mockNavigator: any = {
23
24
  currentRoute: "/river/A1234",
24
25
  getStack: jest.fn(() => []),
25
26
  };
26
27
 
27
- const routeData = {
28
+ const mockRouteData: any = {
28
29
  screenData: {},
29
30
  pathname: "/river/A1234",
30
31
  };
31
32
 
32
- jest.mock("../../logger", () => ({
33
+ jest.doMock("../../logger", () => ({
33
34
  reactHooksLogger: {
34
- addSubsystem: jest.fn(() => logger),
35
+ addSubsystem: jest.fn(() => mockLogger),
35
36
  },
36
37
  }));
37
38
 
38
39
  jest
39
40
  .spyOn(useNavigationHooks, "useNavigation")
40
- .mockImplementation(() => navigator);
41
+ .mockImplementation(() => mockNavigator);
41
42
 
42
- jest.spyOn(navigationHooks, "useRoute").mockImplementation(() => routeData);
43
-
44
- const { useFeedLoader } = require("../useFeedLoader");
43
+ jest.spyOn(useRouteHook, "useRoute").mockImplementation(() => mockRouteData);
45
44
 
46
45
  const mockZappPipesData = {
47
46
  data: {
@@ -87,7 +87,7 @@ export const useFeedLoader = ({
87
87
  );
88
88
  }
89
89
  }
90
- }, [callableFeedUrl, currentFeed?.data]);
90
+ }, [callableFeedUrl, currentFeed?.data?.next]);
91
91
 
92
92
  useEffect(() => {
93
93
  if (
@@ -1,12 +1,12 @@
1
1
  import React from "react";
2
2
  import { useDispatch } from "react-redux";
3
- import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
4
- import {
5
- getDatasourceUrl,
6
- usePipesContexts,
7
- } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils";
3
+
4
+ import { getDatasourceUrl } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/getDatasourceUrl";
5
+ import { usePipesContexts } from "@applicaster/zapp-react-native-ui-components/Decorators/RiverFeedLoader/utils/usePipesContexts";
8
6
  import { clearPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
9
7
 
8
+ import { useRoute } from "../navigation/useRoute";
9
+
10
10
  /**
11
11
  * reset river components cache when screen is unmounted
12
12
  * @param {string} riverId screen id
@@ -1,6 +1,5 @@
1
1
  import * as React from "react";
2
- import { renderHook, act } from "@testing-library/react-hooks";
3
- import { render } from "@testing-library/react-native";
2
+ import { renderHook, render, act } from "@testing-library/react-native";
4
3
  import { View } from "react-native";
5
4
 
6
5
  import { useSequentialLoader, useSequentialRenderItem } from "..";
@@ -66,26 +65,28 @@ describe("flatList hooks", () => {
66
65
 
67
66
  expect(result.current.allLoaded).toBe(false);
68
67
 
69
- result.current.renderItem(
70
- ({ onLoadFinished }) => {
71
- onLoadFinished();
72
- },
73
- { index: 1 }
74
- );
68
+ act(() => {
69
+ result.current.renderItem(
70
+ ({ onLoadFinished }) => {
71
+ onLoadFinished();
72
+ },
73
+ { index: 1 }
74
+ );
75
+ });
75
76
 
76
77
  expect(result.current.allLoaded).toBe(true);
77
78
  });
78
79
  });
79
80
 
80
81
  describe("Rendering wrapper", () => {
81
- it("wraps the elements in the View with display: none style", () => {
82
+ it("wraps the elements in the View with display: none style", async () => {
82
83
  const element1 = { id: 1 };
83
84
  const element2 = { id: 2 };
84
85
  const mockData = [element1, element2];
85
86
 
86
87
  const { result } = renderHook(() => useSequentialRenderItem(mockData));
87
88
 
88
- const { getByTestId } = render(
89
+ const res = render(
89
90
  result.current.renderItem(
90
91
  () => {
91
92
  return <View testID={"test"} />;
@@ -94,7 +95,9 @@ describe("flatList hooks", () => {
94
95
  )
95
96
  );
96
97
 
97
- const element = getByTestId("sequential-river-wrapper-1");
98
+ const element = res.root.findByProps({
99
+ testID: "sequential-river-wrapper-1",
100
+ });
98
101
 
99
102
  expect(element.props.style.display).toEqual("none");
100
103
  });
@@ -106,14 +109,16 @@ describe("flatList hooks", () => {
106
109
 
107
110
  const { result } = renderHook(() => useSequentialRenderItem(mockData));
108
111
 
109
- result.current.renderItem(
110
- ({ onLoadFinished }) => {
111
- onLoadFinished();
112
- },
113
- { item: element1, index: 0 }
114
- );
112
+ act(() => {
113
+ result.current.renderItem(
114
+ ({ onLoadFinished }) => {
115
+ onLoadFinished();
116
+ },
117
+ { item: element1, index: 0 }
118
+ );
119
+ });
115
120
 
116
- const { getByTestId } = render(
121
+ const { root } = render(
117
122
  result.current.renderItem(
118
123
  ({ onLoadFinished }) => {
119
124
  onLoadFinished();
@@ -124,7 +129,9 @@ describe("flatList hooks", () => {
124
129
  )
125
130
  );
126
131
 
127
- const element = getByTestId("sequential-river-wrapper-1");
132
+ const element = root.findByProps({
133
+ testID: "sequential-river-wrapper-1",
134
+ });
128
135
 
129
136
  expect(element.props.style.display).toEqual("flex");
130
137
  });
@@ -136,7 +143,7 @@ describe("flatList hooks", () => {
136
143
 
137
144
  const { result } = renderHook(() => useSequentialRenderItem(mockData));
138
145
 
139
- const { getByTestId } = render(
146
+ const { root } = render(
140
147
  result.current.renderItem(
141
148
  ({ onLoadFinished }) => {
142
149
  onLoadFinished();
@@ -147,7 +154,9 @@ describe("flatList hooks", () => {
147
154
  )
148
155
  );
149
156
 
150
- const element = getByTestId("sequential-river-wrapper-1");
157
+ const element = root.findByProps({
158
+ testID: "sequential-river-wrapper-1",
159
+ });
151
160
 
152
161
  expect(element.props.style.display).toEqual("none");
153
162
  });
@@ -14,10 +14,10 @@ const mocked_return_value = (tv) => ({
14
14
  });
15
15
 
16
16
  const platform = "android";
17
- let tv_flag = false;
17
+ let mock_tv_flag = false;
18
18
 
19
19
  ReactNative.Dimensions.get = jest.fn(
20
- (context) => mocked_return_value(tv_flag)[context]
20
+ (context) => mocked_return_value(mock_tv_flag)[context]
21
21
  );
22
22
 
23
23
  const mockRemoveFn = jest.fn();
@@ -43,7 +43,7 @@ jest.mock("react-native-safe-area-context", () => ({
43
43
 
44
44
  jest.mock("../../../reactUtils", () => ({
45
45
  platformSelect: jest.fn((specs) => specs[platform] || specs.default),
46
- isTV: jest.fn(() => tv_flag),
46
+ isTV: jest.fn(() => mock_tv_flag),
47
47
  }));
48
48
 
49
49
  jest.mock("../../navigation", () => ({
@@ -134,20 +134,20 @@ describe("useDimensions", () => {
134
134
 
135
135
  describe("it applies the scale to the width & height if needed", () => {
136
136
  it("applies the scale on TV, and screen context", () => {
137
- tv_flag = true;
138
- const { screen } = mocked_return_value(tv_flag);
137
+ mock_tv_flag = true;
138
+ const { screen } = mocked_return_value(mock_tv_flag);
139
139
  const { dimensions } = testHook("screen");
140
140
 
141
141
  expect(dimensions).toHaveProperty("height", screen.height * screen.scale);
142
142
  expect(dimensions).toHaveProperty("width", screen.width * screen.scale);
143
143
  expect(dimensions).toHaveProperty("scale", 1);
144
144
 
145
- tv_flag = false;
145
+ mock_tv_flag = false;
146
146
  });
147
147
 
148
148
  it("doesn't apply the scale on mobile with screen context", () => {
149
- tv_flag = false;
150
- const { screen } = mocked_return_value(tv_flag);
149
+ mock_tv_flag = false;
150
+ const { screen } = mocked_return_value(mock_tv_flag);
151
151
  const { dimensions } = testHook("screen");
152
152
 
153
153
  expect(dimensions).toHaveProperty("height", screen.height);
@@ -156,8 +156,8 @@ describe("useDimensions", () => {
156
156
  });
157
157
 
158
158
  it("doesn't apply the scale on TV with window context", () => {
159
- tv_flag = true;
160
- const { window } = mocked_return_value(tv_flag);
159
+ mock_tv_flag = true;
160
+ const { window } = mocked_return_value(mock_tv_flag);
161
161
  const { dimensions } = testHook("window");
162
162
 
163
163
  expect(dimensions).toHaveProperty("height", window.height);
@@ -1,25 +1,14 @@
1
1
  import * as ReactNative from "react-native";
2
+ import NativeDeviceInfo from "react-native/Libraries/Utilities/NativeDeviceInfo";
2
3
 
3
- const mockDimensionsGet = jest.fn(
4
- (type) =>
5
- ({
6
- window: { width: 1, height: 1 },
7
- screen: { width: 360, height: 540 },
8
- }[type])
9
- );
4
+ const mockDimensions = {
5
+ window: { width: 1, height: 1 },
6
+ screen: { width: 360, height: 540 },
7
+ };
10
8
 
11
- ReactNative.Dimensions.get = mockDimensionsGet;
12
-
13
- const mockGetConstants = jest.fn().mockReturnValue({
14
- Dimensions: {
15
- window: { width: 360, height: 540 },
16
- screen: { width: 360, height: 540 },
17
- },
18
- });
9
+ const mockDimensionsGet = jest.fn((type) => mockDimensions[type]);
19
10
 
20
- jest.mock("react-native/Libraries/Utilities/NativeDeviceInfo", () => ({
21
- getConstants: mockGetConstants,
22
- }));
11
+ ReactNative.Dimensions.get = mockDimensionsGet;
23
12
 
24
13
  const { Platform, Dimensions } = ReactNative;
25
14
 
@@ -34,27 +23,24 @@ describe("useDimensions > helpers ( native )", () => {
34
23
 
35
24
  it("should call Dimensions.get for window context", () => {
36
25
  getInitialDimensions("window");
37
- expect(Dimensions.get).toBeCalled();
26
+ expect(Dimensions.get).toHaveBeenCalled();
38
27
  });
39
28
 
40
29
  it("should call Dimensions.get for screen context", () => {
41
30
  getInitialDimensions("screen");
42
- expect(Dimensions.get).toBeCalled();
31
+ expect(Dimensions.get).toHaveBeenCalled();
43
32
  });
44
33
 
45
34
  it("should call NativeDeviceInfo.getConstants for ios when width === height", () => {
46
35
  Platform.OS = "ios";
47
36
 
48
- jest.fn().mockReturnValue({
49
- Dimensions: {
50
- window: { width: 1, height: 1 },
51
- screen: { width: 360, height: 540 },
52
- },
53
- });
37
+ const mockGetConstants = jest
38
+ .spyOn(NativeDeviceInfo, "getConstants")
39
+ .mockReturnValue({ Dimensions: mockDimensions });
54
40
 
55
41
  getInitialDimensions("window");
56
42
 
57
- expect(Dimensions.get).toBeCalled();
58
- expect(mockGetConstants).toBeCalled();
43
+ expect(Dimensions.get).toHaveBeenCalled();
44
+ expect(mockGetConstants).toHaveBeenCalled();
59
45
  });
60
46
  });
@@ -5,7 +5,7 @@ const mockDimensionsGet = jest.fn(
5
5
  ({
6
6
  window: { width: 1, height: 1 },
7
7
  screen: { width: 360, height: 540 },
8
- }[type])
8
+ })[type]
9
9
  );
10
10
 
11
11
  ReactNative.Dimensions.get = mockDimensionsGet;
@@ -52,6 +52,14 @@ export const useDimensions: UseDimensions = (
52
52
  ? { fullDimensions }
53
53
  : { ...fullDimensions };
54
54
 
55
+ if (options.updateForInactiveScreens === undefined) {
56
+ options.updateForInactiveScreens = true;
57
+ }
58
+
59
+ if (options.fullDimensions === undefined) {
60
+ options.fullDimensions = false;
61
+ }
62
+
55
63
  const [dimensions, setDimensions] = useState(getInitialDimensions(context));
56
64
  const deviceInfo = useRef(getDeviceInfo(dimensions, appData));
57
65
 
@@ -3,5 +3,8 @@ export const useNavigation = jest.fn(() => ({
3
3
  screenData: {
4
4
  name: "someName",
5
5
  },
6
+ videoModalState: {
7
+ visible: false,
8
+ },
6
9
  currentRoute: "someRoute",
7
10
  }));