@applicaster/zapp-react-native-utils 15.1.13-alpha.1034774223 → 15.1.13
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/actionsExecutor/ActionExecutor.ts +2 -40
- package/actionsExecutor/ActionExecutorContext.tsx +16 -70
- package/actionsExecutor/actions/index.ts +0 -4
- package/actionsExecutor/actions/refreshComponent.ts +0 -6
- package/actionsExecutor/actions/sendCloudEvent.ts +1 -6
- package/actionsExecutor/consts.ts +0 -23
- package/actionsExecutor/types.ts +1 -1
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +2 -5
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +2 -55
- package/appUtils/playerManager/OverlayObserver/utils.ts +20 -51
- package/arrayUtils/index.ts +0 -79
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +0 -21
- package/configurationUtils/manifestKeyParser.ts +10 -50
- package/manifestUtils/defaultManifestConfigurations/player.js +1 -22
- package/manifestUtils/index.js +0 -3
- package/modalState/__tests__/index.test.ts +1 -30
- package/modalState/index.ts +83 -35
- package/package.json +2 -2
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +54 -0
- package/playerUtils/getPlayerActionButtons.ts +17 -0
- package/playerUtils/index.ts +1 -17
- package/reactHooks/actions/index.ts +2 -67
- package/reactHooks/cell-click/__tests__/index.test.js +64 -0
- package/reactHooks/cell-click/index.ts +21 -14
- package/reactHooks/usePluginConfiguration.ts +3 -6
- package/uiActionsRegistrator/index.ts +203 -25
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +0 -25
- package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +0 -88
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +0 -76
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +0 -212
- package/actionsExecutor/actions/dismissBottomSheet.ts +0 -23
- package/actionsExecutor/actions/openBottomSheet.ts +0 -325
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +0 -4
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +0 -4
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +0 -11
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +0 -4
- package/arrayUtils/__tests__/reorderByIds.test.ts +0 -50
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +0 -260
- package/configurationUtils/modalBlocksParser.ts +0 -296
- package/entryActions/__tests__/buildEntryActions.test.ts +0 -156
- package/entryActions/aliasPresentation.ts +0 -124
- package/entryActions/buildEntryActions.ts +0 -166
- package/entryActions/index.ts +0 -17
- package/entryActions/types.ts +0 -39
- package/manifestUtils/modalBlocks.js +0 -304
- package/modalState/ContentViewModel.ts +0 -113
- package/modalState/EditableCollection.ts +0 -17
- package/modalState/EditableCollectionRegistry.ts +0 -51
- package/modalState/ModalOrchestrator.ts +0 -211
- package/modalState/RemoteEditableCollection.ts +0 -227
- package/modalState/__tests__/ContentViewModel.editable.test.ts +0 -69
- package/modalState/__tests__/ContentViewModel.test.ts +0 -165
- package/modalState/__tests__/EditableCollectionRegistry.test.ts +0 -112
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +0 -47
- package/modalState/__tests__/RemoteEditableCollection.test.ts +0 -326
- package/modalState/__tests__/useBottomSheetContent.test.ts +0 -349
- package/modalState/store.ts +0 -102
- package/modalState/types.ts +0 -159
- package/modalState/useBottomSheetContent.ts +0 -104
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +0 -138
- package/playerUtils/resolvePlayerActions.ts +0 -71
- package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +0 -93
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +0 -107
- package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +0 -52
- package/uiActionsRegistrator/registry.ts +0 -335
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +0 -100
- package/uiActionsRegistrator/usableActionItems.ts +0 -66
- /package/reactHooks/actions/__tests__/{index.test.tsx → index.test.js} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
import { useMemo } from "react";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { usePickFromState } from "@applicaster/zapp-react-native-redux/hooks";
|
|
5
5
|
|
|
6
6
|
// importing this way prevents typescript packages importing from this
|
|
7
7
|
// file to go crazy reporting errors on JS
|
|
@@ -24,11 +24,8 @@ export function parsePluginConfiguration(plugin, manifest) {
|
|
|
24
24
|
return populateFields(plugin, manifest.custom_configuration_fields);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export function usePluginConfiguration<T
|
|
28
|
-
|
|
29
|
-
manifest?: any
|
|
30
|
-
) {
|
|
31
|
-
const plugins = usePlugins();
|
|
27
|
+
export function usePluginConfiguration<T, S>(identifier, manifest) {
|
|
28
|
+
const { plugins } = usePickFromState(["plugins"]);
|
|
32
29
|
|
|
33
30
|
const plugin = useMemo(
|
|
34
31
|
() => R.find(R.propEq("identifier", identifier), plugins),
|
|
@@ -1,25 +1,203 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
export {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
/* eslint-disable no-dupe-class-members */
|
|
2
|
+
import { Observable } from "rxjs";
|
|
3
|
+
import { createLogger } from "../logger";
|
|
4
|
+
|
|
5
|
+
const { log_debug, log_warning, log_verbose } = createLogger({
|
|
6
|
+
subsystem: "UIActionsRegistry",
|
|
7
|
+
category: "ActionRegistration",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The runtime value of a UI action.
|
|
12
|
+
*
|
|
13
|
+
* This is the object that consumers interact with (render buttons for,
|
|
14
|
+
* invoke on press, read initial state from, etc.). It intentionally keeps an
|
|
15
|
+
* open shape (`[K: string]: any`) so that both the modern registry-based
|
|
16
|
+
* actions and the legacy context-provider based actions can be represented by
|
|
17
|
+
* the same structure.
|
|
18
|
+
*/
|
|
19
|
+
export type RegisteredActionValue = {
|
|
20
|
+
state?: any;
|
|
21
|
+
getInitialState?: () => Promise<void>;
|
|
22
|
+
initialEntryState?: (item: ZappEntry | ZappFeed) => CellActionEntryState;
|
|
23
|
+
invokeAction: (
|
|
24
|
+
item: ZappEntry | ZappFeed,
|
|
25
|
+
options?: InvokeArgsOptions
|
|
26
|
+
) => void;
|
|
27
|
+
isActionAvailable?: (item: ZappEntry | ZappFeed) => boolean;
|
|
28
|
+
addListener?: (
|
|
29
|
+
entryId: string,
|
|
30
|
+
listener: CellActionStateListenerFunction
|
|
31
|
+
) => CellActionStateRemoveListenerFunction;
|
|
32
|
+
/**
|
|
33
|
+
* Optional RX stream of the action state for a given entry. When not
|
|
34
|
+
* provided, `observeEntryState` derives one from `initialEntryState` +
|
|
35
|
+
* `addListener` (see below).
|
|
36
|
+
*/
|
|
37
|
+
observeEntryState?: (
|
|
38
|
+
entry: ZappEntry | ZappFeed
|
|
39
|
+
) => Observable<CellActionEntryState>;
|
|
40
|
+
[K: string]: any;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type RegisteredAction = {
|
|
44
|
+
identifier: string; // Plugin identifier or synthetic name
|
|
45
|
+
action: RegisteredActionValue;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* A function that, given an optional context (currently just the `entry`),
|
|
50
|
+
* returns the list of actions it wants to contribute.
|
|
51
|
+
*
|
|
52
|
+
* Returning an array is what allows a single provider (plugin or otherwise) to
|
|
53
|
+
* expose more than one action, and to compute those actions based on the entry.
|
|
54
|
+
*/
|
|
55
|
+
export type UIActionProvider = (params: {
|
|
56
|
+
entry?: ZappEntry | ZappFeed;
|
|
57
|
+
}) => RegisteredAction[];
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Returns an RX `Observable` that emits the action state for `entry`.
|
|
61
|
+
*
|
|
62
|
+
* If the action already exposes its own `observeEntryState`, it is used as-is.
|
|
63
|
+
* Otherwise we build the stream from the legacy imperative API:
|
|
64
|
+
* - it immediately emits `initialEntryState(entry)` (if available), and
|
|
65
|
+
* - it subscribes to further changes via `addListener(entryId, listener)`,
|
|
66
|
+
* unsubscribing automatically when the observable is torn down.
|
|
67
|
+
*
|
|
68
|
+
* This lets every action - old or new - be consumed reactively through a single
|
|
69
|
+
* mechanism, without each consumer having to wire up `addListener` manually.
|
|
70
|
+
*/
|
|
71
|
+
export function observeEntryState(
|
|
72
|
+
action: RegisteredActionValue | undefined,
|
|
73
|
+
entry: ZappEntry | ZappFeed
|
|
74
|
+
): Observable<CellActionEntryState> {
|
|
75
|
+
if (typeof action?.observeEntryState === "function") {
|
|
76
|
+
return action.observeEntryState(entry);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return new Observable<CellActionEntryState>((subscriber) => {
|
|
80
|
+
const initialState = action?.initialEntryState?.(entry);
|
|
81
|
+
|
|
82
|
+
if (initialState !== undefined) {
|
|
83
|
+
subscriber.next(initialState);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const removeListener = action?.addListener?.(
|
|
87
|
+
String((entry as ZappEntry)?.id),
|
|
88
|
+
(state: CellActionEntryState) => subscriber.next(state)
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
return () => removeListener?.();
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
class UIActionsRegistry {
|
|
96
|
+
private registeredActions: Record<string, UIActionProvider> = {};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Register a dynamic action provider under a unique `name`.
|
|
100
|
+
* The provider can return one or more actions and may use the passed `entry`.
|
|
101
|
+
* Returns an unregister function.
|
|
102
|
+
*/
|
|
103
|
+
registerActionProvider(
|
|
104
|
+
name: string,
|
|
105
|
+
actionProvider: UIActionProvider
|
|
106
|
+
): () => void {
|
|
107
|
+
const isOverride = Boolean(this.registeredActions[name]);
|
|
108
|
+
|
|
109
|
+
if (isOverride) {
|
|
110
|
+
log_warning(
|
|
111
|
+
`registerActionProvider: overriding existing provider for "${name}"`,
|
|
112
|
+
{ name }
|
|
113
|
+
);
|
|
114
|
+
} else {
|
|
115
|
+
log_debug(`registerActionProvider: registered "${name}"`, { name });
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
this.registeredActions[name] = actionProvider;
|
|
119
|
+
|
|
120
|
+
return () => {
|
|
121
|
+
// Only remove if it's still the same provider to avoid races where a
|
|
122
|
+
// newer registration replaced this one.
|
|
123
|
+
if (this.registeredActions[name] === actionProvider) {
|
|
124
|
+
delete this.registeredActions[name];
|
|
125
|
+
log_debug(`registerActionProvider: unregistered "${name}"`, { name });
|
|
126
|
+
} else {
|
|
127
|
+
log_debug(
|
|
128
|
+
`registerActionProvider: skipped unregister for "${name}" – newer provider is active`,
|
|
129
|
+
{ name }
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Convenience helper to register a single, static action from anywhere in the
|
|
137
|
+
* app (it does not need to be a plugin). Returns an unregister function.
|
|
138
|
+
*/
|
|
139
|
+
registerAction(
|
|
140
|
+
identifier: string,
|
|
141
|
+
action: RegisteredActionValue
|
|
142
|
+
): () => void {
|
|
143
|
+
log_debug(`registerAction: registering single action "${identifier}"`, {
|
|
144
|
+
identifier,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
return this.registerActionProvider(identifier, () => [
|
|
148
|
+
{ identifier, action },
|
|
149
|
+
]);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
getEntryActions(entry: ZappEntry): RegisteredAction[] {
|
|
153
|
+
const results = Object.keys(this.registeredActions)
|
|
154
|
+
.map((key) => this.registeredActions[key]({ entry }))
|
|
155
|
+
.flatMap((a) => a);
|
|
156
|
+
|
|
157
|
+
log_verbose(
|
|
158
|
+
`getEntryActions: resolved ${results.length} action(s) for entry "${entry?.id}"`,
|
|
159
|
+
{ entryId: entry?.id, identifiers: results.map((r) => r.identifier) }
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
return results;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
getActions(name: string, entry?: ZappEntry | ZappFeed): RegisteredAction[] {
|
|
166
|
+
if (!this.registeredActions[name]) {
|
|
167
|
+
log_warning(`getActions: no provider found for "${name}"`, { name });
|
|
168
|
+
|
|
169
|
+
return [];
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const results = this.registeredActions[name]({ entry }) ?? [];
|
|
173
|
+
|
|
174
|
+
log_verbose(
|
|
175
|
+
`getActions: resolved ${results.length} action(s) for "${name}"`,
|
|
176
|
+
{
|
|
177
|
+
name,
|
|
178
|
+
entryId: (entry as ZappEntry)?.id,
|
|
179
|
+
identifiers: results.map((r) => r.identifier),
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
return results;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Returns the runtime value of the first action registered under `name`, or
|
|
188
|
+
* `undefined`. This mirrors the shape returned by the legacy `useActions`
|
|
189
|
+
* hook, easing migration of single-action consumers.
|
|
190
|
+
*/
|
|
191
|
+
getAction(
|
|
192
|
+
name: string,
|
|
193
|
+
entry?: ZappEntry | ZappFeed
|
|
194
|
+
): RegisteredActionValue | undefined {
|
|
195
|
+
return this.getActions(name, entry)[0]?.action;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
hasAction(name: string): boolean {
|
|
199
|
+
return Boolean(this.registeredActions[name]);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export const uiActionsRegistry = new UIActionsRegistry();
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { dismissBottomSheetAction } from "../dismissBottomSheet";
|
|
2
|
-
import { dismissModal } from "../../../modalState";
|
|
3
|
-
import { ActionResult } from "../../ActionExecutor";
|
|
4
|
-
|
|
5
|
-
jest.mock("../../../modalState", () => ({
|
|
6
|
-
dismissModal: jest.fn(),
|
|
7
|
-
modalOrchestrator: {
|
|
8
|
-
close: jest.fn(),
|
|
9
|
-
},
|
|
10
|
-
}));
|
|
11
|
-
|
|
12
|
-
describe("dismissBottomSheetAction", () => {
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
jest.clearAllMocks();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
it("calls dismissModal and returns ActionResult.Success", async () => {
|
|
18
|
-
const result = await dismissBottomSheetAction({
|
|
19
|
-
type: "dismissBottomSheet",
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
expect(dismissModal).toHaveBeenCalledTimes(1);
|
|
23
|
-
expect(result).toBe(ActionResult.Success);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { loadItemsFromSource } from "../openBottomSheet";
|
|
2
|
-
|
|
3
|
-
const mockCall = jest.fn();
|
|
4
|
-
|
|
5
|
-
jest.mock("@applicaster/zapp-pipes-v2-client", () => ({
|
|
6
|
-
RequestBuilder: jest.fn().mockImplementation(() => ({
|
|
7
|
-
setEntryContext: jest.fn().mockReturnThis(),
|
|
8
|
-
setScreenContext: jest.fn().mockReturnThis(),
|
|
9
|
-
setUrl: jest.fn().mockReturnThis(),
|
|
10
|
-
buildAxiosRequest: jest.fn().mockResolvedValue(undefined),
|
|
11
|
-
call: (...args: any[]) => mockCall(...args),
|
|
12
|
-
})),
|
|
13
|
-
PipesClientResponseHelper: jest.fn().mockImplementation(() => ({
|
|
14
|
-
error: null,
|
|
15
|
-
})),
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
describe("loadItemsFromSource", () => {
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
jest.clearAllMocks();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("returns items plus role and behavior from feed.extensions", async () => {
|
|
24
|
-
mockCall.mockResolvedValueOnce({
|
|
25
|
-
response: {
|
|
26
|
-
entry: [{ id: "a", title: "Playlist A", media_group: [] }],
|
|
27
|
-
extensions: {
|
|
28
|
-
role: "collection_selector",
|
|
29
|
-
behavior: {
|
|
30
|
-
select_mode: "multi",
|
|
31
|
-
current_selection: ["a"],
|
|
32
|
-
selector: "extensions.tag",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const result = await loadItemsFromSource("https://example.com/feed");
|
|
39
|
-
|
|
40
|
-
expect(result.role).toBe("collection_selector");
|
|
41
|
-
|
|
42
|
-
expect(result.behavior).toEqual({
|
|
43
|
-
selectMode: "multi",
|
|
44
|
-
currentSelection: ["a"],
|
|
45
|
-
selector: "extensions.tag",
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
expect(result.items).toHaveLength(1);
|
|
49
|
-
expect(result.items[0].isSelected).toBe(true);
|
|
50
|
-
expect(result.items[0].title).toBe("Playlist A");
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
it("returns undefined role/behavior when feed has no extensions", async () => {
|
|
54
|
-
mockCall.mockResolvedValueOnce({
|
|
55
|
-
response: {
|
|
56
|
-
entry: [{ id: "1", title: "Plain", media_group: [] }],
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const result = await loadItemsFromSource("https://example.com/plain");
|
|
61
|
-
|
|
62
|
-
expect(result.role).toBeUndefined();
|
|
63
|
-
expect(result.behavior).toBeUndefined();
|
|
64
|
-
expect(result.items).toHaveLength(1);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it("preserves events in dynamic_collection_options", async () => {
|
|
68
|
-
mockCall.mockResolvedValueOnce({
|
|
69
|
-
response: {
|
|
70
|
-
entry: [],
|
|
71
|
-
extensions: {
|
|
72
|
-
dynamic_collection_options: {
|
|
73
|
-
operations: "add,remove",
|
|
74
|
-
events: {
|
|
75
|
-
add: [{ type: "showTextInput", options: {} }],
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const result = await loadItemsFromSource("https://example.com/feed");
|
|
83
|
-
|
|
84
|
-
expect(result.dynamicCollection?.events).toEqual({
|
|
85
|
-
add: [{ type: "showTextInput", options: {} }],
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
});
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { openBottomSheetAction } from "../openBottomSheet";
|
|
2
|
-
import { ActionResult } from "../../ActionExecutor";
|
|
3
|
-
import { openBottomSheetModal } from "../../../modalState/store";
|
|
4
|
-
import { modalOrchestrator } from "../../../modalState/ModalOrchestrator";
|
|
5
|
-
|
|
6
|
-
jest.mock("../../../modalState/store", () => ({
|
|
7
|
-
openBottomSheetModal: jest.fn(),
|
|
8
|
-
}));
|
|
9
|
-
|
|
10
|
-
jest.mock("../../../modalState/ModalOrchestrator", () => ({
|
|
11
|
-
modalOrchestrator: {
|
|
12
|
-
open: jest.fn(),
|
|
13
|
-
},
|
|
14
|
-
isPresentSubMenuAction: jest.requireActual("../../../modalState/types")
|
|
15
|
-
.isPresentSubMenuAction,
|
|
16
|
-
}));
|
|
17
|
-
|
|
18
|
-
describe("openBottomSheetAction custom content", () => {
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
jest.clearAllMocks();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it("opens default sheet with contentComponent body props", async () => {
|
|
24
|
-
const CustomContent = function CustomContent() {
|
|
25
|
-
return null;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
const result = await openBottomSheetAction({
|
|
29
|
-
type: "openBottomSheet",
|
|
30
|
-
options: {
|
|
31
|
-
header: { title: "Create Playlist" },
|
|
32
|
-
content: {
|
|
33
|
-
component: CustomContent,
|
|
34
|
-
props: {
|
|
35
|
-
inputLabel: "Name your playlist",
|
|
36
|
-
buttonLabel: "Create",
|
|
37
|
-
defaultValue: "",
|
|
38
|
-
submitAction: { type: "sendCloudEvent", options: {} },
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
} as any);
|
|
43
|
-
|
|
44
|
-
expect(result).toBe(ActionResult.Success);
|
|
45
|
-
expect(openBottomSheetModal).toHaveBeenCalledTimes(1);
|
|
46
|
-
expect(modalOrchestrator.open).not.toHaveBeenCalled();
|
|
47
|
-
|
|
48
|
-
const args = (openBottomSheetModal as jest.Mock).mock.calls[0][0];
|
|
49
|
-
// Default ModalComponent provides the standard header
|
|
50
|
-
expect(args.ModalBottomSheetContent).toBeUndefined();
|
|
51
|
-
|
|
52
|
-
expect(args.modalBottomSheetContentProps).toMatchObject({
|
|
53
|
-
title: "Create Playlist",
|
|
54
|
-
contentComponent: CustomContent,
|
|
55
|
-
contentComponentProps: {
|
|
56
|
-
inputLabel: "Name your playlist",
|
|
57
|
-
buttonLabel: "Create",
|
|
58
|
-
defaultValue: "",
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("returns Error when neither list data nor content.component is provided", async () => {
|
|
64
|
-
const result = await openBottomSheetAction({
|
|
65
|
-
type: "openBottomSheet",
|
|
66
|
-
options: {
|
|
67
|
-
header: { title: "Empty" },
|
|
68
|
-
content: {},
|
|
69
|
-
},
|
|
70
|
-
} as any);
|
|
71
|
-
|
|
72
|
-
expect(result).toBe(ActionResult.Error);
|
|
73
|
-
expect(openBottomSheetModal).not.toHaveBeenCalled();
|
|
74
|
-
expect(modalOrchestrator.open).not.toHaveBeenCalled();
|
|
75
|
-
});
|
|
76
|
-
});
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import { openBottomSheetAction } from "../openBottomSheet";
|
|
2
|
-
import { actionExecutor, ActionResult } from "../../ActionExecutor";
|
|
3
|
-
import { modalOrchestrator } from "../../../modalState/ModalOrchestrator";
|
|
4
|
-
|
|
5
|
-
jest.mock("../../../modalState/store", () => ({
|
|
6
|
-
openBottomSheetModal: jest.fn(),
|
|
7
|
-
}));
|
|
8
|
-
|
|
9
|
-
jest.mock("../../../modalState/ModalOrchestrator", () => ({
|
|
10
|
-
modalOrchestrator: {
|
|
11
|
-
open: jest.fn(),
|
|
12
|
-
replace: jest.fn(),
|
|
13
|
-
stackSize: 0,
|
|
14
|
-
},
|
|
15
|
-
isPresentSubMenuAction: jest.requireActual("../../../modalState/types")
|
|
16
|
-
.isPresentSubMenuAction,
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
describe("openBottomSheetAction inline items", () => {
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
jest.clearAllMocks();
|
|
22
|
-
(modalOrchestrator as any).stackSize = 0;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const speedSheetAction = {
|
|
26
|
-
type: "openBottomSheet",
|
|
27
|
-
options: {
|
|
28
|
-
header: { title: "Playback Speed" },
|
|
29
|
-
content: {
|
|
30
|
-
role: "collection_selector",
|
|
31
|
-
behavior: {
|
|
32
|
-
selectMode: "single",
|
|
33
|
-
currentSelection: ["1"],
|
|
34
|
-
},
|
|
35
|
-
items: [
|
|
36
|
-
{
|
|
37
|
-
id: "0.8",
|
|
38
|
-
title: "0.8x",
|
|
39
|
-
extensions: {
|
|
40
|
-
tap_actions: {
|
|
41
|
-
actions: [
|
|
42
|
-
{ type: "setPlaybackSpeed", options: { value: 0.8 } },
|
|
43
|
-
],
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
id: "1",
|
|
49
|
-
title: "1x",
|
|
50
|
-
extensions: {
|
|
51
|
-
tap_actions: {
|
|
52
|
-
actions: [{ type: "setPlaybackSpeed", options: { value: 1 } }],
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
} as any;
|
|
60
|
-
|
|
61
|
-
it("opens orchestrator with inline items and marks current selection", async () => {
|
|
62
|
-
const result = await openBottomSheetAction(speedSheetAction);
|
|
63
|
-
|
|
64
|
-
expect(result).toBe(ActionResult.Success);
|
|
65
|
-
expect(modalOrchestrator.open).toHaveBeenCalledTimes(1);
|
|
66
|
-
expect(modalOrchestrator.replace).not.toHaveBeenCalled();
|
|
67
|
-
|
|
68
|
-
const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
|
|
69
|
-
|
|
70
|
-
expect(menu.content.items[0].isSelected).toBe(false);
|
|
71
|
-
|
|
72
|
-
expect(menu.content.items[1]).toMatchObject({
|
|
73
|
-
id: "1",
|
|
74
|
-
title: "1x",
|
|
75
|
-
isSelected: true,
|
|
76
|
-
action: { type: "setPlaybackSpeed", options: { value: 1 } },
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("pushes a new sheet by default even when another sheet is already open", async () => {
|
|
81
|
-
(modalOrchestrator as any).stackSize = 1;
|
|
82
|
-
|
|
83
|
-
await openBottomSheetAction(speedSheetAction);
|
|
84
|
-
|
|
85
|
-
expect(modalOrchestrator.open).toHaveBeenCalledTimes(1);
|
|
86
|
-
expect(modalOrchestrator.replace).not.toHaveBeenCalled();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it("replaces the current sheet when options.replace is true", async () => {
|
|
90
|
-
(modalOrchestrator as any).stackSize = 1;
|
|
91
|
-
|
|
92
|
-
await openBottomSheetAction({
|
|
93
|
-
...speedSheetAction,
|
|
94
|
-
options: { ...speedSheetAction.options, replace: true },
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
expect(modalOrchestrator.replace).toHaveBeenCalledTimes(1);
|
|
98
|
-
expect(modalOrchestrator.open).not.toHaveBeenCalled();
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it("executes all actions in tap_actions when onItemPress is called", async () => {
|
|
102
|
-
const multiActionSheet = {
|
|
103
|
-
type: "openBottomSheet",
|
|
104
|
-
options: {
|
|
105
|
-
header: { title: "Target Playlists" },
|
|
106
|
-
content: {
|
|
107
|
-
role: "collection_selector",
|
|
108
|
-
behavior: { selectMode: "none", currentSelection: [] },
|
|
109
|
-
items: [
|
|
110
|
-
{
|
|
111
|
-
id: "playlist-1",
|
|
112
|
-
title: "My Playlist",
|
|
113
|
-
extensions: {
|
|
114
|
-
tap_actions: {
|
|
115
|
-
actions: [
|
|
116
|
-
{
|
|
117
|
-
type: "sendCloudEvent",
|
|
118
|
-
options: { subject: "add_collection_to_collection" },
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
type: "showToast",
|
|
122
|
-
options: { message: "Added to playlist" },
|
|
123
|
-
},
|
|
124
|
-
{ type: "dismissBottomSheet", options: {} },
|
|
125
|
-
],
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
],
|
|
130
|
-
},
|
|
131
|
-
},
|
|
132
|
-
} as any;
|
|
133
|
-
|
|
134
|
-
await openBottomSheetAction(multiActionSheet);
|
|
135
|
-
|
|
136
|
-
const [menu, onItemPress] = (modalOrchestrator.open as jest.Mock).mock
|
|
137
|
-
.calls[0];
|
|
138
|
-
|
|
139
|
-
expect(menu.content.items[0].actions).toHaveLength(3);
|
|
140
|
-
|
|
141
|
-
const handleActionsSpy = jest
|
|
142
|
-
.spyOn(actionExecutor, "handleActions")
|
|
143
|
-
.mockResolvedValue(ActionResult.Success);
|
|
144
|
-
|
|
145
|
-
await onItemPress(menu.content.items[0]);
|
|
146
|
-
|
|
147
|
-
expect(handleActionsSpy).toHaveBeenCalledWith(
|
|
148
|
-
[
|
|
149
|
-
{
|
|
150
|
-
type: "sendCloudEvent",
|
|
151
|
-
options: { subject: "add_collection_to_collection" },
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
type: "showToast",
|
|
155
|
-
options: { message: "Added to playlist" },
|
|
156
|
-
},
|
|
157
|
-
{ type: "dismissBottomSheet", options: {} },
|
|
158
|
-
],
|
|
159
|
-
expect.objectContaining({
|
|
160
|
-
entry: menu.content.items[0],
|
|
161
|
-
})
|
|
162
|
-
);
|
|
163
|
-
|
|
164
|
-
handleActionsSpy.mockRestore();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("executes preceding actions and excludes presentSubMenu from actionExecutor", async () => {
|
|
168
|
-
const subMenuSheet = {
|
|
169
|
-
type: "openBottomSheet",
|
|
170
|
-
options: {
|
|
171
|
-
header: { title: "Menu" },
|
|
172
|
-
content: {
|
|
173
|
-
items: [
|
|
174
|
-
{
|
|
175
|
-
id: "item-with-submenu",
|
|
176
|
-
title: "More Options",
|
|
177
|
-
extensions: {
|
|
178
|
-
tap_actions: {
|
|
179
|
-
actions: [
|
|
180
|
-
{ type: "sendAnalytics", options: { event: "click_more" } },
|
|
181
|
-
{
|
|
182
|
-
type: "presentSubMenu",
|
|
183
|
-
menu: { content: { title: "Sub Options", items: [] } },
|
|
184
|
-
},
|
|
185
|
-
],
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
],
|
|
190
|
-
},
|
|
191
|
-
},
|
|
192
|
-
} as any;
|
|
193
|
-
|
|
194
|
-
await openBottomSheetAction(subMenuSheet);
|
|
195
|
-
|
|
196
|
-
const [menu, onItemPress] = (modalOrchestrator.open as jest.Mock).mock
|
|
197
|
-
.calls[0];
|
|
198
|
-
|
|
199
|
-
const handleActionsSpy = jest
|
|
200
|
-
.spyOn(actionExecutor, "handleActions")
|
|
201
|
-
.mockResolvedValue(ActionResult.Success);
|
|
202
|
-
|
|
203
|
-
await onItemPress(menu.content.items[0]);
|
|
204
|
-
|
|
205
|
-
expect(handleActionsSpy).toHaveBeenCalledWith(
|
|
206
|
-
[{ type: "sendAnalytics", options: { event: "click_more" } }],
|
|
207
|
-
expect.objectContaining({ entry: menu.content.items[0] })
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
handleActionsSpy.mockRestore();
|
|
211
|
-
});
|
|
212
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
-
import { dismissModal, modalOrchestrator } from "../../modalState";
|
|
3
|
-
import { ActionResult } from "../ActionExecutor";
|
|
4
|
-
import { ActionHandler } from "../types";
|
|
5
|
-
import { createLogger } from "../../logger";
|
|
6
|
-
|
|
7
|
-
const { log_info } = createLogger({
|
|
8
|
-
subsystem: "ActionExecutorContext",
|
|
9
|
-
category: "General",
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Dismisses the active bottom sheet / modal.
|
|
14
|
-
*/
|
|
15
|
-
export const dismissBottomSheetAction: ActionHandler<
|
|
16
|
-
any
|
|
17
|
-
> = async (): Promise<ActionResult> => {
|
|
18
|
-
log_info("handleAction: dismissBottomSheet");
|
|
19
|
-
modalOrchestrator.close();
|
|
20
|
-
dismissModal();
|
|
21
|
-
|
|
22
|
-
return ActionResult.Success;
|
|
23
|
-
};
|