@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,325 +0,0 @@
|
|
|
1
|
-
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
-
import {
|
|
3
|
-
PipesClientResponseHelper,
|
|
4
|
-
RequestBuilder,
|
|
5
|
-
} from "@applicaster/zapp-pipes-v2-client";
|
|
6
|
-
import uuidv4 from "uuid/v4";
|
|
7
|
-
import { modalOrchestrator } from "../../modalState/ModalOrchestrator";
|
|
8
|
-
import { openBottomSheetModal } from "../../modalState/store";
|
|
9
|
-
import {
|
|
10
|
-
DynamicCollectionOptions,
|
|
11
|
-
getMenuItemActions,
|
|
12
|
-
isPresentSubMenuAction,
|
|
13
|
-
Menu,
|
|
14
|
-
MenuItem,
|
|
15
|
-
Operation,
|
|
16
|
-
SelectionBehavior,
|
|
17
|
-
} from "../../modalState/types";
|
|
18
|
-
import { actionExecutor, ActionResult } from "../ActionExecutor";
|
|
19
|
-
import { createLogger } from "../../logger";
|
|
20
|
-
|
|
21
|
-
const { log_info, log_error } = createLogger({
|
|
22
|
-
subsystem: "ActionExecutorContext",
|
|
23
|
-
category: "General",
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export type LoadedSheetContent = {
|
|
27
|
-
items: MenuItem[];
|
|
28
|
-
role?: string;
|
|
29
|
-
behavior?: SelectionBehavior;
|
|
30
|
-
dynamicCollection?: DynamicCollectionOptions;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Parse a raw `dynamic_collection_options` block (feed or inline content) into
|
|
35
|
-
* the typed `DynamicCollectionOptions`. `operations` accepts either a CSV
|
|
36
|
-
* string (feed) or an array (already parsed).
|
|
37
|
-
*/
|
|
38
|
-
export function parseDynamicCollectionOptions(
|
|
39
|
-
raw:
|
|
40
|
-
| {
|
|
41
|
-
operations?: string | string[];
|
|
42
|
-
postUrl?: string;
|
|
43
|
-
provider?: string;
|
|
44
|
-
events?: Record<string, any[]>;
|
|
45
|
-
}
|
|
46
|
-
| undefined
|
|
47
|
-
): DynamicCollectionOptions | undefined {
|
|
48
|
-
if (!raw) {
|
|
49
|
-
return undefined;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const operations = Array.isArray(raw.operations)
|
|
53
|
-
? (raw.operations as Operation[])
|
|
54
|
-
: ((raw.operations || "").split(",").filter(Boolean) as Operation[]);
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
operations,
|
|
58
|
-
postUrl: raw.postUrl,
|
|
59
|
-
provider: raw.provider,
|
|
60
|
-
events: raw.events,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Converts a ZappEntry from a pipes feed into a MenuItem.
|
|
66
|
-
* - Icon: first src found in the image media_group.
|
|
67
|
-
* - Primary action: taken from tap_actions.actions[0].
|
|
68
|
-
* - isSelected: true when entry.id is in currentSelection.
|
|
69
|
-
*/
|
|
70
|
-
export function entryToMenuItem(
|
|
71
|
-
entry: ZappEntry,
|
|
72
|
-
currentSelection: string[] = []
|
|
73
|
-
): MenuItem {
|
|
74
|
-
const imageGroup = entry.media_group?.find((g) => g.type === "image");
|
|
75
|
-
|
|
76
|
-
const firstImage = Array.isArray(imageGroup?.media_item)
|
|
77
|
-
? imageGroup.media_item[0]
|
|
78
|
-
: imageGroup?.media_item;
|
|
79
|
-
|
|
80
|
-
// Primary action — first tap_action on the entry
|
|
81
|
-
const tapActions = entry.extensions?.tap_actions?.actions || [];
|
|
82
|
-
const primaryAction = tapActions.length > 0 ? tapActions[0] : undefined;
|
|
83
|
-
|
|
84
|
-
const summary = entry.summary as string;
|
|
85
|
-
|
|
86
|
-
const itemId = String(entry.id ?? entry.title ?? uuidv4());
|
|
87
|
-
|
|
88
|
-
return {
|
|
89
|
-
id: itemId,
|
|
90
|
-
title: entry.title as string,
|
|
91
|
-
summary,
|
|
92
|
-
icon: firstImage?.src,
|
|
93
|
-
isSelected: currentSelection.includes(itemId),
|
|
94
|
-
action: primaryAction,
|
|
95
|
-
actions: tapActions,
|
|
96
|
-
entryActions: entry.extensions?.entry_action || [],
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function parseCurrentSelection(rawSelection: unknown): string[] {
|
|
101
|
-
if (Array.isArray(rawSelection)) {
|
|
102
|
-
return (rawSelection as any[]).map(String);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (rawSelection !== undefined && rawSelection !== null) {
|
|
106
|
-
return [String(rawSelection)];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return [];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function parseBehaviorFromFeed(
|
|
113
|
-
feed: ZappFeed | undefined,
|
|
114
|
-
currentSelection: string[]
|
|
115
|
-
): SelectionBehavior | undefined {
|
|
116
|
-
const raw = feed?.extensions?.behavior;
|
|
117
|
-
|
|
118
|
-
if (!raw && currentSelection.length === 0) {
|
|
119
|
-
return undefined;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
selectMode: raw?.select_mode,
|
|
124
|
-
currentSelection,
|
|
125
|
-
selector: raw?.selector,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function parseBehaviorFromContentOptions(
|
|
130
|
-
content: Record<string, any> | undefined
|
|
131
|
-
): SelectionBehavior | undefined {
|
|
132
|
-
const raw = content?.behavior ?? content?.extensions?.behavior;
|
|
133
|
-
|
|
134
|
-
if (!raw) {
|
|
135
|
-
return undefined;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
selectMode: raw.selectMode ?? raw.select_mode,
|
|
140
|
-
currentSelection: parseCurrentSelection(
|
|
141
|
-
raw.currentSelection ?? raw.current_selection
|
|
142
|
-
),
|
|
143
|
-
selector: raw.selector,
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// Exported so MultiLevelBottomSheetContent can lazy-load sub-levels
|
|
148
|
-
export async function loadItemsFromSource(
|
|
149
|
-
source: string,
|
|
150
|
-
context?: Record<string, any>
|
|
151
|
-
): Promise<LoadedSheetContent> {
|
|
152
|
-
const requestBuilder = new RequestBuilder()
|
|
153
|
-
.setEntryContext(context?.entry || {})
|
|
154
|
-
.setScreenContext(context?.screenData || {})
|
|
155
|
-
.setUrl(source);
|
|
156
|
-
|
|
157
|
-
await requestBuilder.buildAxiosRequest();
|
|
158
|
-
|
|
159
|
-
const responseData = await requestBuilder.call<ZappFeed>();
|
|
160
|
-
|
|
161
|
-
const responseHelper = new PipesClientResponseHelper(responseData);
|
|
162
|
-
|
|
163
|
-
if (responseHelper.error) {
|
|
164
|
-
throw responseHelper.error;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const feed = responseData?.response as ZappFeed;
|
|
168
|
-
|
|
169
|
-
const currentSelection = parseCurrentSelection(
|
|
170
|
-
feed?.extensions?.behavior?.current_selection
|
|
171
|
-
);
|
|
172
|
-
|
|
173
|
-
const items = (feed?.entry || []).map((entry) =>
|
|
174
|
-
entryToMenuItem(entry, currentSelection)
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
const dynamicCollectionOptions = feed?.extensions?.dynamic_collection_options;
|
|
178
|
-
|
|
179
|
-
const dynamicCollection = parseDynamicCollectionOptions(
|
|
180
|
-
dynamicCollectionOptions
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
return {
|
|
184
|
-
items,
|
|
185
|
-
role: feed?.extensions?.role,
|
|
186
|
-
behavior: parseBehaviorFromFeed(feed, currentSelection),
|
|
187
|
-
dynamicCollection,
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export async function openBottomSheetAction(
|
|
192
|
-
action: ActionType,
|
|
193
|
-
context?: Record<string, any>
|
|
194
|
-
): Promise<ActionResult> {
|
|
195
|
-
try {
|
|
196
|
-
const { content, header, themePluginId, styleOverrides } =
|
|
197
|
-
action.options || {};
|
|
198
|
-
|
|
199
|
-
// Custom body component — keep default ModalComponent so standard header
|
|
200
|
-
// (dismiss x) is used; content.component is body-only (e.g. TextInputContent).
|
|
201
|
-
if (content?.component) {
|
|
202
|
-
log_info("openBottomSheet: using custom content component");
|
|
203
|
-
|
|
204
|
-
openBottomSheetModal({
|
|
205
|
-
modalBottomSheetContentProps: {
|
|
206
|
-
title: header?.title,
|
|
207
|
-
summary: header?.subtitle,
|
|
208
|
-
items: [],
|
|
209
|
-
onPress: () => {},
|
|
210
|
-
contentComponent: content.component,
|
|
211
|
-
contentComponentProps: content.props || {},
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
return ActionResult.Success;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const inlineItems: ZappEntry[] = content?.items;
|
|
219
|
-
const itemsUrl: string = content?.itemsUrl;
|
|
220
|
-
|
|
221
|
-
let items: MenuItem[];
|
|
222
|
-
let role: string | undefined;
|
|
223
|
-
let behavior: SelectionBehavior | undefined;
|
|
224
|
-
|
|
225
|
-
let dynamicCollection: DynamicCollectionOptions | undefined;
|
|
226
|
-
|
|
227
|
-
if (Array.isArray(inlineItems) && inlineItems.length > 0) {
|
|
228
|
-
log_info("openBottomSheet: using inline items from action options", {
|
|
229
|
-
count: inlineItems.length,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
role = content?.role ?? content?.extensions?.role;
|
|
233
|
-
behavior = parseBehaviorFromContentOptions(content);
|
|
234
|
-
|
|
235
|
-
items = inlineItems.map((entry) =>
|
|
236
|
-
entryToMenuItem(entry, behavior?.currentSelection ?? [])
|
|
237
|
-
);
|
|
238
|
-
|
|
239
|
-
dynamicCollection = parseDynamicCollectionOptions(
|
|
240
|
-
content?.dynamicCollection ??
|
|
241
|
-
content?.extensions?.dynamic_collection_options
|
|
242
|
-
);
|
|
243
|
-
} else if (itemsUrl) {
|
|
244
|
-
log_info(`openBottomSheet: loading items from source: ${itemsUrl}`);
|
|
245
|
-
|
|
246
|
-
const loaded = await loadItemsFromSource(itemsUrl, context);
|
|
247
|
-
items = loaded.items;
|
|
248
|
-
role = loaded.role ?? content?.role ?? content?.extensions?.role;
|
|
249
|
-
behavior = loaded.behavior ?? parseBehaviorFromContentOptions(content);
|
|
250
|
-
dynamicCollection = loaded.dynamicCollection;
|
|
251
|
-
|
|
252
|
-
log_info(
|
|
253
|
-
`openBottomSheet: loaded ${items.length} items from source: ${itemsUrl}`
|
|
254
|
-
);
|
|
255
|
-
} else {
|
|
256
|
-
log_error(
|
|
257
|
-
"openBottomSheet: no itemsUrl, items, or content.component provided in action options"
|
|
258
|
-
);
|
|
259
|
-
|
|
260
|
-
return ActionResult.Error;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const menu: Menu = {
|
|
264
|
-
header: header
|
|
265
|
-
? {
|
|
266
|
-
title: header.title,
|
|
267
|
-
subtitle: header.subtitle,
|
|
268
|
-
icon: header.icon,
|
|
269
|
-
}
|
|
270
|
-
: undefined,
|
|
271
|
-
content: {
|
|
272
|
-
title: content?.title ?? "",
|
|
273
|
-
items,
|
|
274
|
-
itemsUrl, // stored so the component can reload after an action
|
|
275
|
-
role,
|
|
276
|
-
behavior,
|
|
277
|
-
dynamicCollection,
|
|
278
|
-
themePluginId,
|
|
279
|
-
styleOverrides: styleOverrides ?? content?.styleOverrides,
|
|
280
|
-
},
|
|
281
|
-
};
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Called when the user taps a menu item.
|
|
285
|
-
*
|
|
286
|
-
* - PresentSubMenuAction → handled by the orchestrator (pushes sub-menu)
|
|
287
|
-
* - Any other Action type → forwarded to the action executor, keeping the
|
|
288
|
-
* original execution context so screen/entry data is available to handlers.
|
|
289
|
-
* The pressed item is also added as `entry` so downstream actions can
|
|
290
|
-
* reference it.
|
|
291
|
-
*/
|
|
292
|
-
const onItemPress = async (item: MenuItem): Promise<void> => {
|
|
293
|
-
const actions = getMenuItemActions(item);
|
|
294
|
-
|
|
295
|
-
const executableActions = actions.filter(
|
|
296
|
-
(action) => !isPresentSubMenuAction(action)
|
|
297
|
-
);
|
|
298
|
-
|
|
299
|
-
if (executableActions.length > 0) {
|
|
300
|
-
await actionExecutor.handleActions(
|
|
301
|
-
executableActions as ActionType[],
|
|
302
|
-
{
|
|
303
|
-
...context,
|
|
304
|
-
entry: item as any,
|
|
305
|
-
} as any
|
|
306
|
-
);
|
|
307
|
-
}
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
if (action.options?.replace) {
|
|
311
|
-
modalOrchestrator.replace(menu, onItemPress);
|
|
312
|
-
} else {
|
|
313
|
-
modalOrchestrator.open(menu, onItemPress);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
return ActionResult.Success;
|
|
317
|
-
} catch (error) {
|
|
318
|
-
log_error("openBottomSheet: failed to open bottom sheet", {
|
|
319
|
-
error,
|
|
320
|
-
action,
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
return ActionResult.Error;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export const getUpcomingQueue = async (
|
|
2
|
-
plugin?: QuickBrickPlugin | ZappPlugin
|
|
3
|
-
): Promise<unknown[] | null> => {
|
|
4
|
-
const QueueManager = (plugin as any)?.module?.QueueManager;
|
|
5
|
-
|
|
6
|
-
if (!QueueManager?.instance) {
|
|
7
|
-
return null;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
return QueueManager.instance.getUpcomingQueue();
|
|
11
|
-
};
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { reorderByIds } from "../index";
|
|
2
|
-
|
|
3
|
-
describe("reorderByIds", () => {
|
|
4
|
-
const items = [
|
|
5
|
-
{ id: "1", title: "Track 1" },
|
|
6
|
-
{ id: "2", title: "Track 2" },
|
|
7
|
-
{ id: "3", title: "Track 3" },
|
|
8
|
-
{ id: "4", title: "Track 4" },
|
|
9
|
-
];
|
|
10
|
-
|
|
11
|
-
it("returns an empty array if items is empty or nullish", () => {
|
|
12
|
-
expect(reorderByIds([], ["1"])).toEqual([]);
|
|
13
|
-
expect(reorderByIds(null as any, ["1"])).toEqual([]);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it("returns a copy of items if orderedIds is empty or nullish", () => {
|
|
17
|
-
expect(reorderByIds(items, [])).toEqual(items);
|
|
18
|
-
expect(reorderByIds(items, null as any)).toEqual(items);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
it("reorders items based on the provided orderedIds sequence", () => {
|
|
22
|
-
const result = reorderByIds(items, ["3", "1", "4", "2"]);
|
|
23
|
-
|
|
24
|
-
expect(result.map((i) => i.id)).toEqual(["3", "1", "4", "2"]);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("replaces items in their original slots when reordering a subset", () => {
|
|
28
|
-
const result = reorderByIds(items, ["4", "2"]);
|
|
29
|
-
|
|
30
|
-
expect(result.map((i) => i.id)).toEqual(["1", "4", "3", "2"]);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("ignores IDs in orderedIds that do not exist in items", () => {
|
|
34
|
-
const result = reorderByIds(items, ["unknown", "3", "99", "1"]);
|
|
35
|
-
|
|
36
|
-
expect(result.map((i) => i.id)).toEqual(["3", "2", "1", "4"]);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it("supports custom getId selector function", () => {
|
|
40
|
-
const customItems = [
|
|
41
|
-
{ key: "a", name: "Alpha" },
|
|
42
|
-
{ key: "b", name: "Beta" },
|
|
43
|
-
{ key: "c", name: "Gamma" },
|
|
44
|
-
];
|
|
45
|
-
|
|
46
|
-
const result = reorderByIds(customItems, ["c", "a"], (item) => item.key);
|
|
47
|
-
|
|
48
|
-
expect(result.map((i) => i.key)).toEqual(["c", "b", "a"]);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,260 +0,0 @@
|
|
|
1
|
-
import { parseModalBlocksConfiguration } from "../modalBlocksParser";
|
|
2
|
-
|
|
3
|
-
// Mock the platform selection logic so it's consistent
|
|
4
|
-
jest.mock("../../reactUtils", () => ({
|
|
5
|
-
platformSelect: jest.fn().mockReturnValue("ios"),
|
|
6
|
-
}));
|
|
7
|
-
|
|
8
|
-
describe("parseModalBlocksConfiguration", () => {
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
jest.clearAllMocks();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
it("should return empty structures for missing config or componentName", () => {
|
|
14
|
-
const result1 = parseModalBlocksConfiguration(
|
|
15
|
-
undefined as any,
|
|
16
|
-
"queue_action"
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
expect(result1.header.container).toEqual({});
|
|
20
|
-
|
|
21
|
-
const result2 = parseModalBlocksConfiguration({ foo: "bar" }, "");
|
|
22
|
-
expect(result2.item.background).toEqual({});
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it("should correctly parse the specified flat keys into nested objects", () => {
|
|
26
|
-
// The keys follow: <component_name>_style_<blockName>_<subComponent>_[platform_][state_]<styleName>
|
|
27
|
-
const config = {
|
|
28
|
-
// Header container - default platform, default state
|
|
29
|
-
queue_action_style_header_container_backgroundColor: "#000000",
|
|
30
|
-
|
|
31
|
-
// Header title - default platform, pressed state
|
|
32
|
-
queue_action_style_header_title_pressed_fontColor: "#ffffff",
|
|
33
|
-
|
|
34
|
-
// Item background - ios platform, default state
|
|
35
|
-
queue_action_style_item_background_ios_backgroundColor: "blue",
|
|
36
|
-
|
|
37
|
-
// Item textLabel1 - default platform, focused state
|
|
38
|
-
queue_action_style_item_text_label_1_focused_fontSize: 16,
|
|
39
|
-
|
|
40
|
-
// Ignored key (unrelated to building blocks or queue_action)
|
|
41
|
-
other_action_style_header_title_fontColor: "red",
|
|
42
|
-
some_random_key: "value",
|
|
43
|
-
|
|
44
|
-
// Ignored non-style data keys (should NEVER be parsed as styles)
|
|
45
|
-
item_data_source: "http://pipes.example.com",
|
|
46
|
-
item_url: "http://example.com",
|
|
47
|
-
|
|
48
|
-
// New dot notation from manifest-generator (without plugin prefix)
|
|
49
|
-
"item.text_label_2.fontColor": "green",
|
|
50
|
-
"action.background.pressed_backgroundColor": "black",
|
|
51
|
-
|
|
52
|
-
// New now_playing_item block
|
|
53
|
-
"now_playing_item.text_label_1.fontColor": "yellow",
|
|
54
|
-
"now_playing_item.now_playing_asset.asset": "equalizer.png",
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const componentName = "queue_action";
|
|
58
|
-
|
|
59
|
-
const result = parseModalBlocksConfiguration(config, componentName);
|
|
60
|
-
|
|
61
|
-
// Assert header container default state
|
|
62
|
-
expect(result.header.container.default).toEqual({
|
|
63
|
-
backgroundColor: "#000000",
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// Assert header title pressed state
|
|
67
|
-
// (pressed state will inherit default styles in getAllSpecificStyles if any,
|
|
68
|
-
// but here we just have pressed, so it has default empty from the parser)
|
|
69
|
-
expect(result.header.title.pressed).toEqual({
|
|
70
|
-
fontColor: "#ffffff",
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// Assert item background ios default state
|
|
74
|
-
// (mocked platform is ios, so it should be accepted and assigned to default)
|
|
75
|
-
expect(result.item.background.default).toEqual({
|
|
76
|
-
backgroundColor: "blue",
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
// Assert item textLabel1 focused state
|
|
80
|
-
expect(result.item.textLabel1.focused).toEqual({
|
|
81
|
-
fontSize: 16,
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
// Assert dot notation textLabel2 default state
|
|
85
|
-
expect(result.item.textLabel2.default).toEqual({
|
|
86
|
-
fontColor: "green",
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
// Assert dot notation action background pressed state
|
|
90
|
-
expect(result.action.background.pressed).toEqual({
|
|
91
|
-
backgroundColor: "black",
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// Assert nowPlayingItem states
|
|
95
|
-
expect(result.nowPlayingItem?.textLabel1.default).toEqual({
|
|
96
|
-
fontColor: "yellow",
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
expect(result.nowPlayingItem?.nowPlayingAsset.default).toEqual({
|
|
100
|
-
asset: "equalizer.png",
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
// Assert untouched properties remain empty default style objects
|
|
104
|
-
expect(result.button.title).toEqual({ default: {} });
|
|
105
|
-
expect(result.action.leadingIcon).toEqual({ default: {} });
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
it("should map Studio item.background.focus.* onto focused state", () => {
|
|
109
|
-
const result = parseModalBlocksConfiguration(
|
|
110
|
-
{
|
|
111
|
-
"item.background.default.background_color": "transparent",
|
|
112
|
-
"item.background.focus.background_color": "#FF3B30",
|
|
113
|
-
},
|
|
114
|
-
"playlist-experience"
|
|
115
|
-
);
|
|
116
|
-
|
|
117
|
-
expect(result.item.background.default).toEqual(
|
|
118
|
-
expect.objectContaining({
|
|
119
|
-
backgroundColor: "transparent",
|
|
120
|
-
})
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
expect(result.item.background.focused).toEqual(
|
|
124
|
-
expect.objectContaining({
|
|
125
|
-
backgroundColor: "#FF3B30",
|
|
126
|
-
})
|
|
127
|
-
);
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("should accept Studio text_label1 keys without underscore before digit", () => {
|
|
131
|
-
const result = parseModalBlocksConfiguration(
|
|
132
|
-
{
|
|
133
|
-
"item.text_label1.font_color": "#00FF00",
|
|
134
|
-
"item.text_label1.font_size": 28,
|
|
135
|
-
"item.text_label2.font_color": "#00FFFF",
|
|
136
|
-
},
|
|
137
|
-
"playlist-experience"
|
|
138
|
-
);
|
|
139
|
-
|
|
140
|
-
expect(result.item.textLabel1.default).toEqual(
|
|
141
|
-
expect.objectContaining({
|
|
142
|
-
fontColor: "#00FF00",
|
|
143
|
-
fontSize: 28,
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
expect(result.item.textLabel2.default).toEqual(
|
|
148
|
-
expect.objectContaining({
|
|
149
|
-
fontColor: "#00FFFF",
|
|
150
|
-
})
|
|
151
|
-
);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
it("should map button.create_new_playlist_asset onto leadingIcon.asset", () => {
|
|
155
|
-
const result = parseModalBlocksConfiguration(
|
|
156
|
-
{
|
|
157
|
-
"button.create_new_playlist_asset":
|
|
158
|
-
"https://placehold.co/24x24/FF00FF/FFFFFF/png?text=CN",
|
|
159
|
-
},
|
|
160
|
-
"playlist-experience"
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
expect(result.button.leadingIcon.default).toEqual(
|
|
164
|
-
expect.objectContaining({
|
|
165
|
-
asset: "https://placehold.co/24x24/FF00FF/FFFFFF/png?text=CN",
|
|
166
|
-
})
|
|
167
|
-
);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it("should map item.checkbox_asset and checked_checkbox_asset onto item.checkbox", () => {
|
|
171
|
-
const result = parseModalBlocksConfiguration(
|
|
172
|
-
{
|
|
173
|
-
"item.checkbox_asset":
|
|
174
|
-
"https://placehold.co/24x24/FF3B30/FFFFFF/png?text=CB",
|
|
175
|
-
"item.checked_checkbox_asset":
|
|
176
|
-
"https://placehold.co/24x24/FFD60A/000000/png?text=CK",
|
|
177
|
-
},
|
|
178
|
-
"playlist-experience"
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
expect(result.item.checkbox.default).toEqual(
|
|
182
|
-
expect.objectContaining({
|
|
183
|
-
asset: "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=CB",
|
|
184
|
-
checkedAsset: "https://placehold.co/24x24/FFD60A/000000/png?text=CK",
|
|
185
|
-
})
|
|
186
|
-
);
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("should map reorder/remove Studio assets onto item.actionButtons", () => {
|
|
190
|
-
const result = parseModalBlocksConfiguration(
|
|
191
|
-
{
|
|
192
|
-
"reorder_playlist_item.remove_from_playlist_asset":
|
|
193
|
-
"https://placehold.co/24x24/00FF00/000000/png?text=RM",
|
|
194
|
-
"reorder_playlist_item.reorder_handle_asset":
|
|
195
|
-
"https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
|
|
196
|
-
},
|
|
197
|
-
"playlist-experience"
|
|
198
|
-
);
|
|
199
|
-
|
|
200
|
-
expect(result.item.actionButtons.default).toEqual(
|
|
201
|
-
expect.objectContaining({
|
|
202
|
-
removeAsset: "https://placehold.co/24x24/00FF00/000000/png?text=RM",
|
|
203
|
-
dragAsset: "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
|
|
204
|
-
})
|
|
205
|
-
);
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it("should fall back to flavor1 reorder/remove assets", () => {
|
|
209
|
-
const result = parseModalBlocksConfiguration(
|
|
210
|
-
{
|
|
211
|
-
"playlist_experience_assets_flavor1.remove_from_playlist_asset":
|
|
212
|
-
"https://placehold.co/24x24/00FF00/000000/png?text=RM",
|
|
213
|
-
"playlist_experience_assets_flavor1.reorder_handle_asset":
|
|
214
|
-
"https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
|
|
215
|
-
},
|
|
216
|
-
"playlist-experience"
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
expect(result.item.actionButtons.default).toEqual(
|
|
220
|
-
expect.objectContaining({
|
|
221
|
-
removeAsset: "https://placehold.co/24x24/00FF00/000000/png?text=RM",
|
|
222
|
-
dragAsset: "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
|
|
223
|
-
})
|
|
224
|
-
);
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
it("should fall back to flavor2 reorder/remove assets", () => {
|
|
228
|
-
const result = parseModalBlocksConfiguration(
|
|
229
|
-
{
|
|
230
|
-
"playlist_experience_assets_flavor2.remove_from_playlist_asset":
|
|
231
|
-
"https://placehold.co/24x24/00FF00/000000/png?text=RM",
|
|
232
|
-
"playlist_experience_assets_flavor2.reorder_handle_asset":
|
|
233
|
-
"https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
|
|
234
|
-
},
|
|
235
|
-
"playlist-experience"
|
|
236
|
-
);
|
|
237
|
-
|
|
238
|
-
expect(result.item.actionButtons.default).toEqual(
|
|
239
|
-
expect.objectContaining({
|
|
240
|
-
removeAsset: "https://placehold.co/24x24/00FF00/000000/png?text=RM",
|
|
241
|
-
dragAsset: "https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
|
|
242
|
-
})
|
|
243
|
-
);
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it("should ignore playlist-only asset keys for other theme plugins", () => {
|
|
247
|
-
const result = parseModalBlocksConfiguration(
|
|
248
|
-
{
|
|
249
|
-
"button.create_new_playlist_asset":
|
|
250
|
-
"https://placehold.co/24x24/FF00FF/FFFFFF/png?text=CN",
|
|
251
|
-
"playlist_experience_assets_flavor1.reorder_handle_asset":
|
|
252
|
-
"https://placehold.co/24x24/FF3B30/FFFFFF/png?text=RH",
|
|
253
|
-
},
|
|
254
|
-
"queue-action"
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
expect(result.button.leadingIcon.default?.asset).toBeUndefined();
|
|
258
|
-
expect(result.item.actionButtons.default?.dragAsset).toBeUndefined();
|
|
259
|
-
});
|
|
260
|
-
});
|