@applicaster/quick-brick-core 13.0.0-alpha.1700735421 → 13.0.0-alpha.1711912250
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/ActionsProvider/__tests__/__snapshots__/ActionsProvider.test.js.snap +2 -2
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx +12 -4
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/usePresentSchemeHandler.test.tsx +40 -26
- package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useUrlSchemeHandler.test.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/ModalProvider/ModalBottomSheet/DraggableBottomSheet/index.tsx +0 -1
- package/App/ModalProvider/ModalBottomSheet/ModalBottomSheetFrame.tsx +68 -10
- package/App/ModalProvider/ModalBottomSheet/Overlay.tsx +5 -7
- package/App/ModalProvider/ModalBottomSheet/index.tsx +17 -47
- package/App/ModalProvider/ModalPresenter.tsx +1 -1
- package/App/ModalProvider/index.tsx +7 -3
- package/App/NavigationProvider/NavigationProvider.tsx +29 -43
- package/App/NavigationProvider/__tests__/navigationProvider.test.tsx +0 -44
- package/App/NetworkStatusProvider/__tests__/NetworkStatusProvider.test.tsx +15 -11
- package/App/StoreConnector/__tests__/storeConnector.test.js +9 -6
- package/App/appLifeCycleManager/__tests__/appLifeCycleManager.test.tsx +146 -0
- package/App/appLifeCycleManager/index.tsx +4 -4
- package/App/index.tsx +4 -3
- package/App/remoteContextReloader/getRemoteContextData/getNativeRemoteContextData.ts +14 -0
- package/package.json +10 -10
- package/App/ErrorBoundary/__tests__/errorBoundary.test.js +0 -55
- package/App/ModalProvider/ModalChildrenWrapper/index.web.ts +0 -1
- package/App/NavigationProvider/__tests__/__snapshots__/navigationProvider.test.tsx.snap +0 -68
- package/App/appLifeCycleManager/__tests__/__snapshots__/appLifeCycleManager.test.js.snap +0 -30
- package/App/appLifeCycleManager/__tests__/appLifeCycleManager.test.js +0 -134
- /package/App/ModalProvider/ModalChildrenWrapper/{index.ios.ts → index.ts} +0 -0
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
import { renderHook, act } from "@testing-library/react-hooks";
|
|
4
|
+
import configureStore from "redux-mock-store";
|
|
5
|
+
import thunk from "redux-thunk";
|
|
4
6
|
import { NetworkStatusContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NetworkStatusContext";
|
|
5
7
|
import { NetworkStatusProvider } from "../NetworkStatusProvider";
|
|
6
|
-
import {
|
|
8
|
+
import { Provider } from "react-redux";
|
|
7
9
|
import NetInfo from "@react-native-community/netinfo";
|
|
8
10
|
|
|
11
|
+
const mockStore = configureStore([thunk]);
|
|
12
|
+
|
|
9
13
|
const NetInfoMock = {
|
|
10
14
|
type: "cellular",
|
|
11
15
|
details: {
|
|
@@ -20,9 +24,9 @@ const NetInfoMock = {
|
|
|
20
24
|
const getWrapper = (store) => ({
|
|
21
25
|
// eslint-disable-next-line react/prop-types,react/display-name
|
|
22
26
|
wrapper: ({ children }) => (
|
|
23
|
-
<
|
|
27
|
+
<Provider store={store}>
|
|
24
28
|
<NetworkStatusProvider>{children}</NetworkStatusProvider>
|
|
25
|
-
</
|
|
29
|
+
</Provider>
|
|
26
30
|
),
|
|
27
31
|
});
|
|
28
32
|
|
|
@@ -37,9 +41,9 @@ const useNetInfoMock = () => {
|
|
|
37
41
|
|
|
38
42
|
describe("NetworkStatusProvider", function () {
|
|
39
43
|
it("should return netInfoData", function () {
|
|
40
|
-
const store = {
|
|
44
|
+
const store = mockStore({
|
|
41
45
|
plugins: [{}],
|
|
42
|
-
};
|
|
46
|
+
});
|
|
43
47
|
|
|
44
48
|
// @ts-ignore
|
|
45
49
|
jest.spyOn(NetInfo, "useNetInfo").mockImplementation(useNetInfoMock);
|
|
@@ -55,9 +59,9 @@ describe("NetworkStatusProvider", function () {
|
|
|
55
59
|
it("should call onConnectionLost callback when connection type changes to none", function () {
|
|
56
60
|
const onConnectionLost = jest.fn();
|
|
57
61
|
|
|
58
|
-
const store = {
|
|
62
|
+
const store = mockStore({
|
|
59
63
|
plugins: [{ module: { networkHooks: { onConnectionLost } } }],
|
|
60
|
-
};
|
|
64
|
+
});
|
|
61
65
|
|
|
62
66
|
// @ts-ignore
|
|
63
67
|
jest.spyOn(NetInfo, "useNetInfo").mockImplementation(useNetInfoMock);
|
|
@@ -82,9 +86,9 @@ describe("NetworkStatusProvider", function () {
|
|
|
82
86
|
it("should call onConnectionRestored callback when connection type switches from none", function () {
|
|
83
87
|
const onConnectionRestored = jest.fn();
|
|
84
88
|
|
|
85
|
-
const store = {
|
|
89
|
+
const store = mockStore({
|
|
86
90
|
plugins: [{ module: { networkHooks: { onConnectionRestored } } }],
|
|
87
|
-
};
|
|
91
|
+
});
|
|
88
92
|
|
|
89
93
|
// @ts-ignore
|
|
90
94
|
jest.spyOn(NetInfo, "useNetInfo").mockImplementation(useNetInfoMock);
|
|
@@ -119,9 +123,9 @@ describe("NetworkStatusProvider", function () {
|
|
|
119
123
|
it("should call onConnectionTypeChanged callback when connection type changes", function () {
|
|
120
124
|
const onConnectionTypeChanged = jest.fn();
|
|
121
125
|
|
|
122
|
-
const store = {
|
|
126
|
+
const store = mockStore({
|
|
123
127
|
plugins: [{ module: { networkHooks: { onConnectionTypeChanged } } }],
|
|
124
|
-
};
|
|
128
|
+
});
|
|
125
129
|
|
|
126
130
|
// @ts-ignore
|
|
127
131
|
jest.spyOn(NetInfo, "useNetInfo").mockImplementation(useNetInfoMock);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as ReactIs from "react-is";
|
|
3
3
|
import { View, Text } from "react-native";
|
|
4
|
-
import {
|
|
4
|
+
import { render } from "@testing-library/react-native";
|
|
5
|
+
import configureStore from "redux-mock-store";
|
|
5
6
|
|
|
6
7
|
import { storeConnector } from "../index";
|
|
8
|
+
import { Provider } from "react-redux";
|
|
7
9
|
|
|
8
10
|
const styles = { foo: "bar" };
|
|
9
11
|
const components = { grid: jest.fn() };
|
|
@@ -16,12 +18,12 @@ const Component = (props) => (
|
|
|
16
18
|
</View>
|
|
17
19
|
);
|
|
18
20
|
|
|
19
|
-
const store = {
|
|
21
|
+
const store = configureStore()({
|
|
20
22
|
styles,
|
|
21
23
|
components,
|
|
22
24
|
rivers,
|
|
23
25
|
appSettings,
|
|
24
|
-
};
|
|
26
|
+
});
|
|
25
27
|
|
|
26
28
|
describe("storeConnector", () => {
|
|
27
29
|
it("returns a Component", () => {
|
|
@@ -39,9 +41,10 @@ describe("storeConnector", () => {
|
|
|
39
41
|
it("passes the props to the component", () => {
|
|
40
42
|
const WrappedComponent = storeConnector(Component);
|
|
41
43
|
|
|
42
|
-
const { getByText, getByTestId } =
|
|
43
|
-
<
|
|
44
|
-
|
|
44
|
+
const { getByText, getByTestId } = render(
|
|
45
|
+
<Provider store={store}>
|
|
46
|
+
<WrappedComponent />
|
|
47
|
+
</Provider>
|
|
45
48
|
);
|
|
46
49
|
|
|
47
50
|
expect(getByText("I'm a component")).toBeTruthy();
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import * as React from "react";
|
|
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";
|
|
6
|
+
|
|
7
|
+
let mocked_items: Record<string, any> = {};
|
|
8
|
+
|
|
9
|
+
import { appLifeCycleManager } from "../";
|
|
10
|
+
|
|
11
|
+
const mock_actions = {};
|
|
12
|
+
|
|
13
|
+
jest.mock("@applicaster/zapp-react-native-redux/AppData", () => ({
|
|
14
|
+
loadAppData: jest.fn(() => () => Promise.resolve()),
|
|
15
|
+
}));
|
|
16
|
+
|
|
17
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactHooks/actions", () => ({
|
|
18
|
+
useActions: jest.fn(() => ({ actions: mock_actions })),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock(
|
|
22
|
+
"@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage",
|
|
23
|
+
() => ({
|
|
24
|
+
localStorage: {
|
|
25
|
+
getAllItems: jest.fn(() => Promise.resolve(mocked_items)),
|
|
26
|
+
setItem: jest.fn((key, value) => {
|
|
27
|
+
mocked_items[key] = JSON.stringify(value);
|
|
28
|
+
|
|
29
|
+
return Promise.resolve(true);
|
|
30
|
+
}),
|
|
31
|
+
getItem: jest.fn((key) => {
|
|
32
|
+
if (mocked_items[key]) {
|
|
33
|
+
if (typeof mocked_items[key] === "string") {
|
|
34
|
+
return Promise.resolve(JSON.parse(mocked_items[key]));
|
|
35
|
+
} else {
|
|
36
|
+
return Promise.resolve(mocked_items[key]);
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
return Promise.resolve([]);
|
|
40
|
+
}
|
|
41
|
+
}),
|
|
42
|
+
__reset() {
|
|
43
|
+
mocked_items = {};
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const Component = () => (
|
|
50
|
+
<View>
|
|
51
|
+
<Text>I'm a component</Text>
|
|
52
|
+
</View>
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const QuickBrickManager = {
|
|
56
|
+
sendQuickBrickEvent: jest.fn(),
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const LOADING_ERROR = new Error("loading failed");
|
|
60
|
+
|
|
61
|
+
const appLoader = jest.fn((_dispatch, _getState) => {
|
|
62
|
+
if (_getState().shouldFail) return Promise.reject(LOADING_ERROR);
|
|
63
|
+
|
|
64
|
+
return Promise.resolve();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const store = configureStore([thunk])({});
|
|
68
|
+
const dispatch = store.dispatch;
|
|
69
|
+
|
|
70
|
+
const state = {
|
|
71
|
+
rivers: {},
|
|
72
|
+
plugins: {},
|
|
73
|
+
appSettings: { runtimeConfigurationUrls: { rivers: "http://rivers.url" } },
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
const QUICK_BRICK_READY_EVENT = "quickBrickReady";
|
|
77
|
+
|
|
78
|
+
describe("appLifeCycleManager", () => {
|
|
79
|
+
const decorator = appLifeCycleManager(appLoader, QuickBrickManager);
|
|
80
|
+
const DecoratedComponent = decorator(Component);
|
|
81
|
+
|
|
82
|
+
beforeEach(() => {
|
|
83
|
+
appLoader.mockClear();
|
|
84
|
+
QuickBrickManager.sendQuickBrickEvent.mockClear();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("returns a function to decorate a component", () => {
|
|
88
|
+
expect(decorator).toBeDefined();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("runs the loaders, then sends quickBrickReady event", async () => {
|
|
92
|
+
const testCallback = jest.fn(() => {});
|
|
93
|
+
|
|
94
|
+
render(
|
|
95
|
+
<DecoratedComponent
|
|
96
|
+
dispatch={dispatch}
|
|
97
|
+
{...state}
|
|
98
|
+
testCallback={testCallback}
|
|
99
|
+
/>
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
await waitFor(() => {
|
|
103
|
+
return expect(testCallback).toHaveBeenCalled();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const actions = store.getActions();
|
|
107
|
+
|
|
108
|
+
expect(actions[0]).toMatchObject({ type: "SET_APP_READY" });
|
|
109
|
+
|
|
110
|
+
expect(QuickBrickManager.sendQuickBrickEvent).toHaveBeenCalledWith(
|
|
111
|
+
QUICK_BRICK_READY_EVENT
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
expect(appLoader).toHaveBeenCalled();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("sends the quickBrickReady event when a loader doesn't resolves", async () => {
|
|
118
|
+
const testCallback = jest.fn(() => {});
|
|
119
|
+
|
|
120
|
+
render(
|
|
121
|
+
<DecoratedComponent
|
|
122
|
+
dispatch={dispatch}
|
|
123
|
+
{...state}
|
|
124
|
+
shouldFail
|
|
125
|
+
testCallback={testCallback}
|
|
126
|
+
/>
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const actions = store.getActions();
|
|
130
|
+
|
|
131
|
+
await waitFor(() => {
|
|
132
|
+
return expect(testCallback).toHaveBeenCalled();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
expect(actions[0]).toMatchObject({ type: "SET_APP_READY" });
|
|
136
|
+
expect(actions[1]).toMatchObject({ type: "SET_APP_LAUNCHED" });
|
|
137
|
+
|
|
138
|
+
expect(QuickBrickManager.sendQuickBrickEvent).toHaveBeenCalledWith(
|
|
139
|
+
QUICK_BRICK_READY_EVENT
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
expect(testCallback).toHaveBeenCalled();
|
|
143
|
+
|
|
144
|
+
expect(appLoader).toHaveBeenCalled();
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -182,13 +182,13 @@ export function appLifeCycleManager(appLoader, QuickBrickManager) {
|
|
|
182
182
|
data: { error },
|
|
183
183
|
});
|
|
184
184
|
}
|
|
185
|
-
|
|
186
|
-
makeAppReady();
|
|
187
|
-
checkStoredContextKeys();
|
|
188
185
|
};
|
|
189
186
|
|
|
190
187
|
React.useLayoutEffect(() => {
|
|
191
|
-
prepareApp()
|
|
188
|
+
prepareApp().then(() => {
|
|
189
|
+
makeAppReady();
|
|
190
|
+
checkStoredContextKeys();
|
|
191
|
+
});
|
|
192
192
|
}, []);
|
|
193
193
|
|
|
194
194
|
return <Component {...props} />;
|
package/App/index.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import * as R from "ramda";
|
|
3
|
+
|
|
3
4
|
import {
|
|
4
5
|
initialWindowMetrics,
|
|
5
6
|
SafeAreaProvider,
|
|
@@ -72,11 +73,11 @@ const App = ({
|
|
|
72
73
|
</SplashLoader>
|
|
73
74
|
<ModalProvider />
|
|
74
75
|
</URLSchemeListener>
|
|
75
|
-
<LogicAggregatorContainer
|
|
76
|
-
components={[InteractionManager, ApplyScreenHooks]}
|
|
77
|
-
/>
|
|
78
76
|
<LoadingOverlay />
|
|
79
77
|
</ErrorBoundary>
|
|
78
|
+
<LogicAggregatorContainer
|
|
79
|
+
components={[InteractionManager, ApplyScreenHooks]}
|
|
80
|
+
/>
|
|
80
81
|
</AppContainer>
|
|
81
82
|
</SafeAreaProvider>
|
|
82
83
|
</ThemeManager>
|
|
@@ -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" }));
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@applicaster/quick-brick-core",
|
|
3
|
-
"version": "13.0.0-alpha.
|
|
3
|
+
"version": "13.0.0-alpha.1711912250",
|
|
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-alpha.
|
|
33
|
-
"@applicaster/quick-brick-core-plugins": "13.0.0-alpha.
|
|
34
|
-
"@applicaster/zapp-pipes-v2-client": "13.0.0-alpha.
|
|
35
|
-
"@applicaster/zapp-react-native-bridge": "13.0.0-alpha.
|
|
36
|
-
"@applicaster/zapp-react-native-redux": "13.0.0-alpha.
|
|
37
|
-
"@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.
|
|
38
|
-
"@applicaster/zapp-react-native-utils": "13.0.0-alpha.
|
|
31
|
+
"@applicaster/applicaster-types": "13.0.0-alpha.1711912250",
|
|
32
|
+
"@applicaster/quick-brick-core-plugins": "13.0.0-alpha.1711912250",
|
|
33
|
+
"@applicaster/zapp-pipes-v2-client": "13.0.0-alpha.1711912250",
|
|
34
|
+
"@applicaster/zapp-react-native-bridge": "13.0.0-alpha.1711912250",
|
|
35
|
+
"@applicaster/zapp-react-native-redux": "13.0.0-alpha.1711912250",
|
|
36
|
+
"@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.1711912250",
|
|
37
|
+
"@applicaster/zapp-react-native-utils": "13.0.0-alpha.1711912250",
|
|
39
38
|
"atob": "^2.1.2",
|
|
40
39
|
"axios": "^0.28.0",
|
|
41
40
|
"btoa": "^1.2.1",
|
|
@@ -43,7 +42,7 @@
|
|
|
43
42
|
"md5": "^2.3.0",
|
|
44
43
|
"promise": "^8.3.0",
|
|
45
44
|
"query-string": "7.1.3",
|
|
46
|
-
"react-redux": "
|
|
45
|
+
"react-redux": "^7.2.1",
|
|
47
46
|
"redux": "^4.0.4",
|
|
48
47
|
"reselect": "^4.0.0",
|
|
49
48
|
"url": "^0.11.0",
|
|
@@ -63,6 +62,7 @@
|
|
|
63
62
|
"react-native-fs": "*",
|
|
64
63
|
"react-native-gesture-handler": "*",
|
|
65
64
|
"react-native-linear-gradient": "*",
|
|
65
|
+
"react-native-safe-area-context": "*",
|
|
66
66
|
"react-native-svg": "*",
|
|
67
67
|
"react-native-web": "*",
|
|
68
68
|
"react-native-webview": "*",
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { View, Text } from "react-native";
|
|
3
|
-
import { render } from "@testing-library/react-native";
|
|
4
|
-
|
|
5
|
-
import { ErrorBoundary } from "../index";
|
|
6
|
-
|
|
7
|
-
const TestComponent = ({ error }: { error: any }) => {
|
|
8
|
-
if (error) {
|
|
9
|
-
throw new Error("error !!");
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
return (
|
|
13
|
-
<View>
|
|
14
|
-
<Text>all is good</Text>
|
|
15
|
-
</View>
|
|
16
|
-
);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
describe("<ErrorBoundary />", () => {
|
|
20
|
-
describe("when there is no error", () => {
|
|
21
|
-
it("renders correctly", () => {
|
|
22
|
-
const { getByText } = render(
|
|
23
|
-
<ErrorBoundary>
|
|
24
|
-
<TestComponent />
|
|
25
|
-
</ErrorBoundary>
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
expect(getByText("all is good")).toBeTruthy();
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
describe("When an error is caught", () => {
|
|
33
|
-
const _consoleLog = console.log;
|
|
34
|
-
|
|
35
|
-
beforeAll(() => {
|
|
36
|
-
console.log = jest.fn();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
afterAll(() => {
|
|
40
|
-
console.log = _consoleLog;
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("renders error state correctly", () => {
|
|
44
|
-
const { getByText } = render(
|
|
45
|
-
<ErrorBoundary>
|
|
46
|
-
<TestComponent error />
|
|
47
|
-
</ErrorBoundary>
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
// Note: You'll need to verify what your ErrorBoundary actually renders in error state
|
|
51
|
-
// This is just an example assertion:
|
|
52
|
-
expect(getByText(/error/i)).toBeTruthy();
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Fragment as ModalChildrenWrapper } from "react";
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`<NavigationProvider /> modal feature removes the visible flag when dismissing a modal 1`] = `
|
|
4
|
-
{
|
|
5
|
-
"options": {
|
|
6
|
-
"animated": true,
|
|
7
|
-
"animationType": "slide",
|
|
8
|
-
"onDismiss": [Function],
|
|
9
|
-
"onRequestClose": [Function],
|
|
10
|
-
"onShow": [Function],
|
|
11
|
-
"presentationStyle": "overFullScreen",
|
|
12
|
-
"transparent": true,
|
|
13
|
-
},
|
|
14
|
-
"props": undefined,
|
|
15
|
-
"screen": {
|
|
16
|
-
"id": "A1234",
|
|
17
|
-
"navigations": [],
|
|
18
|
-
"ui_components": [],
|
|
19
|
-
},
|
|
20
|
-
"visible": true,
|
|
21
|
-
}
|
|
22
|
-
`;
|
|
23
|
-
|
|
24
|
-
exports[`<NavigationProvider /> modal feature removes the visible flag when dismissing a modal 2`] = `
|
|
25
|
-
{
|
|
26
|
-
"options": {},
|
|
27
|
-
"props": {},
|
|
28
|
-
"screen": null,
|
|
29
|
-
"visible": false,
|
|
30
|
-
}
|
|
31
|
-
`;
|
|
32
|
-
|
|
33
|
-
exports[`<NavigationProvider /> modal feature sets the modalState when opening a modal 1`] = `undefined`;
|
|
34
|
-
|
|
35
|
-
exports[`<NavigationProvider /> modal feature should reset state to initial when dismissing a modal ( closeModalBottomSheet ) opened by openModalBottomSheet 1`] = `
|
|
36
|
-
{
|
|
37
|
-
"options": {
|
|
38
|
-
"animated": false,
|
|
39
|
-
"animationType": "none",
|
|
40
|
-
"onDismiss": [Function],
|
|
41
|
-
"onRequestClose": [Function],
|
|
42
|
-
"onShow": [Function],
|
|
43
|
-
"presentationStyle": "overFullScreen",
|
|
44
|
-
"transparent": true,
|
|
45
|
-
},
|
|
46
|
-
"props": {},
|
|
47
|
-
"screen": {
|
|
48
|
-
"ModalBottomSheetContent": {
|
|
49
|
-
"id": "A1234",
|
|
50
|
-
"navigations": [],
|
|
51
|
-
"ui_components": [],
|
|
52
|
-
},
|
|
53
|
-
"modalBottomSheetContentProps": {
|
|
54
|
-
"some": "props",
|
|
55
|
-
},
|
|
56
|
-
},
|
|
57
|
-
"visible": true,
|
|
58
|
-
}
|
|
59
|
-
`;
|
|
60
|
-
|
|
61
|
-
exports[`<NavigationProvider /> modal feature should reset state to initial when dismissing a modal ( closeModalBottomSheet ) opened by openModalBottomSheet 2`] = `
|
|
62
|
-
{
|
|
63
|
-
"options": {},
|
|
64
|
-
"props": {},
|
|
65
|
-
"screen": null,
|
|
66
|
-
"visible": false,
|
|
67
|
-
}
|
|
68
|
-
`;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
-
|
|
3
|
-
exports[`appLifeCycleManager runs the loaders, then sends quickBrickReady event 1`] = `
|
|
4
|
-
<View>
|
|
5
|
-
<Text>
|
|
6
|
-
I'm a component
|
|
7
|
-
</Text>
|
|
8
|
-
</View>
|
|
9
|
-
`;
|
|
10
|
-
|
|
11
|
-
exports[`appLifeCycleManager sends the quickBrickReady event when a loader doesn't resolves 1`] = `
|
|
12
|
-
<View>
|
|
13
|
-
<Text>
|
|
14
|
-
I'm a component
|
|
15
|
-
</Text>
|
|
16
|
-
</View>
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
exports[`appLifeCycleManager sends the quickBrickReady event when a loader doesn't resolves 2`] = `
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
{
|
|
23
|
-
"data": {
|
|
24
|
-
"error": [Error: loading failed],
|
|
25
|
-
},
|
|
26
|
-
"message": "AppLifeCycleManager: A loading operation failed: loading failed",
|
|
27
|
-
},
|
|
28
|
-
],
|
|
29
|
-
]
|
|
30
|
-
`;
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { View, Text } from "react-native";
|
|
3
|
-
import { create, act } from "react-test-renderer";
|
|
4
|
-
|
|
5
|
-
const Component = () => (
|
|
6
|
-
<View>
|
|
7
|
-
<Text>I'm a component</Text>
|
|
8
|
-
</View>
|
|
9
|
-
);
|
|
10
|
-
|
|
11
|
-
const mockLogger = {
|
|
12
|
-
warning: jest.fn(),
|
|
13
|
-
log: jest.fn(),
|
|
14
|
-
debug: jest.fn(),
|
|
15
|
-
info: jest.fn(),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
jest.mock("../../logger", () => ({
|
|
19
|
-
coreAppLogger: {
|
|
20
|
-
addSubsystem: jest.fn(() => mockLogger),
|
|
21
|
-
},
|
|
22
|
-
}));
|
|
23
|
-
|
|
24
|
-
const QuickBrickManager = {
|
|
25
|
-
sendQuickBrickEvent: jest.fn(),
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const LOADING_ERROR = new Error("loading failed");
|
|
29
|
-
|
|
30
|
-
const appLoader = jest.fn((_dispatch, _getState) => {
|
|
31
|
-
if (_getState().shouldFail) return Promise.reject(LOADING_ERROR);
|
|
32
|
-
|
|
33
|
-
return Promise.resolve();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const dispatch = jest.fn();
|
|
37
|
-
|
|
38
|
-
const state = {
|
|
39
|
-
rivers: {},
|
|
40
|
-
plugins: {},
|
|
41
|
-
appSettings: { runtimeConfigurationUrls: { rivers: "http://rivers.url" } },
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const QUICK_BRICK_READY_EVENT = "quickBrickReady";
|
|
45
|
-
|
|
46
|
-
const actions = {};
|
|
47
|
-
|
|
48
|
-
jest.doMock("@applicaster/zapp-react-native-utils/reactHooks/actions", () => ({
|
|
49
|
-
useActions: jest.fn(() => ({ actions })),
|
|
50
|
-
}));
|
|
51
|
-
|
|
52
|
-
const { appLifeCycleManager } = require("../index");
|
|
53
|
-
|
|
54
|
-
describe("appLifeCycleManager", () => {
|
|
55
|
-
const decorator = appLifeCycleManager(appLoader, QuickBrickManager);
|
|
56
|
-
|
|
57
|
-
beforeEach(() => {
|
|
58
|
-
mockLogger.warning.mockClear();
|
|
59
|
-
appLoader.mockClear();
|
|
60
|
-
QuickBrickManager.sendQuickBrickEvent.mockClear();
|
|
61
|
-
dispatch.mockClear();
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("returns a function to decorate a component", () => {
|
|
65
|
-
expect(decorator).toBeFunction();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("runs the loaders, then sends quickBrickReady event", (done) => {
|
|
69
|
-
const DecoratedComponent = decorator(Component);
|
|
70
|
-
|
|
71
|
-
let wrapper;
|
|
72
|
-
|
|
73
|
-
const testCallback = () => {
|
|
74
|
-
expect(dispatch).toHaveBeenCalledWith(
|
|
75
|
-
expect.objectContaining({ type: "SET_APP_READY" })
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
expect(QuickBrickManager.sendQuickBrickEvent).toHaveBeenCalledWith(
|
|
79
|
-
QUICK_BRICK_READY_EVENT
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
done();
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
act(() => {
|
|
86
|
-
wrapper = create(
|
|
87
|
-
<DecoratedComponent
|
|
88
|
-
dispatch={dispatch}
|
|
89
|
-
{...state}
|
|
90
|
-
testCallback={testCallback}
|
|
91
|
-
/>
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
96
|
-
expect(appLoader).toHaveBeenCalled();
|
|
97
|
-
expect.assertions(4);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it("sends the quickBrickReady event when a loader doesn't resolves", (done) => {
|
|
101
|
-
const DecoratedComponent = decorator(Component);
|
|
102
|
-
|
|
103
|
-
let wrapper;
|
|
104
|
-
|
|
105
|
-
const testCallback = () => {
|
|
106
|
-
expect(dispatch).toHaveBeenCalledWith(
|
|
107
|
-
expect.objectContaining({ type: "SET_APP_READY" })
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
expect(QuickBrickManager.sendQuickBrickEvent).toHaveBeenCalledWith(
|
|
111
|
-
QUICK_BRICK_READY_EVENT
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
expect(mockLogger.warning.mock.calls).toMatchSnapshot();
|
|
115
|
-
|
|
116
|
-
done();
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
act(() => {
|
|
120
|
-
wrapper = create(
|
|
121
|
-
<DecoratedComponent
|
|
122
|
-
dispatch={dispatch}
|
|
123
|
-
{...state}
|
|
124
|
-
shouldFail
|
|
125
|
-
testCallback={testCallback}
|
|
126
|
-
/>
|
|
127
|
-
);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
expect(wrapper.toJSON()).toMatchSnapshot();
|
|
131
|
-
expect(appLoader).toHaveBeenCalled();
|
|
132
|
-
expect.assertions(5);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
File without changes
|