@applicaster/quick-brick-core 13.0.0-alpha.8620112557 → 13.0.0-alpha.8865907528

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. package/App/ActionsProvider/__tests__/__snapshots__/ActionsProvider.test.js.snap +2 -2
  2. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useOpenSchemeHandler.test.tsx +4 -12
  3. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/usePresentSchemeHandler.test.tsx +26 -40
  4. package/App/DeepLinking/URLSchemeHandler/SchemeHandlerHooks/__tests__/useUrlSchemeHandler.test.tsx +1 -1
  5. package/App/DeepLinking/URLSchemeListener/__tests__/URLSchemeListener.test.js +40 -0
  6. package/App/DeepLinking/URLSchemeListener/index.tsx +1 -1
  7. package/App/ErrorBoundary/__tests__/errorBoundary.test.js +20 -37
  8. package/App/ModalProvider/ModalBottomSheet/index.tsx +4 -2
  9. package/App/ModalProvider/index.tsx +3 -4
  10. package/App/NetworkStatusProvider/__tests__/NetworkStatusProvider.test.tsx +11 -15
  11. package/App/NetworkStatusProvider/utils.ts +0 -1
  12. package/App/StoreConnector/__tests__/storeConnector.test.js +17 -14
  13. package/App/remoteContextReloader/__tests__/remoteContextReloader.test.js +11 -21
  14. package/createZappApp/__tests__/__snapshots__/createZappApp.test.js.snap +5 -128
  15. package/createZappApp/__tests__/createZappApp.test.js +7 -20
  16. package/defaults/__tests__/defaults.test.js +3 -4
  17. package/package.json +11 -14
  18. package/App/DeepLinking/URLSchemeListener/__tests__/URLSchemeListenerTest.js +0 -177
  19. package/App/ErrorBoundary/__tests__/__snapshots__/errorBoundary.test.js.snap +0 -9
  20. package/App/StoreConnector/__tests__/__snapshots__/storeConnector.test.js.snap +0 -35
  21. package/App/remoteContextReloader/__tests__/__snapshots__/remoteContextReloader.test.js.snap +0 -43
@@ -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,
16
15
  "_context": [Circular],
17
16
  },
18
17
  "Provider": {
19
18
  "$$typeof": Symbol(react.provider),
20
19
  "_context": [Circular],
21
20
  },
22
- "_calculateChangedBits": null,
23
21
  "_currentRenderer": null,
24
22
  "_currentRenderer2": {},
25
23
  "_currentValue": null,
26
24
  "_currentValue2": null,
25
+ "_defaultValue": null,
26
+ "_globalName": null,
27
27
  "_threadCount": 0,
28
28
  },
29
29
  "contextProvider": [Function],
@@ -16,7 +16,7 @@ import {
16
16
  } from "../useOpenSchemeHandler/const";
17
17
  import { withInitialPlayerState } from "../useOpenSchemeHandler/utils";
18
18
 
19
- const { log_warning } = require("../../../logger");
19
+ import { log_warning } from "../../../logger";
20
20
 
21
21
  const rivers: Record<string, Partial<ZappRiver>> = {
22
22
  A1234: {
@@ -53,13 +53,10 @@ const navigator = {
53
53
  replace: jest.fn(),
54
54
  push: jest.fn(),
55
55
  goHome: jest.fn(),
56
- };
56
+ } as any;
57
57
 
58
58
  const mockStore = configureStore();
59
-
60
- jest
61
- .spyOn(useNavigationHooks, "useNavigation")
62
- .mockImplementation(() => navigator);
59
+ jest.spyOn(useNavigationHooks, "useNavigation").mockReturnValue(navigator);
63
60
 
64
61
  const helperSpy = jest.spyOn(helpers, "handlePresentNavigation");
65
62
  const feedLoaderSpy = jest.spyOn(feedLoader, "useFeedLoader");
@@ -72,7 +69,7 @@ jest.doMock("@applicaster/zapp-react-native-ui-components/Contexts", () => ({
72
69
  },
73
70
  }));
