@applicaster/quick-brick-core 14.0.0-alpha.5114565431 → 14.0.0-alpha.5203410334

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 (25) hide show
  1. package/App/ActionsProvider/index.js +1 -1
  2. package/App/AppStateDecorator/index.tsx +2 -2
  3. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/usePresentSchemeHandler.test.tsx +11 -4
  4. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useOpenSchemeHandler/index.ts +7 -2
  5. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/usePresentSchemeHandler.ts +6 -4
  6. package/App/DeepLinking/URLSchemeHandler/__tests__/URLSchemeHandler.test.tsx +4 -4
  7. package/App/ModalProvider/ModalChildrenWrapper/index.tsx +2 -7
  8. package/App/NavigationProvider/NavigationProvider.tsx +29 -9
  9. package/App/NavigationProvider/navigator/__tests__/__snapshots__/reducer.test.ts.snap +0 -177
  10. package/App/NavigationProvider/navigator/__tests__/reducer.test.ts +2 -70
  11. package/App/NavigationProvider/navigator/reducer.ts +30 -101
  12. package/App/NavigationProvider/navigator/selectors.ts +2 -1
  13. package/App/RouterDecorator/__tests__/routerDecorator.test.js +3 -3
  14. package/App/StoreConnector/index.ts +1 -1
  15. package/App/__tests__/createQuickBrickApp.test.js +7 -7
  16. package/App/appLifeCycleManager/__tests__/appLifeCycleManager.test.tsx +22 -27
  17. package/App/appLifeCycleManager/index.tsx +5 -6
  18. package/App/index.tsx +29 -25
  19. package/App/remoteContextReloader/__tests__/getRemoteContextData.test.js +11 -12
  20. package/App/remoteContextReloader/getRemoteContextData/getNativeRemoteContextData.ts +5 -3
  21. package/README.md +0 -4
  22. package/createZappApp/__tests__/createZappApp.test.js +11 -0
  23. package/createZappApp/index.tsx +4 -5
  24. package/index.d.ts +0 -1
  25. package/package.json +8 -12
@@ -1,6 +1,8 @@
1
1
  import * as R from "ramda";
2
2
  import { v4 } from "uuid";
3
3
 
