@applicaster/quick-brick-core 15.0.0-rc.5 → 15.0.0-rc.50
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.
- package/App/ActionSetters/index.ts +5 -4
- package/App/ActionsProvider/ActionsProvider.tsx +6 -1
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx +12 -27
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useUrlSchemeHandler.test.tsx +196 -103
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useOpenSchemeHandler/index.ts +4 -7
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/useUrlSchemeHandler.ts +42 -30
- package/App/DeepLinking/URLSchemeHandler/URLSchemeHandler.tsx +4 -1
- package/App/DeepLinking/URLSchemeHandler/__tests__/URLSchemeHandler.test.tsx +20 -13
- package/App/DeepLinking/URLSchemeListener/index.tsx +3 -4
- package/App/ModalProvider/ModalBottomSheet/ModalBottomSheetFrame.tsx +6 -1
- package/App/NavigationProvider/Loader.tsx +3 -4
- package/App/NavigationProvider/NavigationProvider.tsx +21 -35
- package/App/NavigationProvider/ScreenHooks/usePluginScreenHooks.ts +2 -2
- package/App/NavigationProvider/__tests__/navigationProvider.test.tsx +141 -152
- package/App/NavigationProvider/navigator/selectors.ts +21 -5
- package/App/NetworkStatusProvider/NetworkStatusProvider.tsx +2 -2
- package/App/components/ZappAppWrapper.web.ts +2 -2
- package/App/remoteContextReloader/getRemoteContextData/getNativeRemoteContextData.ts +1 -1
- package/App/remoteContextReloader/helpers.ts +3 -3
- package/package.json +8 -8
- package/App/DeepLinking/URLSchemeHandler/__tests__/__snapshots__/URLSchemeHandler.test.tsx.snap +0 -24
|
@@ -3,16 +3,15 @@ import React, { useCallback, useContext } from "react";
|
|
|
3
3
|
import { URLSchemeHandler } from "../URLSchemeHandler";
|
|
4
4
|
import { URLSchemeContext } from "./URLSchemeContextProvider";
|
|
5
5
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
6
|
-
import {
|
|
6
|
+
import { useAppSelector } from "@applicaster/zapp-react-native-redux/hooks";
|
|
7
|
+
import { selectAppReady } from "@applicaster/zapp-react-native-redux";
|
|
7
8
|
|
|
8
9
|
export function URLSchemeListener({ children }: { children: React.ReactNode }) {
|
|
9
10
|
const { url, done } = useContext(URLSchemeContext);
|
|
10
11
|
|
|
11
12
|
const navigator = useNavigation();
|
|
12
13
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
const appReady = appState?.appReady;
|
|
14
|
+
const appReady = useAppSelector(selectAppReady);
|
|
16
15
|
|
|
17
16
|
const onFinish = useCallback(
|
|
18
17
|
(callback) => {
|
|
@@ -42,12 +42,17 @@ const defaultBottomOffset = platformSelect({
|
|
|
42
42
|
android: 0,
|
|
43
43
|
});
|
|
44
44
|
|
|
45
|
+
const SAFE_AREA_BREAKING_API_VERSION = 35;
|
|
46
|
+
|
|
45
47
|
const getSheetHeight = ({ height, bottomOffset, maxHeight }) => {
|
|
46
48
|
return platformSelect({
|
|
47
49
|
ios: height - bottomOffset,
|
|
48
50
|
default:
|
|
49
51
|
(height || maxHeight) -
|
|
50
|
-
(isAndroidPlatform() &&
|
|
52
|
+
(isAndroidPlatform() &&
|
|
53
|
+
!isAndroidVersionAtLeast(SAFE_AREA_BREAKING_API_VERSION)
|
|
54
|
+
? bottomOffset
|
|
55
|
+
: 0),
|
|
51
56
|
});
|
|
52
57
|
};
|
|
53
58
|
|
|
@@ -2,8 +2,9 @@ import React from "react";
|
|
|
2
2
|
import { View, StyleSheet } from "react-native";
|
|
3
3
|
|
|
4
4
|
import { Spinner } from "@applicaster/zapp-react-native-ui-components/Components/Spinner";
|
|
5
|
-
import {
|
|
5
|
+
import { useAppSelector } from "@applicaster/zapp-react-native-redux/hooks";
|
|
6
6
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
7
|
+
import { selectAppLaunched } from "@applicaster/zapp-react-native-redux";
|
|
7
8
|
|
|
8
9
|
type Props = {
|
|
9
10
|
children: React.ReactChild;
|
|
@@ -21,9 +22,7 @@ const styles = StyleSheet.create({
|
|
|
21
22
|
});
|
|
22
23
|
|
|
23
24
|
export function Loader({ children }: Props) {
|
|
24
|
-
const
|
|
25
|
-
appState: { appLaunched },
|
|
26
|
-
} = usePickFromState(["appState"]);
|
|
25
|
+
const appLaunched = useAppSelector(selectAppLaunched);
|
|
27
26
|
|
|
28
27
|
const { currentRoute } = useNavigation();
|
|
29
28
|
|
|
@@ -13,10 +13,6 @@ import {
|
|
|
13
13
|
useGetScreenOrientation,
|
|
14
14
|
} from "@applicaster/zapp-react-native-utils/appUtils/orientationHelper";
|
|
15
15
|
import { focusManager } from "@applicaster/zapp-react-native-utils/focusManager/FocusManager";
|
|
16
|
-
import {
|
|
17
|
-
useContentTypes,
|
|
18
|
-
usePickFromState,
|
|
19
|
-
} from "@applicaster/zapp-react-native-redux/hooks";
|
|
20
16
|
|
|
21
17
|
import reducer, {
|
|
22
18
|
ACTIONS,
|
|
@@ -44,6 +40,7 @@ import {
|
|
|
44
40
|
activeRiverSelector,
|
|
45
41
|
homeRiverSelector,
|
|
46
42
|
lastEntrySelector,
|
|
43
|
+
startUpHookPluginIdentifiersSelector,
|
|
47
44
|
} from "./navigator/selectors";
|
|
48
45
|
|
|
49
46
|
import { coreAppLogger } from "../logger";
|
|
@@ -79,6 +76,16 @@ import { Hook } from "@applicaster/zapp-react-native-utils/appUtils/HooksManager
|
|
|
79
76
|
import { URLSchemeContext } from "../DeepLinking/URLSchemeListener/URLSchemeContextProvider";
|
|
80
77
|
|
|
81
78
|
import { loadingOverlayManager } from "../LoadingOverlay";
|
|
79
|
+
import {
|
|
80
|
+
selectAppLaunched,
|
|
81
|
+
useAppSelector,
|
|
82
|
+
useContentTypes,
|
|
83
|
+
usePlugins,
|
|
84
|
+
} from "@applicaster/zapp-react-native-redux";
|
|
85
|
+
import {
|
|
86
|
+
useLayoutVersion,
|
|
87
|
+
useRivers,
|
|
88
|
+
} from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
82
89
|
|
|
83
90
|
const logger = coreAppLogger.addSubsystem("Navigator");
|
|
84
91
|
|
|
@@ -100,22 +107,11 @@ const platform = getPlatform();
|
|
|
100
107
|
export function NavigationProvider({ children }: Props) {
|
|
101
108
|
const { url: deepLinkURL } = React.useContext(URLSchemeContext);
|
|
102
109
|
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
plugins,
|
|
107
|
-
pluginConfigurations,
|
|
108
|
-
appState: { appLaunched },
|
|
109
|
-
} = usePickFromState([
|
|
110
|
-
"appData",
|
|
111
|
-
"rivers",
|
|
112
|
-
"plugins",
|
|
113
|
-
"pluginConfigurations",
|
|
114
|
-
"appState",
|
|
115
|
-
"contentTypes",
|
|
116
|
-
]);
|
|
117
|
-
|
|
110
|
+
const appLaunched = useAppSelector(selectAppLaunched);
|
|
111
|
+
const layoutVersion = useLayoutVersion();
|
|
112
|
+
const rivers = useRivers();
|
|
118
113
|
const contentTypes = useContentTypes();
|
|
114
|
+
const plugins = usePlugins();
|
|
119
115
|
|
|
120
116
|
const [state, dispatch] = React.useReducer<
|
|
121
117
|
NavigationReducer,
|
|
@@ -477,21 +473,11 @@ export function NavigationProvider({ children }: Props) {
|
|
|
477
473
|
openLoadingOverlay();
|
|
478
474
|
};
|
|
479
475
|
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
const startUpHooksIdentifiers = R.compose(
|
|
484
|
-
R.map((item) => item.plugin.identifier),
|
|
485
|
-
R.filter(
|
|
486
|
-
R.allPass([
|
|
487
|
-
R.pathEq(["plugin", "api", "require_startup_execution"], true),
|
|
488
|
-
R.pathEq(["plugin", "react_native"], true),
|
|
489
|
-
R.pathEq(["plugin", "preload"], true),
|
|
490
|
-
])
|
|
491
|
-
),
|
|
492
|
-
R.values
|
|
493
|
-
)(pluginConfigurations);
|
|
476
|
+
const startUpHooksIdentifiers = useAppSelector(
|
|
477
|
+
startUpHookPluginIdentifiersSelector
|
|
478
|
+
);
|
|
494
479
|
|
|
480
|
+
const checkStartUpHooks = React.useMemo(() => {
|
|
495
481
|
if (startUpHooksIdentifiers?.length) {
|
|
496
482
|
const startUpHooks = R.filter(
|
|
497
483
|
(plugin) => R.includes(plugin.identifier, startUpHooksIdentifiers),
|
|
@@ -523,7 +509,7 @@ export function NavigationProvider({ children }: Props) {
|
|
|
523
509
|
}
|
|
524
510
|
|
|
525
511
|
return false;
|
|
526
|
-
}, [
|
|
512
|
+
}, [startUpHooksIdentifiers, plugins, rivers]);
|
|
527
513
|
|
|
528
514
|
const [startUpHooks, _setStartUpHooks] = React.useState(checkStartUpHooks);
|
|
529
515
|
const currentStartUpHooks = React.useRef(checkStartUpHooks);
|
|
@@ -726,7 +712,7 @@ export function NavigationProvider({ children }: Props) {
|
|
|
726
712
|
activeRiver,
|
|
727
713
|
getPathname: () => pathnameRef.current, // hack use to fix issue causing broken navigation as currentRoute is unreliable
|
|
728
714
|
currentRoute: pathname, // TODO: remove. Current route shouldn't be needed
|
|
729
|
-
previousAction: lastEntrySelector(state)
|
|
715
|
+
previousAction: (lastEntrySelector(state) as any)
|
|
730
716
|
?.action as QuickBrickNavigationActionType,
|
|
731
717
|
push: pushItem,
|
|
732
718
|
replace: replaceItem,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { usePlugins } from "@applicaster/zapp-react-native-redux";
|
|
5
5
|
|
|
6
6
|
enum ReactHooks {
|
|
7
7
|
useEffect = "useEffect",
|
|
@@ -39,7 +39,7 @@ function invokeScreenHook(hooksWrappers) {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
export function usePluginScreenHooks(pathname: string) {
|
|
42
|
-
const
|
|
42
|
+
const plugins = usePlugins();
|
|
43
43
|
|
|
44
44
|
const hooks = React.useMemo(
|
|
45
45
|
() => R.filter(hasScreenHook, plugins) || [],
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { View } from "react-native";
|
|
3
|
-
import { act, create } from "react-test-renderer";
|
|
4
|
-
import { createStore } from "redux";
|
|
5
|
-
import { Provider } from "react-redux";
|
|
6
3
|
|
|
7
4
|
import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
|
|
5
|
+
import { NavigationProvider } from "../NavigationProvider";
|
|
6
|
+
|
|
8
7
|
import { getByTestId } from "@applicaster/zapp-react-native-utils/testUtils/getByTestId";
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
import { renderWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
|
|
9
|
+
import { act } from "@testing-library/react-native";
|
|
10
|
+
|
|
11
|
+
jest.useFakeTimers({
|
|
12
|
+
legacyFakeTimers: true,
|
|
13
|
+
});
|
|
11
14
|
|
|
12
15
|
const rivers = {
|
|
13
16
|
A1234: {
|
|
@@ -27,20 +30,20 @@ const rivers = {
|
|
|
27
30
|
ui_components: [],
|
|
28
31
|
hooks: {
|
|
29
32
|
postload_plugins: [],
|
|
30
|
-
preload_plugins: [
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
],
|
|
33
|
+
// preload_plugins: [
|
|
34
|
+
// {
|
|
35
|
+
// screen_id: "hook_screen",
|
|
36
|
+
// identifier: "test-hook",
|
|
37
|
+
// type: "general",
|
|
38
|
+
// weight: 7,
|
|
39
|
+
// },
|
|
40
|
+
// {
|
|
41
|
+
// screen_id: "hook_screen2",
|
|
42
|
+
// identifier: "test-hook2",
|
|
43
|
+
// type: "general",
|
|
44
|
+
// weight: 7,
|
|
45
|
+
// },
|
|
46
|
+
// ],
|
|
44
47
|
},
|
|
45
48
|
},
|
|
46
49
|
D6543: {
|
|
@@ -81,13 +84,9 @@ const rivers = {
|
|
|
81
84
|
},
|
|
82
85
|
};
|
|
83
86
|
|
|
84
|
-
jest.mock("@applicaster/zapp-react-native-redux
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
rivers,
|
|
88
|
-
plugins: [],
|
|
89
|
-
appState: { appLaunched: true },
|
|
90
|
-
})),
|
|
87
|
+
jest.mock("@applicaster/zapp-react-native-redux", () => ({
|
|
88
|
+
...jest.requireActual("@applicaster/zapp-react-native-redux"),
|
|
89
|
+
usePickFromState: jest.fn(() => ({})),
|
|
91
90
|
useContentTypes: jest.fn(() => ({})),
|
|
92
91
|
}));
|
|
93
92
|
|
|
@@ -107,8 +106,6 @@ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/connection", () => ({
|
|
|
107
106
|
})),
|
|
108
107
|
}));
|
|
109
108
|
|
|
110
|
-
const { NavigationProvider } = require("../NavigationProvider");
|
|
111
|
-
|
|
112
109
|
// eslint-disable-next-line react/prop-types
|
|
113
110
|
const HookComponent = ({ callback, payload }: Props) => {
|
|
114
111
|
if (payload?.id === "D6543") {
|
|
@@ -154,18 +151,13 @@ const failingHook = {
|
|
|
154
151
|
name: "failing hook",
|
|
155
152
|
};
|
|
156
153
|
|
|
157
|
-
|
|
158
|
-
// rivers,
|
|
159
|
-
// plugins: [hookPlugin, hookPlugin2, failingHook],
|
|
160
|
-
// };
|
|
161
|
-
|
|
162
|
-
const store = createStore(() => ({
|
|
154
|
+
const store = {
|
|
163
155
|
appData: { layoutVersion: "v1" },
|
|
164
|
-
contentTypes:
|
|
156
|
+
contentTypes: {},
|
|
165
157
|
rivers,
|
|
166
158
|
plugins: [hookPlugin, hookPlugin2, failingHook],
|
|
167
159
|
appState: { appLaunched: true },
|
|
168
|
-
}
|
|
160
|
+
};
|
|
169
161
|
|
|
170
162
|
const ContextConsumer = () => {
|
|
171
163
|
const { state, ...navigator } = useNavigation();
|
|
@@ -173,6 +165,7 @@ const ContextConsumer = () => {
|
|
|
173
165
|
let renderHook;
|
|
174
166
|
|
|
175
167
|
if (navigator.currentRoute.includes("/hooks/")) {
|
|
168
|
+
// @ts-ignore
|
|
176
169
|
const { hookPlugin, payload, callback } = navigator.screenData;
|
|
177
170
|
const Component = hookPlugin.module.Component;
|
|
178
171
|
|
|
@@ -192,18 +185,21 @@ const ContextConsumer = () => {
|
|
|
192
185
|
|
|
193
186
|
const consoleSpy = jest.spyOn(console, "error").mockImplementation(() => {});
|
|
194
187
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
<Provider store={store}>
|
|
202
|
-
<NavigationProvider>
|
|
203
|
-
<ContextConsumer />
|
|
204
|
-
</NavigationProvider>
|
|
205
|
-
</Provider>
|
|
188
|
+
const renderContextConsumer = (_store = store) =>
|
|
189
|
+
renderWithProviders(
|
|
190
|
+
<NavigationProvider>
|
|
191
|
+
<ContextConsumer />
|
|
192
|
+
</NavigationProvider>,
|
|
193
|
+
_store
|
|
206
194
|
);
|
|
195
|
+
|
|
196
|
+
const getNavigatorValues = (wrapper) => {
|
|
197
|
+
const view = getByTestId(wrapper, "WrapperView");
|
|
198
|
+
const navigator = view.props.navigator;
|
|
199
|
+
|
|
200
|
+
const state = view.props.state;
|
|
201
|
+
|
|
202
|
+
return { navigator, state };
|
|
207
203
|
};
|
|
208
204
|
|
|
209
205
|
afterAll(() => {
|
|
@@ -213,14 +209,12 @@ afterAll(() => {
|
|
|
213
209
|
describe("<NavigationProvider />", () => {
|
|
214
210
|
let wrapper;
|
|
215
211
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
const view = getByTestId(wrapper, "WrapperView");
|
|
212
|
+
beforeEach(() => {
|
|
213
|
+
wrapper = renderContextConsumer();
|
|
214
|
+
});
|
|
222
215
|
|
|
223
|
-
|
|
216
|
+
it("navigator contains expected properties", () => {
|
|
217
|
+
const { navigator } = getNavigatorValues(wrapper);
|
|
224
218
|
expect(navigator.activeRiver).toEqual(rivers.B4567);
|
|
225
219
|
expect(navigator.currentRoute).toEqual("/river/B4567");
|
|
226
220
|
expect(navigator.previousAction).toEqual("REPLACE");
|
|
@@ -236,148 +230,131 @@ describe("<NavigationProvider />", () => {
|
|
|
236
230
|
});
|
|
237
231
|
});
|
|
238
232
|
|
|
239
|
-
|
|
233
|
+
it("pushing a new route sets the data to that route", async () => {
|
|
240
234
|
act(() => {
|
|
241
|
-
wrapper
|
|
235
|
+
getNavigatorValues(wrapper).navigator.push(rivers.A1234);
|
|
242
236
|
});
|
|
243
237
|
|
|
244
|
-
|
|
245
|
-
const view = getByTestId(wrapper, "WrapperView");
|
|
238
|
+
const { navigator, state } = getNavigatorValues(wrapper);
|
|
246
239
|
|
|
247
|
-
|
|
240
|
+
expect(navigator).toHaveProperty("activeRiver", rivers.A1234);
|
|
248
241
|
|
|
249
|
-
|
|
242
|
+
expect(navigator).toHaveProperty(
|
|
243
|
+
"currentRoute",
|
|
244
|
+
"/river/B4567/river/A1234"
|
|
245
|
+
);
|
|
250
246
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
);
|
|
255
|
-
|
|
256
|
-
expect(view.props.navigator.screenData).toEqual({
|
|
257
|
-
...rivers.A1234,
|
|
258
|
-
targetScreen: rivers.A1234,
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
expect(view.props.state.stack.mainStack).toHaveLength(2);
|
|
247
|
+
expect(navigator.screenData).toEqual({
|
|
248
|
+
...rivers.A1234,
|
|
249
|
+
targetScreen: rivers.A1234,
|
|
262
250
|
});
|
|
251
|
+
|
|
252
|
+
expect(state.stack.mainStack).toHaveLength(2);
|
|
263
253
|
});
|
|
264
254
|
|
|
265
255
|
describe("replacing a current route", () => {
|
|
266
|
-
act(() => {
|
|
267
|
-
wrapper = renderContextConsumer();
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
const view = getByTestId(wrapper, "WrapperView");
|
|
271
|
-
|
|
272
256
|
it("sets the data to that route", () => {
|
|
273
|
-
act(() =>
|
|
274
|
-
|
|
257
|
+
act(() => getNavigatorValues(wrapper).navigator.replace(rivers.A1234));
|
|
258
|
+
const { navigator, state } = getNavigatorValues(wrapper);
|
|
259
|
+
expect(navigator).toHaveProperty("activeRiver", rivers.A1234);
|
|
275
260
|
|
|
276
|
-
expect(
|
|
277
|
-
"currentRoute",
|
|
278
|
-
"/river/A1234"
|
|
279
|
-
);
|
|
261
|
+
expect(navigator).toHaveProperty("currentRoute", "/river/A1234");
|
|
280
262
|
|
|
281
|
-
expect(
|
|
263
|
+
expect(navigator.screenData).toEqual({
|
|
282
264
|
...rivers.A1234,
|
|
283
265
|
targetScreen: rivers.A1234,
|
|
284
266
|
});
|
|
285
267
|
|
|
286
|
-
expect(
|
|
268
|
+
expect(state.stack.mainStack).toHaveLength(1);
|
|
287
269
|
});
|
|
288
270
|
});
|
|
289
271
|
|
|
290
272
|
describe("going back", () => {
|
|
291
273
|
describe("when there is no previous route", () => {
|
|
292
|
-
act(() => {
|
|
293
|
-
wrapper = renderContextConsumer();
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
const view = getByTestId(wrapper, "WrapperView");
|
|
297
|
-
|
|
298
274
|
it("returns false when calling canGoBack", () => {
|
|
299
275
|
let result;
|
|
300
276
|
|
|
301
277
|
act(() => {
|
|
302
|
-
result =
|
|
278
|
+
result = getNavigatorValues(wrapper).navigator.canGoBack();
|
|
303
279
|
});
|
|
304
280
|
|
|
305
281
|
expect(result).toBe(false);
|
|
306
282
|
});
|
|
307
283
|
|
|
308
284
|
it("stays on the current route", () => {
|
|
309
|
-
act(() =>
|
|
285
|
+
act(() => getNavigatorValues(wrapper).navigator.goBack());
|
|
286
|
+
const { navigator, state } = getNavigatorValues(wrapper);
|
|
310
287
|
|
|
311
|
-
expect(
|
|
312
|
-
"activeRiver",
|
|
313
|
-
rivers.B4567
|
|
314
|
-
);
|
|
288
|
+
expect(navigator).toHaveProperty("activeRiver", rivers.B4567);
|
|
315
289
|
|
|
316
|
-
expect(
|
|
317
|
-
"currentRoute",
|
|
318
|
-
"/river/B4567"
|
|
319
|
-
);
|
|
290
|
+
expect(navigator).toHaveProperty("currentRoute", "/river/B4567");
|
|
320
291
|
|
|
321
|
-
expect(
|
|
292
|
+
expect(navigator.screenData).toEqual({
|
|
322
293
|
...rivers.B4567,
|
|
323
294
|
targetScreen: rivers.B4567,
|
|
324
295
|
});
|
|
325
296
|
|
|
326
|
-
expect(
|
|
297
|
+
expect(state.stack.mainStack).toHaveLength(1);
|
|
327
298
|
});
|
|
328
299
|
});
|
|
329
300
|
|
|
330
301
|
describe("when there is one route and we're going in a hook", () => {
|
|
331
|
-
|
|
332
|
-
wrapper
|
|
302
|
+
beforeEach(() => {
|
|
303
|
+
getNavigatorValues(wrapper).navigator.replace(rivers.A1234);
|
|
333
304
|
});
|
|
334
305
|
|
|
335
|
-
|
|
336
|
-
|
|
306
|
+
it.skip("returns true when calling goBack()", () => {
|
|
307
|
+
wrapper = renderContextConsumer();
|
|
308
|
+
|
|
309
|
+
act(() => {
|
|
310
|
+
getNavigatorValues(wrapper).navigator.replace(rivers.A1234);
|
|
311
|
+
getNavigatorValues(wrapper).navigator.push(rivers.C0987);
|
|
312
|
+
});
|
|
337
313
|
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
expect(
|
|
341
|
-
expect(
|
|
314
|
+
const { navigator, state } = getNavigatorValues(wrapper);
|
|
315
|
+
|
|
316
|
+
expect(state.stack.mainStack.length).toBeGreaterThan(1);
|
|
317
|
+
expect(navigator.canGoBack()).toEqual(true);
|
|
342
318
|
});
|
|
343
319
|
|
|
344
320
|
// this test is skipped as it doesn't work on this version of react
|
|
345
321
|
// where we can't properly test async actions within components
|
|
346
322
|
it.skip("returns to the previous route when the hook is cancelled", () => {
|
|
347
|
-
|
|
348
|
-
act(() => view.props.navigator.push(rivers.D6543));
|
|
323
|
+
wrapper = renderContextConsumer();
|
|
349
324
|
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
rivers.
|
|
353
|
-
);
|
|
325
|
+
act(() => {
|
|
326
|
+
getNavigatorValues(wrapper).navigator.replace(rivers.A1234);
|
|
327
|
+
getNavigatorValues(wrapper).navigator.push(rivers.D6543);
|
|
328
|
+
});
|
|
354
329
|
|
|
355
|
-
|
|
356
|
-
"currentRoute",
|
|
357
|
-
"/river/A1234"
|
|
358
|
-
);
|
|
330
|
+
const { navigator, state } = getNavigatorValues(wrapper);
|
|
359
331
|
|
|
360
|
-
expect(
|
|
361
|
-
|
|
332
|
+
expect(navigator).toHaveProperty("activeRiver", rivers.A1234);
|
|
333
|
+
|
|
334
|
+
expect(navigator).toHaveProperty("currentRoute", "/river/A1234");
|
|
335
|
+
|
|
336
|
+
expect(navigator.screenData).toEqual(rivers.A1234);
|
|
337
|
+
expect(state.stack.mainStack).toHaveLength(1);
|
|
362
338
|
});
|
|
363
339
|
});
|
|
364
340
|
|
|
365
341
|
describe("when there is a previous route", () => {
|
|
366
|
-
|
|
367
|
-
|
|
342
|
+
beforeEach(() => {
|
|
343
|
+
act(() => getNavigatorValues(wrapper).navigator.push(rivers.A1234));
|
|
344
|
+
|
|
345
|
+
act(() =>
|
|
346
|
+
getNavigatorValues(wrapper).navigator.push({
|
|
347
|
+
...rivers.B4567,
|
|
348
|
+
id: "B4567-1",
|
|
349
|
+
})
|
|
350
|
+
);
|
|
368
351
|
});
|
|
369
352
|
|
|
370
|
-
const view = getByTestId(wrapper, "WrapperView");
|
|
371
|
-
|
|
372
|
-
act(() => view.props.navigator.push(rivers.A1234));
|
|
373
|
-
|
|
374
|
-
act(() => view.props.navigator.push({ ...rivers.B4567, id: "B4567-1" }));
|
|
375
|
-
|
|
376
353
|
it("returns true when calling canGoBack", () => {
|
|
377
354
|
let result;
|
|
378
355
|
|
|
379
356
|
act(() => {
|
|
380
|
-
result =
|
|
357
|
+
result = getNavigatorValues(wrapper).navigator.canGoBack();
|
|
381
358
|
});
|
|
382
359
|
|
|
383
360
|
expect(result).toBeTruthy();
|
|
@@ -387,74 +364,86 @@ describe("<NavigationProvider />", () => {
|
|
|
387
364
|
let result;
|
|
388
365
|
|
|
389
366
|
act(() => {
|
|
390
|
-
result =
|
|
367
|
+
result = getNavigatorValues(wrapper).navigator.canGoBack(
|
|
368
|
+
false,
|
|
369
|
+
"B4567-1"
|
|
370
|
+
);
|
|
391
371
|
});
|
|
392
372
|
|
|
393
373
|
expect(result).toBeTruthy();
|
|
394
374
|
|
|
395
375
|
act(() => {
|
|
396
|
-
result =
|
|
376
|
+
result = getNavigatorValues(wrapper).navigator.canGoBack(
|
|
377
|
+
false,
|
|
378
|
+
"A1234"
|
|
379
|
+
);
|
|
397
380
|
});
|
|
398
381
|
|
|
399
382
|
expect(result).toBeTruthy();
|
|
400
383
|
});
|
|
401
384
|
|
|
402
385
|
it("returns to the previous route", () => {
|
|
403
|
-
expect(
|
|
386
|
+
expect(getNavigatorValues(wrapper).state.stack.mainStack).toHaveLength(
|
|
387
|
+
3
|
|
388
|
+
);
|
|
404
389
|
|
|
405
|
-
act(() =>
|
|
390
|
+
act(() => getNavigatorValues(wrapper).navigator.goBack());
|
|
406
391
|
|
|
407
|
-
expect(
|
|
392
|
+
expect(getNavigatorValues(wrapper).navigator).toHaveProperty(
|
|
408
393
|
"activeRiver",
|
|
409
394
|
rivers.A1234
|
|
410
395
|
);
|
|
411
396
|
|
|
412
|
-
expect(
|
|
397
|
+
expect(getNavigatorValues(wrapper).navigator).toHaveProperty(
|
|
413
398
|
"currentRoute",
|
|
414
399
|
"/river/B4567/river/A1234"
|
|
415
400
|
);
|
|
416
401
|
|
|
417
|
-
expect(
|
|
402
|
+
expect(getNavigatorValues(wrapper).navigator.screenData).toEqual({
|
|
418
403
|
...rivers.A1234,
|
|
419
404
|
targetScreen: rivers.A1234,
|
|
420
405
|
});
|
|
421
406
|
|
|
422
|
-
expect(
|
|
407
|
+
expect(getNavigatorValues(wrapper).state.stack.mainStack).toHaveLength(
|
|
408
|
+
2
|
|
409
|
+
);
|
|
423
410
|
});
|
|
424
411
|
});
|
|
425
412
|
|
|
426
413
|
describe("when there is a previous route and there are hooks", () => {
|
|
427
|
-
|
|
414
|
+
beforeEach(() => {
|
|
428
415
|
wrapper = renderContextConsumer();
|
|
416
|
+
act(() => getNavigatorValues(wrapper).navigator.push(rivers.A1234));
|
|
417
|
+
act(() => getNavigatorValues(wrapper).navigator.push(rivers.C0987));
|
|
429
418
|
});
|
|
430
419
|
|
|
431
|
-
const view = getByTestId(wrapper, "WrapperView");
|
|
432
|
-
act(() => view.props.navigator.push(rivers.A1234));
|
|
433
|
-
act(() => view.props.navigator.push(rivers.C0987));
|
|
434
|
-
|
|
435
420
|
it("returns to the previous entry in the stack which is not a hook", () => {
|
|
436
|
-
expect(
|
|
421
|
+
expect(getNavigatorValues(wrapper).state.stack.mainStack).toHaveLength(
|
|
422
|
+
3
|
|
423
|
+
);
|
|
437
424
|
|
|
438
|
-
expect(
|
|
425
|
+
expect(getNavigatorValues(wrapper).navigator).toHaveProperty(
|
|
439
426
|
"currentRoute",
|
|
440
427
|
"/river/B4567/river/A1234/river/C0987"
|
|
441
428
|
);
|
|
442
429
|
|
|
443
|
-
expect(
|
|
430
|
+
expect(getNavigatorValues(wrapper).navigator.screenData).toMatchObject({
|
|
444
431
|
...rivers.C0987,
|
|
445
432
|
targetScreen: rivers.C0987,
|
|
446
433
|
});
|
|
447
434
|
|
|
448
|
-
act(() =>
|
|
435
|
+
act(() => getNavigatorValues(wrapper).navigator.goBack());
|
|
449
436
|
|
|
450
|
-
expect(
|
|
437
|
+
expect(getNavigatorValues(wrapper).state.stack.mainStack).toHaveLength(
|
|
438
|
+
2
|
|
439
|
+
);
|
|
451
440
|
|
|
452
|
-
expect(
|
|
441
|
+
expect(getNavigatorValues(wrapper).navigator).toHaveProperty(
|
|
453
442
|
"currentRoute",
|
|
454
443
|
"/river/B4567/river/A1234"
|
|
455
444
|
);
|
|
456
445
|
|
|
457
|
-
expect(
|
|
446
|
+
expect(getNavigatorValues(wrapper).navigator.screenData).toMatchObject({
|
|
458
447
|
...rivers.A1234,
|
|
459
448
|
targetScreen: rivers.A1234,
|
|
460
449
|
});
|