@applicaster/quick-brick-core 13.0.0-alpha.3099523645 → 13.0.0-alpha.3144359118

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.
@@ -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";
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/quick-brick-core",
3
- "version": "13.0.0-alpha.3099523645",
3
+ "version": "13.0.0-alpha.3144359118",
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.3099523645",
33
- "@applicaster/quick-brick-core-plugins": "13.0.0-alpha.3099523645",
34
- "@applicaster/zapp-pipes-v2-client": "13.0.0-alpha.3099523645",
35
- "@applicaster/zapp-react-native-bridge": "13.0.0-alpha.3099523645",
36
- "@applicaster/zapp-react-native-redux": "13.0.0-alpha.3099523645",
37
- "@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.3099523645",
38
- "@applicaster/zapp-react-native-utils": "13.0.0-alpha.3099523645",
32
+ "@applicaster/applicaster-types": "13.0.0-alpha.3144359118",
33
+ "@applicaster/quick-brick-core-plugins": "13.0.0-alpha.3144359118",
34
+ "@applicaster/zapp-pipes-v2-client": "13.0.0-alpha.3144359118",
35
+ "@applicaster/zapp-react-native-bridge": "13.0.0-alpha.3144359118",
36
+ "@applicaster/zapp-react-native-redux": "13.0.0-alpha.3144359118",
37
+ "@applicaster/zapp-react-native-ui-components": "13.0.0-alpha.3144359118",
38
+ "@applicaster/zapp-react-native-utils": "13.0.0-alpha.3144359118",
39
39
  "atob": "^2.1.2",
40
40
  "axios": "^0.28.0",
41
41
  "btoa": "^1.2.1",
@@ -57,7 +57,6 @@
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
61
  "react": "*",
63
62
  "react-native": "*",
@@ -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,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
- });