4
+ import { last } from "@applicaster/zapp-react-native-utils/utils";
5
+
4
6
  import {
5
7
  firstStackEntriesSelector,
6
8
  previousStackEntriesSelector,
@@ -18,7 +20,6 @@ export const initialState: NavigationReducerState = {
18
20
  mainStack: [],
19
21
  modal: null,
20
22
  },
21
- location: { key: "", pathname: "/", state: null },
22
23
  options: {
23
24
  videoModal: {
24
25
  visible: false,
@@ -38,7 +39,6 @@ export enum ACTIONS {
38
39
  BACK_PLAYER_NESTED_CONTENT = "BACK_PLAYER_NESTED_CONTENT",
39
40
  REPLACE_TOP = "REPLACE_TOP",
40
41
  SET_NESTED_CONTENT = "SET_NESTED_CONTENT",
41
- SET_LOCATION = "SET_LOCATION",
42
42
  OPEN_VIDEO_MODAL = "OPEN_VIDEO_MODAL",
43
43
  CLOSE_VIDEO_MODAL = "CLOSE_VIDEO_MODAL",
44
44
  MINIMISE_VIDEO_MODAL = "MINIMISE_VIDEO_MODAL",
@@ -174,9 +174,9 @@ function backPlayerNestedContent(state) {
174
174
  return findPlayableAndTruncate(currentState);
175
175
  }
176
176
 
177
- function addNestedContent(stack, payload, locationState: LocationReducerState) {
178
- const locationKey = locationState.key;
179
- const stackIndex = R.findIndex(R.propEq("key", locationKey))(stack);
177
+ function addNestedContent(stack, payload, targetStackEntry) {
178
+ const targetStackKey = targetStackEntry.key;
179
+ const stackIndex = R.findIndex(R.propEq("key", targetStackKey))(stack);
180
180
 
181
181
  return R.adjust(
182
182
  stackIndex,
@@ -190,7 +190,7 @@ function addNestedContent(stack, payload, locationState: LocationReducerState) {
190
190
 
191
191
  function navigationStackReducer(
192
192
  state: NavigationStackReducerState = initialState.stack,
193
- { type = "", payload, meta }: ReducerAction = { type: "" }
193
+ { type = "", payload }: ReducerAction = { type: "" }
194
194
  ) {
195
195
  switch (type) {
196
196
  case ACTIONS.SET_NESTED_CONTENT:
@@ -199,7 +199,7 @@ function navigationStackReducer(
199
199
  mainStack: addNestedContent(
200
200
  state.mainStack,
201
201
  navigationEntry(ACTIONS.REPLACE, payload as AnyRecord),
202
- meta as LocationReducerState
202
+ last(state.mainStack)
203
203
  ),
204
204
  };
205
205
  case ACTIONS.PUSH:
@@ -268,47 +268,6 @@ function navigationStackReducer(
268
268
  }
269
269
  }
270
270
 
271
- function locationReducer(
272
- state = initialState.location,
273
- { type, payload, meta = {} }
274
- ) {
275
- const { route, key, screen, entry, options } = payload;
276
-
277
- switch (type) {
278
- case ACTIONS.BACK:
279
- // eslint-disable-next-line no-case-declarations
280
- const previousEntry = R.compose(
281
- R.last,
282
- payload.route ? firstStackEntriesSelector : previousStackEntriesSelector
283
- )(meta);
284
-
285
- if (previousEntry) {
286
- const { state, key, action } = previousEntry;
287
-
288
- return { pathname: previousEntry.route, state, key, action };
289
- }
290
-
291
- return state;
292
-
293
- case ACTIONS.PUSH:
294
- case ACTIONS.REPLACE:
295
- case ACTIONS.REPLACE_TOP:
296
- case ACTIONS.BACK_PLAYER_NESTED_CONTENT:
297
- return { pathname: route, state: { screen, entry, options }, key };
298
-
299
- case ACTIONS.SET_NESTED_CONTENT:
300
- // eslint-disable-next-line no-case-declarations
301
- const nestedEntry = navigationEntry(
302
- ACTIONS.REPLACE,
303
- payload as AnyRecord
304
- );
305
-
306
- return R.assocPath(["state", "nested"], nestedEntry.state, state);
307
- default:
308
- return state;
309
- }
310
- }
311
-
312
271
  /* Video Modal reducer */
313
272
  export const setVideoModalOpen = (item, options, screen) => ({
314
273
  type: ACTIONS.OPEN_VIDEO_MODAL,
@@ -354,43 +313,28 @@ export const videoModalReducer = (
354
313
  switch (type) {
355
314
  case ACTIONS.OPEN_VIDEO_MODAL: {
356
315
  const { item, options } = payload;
316
+ const mode = options?.mode || MAXIMIZED;
357
317
 
358
- const mode = R.pathOr(MAXIMIZED, ["mode"], options);
359
-
360
- return R.compose(
361
- R.set(R.lensProp("mode"), mode),
362
- R.set(R.lensProp("visible"), true),
363
- R.over(
364
- R.lensProp("item"),
365
- R.unless(R.tryCatch(R.propEq("id", item?.id), R.F), () => item)
366
- )
367
- )(state);
318
+ return {
319
+ ...state,
320
+ visible: true,
321
+ mode,
322
+ item: state.item?.id !== item?.id ? item : state.item,
323
+ };
368
324
  }
369
325
 
370
326
  case ACTIONS.SET_VIDEO_MODAL_ITEM:
371
- return R.set(R.lensProp("item"), payload)(state);
327
+ return { ...state, item: payload };
372
328
  case ACTIONS.CLOSE_VIDEO_MODAL:
373
329
  return initialState.options.videoModal;
374
330
  case ACTIONS.FULLSCREEN_VIDEO_MODAL:
375
- return R.compose(
376
- R.set(R.lensProp("mode"), FULLSCREEN),
377
- R.set(R.lensProp("previousMode"), state.mode)
378
- )(state);
331
+ return { ...state, mode: FULLSCREEN, previousMode: state.mode };
379
332
  case ACTIONS.MINIMISE_VIDEO_MODAL:
380
- return R.compose(
381
- R.set(R.lensProp("mode"), MINIMIZED),
382
- R.set(R.lensProp("previousMode"), state.mode)
383
- )(state);
333
+ return { ...state, mode: MINIMIZED, previousMode: state.mode };
384
334
  case ACTIONS.MAXIMISE_VIDEO_MODAL:
385
- return R.compose(
386
- R.set(R.lensProp("mode"), MAXIMIZED),
387
- R.set(R.lensProp("previousMode"), state.mode)
388
- )(state);
335
+ return { ...state, mode: MAXIMIZED, previousMode: state.mode };
389
336
  case ACTIONS.PIP:
390
- return R.compose(
391
- R.set(R.lensProp("mode"), PIP),
392
- R.set(R.lensProp("previousMode"), state.mode)
393
- )(state);
337
+ return { ...state, mode: PIP, previousMode: state.mode };
394
338
  }
395
339
  };
396
340
 
@@ -406,34 +350,19 @@ export default function navigationReducer(
406
350
  case ACTIONS.REPLACE_TOP:
407
351
  case ACTIONS.BACK:
408
352
  case ACTIONS.BACK_PLAYER_NESTED_CONTENT:
409
- return R.evolve(
410
- {
411
- stack: applyReducer(navigationStackReducer, { type, payload }),
412
- location: applyReducer(locationReducer, {
413
- type,
414
- payload,
415
- meta: state,
416
- }),
417
- },
418
- state
419
- );
353
+ return {
354
+ ...state,
355
+ stack: navigationStackReducer(state.stack, { type, payload }),
356
+ };
420
357
 
421
358
  case ACTIONS.SET_NESTED_CONTENT:
422
- return R.evolve(
423
- {
424
- stack: applyReducer(navigationStackReducer, {
425
- type,
426
- payload,
427
- meta: state.location,
428
- }),
429
- location: applyReducer(locationReducer, {
430
- type,
431
- payload,
432
- meta: state.stack,
433
- }),
434
- },
435
- state
436
- );
359
+ return {
360
+ ...state,
361
+ stack: navigationStackReducer(state.stack, {
362
+ type,
363
+ payload,
364
+ }),
365
+ };
437
366
 
438
367
  case ACTIONS.OPEN_VIDEO_MODAL:
439
368
  case ACTIONS.CLOSE_VIDEO_MODAL:
@@ -1,5 +1,5 @@
1
1
  import * as R from "ramda";
2
- import { createSelector } from "reselect";
2
+ import { createSelector } from "@reduxjs/toolkit";
3
3
 
4
4
  import { getPathAttributes } from "@applicaster/zapp-react-native-utils/navigationUtils";
5
5
 
@@ -7,6 +7,7 @@ const riverSelector = R.prop("rivers");
7
7
  const pathnameSelector = R.prop("pathname");
8
8
  const navigationStackSelector = R.prop("stack");
9
9
 
10
+ // @TODO extract to zapp-react-native-redux/selectors, remove ramda
10
11
  export const homeRiverSelector = createSelector(
11
12
  riverSelector,
12
13
  R.compose(R.find(R.propEq("home", true)), R.values)
@@ -1,6 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { View } from "react-native";
3
- import ReactTestRenderer from "react-test-renderer";
3
+ import { render } from "@testing-library/react-native";
4
4
 
5
5
  import { createRouterDecorator } from "../index";
6
6
 
@@ -26,7 +26,7 @@ describe("routerDecorator", () => {
26
26
  const decorator = createRouterDecorator(Router);
27
27
  const DecoratedComp = decorator(SomeComp);
28
28
 
29
- const wrapper = ReactTestRenderer.create(<DecoratedComp foo="bar" />);
30
- expect(wrapper.toJSON()).toMatchSnapshot();
29
+ const { toJSON } = render(<DecoratedComp foo="bar" />);
30
+ expect(toJSON()).toMatchSnapshot();
31
31
  });
32
32
  });
@@ -1,5 +1,5 @@
1
1
  import * as R from "ramda";
2
- import { connectToStore } from "@applicaster/zapp-react-native-redux";
2
+ import { connectToStore } from "@applicaster/zapp-react-native-redux/utils/connectToStore";
3
3
 
4
4
  const REDUX_STORE_PROPS = [
5
5
  "components",
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable indent */
2
2
  import * as React from "react";
3
- import ReactTestRenderer from "react-test-renderer";
3
+ import { render } from "@testing-library/react-native";
4
4
  import { Provider } from "react-redux";
5
5
  import thunk from "redux-thunk";
6
6
  import configureStore from "redux-mock-store";
@@ -175,13 +175,13 @@ describe("createQuickBrickApp", () => {
175
175
  it("returns a react component and it renders correctly", () => {
176
176
  const QuickBrickApp = createQuickBrickApp(options);
177
177
 
178
- const wrapper = ReactTestRenderer.create(
178
+ const { toJSON } = render(
179
179
  <Provider store={store}>
180
180
  <QuickBrickApp store={store} />
181
181
  </Provider>
182
182
  );
183
183
 
184
- expect(wrapper.toJSON()).toMatchSnapshot();
184
+ expect(toJSON()).toMatchSnapshot();
185
185
  });
186
186
 
187
187
  describe("with no InteractionManager", () => {
@@ -190,13 +190,13 @@ describe("createQuickBrickApp", () => {
190
190
  const { InteractionManager, ...otherOptions } = options;
191
191
  const QuickBrickApp = createQuickBrickApp(otherOptions);
192
192
 
193
- const wrapper = ReactTestRenderer.create(
193
+ const { toJSON } = render(
194
194
  <Provider store={store}>
195
195
  <QuickBrickApp store={store} />
196
196
  </Provider>
197
197
  );
198
198
 
199
- expect(wrapper.toJSON()).toMatchSnapshot();
199
+ expect(toJSON()).toMatchSnapshot();
200
200
  });
201
201
  });
202
202
 
@@ -206,13 +206,13 @@ describe("createQuickBrickApp", () => {
206
206
  const { ContextProviders, ...otherOptions } = options;
207
207
  const QuickBrickApp = createQuickBrickApp(otherOptions);
208
208
 
209
- const wrapper = ReactTestRenderer.create(
209
+ const { toJSON } = render(
210
210
  <Provider store={store}>
211
211
  <QuickBrickApp store={store} />
212
212
  </Provider>
213
213
  );
214
214
 
215
- expect(wrapper.toJSON()).toMatchSnapshot();
215
+ expect(toJSON()).toMatchSnapshot();
216
216
  });
217
217
  });
218
218
  });
@@ -1,8 +1,8 @@
1
1
  import * as React from "react";
2
2
  import { View, Text } from "react-native";
3
- import { render, waitFor } from "@testing-library/react-native";
4
- import thunk from "redux-thunk";
5
- import configureStore from "redux-mock-store";
3
+ import { waitFor } from "@testing-library/react-native";
4
+ import { renderWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
5
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
6
6
 
7
7
  let mocked_items: Record<string, any> = {};
8
8
 
@@ -10,6 +10,13 @@ import { appLifeCycleManager } from "../";
10
10
 
11
11
  const mock_actions = {};
12
12
 
13
+ jest.mock("@applicaster/zapp-react-native-redux", () => ({
14
+ ...jest.requireActual("@applicaster/zapp-react-native-redux"),
15
+ AppData: {
16
+ loadAppData: jest.fn(() => () => Promise.resolve()),
17
+ },
18
+ }));
19
+
13
20
  jest.mock(
14
21
  "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage",
15
22
  () => ({
@@ -19,10 +26,6 @@ jest.mock(
19
26
  })
20
27
  );
21
28
 
22
- jest.mock("@applicaster/zapp-react-native-redux/AppData", () => ({
23
- loadAppData: jest.fn(() => () => Promise.resolve()),
24
- }));
25
-
26
29
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks/actions", () => ({
27
30
  useActions: jest.fn(() => ({ actions: mock_actions })),
28
31
  }));
@@ -31,6 +34,9 @@ jest.mock(
31
34
  "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage",
32
35
  () => ({
33
36
  localStorage: {
37
+ ...jest.requireActual(
38
+ "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage"
39
+ ).localStorage,
34
40
  getAllItems: jest.fn(() => Promise.resolve(mocked_items)),
35
41
  setItem: jest.fn((key, value) => {
36
42
  mocked_items[key] = JSON.stringify(value);
@@ -73,12 +79,8 @@ const appLoader = jest.fn((_dispatch, _getState) => {
73
79
  return Promise.resolve();
74
80
  });
75
81
 
76
- const store = configureStore([thunk])({});
77
- const dispatch = store.dispatch;
78
-
79
82
  const state = {
80
- rivers: {},
81
- plugins: {},
83
+ plugins: {} as QuickBrickPlugin[],
82
84
  appSettings: { runtimeConfigurationUrls: { rivers: "http://rivers.url" } },
83
85
  };
84
86
 
@@ -100,19 +102,16 @@ describe("appLifeCycleManager", () => {
100
102
  it("runs the loaders, then sends quickBrickReady event", async () => {
101
103
  const testCallback = jest.fn(() => {});
102
104
 
103
- render(
104
- <DecoratedComponent
105
- dispatch={dispatch}
106
- {...state}
107
- testCallback={testCallback}
108
- />
105
+ renderWithProviders(
106
+ <DecoratedComponent {...state} testCallback={testCallback} />,
107
+ state
109
108
  );
110
109
 
111
110
  await waitFor(() => {
112
111
  return expect(testCallback).toHaveBeenCalled();
113
112
  });
114
113
 
115
- const actions = store.getActions();
114
+ const actions = appStore.testStore.getActions();
116
115
 
117
116
  expect(actions[0]).toMatchObject({ type: "SET_APP_READY" });
118
117
 
@@ -126,16 +125,12 @@ describe("appLifeCycleManager", () => {
126
125
  it("sends the quickBrickReady event when a loader doesn't resolves", async () => {
127
126
  const testCallback = jest.fn(() => {});
128
127
 
129
- render(
130
- <DecoratedComponent
131
- dispatch={dispatch}
132
- {...state}
133
- shouldFail
134
- testCallback={testCallback}
135
- />
128
+ renderWithProviders(
129
+ <DecoratedComponent {...state} shouldFail testCallback={testCallback} />,
130
+ state
136
131
  );
137
132
 
138
- const actions = store.getActions();
133
+ const actions = appStore.testStore.getActions();
139
134
 
140
135
  await waitFor(() => {
141
136
  return expect(testCallback).toHaveBeenCalled();
@@ -2,7 +2,7 @@ import * as React from "react";
2
2
  import * as R from "ramda";
3
3
 
4
4
  import { sendLaunchEvent } from "@applicaster/zapp-react-native-utils/analyticsUtils";
5
- import { loadAppData } from "@applicaster/zapp-react-native-redux/AppData";
5
+ import { AppData, useAppDispatch } from "@applicaster/zapp-react-native-redux";
6
6
  import {
7
7
  setAppLaunched,
8
8
  setAppReady,
@@ -13,7 +13,6 @@ import { networkStatusReady } from "../NetworkStatusProvider/networkStatusReady"
13
13
  import { updateSessionNumber } from "../SessionCounter/sessionCounter";
14
14
 
15
15
  import { coreAppLogger } from "../logger";
16
- import { Dispatch } from "@reduxjs/toolkit";
17
16
  import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
18
17
  import { isEmptyOrNil } from "@applicaster/zapp-react-native-utils/cellUtils";
19
18
  import { requiredSessionKeys } from "../../const";
@@ -24,7 +23,6 @@ const logger = coreAppLogger.addSubsystem("AppLifeCycleManager");
24
23
  const isAndroid = isAndroidPlatform();
25
24
 
26
25
  type Props = {
27
- dispatch: Dispatch;
28
26
  testCallback: () => void;
29
27
  plugins: QuickBrickPlugin[];
30
28
  appSettings: { runtimeConfigurationUrls: { [key in string]: string } };
@@ -35,6 +33,7 @@ export function appLifeCycleManager(appLoader, QuickBrickManager) {
35
33
  // this function is not called until React View is mounted to activity(ie quickBrickReady event sent)
36
34
  return function AppLifeCycleManagerRenderer(props: Props) {
37
35
  const actionsInitialStateSetters = useActionSetters();
36
+ const dispatch = useAppDispatch();
38
37
  // using useLayoutEffect to call the loader just after the DOM render to mimic componentDidMount timing
39
38
 
40
39
  async function setUpdateSessionNumber(results: unknown[]) {
@@ -93,7 +92,7 @@ export function appLifeCycleManager(appLoader, QuickBrickManager) {
93
92
  }
94
93
 
95
94
  function makeAppReady() {
96
- const { dispatch, testCallback } = props;
95
+ const { testCallback } = props;
97
96
 
98
97
  dispatch(setAppReady());
99
98
  dispatch(setAppLaunched());
@@ -153,14 +152,14 @@ export function appLifeCycleManager(appLoader, QuickBrickManager) {
153
152
 
154
153
  const prepareApp = async () => {
155
154
  // eslint-disable-next-line unused-imports/no-unused-vars
156
- const { dispatch, testCallback, ...state } = props;
155
+ const { testCallback, ...state } = props;
157
156
 
158
157
  try {
159
158
  const getState = () => state;
160
159
 
161
160
  const loaders = [
162
161
  appLoader(dispatch, getState),
163
- dispatch<any>(loadAppData()),
162
+ dispatch<any>(AppData.loadAppData()),
164
163
  networkStatusReady(),
165
164
  ];
166
165
 
package/App/index.tsx CHANGED
@@ -1,6 +1,8 @@
1
1
  import * as React from "react";
2
2
  import * as R from "ramda";
3
3
 
4
+ import { GestureHandlerRootView } from "react-native-gesture-handler";
5
+
4
6
  import {
5
7
  initialWindowMetrics,
6
8
  SafeAreaProvider,
@@ -59,31 +61,33 @@ const App = ({
59
61
  } = props;
60
62
 
61
63
  return (
62
- <ThemeManager plugins={plugins}>
63
- <SafeAreaProvider initialMetrics={initialWindowMetrics}>
64
- <AppContainer styles={styles}>
65
- <ErrorBoundary>
66
- <URLSchemeListener>
67
- <SplashLoader>
68
- <OfflineHandler>
69
- <Layout>
70
- <RouteManager />
71
- </Layout>
72
- </OfflineHandler>
73
- </SplashLoader>
74
- <ModalProvider />
75
- </URLSchemeListener>
76
- <LoadingOverlay />
77
- </ErrorBoundary>
78
- <LogicAggregatorContainer
79
- components={React.useMemo(
80
- () => [InteractionManager, ApplyScreenHooks],
81
- [InteractionManager, ApplyScreenHooks]
82
- )}
83
- />
84
- </AppContainer>
85
- </SafeAreaProvider>
86
- </ThemeManager>
64
+ <GestureHandlerRootView>
65
+ <ThemeManager plugins={plugins}>
66
+ <SafeAreaProvider initialMetrics={initialWindowMetrics}>
67
+ <AppContainer styles={styles}>
68
+ <ErrorBoundary>
69
+ <URLSchemeListener>
70
+ <SplashLoader>
71
+ <OfflineHandler>
72
+ <Layout>
73
+ <RouteManager />
74
+ </Layout>
75
+ </OfflineHandler>
76
+ </SplashLoader>
77
+ <ModalProvider />
78
+ </URLSchemeListener>
79
+ <LoadingOverlay />
80
+ </ErrorBoundary>
81
+ <LogicAggregatorContainer
82
+ components={React.useMemo(
83
+ () => [InteractionManager, ApplyScreenHooks],
84
+ [InteractionManager, ApplyScreenHooks]
85
+ )}
86
+ />
87
+ </AppContainer>
88
+ </SafeAreaProvider>
89
+ </ThemeManager>
90
+ </GestureHandlerRootView>
87
91
  );
88
92
  });
89
93
 
@@ -1,10 +1,16 @@
1
- import * as ReduxModule from "@applicaster/zapp-react-native-redux";
2
1
  import nock from "nock";
3
2
 
4
3
  jest.mock("../../AssetCache", () => ({
5
4
  cacheAssets: jest.fn((x) => x),
6
5
  }));
7
6
 
7
+ const mockLoadAppContextData = jest.fn(() => ({}));
8
+
9
+ jest.mock("@applicaster/zapp-react-native-redux", () => ({
10
+ ...jest.requireActual("@applicaster/zapp-react-native-redux"),
11
+ loadAppContextData: mockLoadAppContextData,
12
+ }));
13
+
8
14
  const uuid = "342ee911-03b6-4a16-adde-ece5ef739feb";
9
15
 
10
16
  const { getRemoteContextData } = require("../getRemoteContextData");
@@ -100,11 +106,12 @@ const failingRuntimeConfigurationUrls = {
100
106
  remote_configurations_url: "http://zapp.com/failing.json",
101
107
  };
102
108
 
103
- let reduxLoaderSpy;
104
109
  const dispatch = jest.fn();
105
110
 
106
111
  describe("getRemoteContextData", () => {
107
112
  beforeEach(() => {
113
+ mockLoadAppContextData.mockClear();
114
+
108
115
  nock("http://zapp.com").persist().get("/layout.json").reply(200, layout);
109
116
 
110
117
  nock("http://zapp.com")
@@ -120,20 +127,12 @@ describe("getRemoteContextData", () => {
120
127
  nock("http://zapp.com")
121
128
  .get("/failing.json")
122
129
  .reply(Math.floor(Math.random() * 200 + 400), 0);
123
-
124
- reduxLoaderSpy = jest
125
- .spyOn(ReduxModule, "loadAppContextData")
126
- .mockImplementation(() => ({}));
127
- });
128
-
129
- afterEach(() => {
130
- reduxLoaderSpy.mockRestore();
131
130
  });
132
131
 
133
132
  it("returns a map of context data with the result of the matched urls", async () => {
134
133
  await getRemoteContextData(dispatch, runtimeConfigurationUrls, plugins);
135
134
 
136
- return expect(reduxLoaderSpy).toHaveBeenCalledWith(
135
+ return expect(mockLoadAppContextData).toHaveBeenCalledWith(
137
136
  dispatch,
138
137
  expect.objectContaining({
139
138
  pluginConfigurations,
@@ -147,7 +146,7 @@ describe("getRemoteContextData", () => {
147
146
  });
148
147
 
149
148
  it("skips the context data if it cannot be retrieved", async () => {
150
- expect(reduxLoaderSpy).not.toHaveBeenCalled();
149
+ expect(mockLoadAppContextData).not.toHaveBeenCalled();
151
150
 
152
151
  return expect(
153
152
  getRemoteContextData(dispatch, failingRuntimeConfigurationUrls, plugins)
@@ -1,12 +1,14 @@
1
1
  import * as R from "ramda";
2
2
  import isEmpty from "lodash/isEmpty";
3
3
  import { Dimensions, NativeModules } from "react-native";
4
- import { loadAppContextData } from "@applicaster/zapp-react-native-redux";
4
+ import {
5
+ loadAppContextData,
6
+ AppData,
7
+ } from "@applicaster/zapp-react-native-redux";
5
8
  import { isTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
6
9
  import { mapPromises } from "@applicaster/zapp-react-native-utils/arrayUtils";
7
10
  import { fetchPluginConfiguration, getPromiseForType } from "../helpers";
8
11
  import { cacheAssets } from "../../AssetCache";
9
- import { actions as appDataActions } from "@applicaster/zapp-react-native-redux/AppData";
10
12
  import { logger } from "@applicaster/zapp-react-native-utils/logger";
11
13
  import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "../consts";
12
14
  const { AppLoaderBridge } = NativeModules;
@@ -74,7 +76,7 @@ export async function getNativeRemoteContextData(
74
76
 
75
77
  const apiVersion = layout?.layout?.["api_version"]; // Taken from remote configuration
76
78
 
77
- dispatch(appDataActions.merge({ layoutVersion: apiVersion || "v1" }));
79
+ dispatch(AppData.actions.merge({ layoutVersion: apiVersion || "v1" }));
78
80
 
79
81
  const resolvedPromises = await mapPromises(getPromiseForType, ["cellStyles"]);
80
82
 
package/README.md CHANGED
@@ -42,10 +42,6 @@ Creates a Zapp App with the provided options :
42
42
  - `module`: the plugin's callable function / React component
43
43
  - `name`: the name of the plugin - should match the `PascalCase`'d identifier of the plugin. If your plugin's identifier is `react-native-article`, the name should be `ReactNativeArticle`
44
44
  - `type`: the type of the plugin, as it is defined in the plugin's manifest in Zapp
45
- - `reduxStoreOptions`: (optional)
46
- - `additionalReducers`: map of reducers to load in the redux store, on top of the existing ones. See available reducers' names to avoid name collision which would override your own custom reducers
47
- - `additionalMiddlewares`: array of additional middlewares to load - by default, the ZappApp will have the `thunk` middleware, but others can be added
48
- - `initialState`: optional initial state for the redux store
49
45
  - `pluginConfigurations`: the remote configuration options for plugins, as coming from Zapp
50
46
  - `remoteConfigurations`: Zapp's remote configurations
51
47
  - `appSettings`: arbitrary app settings which will be stored in the redux store.
@@ -75,6 +75,17 @@ jest.mock("@applicaster/zapp-react-native-bridge/QuickBrick", () => ({
75
75
  getLegacyInitialProps: jest.fn(() => ({ initialProps: {} })),
76
76
  }));
77
77
 
78
+ jest.mock(
79
+ "@applicaster/zapp-react-native-ui-components/Components/River",
80
+ () => {
81
+ const View = require("react-native").View;
82
+
83
+ return {
84
+ River: jest.fn(() => <View testID="mock-river" />),
85
+ };
86
+ }
87
+ );
88
+
78
89
  describe("createZappApp", () => {
79
90
  it("renders the provided React App", () => {
80
91
  const ZappApp = createZappApp({ App });