@applicaster/zapp-react-native-utils 13.0.0-alpha.2322412833 → 13.0.0-alpha.3592223128
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/appUtils/HooksManager/{Hook.ts → Hook.js} +23 -35
- package/appUtils/HooksManager/__tests__/__snapshots__/hook.test.js.snap +2 -4
- package/appUtils/HooksManager/__tests__/hook.test.js +184 -196
- package/appUtils/HooksManager/__tests__/hooksManager.test.js +99 -96
- package/appUtils/HooksManager/{constants.ts → constants.js} +1 -1
- package/appUtils/HooksManager/{index.ts → index.js} +112 -121
- package/appUtils/RiverFocusManager/index.js +12 -17
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +3 -2
- package/appUtils/focusManager/treeDataStructure/Utils/index.js +3 -1
- package/appUtils/{index.ts → index.js} +1 -1
- package/appUtils/keyCodes/__tests__/keyCodes.test.js +3 -3
- package/appUtils/keyCodes/{index.ts → index.js} +0 -2
- package/appUtils/keyCodes/{keys/keyEventMapper.ts → keys.android.js} +19 -0
- package/appUtils/keyCodes/keys.ios.js +46 -0
- package/appUtils/platform/platformUtils.ts +14 -0
- package/domUtils/{cookieManager.ts → cookieManager.js} +2 -1
- package/functionUtils/index.ts +11 -15
- package/modalState/index.ts +5 -1
- package/navigationUtils/index.ts +5 -14
- package/package.json +2 -2
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +2 -10
- package/reactHooks/feed/useFeedLoader.tsx +4 -9
- package/reactHooks/navigation/index.ts +4 -7
- package/reactHooks/utils/index.ts +1 -1
- package/reactUtils/index.ts +14 -0
- package/appUtils/HooksManager/__tests__/__snapshots__/hooksManager.test.js.snap +0 -693
- package/appUtils/HooksManager/types.ts +0 -116
- package/appUtils/keyCodes/keys/index.ts +0 -3
- package/appUtils/keyCodes/keys/keys.android.ts +0 -18
- package/appUtils/keyCodes/keys/keys.ios.ts +0 -25
- package/appUtils/keyCodes/keys/keys.ts +0 -15
- /package/appUtils/HooksManager/{logger.ts → logger.js} +0 -0
- /package/appUtils/{directionHelper.ts → directionHelper.js} +0 -0
- /package/appUtils/keyCodes/{androidTVKeys.ts → androidTVKeys.js} +0 -0
- /package/appUtils/keyCodes/{keys/keys.web.ts → keys.web.js} +0 -0
- /package/appUtils/keyCodes/{keys/keysByPlatform.ts → keysByPlatform.js} +0 -0
- /package/appUtils/{localizationsHelper.ts → localizationsHelper.js} +0 -0
- /package/domUtils/{logger.ts → logger.js} +0 -0
|
@@ -4,7 +4,6 @@ import { isFunction } from "../../functionUtils";
|
|
|
4
4
|
import { HOOKS_EVENTS, HOOKS_TRANSITION_TYPE } from "./constants";
|
|
5
5
|
|
|
6
6
|
import { hooksManagerLogger } from "./logger";
|
|
7
|
-
import type { Hook as HookInterface, HookIniObj } from "./types";
|
|
8
7
|
|
|
9
8
|
const BASE_HOOK_PROPERTIES = ["screen_id", "identifier", "weight"];
|
|
10
9
|
|
|
@@ -15,9 +14,7 @@ const BASE_HOOK_PROPERTIES = ["screen_id", "identifier", "weight"];
|
|
|
15
14
|
* @param {string} hookEventName
|
|
16
15
|
* @returns {number} index
|
|
17
16
|
*/
|
|
18
|
-
const hookState
|
|
19
|
-
arg0: typeof HOOKS_EVENTS[keyof typeof HOOKS_EVENTS]
|
|
20
|
-
) => number = R.indexOf(R.__, R.values(HOOKS_EVENTS));
|
|
17
|
+
const hookState = R.indexOf(R.__, R.values(HOOKS_EVENTS));
|
|
21
18
|
|
|
22
19
|
/**
|
|
23
20
|
* assigns property to a given context
|
|
@@ -31,20 +28,17 @@ function assignProp(context) {
|
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
/**
|
|
34
|
-
* Representation of a hook plugin
|
|
31
|
+
* Representation of a hook plugin with full data
|
|
35
32
|
*/
|
|
36
|
-
export class Hook
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
public configuration: HookInterface["configuration"];
|
|
46
|
-
|
|
47
|
-
constructor({ hook, hooks, manager }: HookIniObj) {
|
|
33
|
+
export class Hook {
|
|
34
|
+
/**
|
|
35
|
+
* constructs the hook
|
|
36
|
+
* @param {object} Options
|
|
37
|
+
* @param {object} Options.hook hook object
|
|
38
|
+
* @param {Array<Object>} Options.hooks array of hooks siblings in the current process
|
|
39
|
+
* @param {object} manager hook manager to process the hooks
|
|
40
|
+
*/
|
|
41
|
+
constructor({ hook, hooks, manager }) {
|
|
48
42
|
R.forEachObjIndexed(assignProp(this), hook);
|
|
49
43
|
this.manager = manager;
|
|
50
44
|
|
|
@@ -61,28 +55,25 @@ export class Hook implements HookInterface {
|
|
|
61
55
|
* @param {string} event name
|
|
62
56
|
* @param {Array<Any>} args variadic arguments to invoke the handler with
|
|
63
57
|
*/
|
|
64
|
-
setStateAndNotify(
|
|
65
|
-
event: typeof HOOKS_EVENTS[keyof typeof HOOKS_EVENTS],
|
|
66
|
-
...args
|
|
67
|
-
) {
|
|
58
|
+
setStateAndNotify(event, ...args) {
|
|
68
59
|
this.state = hookState(event);
|
|
69
|
-
this.manager.
|
|
60
|
+
this.manager.invokeHandler(event, ...args);
|
|
70
61
|
}
|
|
71
62
|
|
|
72
63
|
/**
|
|
73
64
|
* returns react component of the the hook modal presenter
|
|
74
65
|
* @returns {React.ComponentType<any>}
|
|
75
66
|
*/
|
|
76
|
-
getModalContainer()
|
|
77
|
-
return this.module
|
|
67
|
+
getModalContainer() {
|
|
68
|
+
return this.module && this.module.ModalContainer;
|
|
78
69
|
}
|
|
79
70
|
|
|
80
71
|
/**
|
|
81
72
|
* tells whether the hook should be presented as a screen
|
|
82
73
|
* @returns {boolean}
|
|
83
74
|
*/
|
|
84
|
-
shouldPresentScreenHook()
|
|
85
|
-
return
|
|
75
|
+
shouldPresentScreenHook() {
|
|
76
|
+
return (
|
|
86
77
|
(this.screen_id && this.general?.allow_screen_plugin_presentation) ||
|
|
87
78
|
(this.module && this.module.presentFullScreen) ||
|
|
88
79
|
(!this.module?.presentFullScreen &&
|
|
@@ -96,7 +87,7 @@ export class Hook implements HookInterface {
|
|
|
96
87
|
* tells whether the hook should be presented as a modal screen
|
|
97
88
|
* @returns {boolean}
|
|
98
89
|
*/
|
|
99
|
-
isModalHook()
|
|
90
|
+
isModalHook() {
|
|
100
91
|
return (
|
|
101
92
|
this.screen_id &&
|
|
102
93
|
this.general?.transition_type === HOOKS_TRANSITION_TYPE.MODAL
|
|
@@ -108,7 +99,7 @@ export class Hook implements HookInterface {
|
|
|
108
99
|
* if it doesn't return success
|
|
109
100
|
* @returns { boolean}
|
|
110
101
|
*/
|
|
111
|
-
isFlowBlocker()
|
|
102
|
+
isFlowBlocker() {
|
|
112
103
|
return (
|
|
113
104
|
(this.general && this.general.is_flow_blocker) ||
|
|
114
105
|
(this.module && this.module.isFlowBlocker && this.module.isFlowBlocker())
|
|
@@ -120,7 +111,7 @@ export class Hook implements HookInterface {
|
|
|
120
111
|
* @param {object} payload to pass to the hook
|
|
121
112
|
* @returns { boolean}
|
|
122
113
|
*/
|
|
123
|
-
skipHook(payload
|
|
114
|
+
skipHook(payload) {
|
|
124
115
|
const _skipHook = R.compose(
|
|
125
116
|
R.ifElse(isFunction, R.apply(R.__, [payload]), R.F),
|
|
126
117
|
R.path(["module", "skipHook"])
|
|
@@ -142,10 +133,7 @@ export class Hook implements HookInterface {
|
|
|
142
133
|
* @param {object} payload to pass to the hook
|
|
143
134
|
* @param {function} next callback to invoke for processing next hook
|
|
144
135
|
*/
|
|
145
|
-
execute
|
|
146
|
-
payload: T,
|
|
147
|
-
next: (arg0: { payload: T; success?: boolean }) => void
|
|
148
|
-
): void {
|
|
136
|
+
execute(payload, next) {
|
|
149
137
|
if (this.skipHook(payload)) {
|
|
150
138
|
next({ payload, success: true });
|
|
151
139
|
|
|
@@ -164,7 +152,7 @@ export class Hook implements HookInterface {
|
|
|
164
152
|
|
|
165
153
|
this.setStateAndNotify(HOOKS_EVENTS.START_BACKGROUND_HOOK, this);
|
|
166
154
|
|
|
167
|
-
this.manager.runInBackground(this, payload, next, (_payload
|
|
155
|
+
this.manager.runInBackground(this, payload, next, (_payload) =>
|
|
168
156
|
this.manager.presentScreenHook(this, _payload || payload, next)
|
|
169
157
|
);
|
|
170
158
|
} else if (this.shouldPresentScreenHook()) {
|
|
@@ -187,7 +175,7 @@ export class Hook implements HookInterface {
|
|
|
187
175
|
* - AND next hook has the same weight as the current one
|
|
188
176
|
* @returns {boolean}
|
|
189
177
|
*/
|
|
190
|
-
shouldStartNextHook(nextHook
|
|
178
|
+
shouldStartNextHook(nextHook) {
|
|
191
179
|
return (
|
|
192
180
|
nextHook &&
|
|
193
181
|
!this.shouldPresentScreenHook() &&
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
2
|
|
|
3
|
-
exports[`Hook
|
|
3
|
+
exports[`Hook Properties has all the hook properties 1`] = `
|
|
4
4
|
Hook {
|
|
5
5
|
"advertising": Object {},
|
|
6
6
|
"general": Object {
|
|
@@ -13,10 +13,8 @@ Hook {
|
|
|
13
13
|
"lastHook": true,
|
|
14
14
|
"manager": Object {
|
|
15
15
|
"executeHook": [MockFunction],
|
|
16
|
+
"invokeHandler": [MockFunction],
|
|
16
17
|
"presentScreenHook": [MockFunction],
|
|
17
|
-
"subscriber": Object {
|
|
18
|
-
"invokeHandler": [MockFunction],
|
|
19
|
-
},
|
|
20
18
|
},
|
|
21
19
|
"name": "Hook Screen",
|
|
22
20
|
"navigations": Array [],
|
|
@@ -29,9 +29,7 @@ const hooks = (options, otherHook = null) =>
|
|
|
29
29
|
const manager = {
|
|
30
30
|
presentScreenHook: jest.fn(),
|
|
31
31
|
executeHook: jest.fn(),
|
|
32
|
-
|
|
33
|
-
invokeHandler: jest.fn(),
|
|
34
|
-
},
|
|
32
|
+
invokeHandler: jest.fn(),
|
|
35
33
|
};
|
|
36
34
|
|
|
37
35
|
const getHook = (options, otherHook) =>
|
|
@@ -44,267 +42,257 @@ const getHook = (options, otherHook) =>
|
|
|
44
42
|
function clearMocks() {
|
|
45
43
|
manager.presentScreenHook.mockClear();
|
|
46
44
|
manager.executeHook.mockClear();
|
|
47
|
-
manager.
|
|
45
|
+
manager.invokeHandler.mockClear();
|
|
48
46
|
}
|
|
49
47
|
|
|
50
|
-
describe("Hook", () => {
|
|
51
|
-
|
|
52
|
-
const hookPlugin = getHook({});
|
|
48
|
+
describe("Hook Properties", () => {
|
|
49
|
+
const hookPlugin = getHook({});
|
|
53
50
|
|
|
54
|
-
|
|
51
|
+
beforeEach(clearMocks);
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
});
|
|
53
|
+
it("has all the hook properties", () => {
|
|
54
|
+
expect(hookPlugin).toMatchSnapshot();
|
|
59
55
|
});
|
|
56
|
+
});
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const hookPlugin = getHook({
|
|
66
|
-
general: {},
|
|
67
|
-
module: { ModalContainer },
|
|
68
|
-
});
|
|
58
|
+
describe("getModalContainer", () => {
|
|
59
|
+
it("returns ModalContainer", () => {
|
|
60
|
+
const ModalContainer = jest.fn();
|
|
69
61
|
|
|
70
|
-
|
|
62
|
+
const hookPlugin = getHook({
|
|
63
|
+
general: {},
|
|
64
|
+
module: { ModalContainer },
|
|
71
65
|
});
|
|
66
|
+
|
|
67
|
+
expect(hookPlugin.getModalContainer()).toBe(ModalContainer);
|
|
72
68
|
});
|
|
69
|
+
});
|
|
73
70
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
71
|
+
describe("isFlowBlocker", () => {
|
|
72
|
+
it("returns true if the hook is flow blocker", () => {
|
|
73
|
+
const hookPlugin = getHook({ general: { is_flow_blocker: true } });
|
|
77
74
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
expect(hookPlugin.isFlowBlocker()).toBe(true);
|
|
84
|
-
expect(hookWithoutScreen.isFlowBlocker()).toBe(true);
|
|
75
|
+
const hookWithoutScreen = getHook({
|
|
76
|
+
general: {},
|
|
77
|
+
module: { isFlowBlocker: () => true },
|
|
85
78
|
});
|
|
86
79
|
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
expect(hookPlugin.isFlowBlocker()).toBe(true);
|
|
81
|
+
expect(hookWithoutScreen.isFlowBlocker()).toBe(true);
|
|
82
|
+
});
|
|
89
83
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
module: { isFlowBlocker: () => false },
|
|
93
|
-
});
|
|
84
|
+
it("returns false otherwise", () => {
|
|
85
|
+
const hookPlugin = getHook({ general: { is_flow_blocker: false } });
|
|
94
86
|
|
|
95
|
-
|
|
96
|
-
|
|
87
|
+
const hookWithoutScreen = getHook({
|
|
88
|
+
general: {},
|
|
89
|
+
module: { isFlowBlocker: () => false },
|
|
97
90
|
});
|
|
91
|
+
|
|
92
|
+
expect(hookPlugin.isFlowBlocker()).toBeFalsy();
|
|
93
|
+
expect(hookWithoutScreen.isFlowBlocker()).toBeFalsy();
|
|
98
94
|
});
|
|
95
|
+
});
|
|
99
96
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
describe("skipHook", () => {
|
|
98
|
+
it("returns true if the hooks module skipHook method returns true", () => {
|
|
99
|
+
const hookPlugin = getHook({ module: { skipHook: () => true } });
|
|
103
100
|
|
|
104
|
-
|
|
105
|
-
|
|
101
|
+
expect(hookPlugin.skipHook()).toBe(true);
|
|
102
|
+
});
|
|
106
103
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
104
|
+
it("returns false otherwise", () => {
|
|
105
|
+
const hookPlugin = getHook({ module: { skipHook: false } });
|
|
106
|
+
const hookPluginWithUndefinedSkipHook = getHook({ module: {} });
|
|
110
107
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
});
|
|
108
|
+
expect(hookPlugin.skipHook()).toBeFalsy();
|
|
109
|
+
expect(hookPluginWithUndefinedSkipHook.skipHook()).toBeFalsy();
|
|
114
110
|
});
|
|
111
|
+
});
|
|
115
112
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
it("returns false otherwise", () => {
|
|
123
|
-
const hookPlugin = getHook(
|
|
124
|
-
{},
|
|
125
|
-
{
|
|
126
|
-
screen_id: "B4567",
|
|
127
|
-
type: "general",
|
|
128
|
-
identifier: "some_hook",
|
|
129
|
-
weight: 2,
|
|
130
|
-
}
|
|
131
|
-
);
|
|
113
|
+
describe("lastHook", () => {
|
|
114
|
+
it("returns true if the current hook is the last one", () => {
|
|
115
|
+
const hookPlugin = getHook({});
|
|
116
|
+
expect(hookPlugin.lastHook).toBe(true);
|
|
117
|
+
});
|
|
132
118
|
|
|
133
|
-
|
|
134
|
-
|
|
119
|
+
it("returns false otherwise", () => {
|
|
120
|
+
const hookPlugin = getHook(
|
|
121
|
+
{},
|
|
122
|
+
{
|
|
123
|
+
screen_id: "B4567",
|
|
124
|
+
type: "general",
|
|
125
|
+
identifier: "some_hook",
|
|
126
|
+
weight: 2,
|
|
127
|
+
}
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(hookPlugin.lastHook).toBe(false);
|
|
135
131
|
});
|
|
132
|
+
});
|
|
136
133
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
134
|
+
describe("setStateAndNotify", () => {
|
|
135
|
+
let hookPlugin;
|
|
136
|
+
const args = ["foo", { bar: 42 }];
|
|
140
137
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
138
|
+
beforeEach(() => {
|
|
139
|
+
clearMocks();
|
|
140
|
+
hookPlugin = getHook({});
|
|
141
|
+
});
|
|
145
142
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
143
|
+
it("changes the hook's state", () => {
|
|
144
|
+
hookPlugin.setStateAndNotify(HOOKS_EVENTS.START, ...args);
|
|
145
|
+
expect(hookPlugin.state).toEqual(1);
|
|
146
|
+
});
|
|
150
147
|
|
|
151
|
-
|
|
152
|
-
|
|
148
|
+
it("calls invokes the handler on the hook manager", () => {
|
|
149
|
+
hookPlugin.setStateAndNotify(HOOKS_EVENTS.START, ...args);
|
|
153
150
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
});
|
|
151
|
+
expect(manager.invokeHandler).toHaveBeenCalledWith(
|
|
152
|
+
HOOKS_EVENTS.START,
|
|
153
|
+
...args
|
|
154
|
+
);
|
|
159
155
|
});
|
|
156
|
+
});
|
|
160
157
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
const hookWithoutRiver = getHook({
|
|
166
|
-
screen_id: undefined,
|
|
167
|
-
module: { presentFullScreen: true },
|
|
168
|
-
});
|
|
158
|
+
describe("shouldPresentScreenHook", () => {
|
|
159
|
+
it("returns true if the hook has a screenId and allows screen presentation", () => {
|
|
160
|
+
const hookPlugin = getHook({});
|
|
169
161
|
|
|
170
|
-
|
|
171
|
-
|
|
162
|
+
const hookWithoutRiver = getHook({
|
|
163
|
+
screen_id: undefined,
|
|
164
|
+
module: { presentFullScreen: true },
|
|
172
165
|
});
|
|
173
166
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
});
|
|
167
|
+
expect(hookPlugin.shouldPresentScreenHook()).toBe(true);
|
|
168
|
+
expect(hookWithoutRiver.shouldPresentScreenHook()).toBe(true);
|
|
169
|
+
});
|
|
178
170
|
|
|
179
|
-
|
|
171
|
+
it("returns true if the hook is modal presentation", () => {
|
|
172
|
+
const hookPlugin = getHook({
|
|
173
|
+
general: { transition_type: HOOKS_TRANSITION_TYPE.MODAL },
|
|
180
174
|
});
|
|
181
175
|
|
|
182
|
-
|
|
183
|
-
|
|
176
|
+
expect(hookPlugin.shouldPresentScreenHook()).toBe(true);
|
|
177
|
+
});
|
|
184
178
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
module: { presentFullScreen: false },
|
|
188
|
-
});
|
|
179
|
+
it("returns false otherwise", () => {
|
|
180
|
+
const hookWithoutScreen = getHook({ screen_id: undefined });
|
|
189
181
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
182
|
+
const hookWithoutRiver = getHook({
|
|
183
|
+
screen_id: undefined,
|
|
184
|
+
module: { presentFullScreen: false },
|
|
185
|
+
});
|
|
193
186
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
});
|
|
187
|
+
const hookWithoutAllowScreen = getHook({
|
|
188
|
+
general: { allow_screen_plugin_presentation: false },
|
|
189
|
+
});
|
|
198
190
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
expect(hookWithoutRiver.shouldPresentScreenHook()).toBeFalsy();
|
|
191
|
+
const hookWithoutScreenAndAllow = getHook({
|
|
192
|
+
general: { allow_screen_plugin_presentation: false },
|
|
193
|
+
screen_id: null,
|
|
203
194
|
});
|
|
195
|
+
|
|
196
|
+
expect(hookWithoutScreen.shouldPresentScreenHook()).toBeFalsy();
|
|
197
|
+
expect(hookWithoutAllowScreen.shouldPresentScreenHook()).toBeFalsy();
|
|
198
|
+
expect(hookWithoutScreenAndAllow.shouldPresentScreenHook()).toBeFalsy();
|
|
199
|
+
expect(hookWithoutRiver.shouldPresentScreenHook()).toBeFalsy();
|
|
204
200
|
});
|
|
201
|
+
});
|
|
205
202
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
203
|
+
describe("shouldStartNexHook", () => {
|
|
204
|
+
const hookPlugin = getHook({});
|
|
205
|
+
const hookWithoutScreen = getHook({ screen_id: undefined });
|
|
209
206
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
207
|
+
it("returns true if the nextHook has the same weight and is not a screen", () => {
|
|
208
|
+
expect(
|
|
209
|
+
hookWithoutScreen.shouldStartNextHook({
|
|
210
|
+
weight: hookWithoutScreen.weight,
|
|
211
|
+
})
|
|
212
|
+
).toBe(true);
|
|
213
|
+
});
|
|
217
214
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
})
|
|
229
|
-
).toBeFalsy();
|
|
230
|
-
});
|
|
215
|
+
it("returns false otherwise", () => {
|
|
216
|
+
// even if weight if the same, since hookPlugin should present a screen,
|
|
217
|
+
// it cannot run in parallel
|
|
218
|
+
expect(hookPlugin.shouldStartNextHook({ weight: hookPlugin })).toBeFalsy();
|
|
219
|
+
|
|
220
|
+
expect(
|
|
221
|
+
hookWithoutScreen.shouldStartNextHook({
|
|
222
|
+
weight: hookWithoutScreen.weight + 1,
|
|
223
|
+
})
|
|
224
|
+
).toBeFalsy();
|
|
231
225
|
});
|
|
226
|
+
});
|
|
232
227
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
228
|
+
describe("execute", () => {
|
|
229
|
+
const payload = { foo: "bar" };
|
|
230
|
+
const next = jest.fn();
|
|
236
231
|
|
|
237
|
-
|
|
232
|
+
beforeEach(clearMocks);
|
|
238
233
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
234
|
+
describe("when the hook execution should be skipped", () => {
|
|
235
|
+
it("doesn't execute the hook, and goes to the next", () => {
|
|
236
|
+
const hookPlugin = getHook({ module: { skipHook: () => true } });
|
|
237
|
+
hookPlugin.execute(payload, next);
|
|
243
238
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
});
|
|
239
|
+
expect(manager.presentScreenHook).not.toHaveBeenCalled();
|
|
240
|
+
expect(manager.executeHook).not.toHaveBeenCalled();
|
|
241
|
+
expect(next).toHaveBeenCalledWith({ payload, success: true });
|
|
248
242
|
});
|
|
243
|
+
});
|
|
249
244
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
245
|
+
describe("when the hook is not in pending state", () => {
|
|
246
|
+
it("doesn't execute the hook, and goes to the next", () => {
|
|
247
|
+
const hookPlugin = getHook({});
|
|
248
|
+
hookPlugin.setStateAndNotify(HOOKS_EVENTS.START);
|
|
249
|
+
hookPlugin.execute(payload, next);
|
|
255
250
|
|
|
256
|
-
|
|
251
|
+
const hookStateSpy = jest.spyOn(hookPlugin, "setStateAndNotify");
|
|
257
252
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
253
|
+
expect(hookStateSpy).not.toHaveBeenCalled();
|
|
254
|
+
expect(manager.presentScreenHook).not.toHaveBeenCalled();
|
|
255
|
+
expect(manager.executeHook).not.toHaveBeenCalled();
|
|
256
|
+
expect(next).toHaveBeenCalledWith({ payload });
|
|
262
257
|
|
|
263
|
-
|
|
264
|
-
});
|
|
258
|
+
hookStateSpy.mockRestore();
|
|
265
259
|
});
|
|
260
|
+
});
|
|
266
261
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
262
|
+
describe("when the screen should be presented", () => {
|
|
263
|
+
it("executes the hook", () => {
|
|
264
|
+
const hookPlugin = getHook({});
|
|
265
|
+
const hookStateSpy = jest.spyOn(hookPlugin, "setStateAndNotify");
|
|
271
266
|
|
|
272
|
-
|
|
267
|
+
hookPlugin.execute(payload, next);
|
|
273
268
|
|
|
274
|
-
|
|
275
|
-
HOOKS_EVENTS.START,
|
|
276
|
-
hookPlugin
|
|
277
|
-
);
|
|
269
|
+
expect(hookStateSpy).toHaveBeenCalledWith(HOOKS_EVENTS.START, hookPlugin);
|
|
278
270
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
});
|
|
271
|
+
expect(manager.presentScreenHook).toHaveBeenCalledWith(
|
|
272
|
+
hookPlugin,
|
|
273
|
+
payload,
|
|
274
|
+
next
|
|
275
|
+
);
|
|
285
276
|
});
|
|
277
|
+
});
|
|
286
278
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
279
|
+
describe("when the hook is headless", () => {
|
|
280
|
+
it("executes the hook", () => {
|
|
281
|
+
const hookPlugin = getHook({
|
|
282
|
+
general: { allow_screen_plugin_presentation: false },
|
|
283
|
+
});
|
|
292
284
|
|
|
293
|
-
|
|
285
|
+
const hookStateSpy = jest.spyOn(hookPlugin, "setStateAndNotify");
|
|
294
286
|
|
|
295
|
-
|
|
287
|
+
hookPlugin.execute(payload, next);
|
|
296
288
|
|
|
297
|
-
|
|
298
|
-
HOOKS_EVENTS.START,
|
|
299
|
-
hookPlugin
|
|
300
|
-
);
|
|
289
|
+
expect(hookStateSpy).toHaveBeenCalledWith(HOOKS_EVENTS.START, hookPlugin);
|
|
301
290
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
});
|
|
291
|
+
expect(manager.executeHook).toHaveBeenCalledWith(
|
|
292
|
+
hookPlugin,
|
|
293
|
+
payload,
|
|
294
|
+
next
|
|
295
|
+
);
|
|
308
296
|
});
|
|
309
297
|
});
|
|
310
298
|
});
|