74
71
 
75
- jest.doMock("../../../logger", () => ({
72
+ jest.mock("../../../logger", () => ({
76
73
  log_info: jest.fn(),
77
74
  log_error: jest.fn(),
78
75
  log_warning: jest.fn(),
@@ -80,10 +77,6 @@ jest.doMock("../../../logger", () => ({
80
77
  log_debug: jest.fn(),
81
78
  }));
82
79
 
83
- jest.useFakeTimers({
84
- legacyFakeTimers: true,
85
- });
86
-
87
80
  // to use import instead of require it's required to use jest.mock above
88
81
  const { useOpenSchemeHandler } = require("../useOpenSchemeHandler");
89
82
 
@@ -192,7 +185,6 @@ describe("useOpenSchemeHandler", () => {
192
185
  it("doesn't log a warning", async () => {
193
186
  const tests = () => {
194
187
  expect(log_warning).not.toHaveBeenCalled();
195
- expect.assertions(1);
196
188
  };
197
189
 
198
190
  await testHook({ url, query, tests });
@@ -1,14 +1,13 @@
1
- import * as React from "react";
2
1
  import * as R from "ramda";
3
2
  import axios from "axios";
4
- import { renderHook } from "@testing-library/react-hooks";
3
+ import { renderHook } from "@testing-library/react-native";
5
4
  import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
6
- import * as zappRedux from "@applicaster/zapp-react-native-redux";
7
5
  import * as helpers from "../../../helpers";
8
6
  import * as feedLoader from "@applicaster/zapp-react-native-utils/reactHooks/feed/useFeedLoader";
9
7
  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";
12
11
  import configureStore from "redux-mock-store";
13
12
 
14
13
  const rivers = {
@@ -20,23 +19,22 @@ const rivers = {
20
19
  const navigator = {
21
20
  currentRoute: "/river/A1234",
22
21
  replace: jest.fn(),
23
- };
22
+ goHome: jest.fn(),
23
+ } as any;
24
24
 
25
25
  const mockStore = configureStore();
26
26
 
27
- jest
28
- .spyOn(useNavigationHooks, "useNavigation")
29
- .mockImplementation(() => navigator);
27
+ jest.spyOn(useNavigationHooks, "useNavigation").mockReturnValue(navigator);
30
28
 
31
29
  const helperSpy = jest.spyOn(helpers, "handlePresentNavigation");
32
30
  const feedLoaderSpy = jest.spyOn(feedLoader, "useFeedLoader");
33
31
 
34
- const { usePresentSchemeHandler } = require("../usePresentSchemeHandler");
35
-
36
32
  const onFinish = jest.fn((cb) => {
37
33
  cb();
38
34
  });
39
35
 
36
+ jest.useFakeTimers();
37
+
40
38
  describe("usePresentSchemeHandler", () => {
41
39
  beforeEach(() => {
42
40
  onFinish.mockClear();
@@ -44,11 +42,7 @@ describe("usePresentSchemeHandler", () => {
44
42
  navigator.replace.mockClear();
45
43
  });
46
44
 
47
- const store = mockStore({ test: "test", rivers });
48
-
49
- const wrapper: React.FC<any> = ({ children }) => (
50
- <Provider store={store}>{children}</Provider>
51
- );
45
+ const store = { test: "test", rivers };
52
46
 
53
47
  describe("loading link url", () => {
54
48
  const query = { link_url: "http://applicaster.com" };
@@ -59,10 +53,11 @@ describe("usePresentSchemeHandler", () => {
59
53
 
60
54
  it("opens the link entry", () => {
61
55
  renderHook(() => usePresentSchemeHandler({ query, url, onFinish }), {
62
- wrapper,
56
+ wrapper: WrappedWithProviders,
57
+ initialProps: { store },
63
58
  });
64
59
 
65
- expect(onFinish).toBeCalled();
60
+ expect(onFinish).toHaveBeenCalled();
66
61
 
67
62
  expect(helperSpy).toBeCalledWith(
68
63
  expect.objectContaining({
@@ -96,7 +91,8 @@ describe("usePresentSchemeHandler", () => {
96
91
  onFinish,
97
92
  }),
98
93
  {
99
- wrapper,
94
+ wrapper: WrappedWithProviders,
95
+ initialProps: { store },
100
96
  }
101
97
  );
102
98
 
@@ -123,7 +119,8 @@ describe("usePresentSchemeHandler", () => {
123
119
  )}&show_nav_bar=true`;
124
120
 
125
121
  renderHook(() => usePresentSchemeHandler({ query, url, onFinish }), {
126
- wrapper,
122
+ wrapper: WrappedWithProviders,
123
+ initialProps: { store },
127
124
  });
128
125
 
129
126
  expect(onFinish).toBeCalled();
@@ -155,22 +152,22 @@ describe("usePresentSchemeHandler", () => {
155
152
  )}&screen_id=${screen_id}`;
156
153
 
157
154
  renderHook(() => usePresentSchemeHandler({ query, url, onFinish }), {
158
- wrapper,
155
+ wrapper: WrappedWithProviders,
156
+ initialProps: { store },
159
157
  });
160
158
 
161
159
  expect(onFinish).toBeCalled();
162
160
 
163
- expect(helperSpy).toBeCalledWith(
161
+ expect(helperSpy).toHaveBeenCalledWith(
164
162
  expect.objectContaining({
165
163
  data: {
166
164
  id: "url_scheme_entry",
167
165
  type: { value: "link" },
168
- screen_type: screen_id,
169
166
  link: { href: query.link_url, type: "text/html" },
170
167
  extensions: { showNavBar: false },
171
168
  },
172
- navigator,
173
- pushScreen: expect.anything(),
169
+ navigator: expect.anything(),
170
+ pushScreen: "http://applicaster.com",
174
171
  })
175
172
  );
176
173
  });
@@ -180,9 +177,7 @@ describe("usePresentSchemeHandler", () => {
180
177
  it("Re-sets app ready state and calls loadAppContextData with new river and cellStyles data", async () => {
181
178
  const store = mockStore({ test: "test" });
182
179
 
183
- const wrapper: React.FC<any> = ({ children }) => (
184
- <Provider store={store}>{children}</Provider>
185
- );
180
+ const wrapper = WrappedWithProviders;
186
181
 
187
182
  const query = {
188
183
  rivers_configuration_id: "test",
@@ -190,7 +185,6 @@ describe("usePresentSchemeHandler", () => {
190
185
 
191
186
  const storageSpy = jest.spyOn(sessionStorage, "getAllItems");
192
187
  const axiosGetSpy = jest.spyOn(axios, "get");
193
- const zappReduxSpy = jest.spyOn(zappRedux, "loadAppContextData");
194
188
 
195
189
  const getAllItems = jest.fn().mockResolvedValue({
196
190
  accountsAccountId: "accountsAccountId",
@@ -204,7 +198,6 @@ describe("usePresentSchemeHandler", () => {
204
198
 
205
199
  storageSpy.mockImplementation(getAllItems);
206
200
  axiosGetSpy.mockImplementation(get);
207
- zappReduxSpy.mockReturnValue(null);
208
201
 
209
202
  renderHook(() => usePresentSchemeHandler({ query, url: "", onFinish }), {
210
203
  wrapper,
@@ -217,13 +210,6 @@ describe("usePresentSchemeHandler", () => {
217
210
  actions?.find(R.propEq("type", "SET_APP_NOT_READY"))
218
211
  ).toBeDefined();
219
212
 
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
-
227
213
  expect(navigator.replace).toBeCalledWith({});
228
214
  };
229
215
  });
@@ -261,7 +247,7 @@ describe("usePresentSchemeHandler", () => {
261
247
  },
262
248
  }),
263
249
  {
264
- wrapper,
250
+ wrapper: WrappedWithProviders,
265
251
  }
266
252
  );
267
253
 
@@ -293,7 +279,7 @@ describe("usePresentSchemeHandler", () => {
293
279
  },
294
280
  }),
295
281
  {
296
- wrapper,
282
+ wrapper: WrappedWithProviders,
297
283
  }
298
284
  );
299
285
 
@@ -325,7 +311,7 @@ describe("usePresentSchemeHandler", () => {
325
311
  },
326
312
  }),
327
313
  {
328
- wrapper,
314
+ wrapper: WrappedWithProviders,
329
315
  }
330
316
  );
331
317
 
@@ -357,7 +343,7 @@ describe("usePresentSchemeHandler", () => {
357
343
  },
358
344
  }),
359
345
  {
360
- wrapper,
346
+ wrapper: WrappedWithProviders,
361
347
  }
362
348
  );
363
349
 
@@ -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
- const { log_warning } = require("../../../logger");
8
+ import { log_warning } from "../../../logger";
9
9
 
10
10
  const mockStore = configureStore();
11
11
 
@@ -0,0 +1,40 @@
1
+ import * as React from "react";
2
+ import { View, Text } from "react-native";
3
+ import { renderWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
4
+
5
+ import { URLSchemeListener } from "../index";
6
+
7
+ const TestComponent = (props) => (
8
+ <View testID="test-comp" {...props}>
9
+ <Text>I'm a test component</Text>
10
+ </View>
11
+ );
12
+
13
+ const navigator = {
14
+ push: jest.fn(),
15
+ replace: jest.fn(),
16
+ };
17
+
18
+ jest.spyOn(console, "warn").mockImplementation(() => jest.fn());
19
+
20
+ function clearMocks() {
21
+ navigator.push.mockClear();
22
+ navigator.replace.mockClear();
23
+ console.warn.mockClear();
24
+ }
25
+
26
+ describe("URLSchemeHandler", () => {
27
+ const renderComponent = (props = {}) =>
28
+ renderWithProviders(
29
+ <URLSchemeListener {...props}>
30
+ <TestComponent />
31
+ </URLSchemeListener>
32
+ );
33
+
34
+ beforeEach(clearMocks);
35
+
36
+ it("renders correctly (default case)", () => {
37
+ const { getByTestId } = renderComponent();
38
+ expect(getByTestId("test-comp")).toBeDefined();
39
+ });
40
+ });
@@ -5,7 +5,7 @@ import { URLSchemeContext } from "./URLSchemeContextProvider";
5
5
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
6
6
  import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
7
7
 
8
- export function URLSchemeListener({ children }) {
8
+ export function URLSchemeListener({ children }: { children: React.ReactNode }) {
9
9
  const { url, done } = useContext(URLSchemeContext);
10
10
 
11
11
  const navigator = useNavigation();
@@ -1,7 +1,6 @@
1
1
  import React from "react";
2
2
  import { View, Text } from "react-native";
3
- import { shallow } from "enzyme";
4
- import { shallowToJson } from "enzyme-to-json";
3
+ import { render } from "@testing-library/react-native";
5
4
 
6
5
  import { ErrorBoundary } from "../index";
7
6
 
@@ -17,56 +16,40 @@ const TestComponent = ({ error }: { error: any }) => {
17
16
  );
18
17
  };
19
18
 
20
- const errorState = {
21
- hasError: true,
22
- error: new Error("oh no"),
23
- info: { componentStack: "error at ... \n ..." },
24
- };
25
-
26
19
  describe("<ErrorBoundary />", () => {
27
20
  describe("when there is no error", () => {
28
- const wrapper = shallow(
29
- <ErrorBoundary>
30
- <TestComponent />
31
- </ErrorBoundary>
32
- );
33
-
34
21
  it("renders correctly", () => {
35
- expect(shallowToJson(wrapper)).toMatchSnapshot();
22
+ const { getByText } = render(
23
+ <ErrorBoundary>
24
+ <TestComponent />
25
+ </ErrorBoundary>
26
+ );
27
+
28
+ expect(getByText("all is good")).toBeTruthy();
36
29
  });
37
30
  });
38
31
 
39
32
  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);
33
+ const _consoleLog = console.log;
54
34
 
55
35
  beforeAll(() => {
56
- console.log = jest.fn(); // eslint-disable-line no-console
36
+ console.log = jest.fn();
57
37
  });
58
38
 
59
39
  afterAll(() => {
60
- console.log = _consoleLog; // eslint-disable-line no-console
40
+ console.log = _consoleLog;
61
41
  });
62
42
 
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
- });
43
+ it("renders error state correctly", () => {
44
+ const { getByText } = render(
45
+ <ErrorBoundary>
46
+ <TestComponent error />
47
+ </ErrorBoundary>
48
+ );
67
49
 
68
- it("renders correctly", () => {
69
- expect(shallowToJson(wrapper)).toMatchSnapshot();
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();
70
53
  });
71
54
  });
72
55
  });
@@ -4,7 +4,7 @@ import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils"
4
4
  import { useSafeAreaInsets } from "react-native-safe-area-context";
5
5
 
6
6
  import React, { useCallback, useEffect, useMemo, useState } from "react";
7
- import { View, StyleSheet, Keyboard } from "react-native";
7
+ import { Keyboard, StyleSheet, View } from "react-native";
8
8
 
9
9
  import { Overlay } from "./Overlay";
10
10
  import { ModalBottomSheetFrame } from "./ModalBottomSheetFrame";
@@ -83,6 +83,8 @@ export function ModalBottomSheet(props: Props) {
83
83
  [isTablet]
84
84
  );
85
85
 
86
+ const modalVisible = visible && sheetHeight > 0;
87
+
86
88
  return (
87
89
  <View style={styles.container}>
88
90
  <Overlay
@@ -98,7 +100,7 @@ export function ModalBottomSheet(props: Props) {
98
100
  paddingBottom={bottomOffset}
99
101
  maxWidth={maxWidth}
100
102
  dimensions={dimensions}
101
- visible={visible && sheetHeight > 0}
103
+ visible={modalVisible}
102
104
  closeToast={dismiss}
103
105
  handleProps={{
104
106
  enabled: sheetHandleEnabled,
@@ -35,13 +35,12 @@ export function ModalProvider() {
35
35
 
36
36
  const pathname = `${ROUTE_TYPES.MODAL}/${modalScreenProps?.screenId}`;
37
37
 
38
+ const shouldShowModal = modalVisible && modalState?.visible;
39
+
38
40
  return (
39
41
  <PathnameContext.Provider value={pathname}>
40
42
  <ScreenContextProvider pathname={pathname}>
41
- <ModalPresenter
42
- visible={modalVisible && modalState?.visible}
43
- {...modalState?.options}
44
- >
43
+ <ModalPresenter visible={shouldShowModal} {...modalState?.options}>
45
44
  <ModalChildrenWrapper>
46
45
  <ModalContent modalScreenProps={modalScreenProps} />
47
46
  </ModalChildrenWrapper>
@@ -1,15 +1,11 @@
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";
6
4
  import { NetworkStatusContext } from "@applicaster/zapp-react-native-ui-components/Contexts/NetworkStatusContext";
7
5
  import { NetworkStatusProvider } from "../NetworkStatusProvider";
8
- import { Provider } from "react-redux";
6
+ import { WrappedWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
9
7
  import NetInfo from "@react-native-community/netinfo";
10
8
 
11
- const mockStore = configureStore([thunk]);
12
-
13
9
  const NetInfoMock = {
14
10
  type: "cellular",
15
11
  details: {
@@ -24,9 +20,9 @@ const NetInfoMock = {
24
20
  const getWrapper = (store) => ({
25
21
  // eslint-disable-next-line react/prop-types,react/display-name
26
22
  wrapper: ({ children }) => (
27
- <Provider store={store}>
23
+ <WrappedWithProviders store={store}>
28
24
  <NetworkStatusProvider>{children}</NetworkStatusProvider>
29
- </Provider>
25
+ </WrappedWithProviders>
30
26
  ),
31
27
  });
32
28
 
@@ -41,9 +37,9 @@ const useNetInfoMock = () => {
41
37
 
42
38
  describe("NetworkStatusProvider", function () {
43
39
  it("should return netInfoData", function () {
44
- const store = mockStore({
40
+ const store = {
45
41
  plugins: [{}],
46
- });
42
+ };
47
43
 
48
44
  // @ts-ignore
49
45
  jest.spyOn(NetInfo, "useNetInfo").mockImplementation(useNetInfoMock);
@@ -59,9 +55,9 @@ describe("NetworkStatusProvider", function () {
59
55
  it("should call onConnectionLost callback when connection type changes to none", function () {
60
56
  const onConnectionLost = jest.fn();
61
57
 
62
- const store = mockStore({
58
+ const store = {
63
59
  plugins: [{ module: { networkHooks: { onConnectionLost } } }],
64
- });
60
+ };
65
61
 
66
62
  // @ts-ignore
67
63
  jest.spyOn(NetInfo, "useNetInfo").mockImplementation(useNetInfoMock);
@@ -86,9 +82,9 @@ describe("NetworkStatusProvider", function () {
86
82
  it("should call onConnectionRestored callback when connection type switches from none", function () {
87
83
  const onConnectionRestored = jest.fn();
88
84
 
89
- const store = mockStore({
85
+ const store = {
90
86
  plugins: [{ module: { networkHooks: { onConnectionRestored } } }],
91
- });
87
+ };
92
88
 
93
89
  // @ts-ignore
94
90
  jest.spyOn(NetInfo, "useNetInfo").mockImplementation(useNetInfoMock);
@@ -123,9 +119,9 @@ describe("NetworkStatusProvider", function () {
123
119
  it("should call onConnectionTypeChanged callback when connection type changes", function () {
124
120
  const onConnectionTypeChanged = jest.fn();
125
121
 
126
- const store = mockStore({
122
+ const store = {
127
123
  plugins: [{ module: { networkHooks: { onConnectionTypeChanged } } }],
128
- });
124
+ };
129
125
 
130
126
  // @ts-ignore
131
127
  jest.spyOn(NetInfo, "useNetInfo").mockImplementation(useNetInfoMock);
@@ -1,4 +1,3 @@
1
- /// <reference types="@types/tizen-tv-webapis" />
2
1
  import * as R from "ramda";
3
2
 
4
3
  import { NetInfoState } from "@react-native-community/netinfo";
@@ -1,9 +1,7 @@
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 { shallow } from "enzyme";
5
- import { shallowToJson } from "enzyme-to-json";
6
- import configureStore from "redux-mock-store";
4
+ import { renderWithProviders } from "@applicaster/zapp-react-native-utils/testUtils";
7
5
 
8
6
  import { storeConnector } from "../index";
9
7
 
@@ -12,23 +10,22 @@ const components = { grid: jest.fn() };
12
10
  const rivers = { A123: { name: "home", id: "A123" } };
13
11
  const appSettings = { bundleIdentifier: "com.app.test" };
14
12
 
15
- const Component = () => (
16
- <View>
13
+ const Component = (props) => (
14
+ <View testID="test-comp" {...props}>
17
15
  <Text>I'm a component</Text>
18
16
  </View>
19
17
  );
20
18
 
21
- const store = configureStore()({
19
+ const store = {
22
20
  styles,
23
21
  components,
24
22
  rivers,
25
23
  appSettings,
26
- });
24
+ };
27
25
 
28
26
  describe("storeConnector", () => {
29
27
  it("returns a Component", () => {
30
28
  const WrappedComponent = storeConnector(Component);
31
-
32
29
  expect(ReactIs.isValidElementType(WrappedComponent)).toBe(true);
33
30
 
34
31
  expect(WrappedComponent).toEqual(
@@ -41,12 +38,18 @@ describe("storeConnector", () => {
41
38
 
42
39
  it("passes the props to the component", () => {
43
40
  const WrappedComponent = storeConnector(Component);
44
- const wrapper = shallow(<WrappedComponent store={store} />).dive();
45
- const wrapperProps = wrapper.first().props();
46
41
 
47
- expect(shallowToJson(wrapper)).toMatchSnapshot();
48
- expect(wrapperProps).toHaveProperty("components", components);
49
- expect(wrapperProps).toHaveProperty("rivers", rivers);
50
- expect(wrapperProps).toHaveProperty("appSettings", appSettings);
42
+ const { getByText, getByTestId } = renderWithProviders(
43
+ <WrappedComponent />,
44
+ store
45
+ );
46
+
47
+ expect(getByText("I'm a component")).toBeTruthy();
48
+
49
+ expect(getByTestId("test-comp").props).toMatchObject({
50
+ appSettings,
51
+ components,
52
+ rivers,
53
+ });
51
54
  });
52
55
  });
@@ -1,7 +1,6 @@
1
1
  import * as React from "react";
2
2
  import { View, Text } from "react-native";
3
- import { shallow } from "enzyme";
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("adds a componentDidMount method", () => {
34
- const wrapper = shallow(
35
- <WrappedComponent {...{ appSettings, plugins, dispatch }} />
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,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
- <Provider
104
- store={
105
- {
106
- "@@observable": [Function],
107
- "dispatch": [Function],
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 { shallow } from "enzyme";
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
- const wrapper = shallow(<ZappApp />);
90
-
91
- expect(shallowToJson(wrapper)).toMatchSnapshot();
81
+ render(<ZappApp />);
82
+ expect(screen.toJSON()).toMatchSnapshot();
92
83
  });
93
84
 
94
- it("has a <Provider /> component with an initialized store", () => {
85
+ it("has a Provider component with an initialized store", () => {
95
86
  const ZappApp = createZappApp(zappAppConfig);
96
- const wrapper = shallow(<ZappApp />);
97
-
98
- const providerNode = wrapper.find(Provider);
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 wrapper = shallow(<EmptyZappApp />);
9
- expect(shallowToJson(wrapper)).toMatchSnapshot();
7
+ const { toJSON } = render(<EmptyZappApp />);
8
+ expect(toJSON()).toMatchSnapshot();
10
9
  });
11
10
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-core",
3
- "version": "13.0.0-alpha.8620112557",
3
+ "version": "13.0.0-alpha.8865907528",
4
4
  "description": "Core package for Applicaster's Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -29,13 +29,13 @@
29
29
  },
30
30
  "homepage": "https://github.com/applicaster/quickbrick#readme",
31
31
  "dependencies": {
32
- "@applicaster/applicaster-types": "13.0.0-alpha.8620112557",
33
- "@applicaster/quick-brick-core-plugins": "13.0.0-alpha.8620112557",
34
- "@applicaster/zapp-pipes-v2-client": "13.0.0-alpha.8620112557",
35
- "@applicaster/zapp-react-native-bridge": "13.0.0-alpha.8620112557",
36
- "@applicaster/zapp-react-native-redux": "13.0.0-alpha.8620112557",
37
- "@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.8620112557",
38
- "@applicaster/zapp-react-native-utils": "13.0.0-alpha.8620112557",
32
+ "@applicaster/applicaster-types": "13.0.0-alpha.8865907528",
33
+ "@applicaster/quick-brick-core-plugins": "13.0.0-alpha.8865907528",
34
+ "@applicaster/zapp-pipes-v2-client": "13.0.0-alpha.8865907528",
35
+ "@applicaster/zapp-react-native-bridge": "13.0.0-alpha.8865907528",
36
+ "@applicaster/zapp-react-native-redux": "13.0.0-alpha.8865907528",
37
+ "@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.8865907528",
38
+ "@applicaster/zapp-react-native-utils": "13.0.0-alpha.8865907528",
39
39
  "atob": "^2.1.2",
40
40
  "axios": "^0.28.0",
41
41
  "btoa": "^1.2.1",
@@ -43,7 +43,7 @@
43
43
  "md5": "^2.3.0",
44
44
  "promise": "^8.3.0",
45
45
  "query-string": "7.1.3",
46
- "react-redux": "^7.2.1",
46
+ "react-redux": "9.2.0",
47
47
  "redux": "^4.0.4",
48
48
  "reselect": "^4.0.0",
49
49
  "url": "^0.11.0",
@@ -57,10 +57,9 @@
57
57
  "@applicaster/zapp-react-native-tvos-ui-components": "*",
58
58
  "@babel/runtime": "*",
59
59
  "@react-native-community/netinfo": "*",
60
- "@types/node": "*",
61
60
  "immer": "*",
62
- "react": "17.0.2",
63
- "react-native": "0.68.6",
61
+ "react": "*",
62
+ "react-native": "*",
64
63
  "react-native-fs": "*",
65
64
  "react-native-gesture-handler": "*",
66
65
  "react-native-linear-gradient": "*",
@@ -73,8 +72,6 @@
73
72
  "zustand": "*"
74
73
  },
75
74
  "devDependencies": {
76
- "@types/react-native": "0.69.6",
77
- "@types/tizen-tv-webapis": "^2.0.1",
78
75
  "nock": "^10.0.0",
79
76
  "redux-mock-store": "^1.5.3"
80
77
  },
@@ -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,35 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`storeConnector passes the props to the component 1`] = `
4
- <Component
5
- appSettings={
6
- {
7
- "bundleIdentifier": "com.app.test",
8
- }
9
- }
10
- components={
11
- {
12
- "grid": [MockFunction],
13
- }
14
- }
15
- dispatch={[Function]}
16
- rivers={
17
- {
18
- "A123": {
19
- "id": "A123",
20
- "name": "home",
21
- },
22
- }
23
- }
24
- store={
25
- {
26
- "clearActions": [Function],
27
- "dispatch": [Function],
28
- "getActions": [Function],
29
- "getState": [Function],
30
- "replaceReducer": [Function],
31
- "subscribe": [Function],
32
- }
33
- }
34
- />
35
- `;
@@ -1,43 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`remoteContextReloader adds a componentDidMount method 1`] = `
4
- <Component
5
- appSettings={
6
- {
7
- "runtimeConfigurationUrls": {
8
- "foo": "bar",
9
- },
10
- }
11
- }
12
- dispatch={[MockFunction]}
13
- plugins={[]}
14
- />
15
- `;
16
-
17
- exports[`remoteContextReloader when in __DEV__ doesn't invoke the context reloader 1`] = `
18
- <Component
19
- appSettings={
20
- {
21
- "runtimeConfigurationUrls": {
22
- "foo": "bar",
23
- },
24
- }
25
- }
26
- dispatch={[MockFunction]}
27
- plugins={[]}
28
- />
29
- `;
30
-
31
- exports[`remoteContextReloader when not in __DEV__ invokes the context reloader 1`] = `
32
- <Component
33
- appSettings={
34
- {
35
- "runtimeConfigurationUrls": {
36
- "foo": "bar",
37
- },
38
- }
39
- }
40
- dispatch={[MockFunction]}
41
- plugins={[]}
42
- />
43
- `;