@applicaster/quick-brick-core 13.0.0-alpha.8865907528 → 13.0.0-alpha.9053464934
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/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/remoteContextReloader/getRemoteContextData/getNativeRemoteContextData.ts +14 -0
- package/package.json +9 -10
- package/App/ErrorBoundary/__tests__/errorBoundary.test.js +0 -55
- package/App/appLifeCycleManager/__tests__/__snapshots__/appLifeCycleManager.test.js.snap +0 -30
- package/App/appLifeCycleManager/__tests__/appLifeCycleManager.test.js +0 -134
|
@@ -12,18 +12,18 @@ exports[`Actions Provider renders children 1`] = `
|
|
|
12
12
|
"$$typeof": Symbol(react.context),
|
|
13
13
|
"Consumer": {
|
|
14
14
|
"$$typeof": Symbol(react.context),
|
|
15
|
+
"_calculateChangedBits": null,
|
|
15
16
|
"_context": [Circular],
|
|
16
17
|
},
|
|
17
18
|
"Provider": {
|
|
18
19
|
"$$typeof": Symbol(react.provider),
|
|
19
20
|
"_context": [Circular],
|
|
20
21
|
},
|
|
22
|
+
"_calculateChangedBits": null,
|
|
21
23
|
"_currentRenderer": null,
|
|
22
24
|
"_currentRenderer2": {},
|
|
23
25
|
"_currentValue": null,
|
|
24
26
|
"_currentValue2": null,
|
|
25
|
-
"_defaultValue": null,
|
|
26
|
-
"_globalName": null,
|
|
27
27
|
"_threadCount": 0,
|
|
28
28
|
},
|
|
29
29
|
"contextProvider": [Function],
|
package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
} from "../useOpenSchemeHandler/const";
|
|
17
17
|
import { withInitialPlayerState } from "../useOpenSchemeHandler/utils";
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const { log_warning } = require("../../../logger");
|
|
20
20
|
|
|
21
21
|
const rivers: Record<string, Partial<ZappRiver>> = {
|
|
22
22
|
A1234: {
|
|
@@ -53,10 +53,13 @@ const navigator = {
|
|
|
53
53
|
replace: jest.fn(),
|
|
54
54
|
push: jest.fn(),
|
|
55
55
|
goHome: jest.fn(),
|
|
56
|
-
}
|
|
56
|
+
};
|
|
57
57
|
|
|
58
58
|
const mockStore = configureStore();
|
|
59
|
-
|
|
59
|
+
|
|
60
|
+
jest
|
|
61
|
+
.spyOn(useNavigationHooks, "useNavigation")
|
|
62
|
+
.mockImplementation(() => navigator);
|
|
60
63
|
|
|
61
64
|
const helperSpy = jest.spyOn(helpers, "handlePresentNavigation");
|
|
62
65
|
const feedLoaderSpy = jest.spyOn(feedLoader, "useFeedLoader");
|
|
@@ -69,7 +72,7 @@ jest.doMock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
|
|
|
69
72
|
},
|
|
70
73
|
}));
|
|
71
74
|
|
|
72
|
-
jest.
|
|
75
|
+
jest.doMock("../../../logger", () => ({
|
|
73
76
|
log_info: jest.fn(),
|
|
74
77
|
log_error: jest.fn(),
|
|
75
78
|
log_warning: jest.fn(),
|
|
@@ -77,6 +80,10 @@ jest.mock("../../../logger", () => ({
|
|
|
77
80
|
log_debug: jest.fn(),
|
|
78
81
|
}));
|
|
79
82
|
|
|
83
|
+
jest.useFakeTimers({
|
|
84
|
+
legacyFakeTimers: true,
|
|
85
|
+
});
|
|
86
|
+
|
|
80
87
|
// to use import instead of require it's required to use jest.mock above
|
|
81
88
|
const { useOpenSchemeHandler } = require("../useOpenSchemeHandler");
|
|
82
89
|
|
|
@@ -185,6 +192,7 @@ describe("useOpenSchemeHandler", () => {
|
|
|
185
192
|
it("doesn't log a warning", async () => {
|
|
186
193
|
const tests = () => {
|
|
187
194
|
expect(log_warning).not.toHaveBeenCalled();
|
|
195
|
+
expect.assertions(1);
|
|
188
196
|
};
|
|
189
197
|
|
|
190
198
|
await testHook({ url, query, tests });
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import * as React from "react";
|
|
1
2
|
import * as R from "ramda";
|
|
2
3
|
import axios from "axios";
|
|
3
|
-
import { renderHook } from "@testing-library/react-
|
|
4
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
4
5
|
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
6
|
+
import * as zappRedux from "@applicaster/zapp-react-native-redux";
|
|
5
7
|
import * as helpers from "../../../helpers";
|
|
6
8
|
import * as feedLoader from "@applicaster/zapp-react-native-utils/reactHooks/feed/useFeedLoader";
|
|
7
9
|
import * as useNavigationHooks from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation";
|
|
8
|
-
import { WrappedWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
|
|
9
|
-
import { usePresentSchemeHandler } from "../usePresentSchemeHandler";
|
|
10
10
|
|
|
11
|
+
import { Provider } from "react-redux";
|
|
11
12
|
import configureStore from "redux-mock-store";
|
|
12
13
|
|
|
13
14
|
const rivers = {
|
|
@@ -19,22 +20,23 @@ const rivers = {
|
|
|
19
20
|
const navigator = {
|
|
20
21
|
currentRoute: "/river/A1234",
|
|
21
22
|
replace: jest.fn(),
|
|
22
|
-
|
|
23
|
-
} as any;
|
|
23
|
+
};
|
|
24
24
|
|
|
25
25
|
const mockStore = configureStore();
|
|
26
26
|
|
|
27
|
-
jest
|
|
27
|
+
jest
|
|
28
|
+
.spyOn(useNavigationHooks, "useNavigation")
|
|
29
|
+
.mockImplementation(() => navigator);
|
|
28
30
|
|
|
29
31
|
const helperSpy = jest.spyOn(helpers, "handlePresentNavigation");
|
|
30
32
|
const feedLoaderSpy = jest.spyOn(feedLoader, "useFeedLoader");
|
|
31
33
|
|
|
34
|
+
const { usePresentSchemeHandler } = require("../usePresentSchemeHandler");
|
|
35
|
+
|
|
32
36
|
const onFinish = jest.fn((cb) => {
|
|
33
37
|
cb();
|
|
34
38
|
});
|
|
35
39
|
|
|
36
|
-
jest.useFakeTimers();
|
|
37
|
-
|
|
38
40
|
describe("usePresentSchemeHandler", () => {
|
|
39
41
|
beforeEach(() => {
|
|
40
42
|
onFinish.mockClear();
|
|
@@ -42,7 +44,11 @@ describe("usePresentSchemeHandler", () => {
|
|
|
42
44
|
navigator.replace.mockClear();
|
|
43
45
|
});
|
|
44
46
|
|
|
45
|
-
const store = { test: "test", rivers };
|
|
47
|
+
const store = mockStore({ test: "test", rivers });
|
|
48
|
+
|
|
49
|
+
const wrapper: React.FC<any> = ({ children }) => (
|
|
50
|
+
<Provider store={store}>{children}</Provider>
|
|
51
|
+
);
|
|
46
52
|
|
|
47
53
|
describe("loading link url", () => {
|
|
48
54
|
const query = { link_url: "http://applicaster.com" };
|
|
@@ -53,11 +59,10 @@ describe("usePresentSchemeHandler", () => {
|
|
|
53
59
|
|
|
54
60
|
it("opens the link entry", () => {
|
|
55
61
|
renderHook(() => usePresentSchemeHandler({ query, url, onFinish }), {
|
|
56
|
-
wrapper
|
|
57
|
-
initialProps: { store },
|
|
62
|
+
wrapper,
|
|
58
63
|
});
|
|
59
64
|
|
|
60
|
-
expect(onFinish).
|
|
65
|
+
expect(onFinish).toBeCalled();
|
|
61
66
|
|
|
62
67
|
expect(helperSpy).toBeCalledWith(
|
|
63
68
|
expect.objectContaining({
|
|
@@ -91,8 +96,7 @@ describe("usePresentSchemeHandler", () => {
|
|
|
91
96
|
onFinish,
|
|
92
97
|
}),
|
|
93
98
|
{
|
|
94
|
-
wrapper
|
|
95
|
-
initialProps: { store },
|
|
99
|
+
wrapper,
|
|
96
100
|
}
|
|
97
101
|
);
|
|
98
102
|
|
|
@@ -119,8 +123,7 @@ describe("usePresentSchemeHandler", () => {
|
|
|
119
123
|
)}&show_nav_bar=true`;
|
|
120
124
|
|
|
121
125
|
renderHook(() => usePresentSchemeHandler({ query, url, onFinish }), {
|
|
122
|
-
wrapper
|
|
123
|
-
initialProps: { store },
|
|
126
|
+
wrapper,
|
|
124
127
|
});
|
|
125
128
|
|
|
126
129
|
expect(onFinish).toBeCalled();
|
|
@@ -152,22 +155,22 @@ describe("usePresentSchemeHandler", () => {
|
|
|
152
155
|
)}&screen_id=${screen_id}`;
|
|
153
156
|
|
|
154
157
|
renderHook(() => usePresentSchemeHandler({ query, url, onFinish }), {
|
|
155
|
-
wrapper
|
|
156
|
-
initialProps: { store },
|
|
158
|
+
wrapper,
|
|
157
159
|
});
|
|
158
160
|
|
|
159
161
|
expect(onFinish).toBeCalled();
|
|
160
162
|
|
|
161
|
-
expect(helperSpy).
|
|
163
|
+
expect(helperSpy).toBeCalledWith(
|
|
162
164
|
expect.objectContaining({
|
|
163
165
|
data: {
|
|
164
166
|
id: "url_scheme_entry",
|
|
165
167
|
type: { value: "link" },
|
|
168
|
+
screen_type: screen_id,
|
|
166
169
|
link: { href: query.link_url, type: "text/html" },
|
|
167
170
|
extensions: { showNavBar: false },
|
|
168
171
|
},
|
|
169
|
-
navigator
|
|
170
|
-
pushScreen:
|
|
172
|
+
navigator,
|
|
173
|
+
pushScreen: expect.anything(),
|
|
171
174
|
})
|
|
172
175
|
);
|
|
173
176
|
});
|
|
@@ -177,7 +180,9 @@ describe("usePresentSchemeHandler", () => {
|
|
|
177
180
|
it("Re-sets app ready state and calls loadAppContextData with new river and cellStyles data", async () => {
|
|
178
181
|
const store = mockStore({ test: "test" });
|
|
179
182
|
|
|
180
|
-
const wrapper =
|
|
183
|
+
const wrapper: React.FC<any> = ({ children }) => (
|
|
184
|
+
<Provider store={store}>{children}</Provider>
|
|
185
|
+
);
|
|
181
186
|
|
|
182
187
|
const query = {
|
|
183
188
|
rivers_configuration_id: "test",
|
|
@@ -185,6 +190,7 @@ describe("usePresentSchemeHandler", () => {
|
|
|
185
190
|
|
|
186
191
|
const storageSpy = jest.spyOn(sessionStorage, "getAllItems");
|
|
187
192
|
const axiosGetSpy = jest.spyOn(axios, "get");
|
|
193
|
+
const zappReduxSpy = jest.spyOn(zappRedux, "loadAppContextData");
|
|
188
194
|
|
|
189
195
|
const getAllItems = jest.fn().mockResolvedValue({
|
|
190
196
|
accountsAccountId: "accountsAccountId",
|
|
@@ -198,6 +204,7 @@ describe("usePresentSchemeHandler", () => {
|
|
|
198
204
|
|
|
199
205
|
storageSpy.mockImplementation(getAllItems);
|
|
200
206
|
axiosGetSpy.mockImplementation(get);
|
|
207
|
+
zappReduxSpy.mockReturnValue(null);
|
|
201
208
|
|
|
202
209
|
renderHook(() => usePresentSchemeHandler({ query, url: "", onFinish }), {
|
|
203
210
|
wrapper,
|
|
@@ -210,6 +217,13 @@ describe("usePresentSchemeHandler", () => {
|
|
|
210
217
|
actions?.find(R.propEq("type", "SET_APP_NOT_READY"))
|
|
211
218
|
).toBeDefined();
|
|
212
219
|
|
|
220
|
+
expect(actions?.find(R.propEq("type", "SET_APP_READY"))).toBeDefined();
|
|
221
|
+
|
|
222
|
+
expect(zappReduxSpy).toBeCalledWith(expect.any(Function), {
|
|
223
|
+
cellStyles: "url",
|
|
224
|
+
rivers: "url",
|
|
225
|
+
});
|
|
226
|
+
|
|
213
227
|
expect(navigator.replace).toBeCalledWith({});
|
|
214
228
|
};
|
|
215
229
|
});
|
|
@@ -247,7 +261,7 @@ describe("usePresentSchemeHandler", () => {
|
|
|
247
261
|
},
|
|
248
262
|
}),
|
|
249
263
|
{
|
|
250
|
-
wrapper
|
|
264
|
+
wrapper,
|
|
251
265
|
}
|
|
252
266
|
);
|
|
253
267
|
|
|
@@ -279,7 +293,7 @@ describe("usePresentSchemeHandler", () => {
|
|
|
279
293
|
},
|
|
280
294
|
}),
|
|
281
295
|
{
|
|
282
|
-
wrapper
|
|
296
|
+
wrapper,
|
|
283
297
|
}
|
|
284
298
|
);
|
|
285
299
|
|
|
@@ -311,7 +325,7 @@ describe("usePresentSchemeHandler", () => {
|
|
|
311
325
|
},
|
|
312
326
|
}),
|
|
313
327
|
{
|
|
314
|
-
wrapper
|
|
328
|
+
wrapper,
|
|
315
329
|
}
|
|
316
330
|
);
|
|
317
331
|
|
|
@@ -343,7 +357,7 @@ describe("usePresentSchemeHandler", () => {
|
|
|
343
357
|
},
|
|
344
358
|
}),
|
|
345
359
|
{
|
|
346
|
-
wrapper
|
|
360
|
+
wrapper,
|
|
347
361
|
}
|
|
348
362
|
);
|
|
349
363
|
|
package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useUrlSchemeHandler.test.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import * as URLHandlersMap from "..";
|
|
|
5
5
|
import { Provider } from "react-redux";
|
|
6
6
|
import configureStore from "redux-mock-store";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
const { log_warning } = require("../../../logger");
|
|
9
9
|
|
|
10
10
|
const mockStore = configureStore();
|
|
11
11
|
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, Text, TouchableOpacity } from "react-native";
|
|
3
|
+
import { render, fireEvent, act } from "@testing-library/react-native";
|
|
4
|
+
import { useErrorStore } from "../store";
|
|
5
|
+
import { ErrorBoundary } from "../index";
|
|
6
|
+
|
|
7
|
+
jest.mock(
|
|
8
|
+
"@applicaster/zapp-react-native-ui-components/Components/ErrorScreen",
|
|
9
|
+
() => ({
|
|
10
|
+
// eslint-disable-next-line react/prop-types
|
|
11
|
+
ErrorScreen: ({ dismissError, message, buttons }) => (
|
|
12
|
+
<View testID="error-screen">
|
|
13
|
+
<Text testID="error-message">{message || "Default error message"}</Text>
|
|
14
|
+
{/* eslint-disable-next-line react/prop-types */}
|
|
15
|
+
{buttons?.map((button, index) => (
|
|
16
|
+
<TouchableOpacity
|
|
17
|
+
key={index}
|
|
18
|
+
onPress={button.onPress}
|
|
19
|
+
testID={`button-${index}`}
|
|
20
|
+
>
|
|
21
|
+
<Text>{button.text}</Text>
|
|
22
|
+
</TouchableOpacity>
|
|
23
|
+
))}
|
|
24
|
+
|
|
25
|
+
{dismissError ? (
|
|
26
|
+
<TouchableOpacity onPress={dismissError} testID="dismiss-button">
|
|
27
|
+
<Text>Dismiss Error</Text>
|
|
28
|
+
</TouchableOpacity>
|
|
29
|
+
) : null}
|
|
30
|
+
</View>
|
|
31
|
+
),
|
|
32
|
+
})
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
jest.mock("@applicaster/zapp-react-native-bridge/QuickBrick", () => ({
|
|
36
|
+
sendQuickBrickEvent: jest.fn(),
|
|
37
|
+
QUICK_BRICK_EVENTS: {
|
|
38
|
+
FORCE_APP_RELOAD: "force_app_reload",
|
|
39
|
+
},
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
jest.mock("@applicaster/zapp-react-native-utils/logger", () => ({
|
|
43
|
+
coreLogger: {
|
|
44
|
+
addSubsystem: () => ({
|
|
45
|
+
error: jest.fn(),
|
|
46
|
+
}),
|
|
47
|
+
},
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
// eslint-disable-next-line react/prop-types
|
|
51
|
+
const TestComponent = ({ error, errorMessage = "error !!" }) => {
|
|
52
|
+
if (error) {
|
|
53
|
+
throw new Error(errorMessage);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<View>
|
|
58
|
+
<Text>all is good</Text>
|
|
59
|
+
</View>
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
describe("<ErrorBoundary />", () => {
|
|
64
|
+
// Clear all error states between tests
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
useErrorStore.getState().dismissError();
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe("when there is no error", () => {
|
|
70
|
+
it("renders children correctly", () => {
|
|
71
|
+
const { getByText } = render(
|
|
72
|
+
<ErrorBoundary>
|
|
73
|
+
<TestComponent />
|
|
74
|
+
</ErrorBoundary>
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
expect(getByText("all is good")).toBeTruthy();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
describe("when an error is caught", () => {
|
|
82
|
+
const _consoleLogs = {
|
|
83
|
+
error: console.error,
|
|
84
|
+
log: console.log,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
beforeAll(() => {
|
|
88
|
+
console.error = jest.fn();
|
|
89
|
+
console.log = jest.fn();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
afterAll(() => {
|
|
93
|
+
console.error = _consoleLogs.error;
|
|
94
|
+
console.log = _consoleLogs.log;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("renders error state with default values (recoverable error)", () => {
|
|
98
|
+
const { getByTestId } = render(
|
|
99
|
+
<ErrorBoundary>
|
|
100
|
+
<TestComponent error />
|
|
101
|
+
</ErrorBoundary>
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
expect(getByTestId("error-screen")).toBeTruthy();
|
|
105
|
+
expect(getByTestId("dismiss-button")).toBeTruthy(); // Should be recoverable by default
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("handles non-recoverable errors (no dismiss button)", () => {
|
|
109
|
+
const { getByTestId, queryByTestId } = render(
|
|
110
|
+
<ErrorBoundary recoverable={false}>
|
|
111
|
+
<TestComponent error />
|
|
112
|
+
</ErrorBoundary>
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
expect(getByTestId("error-screen")).toBeTruthy();
|
|
116
|
+
expect(queryByTestId("dismiss-button")).toBeFalsy(); // Should not be recoverable
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("shows custom error message from caught error", () => {
|
|
120
|
+
const customErrorMessage = "Custom error message for testing";
|
|
121
|
+
|
|
122
|
+
const { getByTestId } = render(
|
|
123
|
+
<ErrorBoundary>
|
|
124
|
+
<TestComponent error errorMessage={customErrorMessage} />
|
|
125
|
+
</ErrorBoundary>
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
// The error info should be passed to the ErrorScreen
|
|
129
|
+
expect(getByTestId("error-message").props.children).toBeTruthy();
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("can dismiss the error and restore the UI", () => {
|
|
133
|
+
// First render with error
|
|
134
|
+
const { getByTestId, queryByText, rerender } = render(
|
|
135
|
+
<ErrorBoundary>
|
|
136
|
+
<TestComponent error />
|
|
137
|
+
</ErrorBoundary>
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
// Verify error screen is shown
|
|
141
|
+
expect(getByTestId("error-screen")).toBeTruthy();
|
|
142
|
+
|
|
143
|
+
// Dismiss the error
|
|
144
|
+
fireEvent.press(getByTestId("dismiss-button"));
|
|
145
|
+
|
|
146
|
+
// Force rerender to see the change
|
|
147
|
+
rerender(
|
|
148
|
+
<ErrorBoundary>
|
|
149
|
+
<TestComponent />
|
|
150
|
+
</ErrorBoundary>
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
// Now the regular content should be visible
|
|
154
|
+
expect(queryByText("all is good")).toBeTruthy();
|
|
155
|
+
});
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe("error store functionality", () => {
|
|
159
|
+
it("properly sets error state", () => {
|
|
160
|
+
const error = new Error("Test error");
|
|
161
|
+
const errorInfo = "Test error info";
|
|
162
|
+
|
|
163
|
+
act(() => {
|
|
164
|
+
useErrorStore.getState().setError(error, errorInfo, true);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
const state = useErrorStore.getState();
|
|
168
|
+
expect(state.hasError).toBe(true);
|
|
169
|
+
expect(state.error).toBe(error);
|
|
170
|
+
expect(state.info).toBe(errorInfo);
|
|
171
|
+
expect(state.recoverable).toBe(true);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("properly resets error state", () => {
|
|
175
|
+
// First set an error
|
|
176
|
+
act(() => {
|
|
177
|
+
useErrorStore
|
|
178
|
+
.getState()
|
|
179
|
+
.setError(new Error("Test error"), "Info", true);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// Then dismiss it
|
|
183
|
+
act(() => {
|
|
184
|
+
useErrorStore.getState().dismissError();
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const state = useErrorStore.getState();
|
|
188
|
+
expect(state.hasError).toBe(false);
|
|
189
|
+
expect(state.error).toBeUndefined();
|
|
190
|
+
expect(state.info).toBeUndefined();
|
|
191
|
+
expect(state.recoverable).toBe(true); // Default value when reset
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("remembers recoverable state", () => {
|
|
195
|
+
act(() => {
|
|
196
|
+
useErrorStore
|
|
197
|
+
.getState()
|
|
198
|
+
.setError(new Error("Test error"), "Info", false);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
const state = useErrorStore.getState();
|
|
202
|
+
expect(state.recoverable).toBe(false);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe("integration with ErrorScreen", () => {
|
|
207
|
+
it("renders restart app button for non-recoverable errors", () => {
|
|
208
|
+
const { getAllByTestId } = render(
|
|
209
|
+
<ErrorBoundary recoverable={false}>
|
|
210
|
+
<TestComponent error />
|
|
211
|
+
</ErrorBoundary>
|
|
212
|
+
);
|
|
213
|
+
|
|
214
|
+
// Should have the restart app button
|
|
215
|
+
const buttons = getAllByTestId(/button-/);
|
|
216
|
+
expect(buttons.length).toBeGreaterThan(0);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it("passes error info to the ErrorScreen component", () => {
|
|
220
|
+
const customErrorMessage = "Very specific error message";
|
|
221
|
+
|
|
222
|
+
const { getByTestId } = render(
|
|
223
|
+
<ErrorBoundary>
|
|
224
|
+
<TestComponent error errorMessage={customErrorMessage} />
|
|
225
|
+
</ErrorBoundary>
|
|
226
|
+
);
|
|
227
|
+
|
|
228
|
+
// The error info should be visible in the UI
|
|
229
|
+
expect(getByTestId("error-message")).toBeTruthy();
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { act, renderHook } from "@testing-library/react-hooks";
|
|
2
|
+
import { useErrorStore } from "../store";
|
|
3
|
+
|
|
4
|
+
describe("Error Store", () => {
|
|
5
|
+
beforeEach(() => {
|
|
6
|
+
act(() => {
|
|
7
|
+
useErrorStore.getState().dismissError();
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe("Initial state", () => {
|
|
12
|
+
it("should have correct default values", () => {
|
|
13
|
+
const { result } = renderHook(() => useErrorStore());
|
|
14
|
+
|
|
15
|
+
expect(result.current).toMatchObject({
|
|
16
|
+
hasError: false,
|
|
17
|
+
error: undefined,
|
|
18
|
+
info: undefined,
|
|
19
|
+
recoverable: true,
|
|
20
|
+
setError: expect.any(Function),
|
|
21
|
+
dismissError: expect.any(Function),
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("setError action", () => {
|
|
27
|
+
it("should set error state with provided values", () => {
|
|
28
|
+
const testError = new Error("Test error");
|
|
29
|
+
const testInfo = "Test error info";
|
|
30
|
+
const isRecoverable = true;
|
|
31
|
+
|
|
32
|
+
const { result } = renderHook(() => useErrorStore());
|
|
33
|
+
|
|
34
|
+
act(() => {
|
|
35
|
+
result.current.setError(testError, testInfo, isRecoverable);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
expect(result.current).toMatchObject({
|
|
39
|
+
hasError: true,
|
|
40
|
+
error: testError,
|
|
41
|
+
info: testInfo,
|
|
42
|
+
recoverable: isRecoverable,
|
|
43
|
+
setError: expect.any(Function),
|
|
44
|
+
dismissError: expect.any(Function),
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should set non-recoverable error when specified", () => {
|
|
49
|
+
const testError = new Error("Test error");
|
|
50
|
+
const testInfo = "Test error info";
|
|
51
|
+
const isRecoverable = false;
|
|
52
|
+
|
|
53
|
+
const { result } = renderHook(() => useErrorStore());
|
|
54
|
+
|
|
55
|
+
act(() => {
|
|
56
|
+
result.current.setError(testError, testInfo, isRecoverable);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
expect(result.current).toMatchObject({
|
|
60
|
+
recoverable: false,
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should default to recoverable error when not specified", () => {
|
|
65
|
+
const testError = new Error("Test error");
|
|
66
|
+
const testInfo = "Test error info";
|
|
67
|
+
|
|
68
|
+
const { result } = renderHook(() => useErrorStore());
|
|
69
|
+
|
|
70
|
+
act(() => {
|
|
71
|
+
result.current.setError(testError, testInfo);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
expect(result.current).toMatchObject({
|
|
75
|
+
recoverable: true,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe("dismissError action", () => {
|
|
81
|
+
it("should reset error state to defaults", () => {
|
|
82
|
+
const testError = new Error("Test error");
|
|
83
|
+
const { result } = renderHook(() => useErrorStore());
|
|
84
|
+
|
|
85
|
+
act(() => {
|
|
86
|
+
result.current.setError(testError, "info", false);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
expect(result.current).toMatchObject({
|
|
90
|
+
hasError: true,
|
|
91
|
+
recoverable: false,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
act(() => {
|
|
95
|
+
result.current.dismissError();
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
expect(result.current).toMatchObject({
|
|
99
|
+
hasError: false,
|
|
100
|
+
error: undefined,
|
|
101
|
+
info: undefined,
|
|
102
|
+
recoverable: true,
|
|
103
|
+
setError: expect.any(Function),
|
|
104
|
+
dismissError: expect.any(Function),
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
describe("Direct store access via API", () => {
|
|
110
|
+
it("should allow direct access to store outside React components", () => {
|
|
111
|
+
act(() => {
|
|
112
|
+
useErrorStore
|
|
113
|
+
.getState()
|
|
114
|
+
.setError(new Error("API error"), "API info", false);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const { result } = renderHook(() => useErrorStore());
|
|
118
|
+
|
|
119
|
+
expect(result.current).toMatchObject({
|
|
120
|
+
hasError: true,
|
|
121
|
+
error: expect.objectContaining({ message: "API error" }),
|
|
122
|
+
info: "API info",
|
|
123
|
+
recoverable: false,
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it("should allow clearing errors via API", () => {
|
|
128
|
+
act(() => {
|
|
129
|
+
useErrorStore.getState().setError(new Error("API error"), "API info");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
act(() => {
|
|
133
|
+
useErrorStore.getState().dismissError();
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const { result } = renderHook(() => useErrorStore());
|
|
137
|
+
|
|
138
|
+
expect(result.current).toMatchObject({
|
|
139
|
+
hasError: false,
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
});
|
|
@@ -1,42 +1,66 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import pick from "lodash/pick";
|
|
2
3
|
|
|
3
4
|
import { coreLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
4
5
|
import { ErrorScreen } from "@applicaster/zapp-react-native-ui-components/Components/ErrorScreen";
|
|
5
6
|
|
|
7
|
+
import { useErrorStore } from "./store";
|
|
8
|
+
import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
9
|
+
|
|
6
10
|
const errorBoundaryLogger = coreLogger.addSubsystem("react_error-boundary");
|
|
7
11
|
|
|
8
12
|
type Props = {
|
|
9
13
|
children: React.ReactNode;
|
|
14
|
+
recoverable?: boolean;
|
|
10
15
|
};
|
|
11
16
|
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
error?: Error;
|
|
15
|
-
info?: string;
|
|
17
|
+
type ErrorBoundaryContentProps = {
|
|
18
|
+
children: React.ReactNode;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
const restartApp = () => {
|
|
22
|
+
QuickBrickManager.sendQuickBrickEvent(
|
|
23
|
+
QuickBrickManager.QUICK_BRICK_EVENTS.FORCE_APP_RELOAD
|
|
24
|
+
);
|
|
25
|
+
};
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const restartButton = {
|
|
28
|
+
text: "Restart the app",
|
|
29
|
+
onPress: restartApp,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const buttons = [restartButton];
|
|
33
|
+
|
|
34
|
+
const ErrorBoundaryContent: React.FC<ErrorBoundaryContentProps> = ({
|
|
35
|
+
children,
|
|
36
|
+
}) => {
|
|
37
|
+
const { hasError, dismissError, info } = pick(
|
|
38
|
+
useErrorStore((state) => state),
|
|
39
|
+
["hasError", "dismissError", "info"]
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
if (hasError) {
|
|
43
|
+
return (
|
|
44
|
+
<ErrorScreen
|
|
45
|
+
dismissError={dismissError}
|
|
46
|
+
message={info}
|
|
47
|
+
buttons={buttons}
|
|
48
|
+
/>
|
|
49
|
+
);
|
|
27
50
|
}
|
|
28
51
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
52
|
+
return <>{children}</>;
|
|
53
|
+
};
|
|
32
54
|
|
|
33
|
-
|
|
34
|
-
|
|
55
|
+
export class ErrorBoundary extends React.Component<Props> {
|
|
56
|
+
componentDidCatch(error, info) {
|
|
57
|
+
errorBoundaryLogger.error({ error, data: info, message: error.message });
|
|
58
|
+
const { recoverable = true } = this.props;
|
|
35
59
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
60
|
+
useErrorStore.getState().setError(error, info, recoverable);
|
|
61
|
+
}
|
|
39
62
|
|
|
40
|
-
|
|
63
|
+
render() {
|
|
64
|
+
return <ErrorBoundaryContent>{this.props.children}</ErrorBoundaryContent>;
|
|
41
65
|
}
|
|
42
66
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { create } from "zustand";
|
|
2
|
+
|
|
3
|
+
type ErrorState = {
|
|
4
|
+
hasError: boolean;
|
|
5
|
+
error?: Error;
|
|
6
|
+
info?: string;
|
|
7
|
+
recoverable: boolean;
|
|
8
|
+
setError: (error: Error, info: string, recoverable?: boolean) => void;
|
|
9
|
+
dismissError: () => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const useErrorStore = create<ErrorState>((set) => ({
|
|
13
|
+
hasError: false,
|
|
14
|
+
error: undefined,
|
|
15
|
+
info: undefined,
|
|
16
|
+
recoverable: true,
|
|
17
|
+
setError: (error: Error, info: string, recoverable = true) =>
|
|
18
|
+
set({ hasError: true, error, info, recoverable }),
|
|
19
|
+
dismissError: () =>
|
|
20
|
+
set({
|
|
21
|
+
hasError: false,
|
|
22
|
+
error: undefined,
|
|
23
|
+
info: undefined,
|
|
24
|
+
recoverable: true,
|
|
25
|
+
}),
|
|
26
|
+
}));
|
|
@@ -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} />;
|
|
@@ -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.9053464934",
|
|
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.9053464934",
|
|
32
|
+
"@applicaster/quick-brick-core-plugins": "13.0.0-alpha.9053464934",
|
|
33
|
+
"@applicaster/zapp-pipes-v2-client": "13.0.0-alpha.9053464934",
|
|
34
|
+
"@applicaster/zapp-react-native-bridge": "13.0.0-alpha.9053464934",
|
|
35
|
+
"@applicaster/zapp-react-native-redux": "13.0.0-alpha.9053464934",
|
|
36
|
+
"@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.9053464934",
|
|
37
|
+
"@applicaster/zapp-react-native-utils": "13.0.0-alpha.9053464934",
|
|
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",
|
|
@@ -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,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
|
-
});
|