@applicaster/quick-brick-core 13.0.0-alpha.9946926334 → 13.0.0-rc.100
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/DeepLinking/URLSchemeListener/URLSchemeContextProvider.tsx +14 -7
- package/App/DeepLinking/URLSchemeListener/__tests__/URLSchemeListener.test.js +40 -0
- package/App/DeepLinking/URLSchemeListener/index.tsx +1 -1
- package/App/ErrorBoundary/__tests__/errorBoundary.test.jsx +232 -0
- package/App/ErrorBoundary/__tests__/store.test.js +143 -0
- package/App/ErrorBoundary/index.tsx +45 -21
- package/App/ErrorBoundary/store.ts +26 -0
- package/App/LoadingOverlay/LoadingOverlayManager.tsx +27 -0
- package/App/LoadingOverlay/index.tsx +49 -0
- package/App/LoadingOverlay/useLoadingOverlayVisibility.tsx +18 -0
- package/App/ModalProvider/ModalBottomSheet/Overlay.tsx +5 -7
- package/App/ModalProvider/ModalBottomSheet/index.tsx +6 -10
- package/App/ModalProvider/index.tsx +5 -6
- package/App/NavigationProvider/NavigationProvider.tsx +56 -43
- package/App/NavigationProvider/__tests__/navigationProvider.test.tsx +0 -44
- package/App/NetworkStatusProvider/utils.ts +0 -1
- package/App/StoreConnector/__tests__/storeConnector.test.js +17 -11
- package/App/appLifeCycleManager/__tests__/appLifeCycleManager.test.tsx +146 -0
- package/App/appLifeCycleManager/index.tsx +6 -7
- package/App/index.tsx +6 -3
- package/App/remoteContextReloader/__tests__/remoteContextReloader.test.js +11 -21
- package/App/remoteContextReloader/getRemoteContextData/getNativeRemoteContextData.ts +14 -0
- package/createZappApp/__tests__/__snapshots__/createZappApp.test.js.snap +5 -128
- package/createZappApp/__tests__/createZappApp.test.js +7 -20
- package/defaults/__tests__/defaults.test.js +3 -4
- package/index.d.ts +1 -1
- package/package.json +10 -14
- package/App/DeepLinking/URLSchemeListener/__tests__/URLSchemeListenerTest.js +0 -177
- package/App/ErrorBoundary/__tests__/__snapshots__/errorBoundary.test.js.snap +0 -9
- package/App/ErrorBoundary/__tests__/errorBoundary.test.js +0 -72
- package/App/ModalProvider/ModalChildrenWrapper/index.web.ts +0 -1
- package/App/NavigationProvider/__tests__/__snapshots__/navigationProvider.test.tsx.snap +0 -68
- package/App/StoreConnector/__tests__/__snapshots__/storeConnector.test.js.snap +0 -35
- package/App/appLifeCycleManager/__tests__/__snapshots__/appLifeCycleManager.test.js.snap +0 -30
- package/App/appLifeCycleManager/__tests__/appLifeCycleManager.test.js +0 -134
- package/App/remoteContextReloader/__tests__/__snapshots__/remoteContextReloader.test.js.snap +0 -43
- /package/App/ModalProvider/ModalChildrenWrapper/{index.ios.ts → index.ts} +0 -0
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { View, Text } from "react-native";
|
|
3
|
-
import {
|
|
4
|
-
import { shallowToJson } from "enzyme-to-json";
|
|
3
|
+
import { render } from "@testing-library/react-native";
|
|
5
4
|
|
|
6
5
|
import { remoteContextReloader } from "../index";
|
|
7
6
|
import * as ContextReloader from "../getRemoteContextData";
|
|
@@ -25,19 +24,21 @@ const dispatch = jest.fn();
|
|
|
25
24
|
|
|
26
25
|
describe("remoteContextReloader", () => {
|
|
27
26
|
const WrappedComponent = remoteContextReloader(Component);
|
|
27
|
+
let rendered;
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
rendered = render(
|
|
31
|
+
<WrappedComponent {...{ appSettings, plugins, dispatch }} />
|
|
32
|
+
);
|
|
33
|
+
});
|
|
28
34
|
|
|
29
35
|
afterEach(() => {
|
|
30
36
|
jest.clearAllMocks();
|
|
31
37
|
});
|
|
32
38
|
|
|
33
|
-
it("
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
expect(shallowToJson(wrapper)).toMatchSnapshot();
|
|
39
|
-
expect(wrapper.instance()).toHaveProperty("componentDidMount");
|
|
40
|
-
expect(wrapper.instance().componentDidMount).toBeFunction();
|
|
39
|
+
it("calls componentDidMount and renders correctly", () => {
|
|
40
|
+
const { getByText } = rendered;
|
|
41
|
+
expect(getByText("I'm a component")).toBeTruthy();
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
describe("when in __DEV__", () => {
|
|
@@ -47,11 +48,6 @@ describe("remoteContextReloader", () => {
|
|
|
47
48
|
});
|
|
48
49
|
|
|
49
50
|
it("doesn't invoke the context reloader", () => {
|
|
50
|
-
const wrapper = shallow(
|
|
51
|
-
<WrappedComponent {...{ appSettings, plugins, dispatch }} />
|
|
52
|
-
);
|
|
53
|
-
|
|
54
|
-
expect(shallowToJson(wrapper)).toMatchSnapshot();
|
|
55
51
|
expect(spy).not.toHaveBeenCalled();
|
|
56
52
|
});
|
|
57
53
|
});
|
|
@@ -62,12 +58,6 @@ describe("remoteContextReloader", () => {
|
|
|
62
58
|
});
|
|
63
59
|
|
|
64
60
|
it("invokes the context reloader", () => {
|
|
65
|
-
const wrapper = shallow(
|
|
66
|
-
<WrappedComponent {...{ appSettings, plugins, dispatch }} />
|
|
67
|
-
);
|
|
68
|
-
|
|
69
|
-
expect(shallowToJson(wrapper)).toMatchSnapshot();
|
|
70
|
-
|
|
71
61
|
expect(spy).toHaveBeenCalledWith(
|
|
72
62
|
dispatch,
|
|
73
63
|
appSettings.runtimeConfigurationUrls,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
|
+
import isEmpty from "lodash/isEmpty";
|
|
2
3
|
import { Dimensions, NativeModules } from "react-native";
|
|
3
4
|
import { loadAppContextData } from "@applicaster/zapp-react-native-redux";
|
|
4
5
|
import { isTablet } from "@applicaster/zapp-react-native-utils/reactHooks";
|
|
@@ -10,6 +11,7 @@ import { logger } from "@applicaster/zapp-react-native-utils/logger";
|
|
|
10
11
|
import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "../consts";
|
|
11
12
|
const { AppLoaderBridge } = NativeModules;
|
|
12
13
|
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
14
|
+
import { useErrorStore } from "../../ErrorBoundary/store";
|
|
13
15
|
|
|
14
16
|
export async function getNativeRemoteContextData(
|
|
15
17
|
dispatch,
|
|
@@ -58,6 +60,18 @@ export async function getNativeRemoteContextData(
|
|
|
58
60
|
|
|
59
61
|
const layout = await getPromiseForType("layout");
|
|
60
62
|
|
|
63
|
+
const layoutLoadingErrorMessage = "Failed to load layout data";
|
|
64
|
+
|
|
65
|
+
if (isEmpty(layout)) {
|
|
66
|
+
useErrorStore
|
|
67
|
+
.getState()
|
|
68
|
+
.setError(
|
|
69
|
+
new Error(layoutLoadingErrorMessage),
|
|
70
|
+
layoutLoadingErrorMessage,
|
|
71
|
+
false
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
61
75
|
const apiVersion = layout?.layout?.["api_version"]; // Taken from remote configuration
|
|
62
76
|
|
|
63
77
|
dispatch(appDataActions.merge({ layoutVersion: apiVersion || "v1" }));
|
|
@@ -1,132 +1,9 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`createZappApp has a <Provider /> component with an initialized store 1`] = `
|
|
4
|
-
{
|
|
5
|
-
"appData": {
|
|
6
|
-
"countryLocale": "GB",
|
|
7
|
-
"languageLocale": "en",
|
|
8
|
-
"layoutVersion": "v1",
|
|
9
|
-
"quickBrickEvent": [MockFunction],
|
|
10
|
-
},
|
|
11
|
-
"appSettings": {
|
|
12
|
-
"runtimeConfigurationUrls": {},
|
|
13
|
-
},
|
|
14
|
-
"appState": {
|
|
15
|
-
"appLaunched": false,
|
|
16
|
-
"appReady": false,
|
|
17
|
-
"appState": {
|
|
18
|
-
"currentState": null,
|
|
19
|
-
"eventType": null,
|
|
20
|
-
"isAvailable": null,
|
|
21
|
-
"nextState": null,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
"cellStyles": {},
|
|
25
|
-
"components": {
|
|
26
|
-
"AppContainer": [Function],
|
|
27
|
-
"ContentScreen": [Function],
|
|
28
|
-
"HookRenderer": [Function],
|
|
29
|
-
"ModalComponent": [Function],
|
|
30
|
-
"PlayerContainer": {
|
|
31
|
-
"$$typeof": Symbol(react.memo),
|
|
32
|
-
"WrappedComponent": {
|
|
33
|
-
"$$typeof": Symbol(react.memo),
|
|
34
|
-
"compare": null,
|
|
35
|
-
"type": [Function],
|
|
36
|
-
},
|
|
37
|
-
"compare": null,
|
|
38
|
-
"type": [Function],
|
|
39
|
-
},
|
|
40
|
-
"QBImage": [Function],
|
|
41
|
-
"River": {
|
|
42
|
-
"$$typeof": Symbol(react.memo),
|
|
43
|
-
"WrappedComponent": [Function],
|
|
44
|
-
"compare": null,
|
|
45
|
-
"type": [Function],
|
|
46
|
-
},
|
|
47
|
-
"TextInputTv": {
|
|
48
|
-
"$$typeof": Symbol(react.forward_ref),
|
|
49
|
-
"render": [Function],
|
|
50
|
-
},
|
|
51
|
-
"Touchable": [Function],
|
|
52
|
-
},
|
|
53
|
-
"contentTypes": null,
|
|
54
|
-
"localizations": {},
|
|
55
|
-
"pipesEndpoints": null,
|
|
56
|
-
"pluginConfigurations": {
|
|
57
|
-
"pc1": {
|
|
58
|
-
"configuration_json": null,
|
|
59
|
-
"plugin": {
|
|
60
|
-
"api": {},
|
|
61
|
-
"identifier": "pc1",
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
"pc2": {
|
|
65
|
-
"configuration_json": {
|
|
66
|
-
"foo": "bar",
|
|
67
|
-
},
|
|
68
|
-
"plugin": {
|
|
69
|
-
"api": {},
|
|
70
|
-
"identifier": "pc2",
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
"plugins": [
|
|
75
|
-
{
|
|
76
|
-
"configuration": null,
|
|
77
|
-
"identifier": "pc1",
|
|
78
|
-
"module": [MockFunction],
|
|
79
|
-
"name": "Plugin1",
|
|
80
|
-
"type": "general",
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
"configuration": {
|
|
84
|
-
"foo": "bar",
|
|
85
|
-
},
|
|
86
|
-
"identifier": "pc2",
|
|
87
|
-
"module": [MockFunction],
|
|
88
|
-
"name": "Plugin2",
|
|
89
|
-
"type": "general",
|
|
90
|
-
},
|
|
91
|
-
],
|
|
92
|
-
"presetsMapping": {},
|
|
93
|
-
"remoteConfigurations": {
|
|
94
|
-
"localizations": {},
|
|
95
|
-
},
|
|
96
|
-
"rivers": {},
|
|
97
|
-
"styles": {},
|
|
98
|
-
"zappPipes": {},
|
|
99
|
-
}
|
|
100
|
-
`;
|
|
101
|
-
|
|
102
3
|
exports[`createZappApp renders the provided React App 1`] = `
|
|
103
|
-
<
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
"getState": [Function],
|
|
109
|
-
"replaceReducer": [Function],
|
|
110
|
-
"subscribe": [Function],
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
>
|
|
114
|
-
<EmptyZappApp />
|
|
115
|
-
</Provider>
|
|
116
|
-
`;
|
|
117
|
-
|
|
118
|
-
exports[`createZappApp returns a react component 1`] = `
|
|
119
|
-
<Provider
|
|
120
|
-
store={
|
|
121
|
-
{
|
|
122
|
-
"@@observable": [Function],
|
|
123
|
-
"dispatch": [Function],
|
|
124
|
-
"getState": [Function],
|
|
125
|
-
"replaceReducer": [Function],
|
|
126
|
-
"subscribe": [Function],
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
>
|
|
130
|
-
<EmptyZappApp />
|
|
131
|
-
</Provider>
|
|
4
|
+
<View>
|
|
5
|
+
<Text>
|
|
6
|
+
Welcome to the QuickBrick App
|
|
7
|
+
</Text>
|
|
8
|
+
</View>
|
|
132
9
|
`;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { View, Text } from "react-native";
|
|
3
|
-
import {
|
|
4
|
-
import { shallowToJson } from "enzyme-to-json";
|
|
3
|
+
import { render, screen } from "@testing-library/react-native";
|
|
5
4
|
import QuickBrickComponents from "@applicaster/zapp-react-native-ui-components";
|
|
6
5
|
import { Provider } from "react-redux";
|
|
7
6
|
|
|
@@ -77,27 +76,17 @@ jest.mock("@applicaster/zapp-react-native-bridge/QuickBrick", () => ({
|
|
|
77
76
|
}));
|
|
78
77
|
|
|
79
78
|
describe("createZappApp", () => {
|
|
80
|
-
it("returns a react component", () => {
|
|
81
|
-
const ZappApp = createZappApp({});
|
|
82
|
-
const wrapper = shallow(<ZappApp />);
|
|
83
|
-
|
|
84
|
-
expect(shallowToJson(wrapper)).toMatchSnapshot();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
79
|
it("renders the provided React App", () => {
|
|
88
80
|
const ZappApp = createZappApp({ App });
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
expect(shallowToJson(wrapper)).toMatchSnapshot();
|
|
81
|
+
render(<ZappApp />);
|
|
82
|
+
expect(screen.toJSON()).toMatchSnapshot();
|
|
92
83
|
});
|
|
93
84
|
|
|
94
|
-
it("has a
|
|
85
|
+
it("has a Provider component with an initialized store", () => {
|
|
95
86
|
const ZappApp = createZappApp(zappAppConfig);
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
const store = providerNode.prop("store");
|
|
100
|
-
expect(providerNode.length).toBe(1);
|
|
87
|
+
const { UNSAFE_root } = render(<ZappApp />);
|
|
88
|
+
const providerInstance = UNSAFE_root.findByType(Provider);
|
|
89
|
+
const store = providerInstance.props.store;
|
|
101
90
|
|
|
102
91
|
expect(store).toEqual(
|
|
103
92
|
expect.objectContaining({
|
|
@@ -108,8 +97,6 @@ describe("createZappApp", () => {
|
|
|
108
97
|
})
|
|
109
98
|
);
|
|
110
99
|
|
|
111
|
-
expect(store.getState()).toMatchSnapshot();
|
|
112
|
-
|
|
113
100
|
expect(store.getState()).toEqual(
|
|
114
101
|
expect.objectContaining({
|
|
115
102
|
styles: expect.any(Object),
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
2
3
|
import { EmptyZappApp } from "../index";
|
|
3
|
-
import { shallow } from "enzyme";
|
|
4
|
-
import { shallowToJson } from "enzyme-to-json";
|
|
5
4
|
|
|
6
5
|
describe("<EmptyZappApp />", () => {
|
|
7
6
|
it("renders correctly", () => {
|
|
8
|
-
const
|
|
9
|
-
expect(
|
|
7
|
+
const { toJSON } = render(<EmptyZappApp />);
|
|
8
|
+
expect(toJSON()).toMatchSnapshot();
|
|
10
9
|
});
|
|
11
10
|
});
|
package/index.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ type AnyValue = void | string | number | boolean | AnyArray | AnyRecord;
|
|
|
24
24
|
declare type ReducerAction<
|
|
25
25
|
T extends string = string,
|
|
26
26
|
P extends AnyValue = AnyValue,
|
|
27
|
-
M extends AnyRecord = AnyRecord
|
|
27
|
+
M extends AnyRecord = AnyRecord,
|
|
28
28
|
> = {
|
|
29
29
|
type: T;
|
|
30
30
|
payload?: P;
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/quick-brick-core",
|
|
3
|
-
"version": "13.0.0-
|
|
3
|
+
"version": "13.0.0-rc.100",
|
|
4
4
|
"description": "Core package for Applicaster's Quick Brick App",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "jest -w=2",
|
|
9
8
|
"build": "echo 'skipping ts build for core packages'"
|
|
10
9
|
},
|
|
11
10
|
"repository": {
|
|
@@ -29,13 +28,13 @@
|
|
|
29
28
|
},
|
|
30
29
|
"homepage": "https://github.com/applicaster/quickbrick#readme",
|
|
31
30
|
"dependencies": {
|
|
32
|
-
"@applicaster/applicaster-types": "13.0.0-
|
|
33
|
-
"@applicaster/quick-brick-core-plugins": "13.0.0-
|
|
34
|
-
"@applicaster/zapp-pipes-v2-client": "13.0.0-
|
|
35
|
-
"@applicaster/zapp-react-native-bridge": "13.0.0-
|
|
36
|
-
"@applicaster/zapp-react-native-redux": "13.0.0-
|
|
37
|
-
"@applicaster/zapp-react-native-ui-components": "13.0.0-
|
|
38
|
-
"@applicaster/zapp-react-native-utils": "13.0.0-
|
|
31
|
+
"@applicaster/applicaster-types": "13.0.0-rc.100",
|
|
32
|
+
"@applicaster/quick-brick-core-plugins": "13.0.0-rc.100",
|
|
33
|
+
"@applicaster/zapp-pipes-v2-client": "13.0.0-rc.100",
|
|
34
|
+
"@applicaster/zapp-react-native-bridge": "13.0.0-rc.100",
|
|
35
|
+
"@applicaster/zapp-react-native-redux": "13.0.0-rc.100",
|
|
36
|
+
"@applicaster/zapp-react-native-ui-components": "13.0.0-rc.100",
|
|
37
|
+
"@applicaster/zapp-react-native-utils": "13.0.0-rc.100",
|
|
39
38
|
"atob": "^2.1.2",
|
|
40
39
|
"axios": "^0.28.0",
|
|
41
40
|
"btoa": "^1.2.1",
|
|
@@ -57,10 +56,9 @@
|
|
|
57
56
|
"@applicaster/zapp-react-native-tvos-ui-components": "*",
|
|
58
57
|
"@babel/runtime": "*",
|
|
59
58
|
"@react-native-community/netinfo": "*",
|
|
60
|
-
"@types/node": "*",
|
|
61
59
|
"immer": "*",
|
|
62
|
-
"react": "
|
|
63
|
-
"react-native": "
|
|
60
|
+
"react": "*",
|
|
61
|
+
"react-native": "*",
|
|
64
62
|
"react-native-fs": "*",
|
|
65
63
|
"react-native-gesture-handler": "*",
|
|
66
64
|
"react-native-linear-gradient": "*",
|
|
@@ -73,8 +71,6 @@
|
|
|
73
71
|
"zustand": "*"
|
|
74
72
|
},
|
|
75
73
|
"devDependencies": {
|
|
76
|
-
"@types/react-native": "0.69.6",
|
|
77
|
-
"@types/tizen-tv-webapis": "^2.0.1",
|
|
78
74
|
"nock": "^10.0.0",
|
|
79
75
|
"redux-mock-store": "^1.5.3"
|
|
80
76
|
},
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { View, Text } from "react-native";
|
|
3
|
-
import { shallow } from "enzyme";
|
|
4
|
-
import { shallowToJson } from "enzyme-to-json";
|
|
5
|
-
|
|
6
|
-
import { URLSchemeListener } from "../index";
|
|
7
|
-
|
|
8
|
-
const URL = "url";
|
|
9
|
-
|
|
10
|
-
const TestComponent = () => (
|
|
11
|
-
<View>
|
|
12
|
-
<Text>I'm a test component</Text>
|
|
13
|
-
</View>
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
const ReactNative = require("react-native");
|
|
17
|
-
const { Linking } = ReactNative;
|
|
18
|
-
|
|
19
|
-
const navigator = {
|
|
20
|
-
push: jest.fn(),
|
|
21
|
-
replace: jest.fn(),
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
jest.spyOn(console, "warn").mockImplementation(() => jest.fn());
|
|
25
|
-
|
|
26
|
-
function clearMocks() {
|
|
27
|
-
navigator.push.mockClear();
|
|
28
|
-
navigator.replace.mockClear();
|
|
29
|
-
console.warn.mockClear(); // eslint-disable-line no-console
|
|
30
|
-
Linking.__resetListeners();
|
|
31
|
-
Linking.__clearInitialURL();
|
|
32
|
-
Linking.addEventListener.mockClear();
|
|
33
|
-
Linking.removeEventListener.mockClear();
|
|
34
|
-
Linking.getInitialURL.mockClear();
|
|
35
|
-
Linking.openURL.mockClear();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
describe("URLSchemeHandler", () => {
|
|
39
|
-
const getWrapper = (props) =>
|
|
40
|
-
shallow(
|
|
41
|
-
<URLSchemeListener navigator={navigator} {...props}>
|
|
42
|
-
<TestComponent />
|
|
43
|
-
</URLSchemeListener>
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
beforeEach(clearMocks);
|
|
47
|
-
|
|
48
|
-
it("renders correctly", () => {
|
|
49
|
-
const wrapper = getWrapper();
|
|
50
|
-
expect(shallowToJson(wrapper)).toMatchSnapshot();
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
describe("linking registration", () => {
|
|
54
|
-
beforeEach(clearMocks);
|
|
55
|
-
|
|
56
|
-
it("registers the listener when the component mounts", () => {
|
|
57
|
-
const wrapper = getWrapper();
|
|
58
|
-
const instance = wrapper.instance();
|
|
59
|
-
|
|
60
|
-
expect(shallowToJson(wrapper)).toMatchSnapshot();
|
|
61
|
-
|
|
62
|
-
expect(Linking.addEventListener).toHaveBeenCalledWith(
|
|
63
|
-
URL,
|
|
64
|
-
instance.handleOpenUrl
|
|
65
|
-
);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("unregisters the listener when the component unmounts", () => {
|
|
69
|
-
const wrapper = getWrapper();
|
|
70
|
-
const instance = wrapper.instance();
|
|
71
|
-
wrapper.unmount();
|
|
72
|
-
|
|
73
|
-
expect(Linking.removeEventListener).toHaveBeenCalledWith(
|
|
74
|
-
URL,
|
|
75
|
-
instance.handleOpenUrl
|
|
76
|
-
);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
describe("initial url", () => {
|
|
81
|
-
beforeEach(clearMocks);
|
|
82
|
-
|
|
83
|
-
it("tries to get the initial url", () => {
|
|
84
|
-
const listenerSpy = jest.fn();
|
|
85
|
-
const wrapper = getWrapper({ listenerSpy });
|
|
86
|
-
|
|
87
|
-
expect(shallowToJson(wrapper)).toMatchSnapshot();
|
|
88
|
-
expect(listenerSpy).toHaveBeenCalledWith("getInitialURL");
|
|
89
|
-
expect(Linking.getInitialURL).toHaveBeenCalled();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("gets the initial url and redirect to it if it exists", async () => {
|
|
93
|
-
const listenerSpy = jest.fn();
|
|
94
|
-
const url = "http://foo.com";
|
|
95
|
-
Linking.__setInitialURL(url);
|
|
96
|
-
|
|
97
|
-
const wrapper = getWrapper({ listenerSpy });
|
|
98
|
-
const instance = wrapper.instance();
|
|
99
|
-
|
|
100
|
-
await instance.componentDidMount();
|
|
101
|
-
|
|
102
|
-
expect(listenerSpy).toHaveBeenCalledWith("getInitialURL");
|
|
103
|
-
|
|
104
|
-
expect(navigator.replace).toHaveBeenCalledWith(
|
|
105
|
-
expect.objectContaining({ url })
|
|
106
|
-
);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("doesn't try to navigate if there is no initial url", async () => {
|
|
110
|
-
const listenerSpy = jest.fn();
|
|
111
|
-
|
|
112
|
-
const wrapper = getWrapper({ listenerSpy });
|
|
113
|
-
const instance = wrapper.instance();
|
|
114
|
-
jest.spyOn(instance, "handleOpenUrlError");
|
|
115
|
-
|
|
116
|
-
await instance.componentDidMount();
|
|
117
|
-
|
|
118
|
-
expect(listenerSpy).toHaveBeenCalledWith("getInitialURL");
|
|
119
|
-
expect(listenerSpy).not.toHaveBeenCalledWith("canOpenURL");
|
|
120
|
-
expect(navigator.replace).not.toHaveBeenCalled();
|
|
121
|
-
});
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
describe("url scheme handler", () => {
|
|
125
|
-
beforeEach(clearMocks);
|
|
126
|
-
|
|
127
|
-
it("invokes the listener when a url is triggered", () => {
|
|
128
|
-
const listenerSpy = jest.fn();
|
|
129
|
-
const wrapper = getWrapper({ listenerSpy });
|
|
130
|
-
const url = "http://foo.com";
|
|
131
|
-
|
|
132
|
-
Linking.__callUrl(url);
|
|
133
|
-
|
|
134
|
-
expect(shallowToJson(wrapper)).toMatchSnapshot();
|
|
135
|
-
|
|
136
|
-
expect(listenerSpy).toHaveBeenCalledWith(
|
|
137
|
-
"handleOpenUrl",
|
|
138
|
-
expect.objectContaining({ url })
|
|
139
|
-
);
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
it("invokes the navigator if a url is triggered and the url is valid", async () => {
|
|
143
|
-
const listenerSpy = jest.fn();
|
|
144
|
-
const wrapper = getWrapper({ listenerSpy });
|
|
145
|
-
const instance = wrapper.instance();
|
|
146
|
-
const spy = jest.spyOn(instance, "handleOpenUrl");
|
|
147
|
-
const url = "http://foo.com";
|
|
148
|
-
|
|
149
|
-
Linking.__callUrl(url);
|
|
150
|
-
|
|
151
|
-
await spy;
|
|
152
|
-
|
|
153
|
-
expect(navigator.replace).toHaveBeenCalledWith(
|
|
154
|
-
expect.objectContaining({ url })
|
|
155
|
-
);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("doesn't invoke the navigator if a url is triggered and the url is undefined", async () => {
|
|
159
|
-
const listenerSpy = jest.fn();
|
|
160
|
-
const wrapper = getWrapper({ listenerSpy });
|
|
161
|
-
const instance = wrapper.instance();
|
|
162
|
-
const spy = jest.spyOn(instance, "handleOpenUrl");
|
|
163
|
-
const url = undefined; // eslint-disable no-undefined
|
|
164
|
-
|
|
165
|
-
Linking.__callUrl(url);
|
|
166
|
-
|
|
167
|
-
await spy;
|
|
168
|
-
|
|
169
|
-
expect(listenerSpy).toHaveBeenCalledWith(
|
|
170
|
-
"handleOpenUrl",
|
|
171
|
-
expect.objectContaining({ url })
|
|
172
|
-
);
|
|
173
|
-
|
|
174
|
-
expect(navigator.replace).not.toHaveBeenCalled();
|
|
175
|
-
});
|
|
176
|
-
});
|
|
177
|
-
});
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`<ErrorBoundary /> When an error is caught renders correctly 1`] = `
|
|
4
|
-
<ErrorScreen
|
|
5
|
-
dismissError={[Function]}
|
|
6
|
-
/>
|
|
7
|
-
`;
|
|
8
|
-
|
|
9
|
-
exports[`<ErrorBoundary /> when there is no error renders correctly 1`] = `<TestComponent />`;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { View, Text } from "react-native";
|
|
3
|
-
import { shallow } from "enzyme";
|
|
4
|
-
import { shallowToJson } from "enzyme-to-json";
|
|
5
|
-
|
|
6
|
-
import { ErrorBoundary } from "../index";
|
|
7
|
-
|
|
8
|
-
const TestComponent = ({ error }: { error: any }) => {
|
|
9
|
-
if (error) {
|
|
10
|
-
throw new Error("error !!");
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
<View>
|
|
15
|
-
<Text>all is good</Text>
|
|
16
|
-
</View>
|
|
17
|
-
);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const errorState = {
|
|
21
|
-
hasError: true,
|
|
22
|
-
error: new Error("oh no"),
|
|
23
|
-
info: { componentStack: "error at ... \n ..." },
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
describe("<ErrorBoundary />", () => {
|
|
27
|
-
describe("when there is no error", () => {
|
|
28
|
-
const wrapper = shallow(
|
|
29
|
-
<ErrorBoundary>
|
|
30
|
-
<TestComponent />
|
|
31
|
-
</ErrorBoundary>
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
it("renders correctly", () => {
|
|
35
|
-
expect(shallowToJson(wrapper)).toMatchSnapshot();
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe("When an error is caught", () => {
|
|
40
|
-
const _consoleLog = console.log; // eslint-disable-line no-console
|
|
41
|
-
|
|
42
|
-
const didCatchSpy = jest.spyOn(
|
|
43
|
-
ErrorBoundary.prototype,
|
|
44
|
-
"componentDidCatch"
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
const wrapper = shallow(
|
|
48
|
-
<ErrorBoundary>
|
|
49
|
-
<TestComponent error />
|
|
50
|
-
</ErrorBoundary>
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
wrapper.setState(errorState);
|
|
54
|
-
|
|
55
|
-
beforeAll(() => {
|
|
56
|
-
console.log = jest.fn(); // eslint-disable-line no-console
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
afterAll(() => {
|
|
60
|
-
console.log = _consoleLog; // eslint-disable-line no-console
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it.skip("the componentDidCatch method is called", () => {
|
|
64
|
-
// a current bug with enzyme doesn't allow this to be tested
|
|
65
|
-
expect(didCatchSpy).toHaveBeenCalled();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("renders correctly", () => {
|
|
69
|
-
expect(shallowToJson(wrapper)).toMatchSnapshot();
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Fragment as ModalChildrenWrapper } from "react";
|