@applicaster/zapp-react-native-utils 15.1.5 → 15.1.6-alpha.2015591222

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 (43) hide show
  1. package/actionsExecutor/ActionExecutor.ts +8 -10
  2. package/actionsExecutor/ActionExecutorContext.tsx +49 -340
  3. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +22 -0
  4. package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
  5. package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +76 -0
  6. package/actionsExecutor/actions/__tests__/showToast.test.ts +63 -0
  7. package/actionsExecutor/actions/appRestart.ts +24 -0
  8. package/actionsExecutor/actions/confirmDialog.ts +53 -0
  9. package/actionsExecutor/actions/dismissBottomSheet.ts +22 -0
  10. package/actionsExecutor/actions/index.ts +34 -0
  11. package/actionsExecutor/actions/localStorageRemove.ts +27 -0
  12. package/actionsExecutor/actions/localStorageSet.ts +28 -0
  13. package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
  14. package/actionsExecutor/actions/navigateToScreen.ts +123 -0
  15. package/actionsExecutor/actions/openBottomSheet.ts +318 -0
  16. package/actionsExecutor/actions/refreshComponent.ts +85 -0
  17. package/actionsExecutor/actions/screenSetVariable.ts +35 -0
  18. package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
  19. package/actionsExecutor/actions/sendCloudEvent.ts +96 -0
  20. package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
  21. package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
  22. package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
  23. package/actionsExecutor/actions/showToast.ts +31 -0
  24. package/actionsExecutor/actions/switchLayout.ts +40 -0
  25. package/actionsExecutor/feedDecorator.ts +6 -6
  26. package/actionsExecutor/types.ts +59 -0
  27. package/modalState/ContentViewModel.ts +111 -0
  28. package/modalState/EditableCollection.ts +17 -0
  29. package/modalState/EditableCollectionRegistry.ts +51 -0
  30. package/modalState/ModalOrchestrator.ts +198 -0
  31. package/modalState/RemoteEditableCollection.ts +189 -0
  32. package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
  33. package/modalState/__tests__/ContentViewModel.test.ts +165 -0
  34. package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
  35. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +28 -0
  36. package/modalState/__tests__/RemoteEditableCollection.test.ts +259 -0
  37. package/modalState/__tests__/useBottomSheetContent.test.ts +372 -0
  38. package/modalState/index.ts +30 -83
  39. package/modalState/store.ts +102 -0
  40. package/modalState/types.ts +110 -0
  41. package/modalState/useBottomSheetContent.ts +98 -0
  42. package/package.json +2 -2
  43. package/reactHooks/layout/index.ts +1 -1
@@ -1,4 +1,5 @@
1
1
  import { createLogger } from "../logger";
2
+ import type { ActionExecutionContext, ActionHandler } from "./types";
2
3
 
3
4
  export enum ActionResult {
4
5
  Success = "success",
@@ -12,12 +13,12 @@ const { log_error, log_debug, log_info } = createLogger({
12
13
  });
13
14
 
14
15
  class ActionExecutor {
15
- private registeredActions: Record<string, any> = {};
16
- // TODO: Remove context
16
+ private registeredActions: Record<string, ActionHandler> = {};
17
17
 
18
+ // TODO: Remove context
18
19
  handleAction = async (
19
20
  action: ActionType,
20
- context?: Record<string, any>
21
+ context?: ActionExecutionContext
21
22
  ): Promise<ActionResult> => {
22
23
  const handler = this.registeredActions[action.type];
23
24
  const entry = context?.entry as ZappEntry;
@@ -52,7 +53,7 @@ class ActionExecutor {
52
53
 
53
54
  handleActions = async (
54
55
  actionTypes: ActionType[],
55
- context?: Record<string, any>
56
+ context?: ActionExecutionContext
56
57
  ): Promise<ActionResult> => {
57
58
  for (const action of actionTypes) {
58
59
  // TODO: Handle action result error
@@ -70,7 +71,7 @@ class ActionExecutor {
70
71
 
71
72
  handleEntryActions = async (
72
73
  entry: ZappEntry,
73
- context?: Record<string, any>
74
+ context?: ActionExecutionContext
74
75
  ): Promise<ActionResult> => {
75
76
  const tapActions = entry.extensions?.tap_actions?.actions;
76
77
 
@@ -98,12 +99,9 @@ class ActionExecutor {
98
99
  delete this.registeredActions[actionType];
99
100
  };
100
101
 
101
- registerAction = (
102
+ registerAction = <TOptions = Record<string, any>>(
102
103
  type: string,
103
- handler: (
104
- action: ActionType,
105
- context?: Record<string, any>
106
- ) => Promise<ActionResult>
104
+ handler: ActionHandler<TOptions>
107
105
  ) => {
108
106
  if (this.registeredActions[type]) {
109
107
  log_error(`registerAction: action type: ${type} already registered`);
@@ -5,312 +5,96 @@ import {
5
5
  actionExecutor as _actionExecutor,
6
6
  ActionResult,
7
7
  } from "./ActionExecutor";
8
- import {
9
- batchRemoveAllFromNamespaceForStorage,
10
- batchRemoveFromStorage,
11
- batchSave,
12
- } from "../zappFrameworkUtils/localStorageHelper";
8
+ import { ActionExecutionContext, ActionHandler } from "./types";
9
+ import { batchRemoveAllFromNamespaceForStorage } from "../zappFrameworkUtils/localStorageHelper";
13
10
  import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
14
11
 
15
- import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickBrick";
16
- import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickBrick";
17
- import { showConfirmationDialog } from "../alertUtils";
18
- import { createCloudEvent, sendCloudEvent } from "../cloudEventsUtils";
19
- import { createLogger } from "../logger";
20
- import { ACTIVE_LAYOUT_ID_STORAGE_KEY } from "@applicaster/quick-brick-core/App/remoteContextReloader/consts";
21
- import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
22
- import { loadPipesData } from "@applicaster/zapp-react-native-redux/ZappPipes";
23
- import {
24
- EntryResolver,
25
- resolveObjectValues,
26
- } from "../appUtils/contextKeysManager/contextResolver";
27
- import { useNavigation } from "../reactHooks";
28
- import {
29
- getInflatedDataSourceUrl,
30
- getSearchContext,
31
- } from "../reactHooks/feed/useInflatedUrl";
32
-
33
- import {
34
- useContentTypes,
35
- usePickFromState,
36
- } from "@applicaster/zapp-react-native-redux/hooks";
12
+ import { useNavigation, useRivers } from "../reactHooks";
13
+ import { useContentTypes } from "@applicaster/zapp-react-native-redux/hooks";
37
14
  import { useSubscriberFor } from "../reactHooks/useSubscriberFor";
38
15
  import { APP_EVENTS } from "../appUtils/events";
39
- import {
40
- localStorageToggleFlag,
41
- sessionStorageToggleFlag,
42
- } from "./StorageActions";
16
+ import { createLogger } from "../logger";
43
17
 
44
- import { screenSetVariable, screenToggleFlag } from "./ScreenActions";
45
18
  import {
46
- StorageValuesToAdd,
47
- StorageValuesToRemove,
48
- } from "../zappFrameworkUtils/types";
19
+ appRestartAction,
20
+ confirmDialogAction,
21
+ createNavigateToScreenAction,
22
+ dismissBottomSheetAction,
23
+ localStorageRemoveAction,
24
+ localStorageSetAction,
25
+ localStorageToggleFlagAction,
26
+ openBottomSheetAction,
27
+ refreshComponentAction,
28
+ screenSetVariableAction,
29
+ screenToggleFlagAction,
30
+ sendCloudEventAction,
31
+ sessionStorageRemoveAction,
32
+ sessionStorageSetAction,
33
+ sessionStorageToggleFlagAction,
34
+ switchLayoutAction,
35
+ showToastAction,
36
+ } from "./actions";
49
37
 
50
38
  export const { log_error, log_info, log_debug } = createLogger({
51
39
  subsystem: "ActionExecutorContext",
52
40
  category: "General",
53
41
  });
54
42
 
55
- type ActionExecutorContextType = {
56
- registerAction: (
43
+ export type ActionExecutorContextType = {
44
+ registerAction: <TOptions = Record<string, any>>(
57
45
  type: string,
58
- handler: (
59
- action: ActionType,
60
- context?: Record<string, any>
61
- ) => Promise<ActionResult>
46
+ handler: ActionHandler<TOptions>
62
47
  ) => void;
63
48
  unregisterAction: (type: string) => void;
64
49
  handleAction: (
65
50
  action: ActionType,
66
- context?: Record<string, any>
51
+ context?: ActionExecutionContext
67
52
  ) => Promise<ActionResult>;
68
53
  handleActions: (
69
54
  actions: ActionType[],
70
- context: Record<string, any>
55
+ context?: ActionExecutionContext
71
56
  ) => Promise<ActionResult>;
72
57
  handleEntryActions: (
73
58
  entry: ZappEntry,
74
- context?: Record<string, any>
59
+ context?: ActionExecutionContext
75
60
  ) => Promise<ActionResult>;
76
61
  };
62
+
77
63
  type Props = {
78
64
  children: React.ReactNode;
79
65
  };
80
66
 
81
- /** Prefer component data.source, otherwise direct UIComponentContext parent. */
82
- function getComponentFeedData(component) {
83
- if (component?.data?.source) {
84
- return component.data;
85
- }
86
-
87
- if (component?.parent?.data?.source) {
88
- return component.parent.data;
89
- }
90
-
91
- return null;
92
- }
93
-
94
67
  const prepareDefaultActions = (actionExecutor) => {
95
- actionExecutor.registerAction("localStorageSet", async (action) => {
96
- const namespaces: StorageValuesToAdd = action.options.content;
97
- await batchSave(namespaces, localStorage);
98
- // TODO: Add support for ownershipKey and ownershipNamespace
99
-
100
- return ActionResult.Success;
101
- });
102
-
103
- actionExecutor.registerAction("sessionStorageSet", async (action) => {
104
- const namespaces: StorageValuesToAdd = action.options.content;
105
- await batchSave(namespaces, sessionStorage);
106
- // TODO: Add support for ownershipKey and ownershipNamespace
107
-
108
- return ActionResult.Success;
109
- });
110
-
111
- actionExecutor.registerAction("localStorageRemove", async (action) => {
112
- const namespaces: StorageValuesToRemove = action.options.content;
113
- await batchRemoveFromStorage(namespaces, localStorage);
114
- // TODO: Add support for ownershipKey and ownershipNamespace
115
-
116
- return ActionResult.Success;
117
- });
118
-
119
- actionExecutor.registerAction("sessionStorageRemove", async (action) => {
120
- const namespaces: StorageValuesToRemove = action.options.content;
121
- await batchRemoveFromStorage(namespaces, sessionStorage);
122
- // TODO: Add support for ownershipKey and ownershipNamespace
123
-
124
- return ActionResult.Success;
125
- });
68
+ actionExecutor.registerAction("localStorageSet", localStorageSetAction);
69
+ actionExecutor.registerAction("sessionStorageSet", sessionStorageSetAction);
70
+ actionExecutor.registerAction("localStorageRemove", localStorageRemoveAction);
126
71
 
127
72
  actionExecutor.registerAction(
128
- "refreshComponent",
129
- async (_action, context) => {
130
- const dispatch = appStore.getDispatch();
131
-
132
- const componentData = getComponentFeedData(context?.component);
133
-
134
- const source = componentData?.source;
135
- const mapping = componentData?.mapping;
136
-
137
- let dataSource = source;
138
-
139
- if (source && mapping) {
140
- dataSource =
141
- getInflatedDataSourceUrl({
142
- source,
143
- contexts: {
144
- entry: context?.entryContext,
145
- screen: context?.screenData,
146
- search: getSearchContext(null, mapping),
147
- },
148
- mapping,
149
- }) || source;
150
- }
151
-
152
- log_info(`handleAction: refreshComponent for dataSource:${dataSource}`, {
153
- source,
154
- inflatedUrl: dataSource,
155
- mapping,
156
- entryContextId: context?.entryContext?.id,
157
- entryId: context?.entry?.id,
158
- });
159
-
160
- // TODO: In theory we should wait callback to complete, before completing the action, but now it's not needed
161
- // TODO: handle focused item removal
162
- dispatch(
163
- loadPipesData(dataSource, {
164
- silentRefresh: false,
165
- clearCache: true,
166
- riverId: context?.screenData?.id,
167
- })
168
- );
169
-
170
- return ActionResult.Success;
171
- }
73
+ "sessionStorageRemove",
74
+ sessionStorageRemoveAction
172
75
  );
173
76
 
174
- actionExecutor.registerAction("switchLayout", async (action) => {
175
- log_info("handleAction: switchLayout event");
176
-
177
- await localStorage.setItem(
178
- ACTIVE_LAYOUT_ID_STORAGE_KEY,
179
- action.options.layoutId
180
- );
181
-
182
- QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
183
-
184
- return ActionResult.Success;
185
- });
186
-
187
- actionExecutor.registerAction("appRestart", async () => {
188
- log_info(`handleAction: ${QUICK_BRICK_EVENTS.FORCE_APP_RELOAD} event`);
189
-
190
- QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
191
-
192
- return ActionResult.Success;
193
- });
194
-
195
- actionExecutor.registerAction("confirmDialog", async (action) => {
196
- log_info("handleAction: confirmDialog event");
197
-
198
- return new Promise<ActionResult>((resolve) => {
199
- showConfirmationDialog({
200
- ...action.options,
201
- confirmCompletion: () => resolve(ActionResult.Success),
202
- cancelCompletion: () => resolve(ActionResult.Cancel),
203
- });
204
- });
205
- });
206
-
207
- actionExecutor.registerAction("sendCloudEvent", async (action, context) => {
208
- try {
209
- const options = action.options;
210
-
211
- const entry = context?.entry || {};
212
- const entryResolver = new EntryResolver(entry);
213
- const screenData = context?.screenStateStore?.getState().data || {};
214
- const screenResolver = new EntryResolver(screenData || {});
215
-
216
- const data =
217
- options?.data && options.inflateData
218
- ? await resolveObjectValues(options.data, {
219
- entry: entryResolver,
220
- screen: screenResolver,
221
- })
222
- : options?.data || entry;
223
-
224
- const cloudEvent = await createCloudEvent({
225
- type: options.type || "com.applicaster.selector.action.v1",
226
- data,
227
- subject: options.subject || entry?.id,
228
- });
229
-
230
- log_info("handleAction: sendCloudEvent event", { cloudEvent });
231
-
232
- const { error, code } = await sendCloudEvent(cloudEvent, options.url);
233
-
234
- if (error) {
235
- log_error("sendCloudEvent: error sending cloud event", { error });
236
-
237
- return ActionResult.Error;
238
- }
239
-
240
- if (code && code >= 200 && code < 300 && !error) {
241
- log_info("sendCloudEvent: cloud event sent successfully");
242
-
243
- return ActionResult.Success;
244
- }
245
- } catch (error) {
246
- log_error("sendCloudEvent: error sending cloud event", {
247
- action,
248
- error,
249
- });
250
- }
251
-
252
- return ActionResult.Error;
253
- });
77
+ actionExecutor.registerAction("refreshComponent", refreshComponentAction);
78
+ actionExecutor.registerAction("switchLayout", switchLayoutAction);
79
+ actionExecutor.registerAction("appRestart", appRestartAction);
80
+ actionExecutor.registerAction("confirmDialog", confirmDialogAction);
81
+ actionExecutor.registerAction("sendCloudEvent", sendCloudEventAction);
254
82
 
255
83
  actionExecutor.registerAction(
256
84
  "sessionStorageToggleFlag",
257
- async (
258
- action: ActionType,
259
- context?: Record<string, any>
260
- ): Promise<ActionResult> => {
261
- return await sessionStorageToggleFlag(context, action);
262
- }
85
+ sessionStorageToggleFlagAction
263
86
  );
264
87
 
265
88
  actionExecutor.registerAction(
266
89
  "localStorageToggleFlag",
267
- async (
268
- action: ActionType,
269
- context?: Record<string, any>
270
- ): Promise<ActionResult> => {
271
- return await localStorageToggleFlag(context, action);
272
- }
273
- );
274
-
275
- actionExecutor.registerAction(
276
- "screenSetVariable",
277
- async (
278
- action: ActionType,
279
- context?: Record<string, any>
280
- ): Promise<ActionResult> => {
281
- const route = context?.screenRoute;
282
- const screenStateStore = context?.screenStateStore;
283
-
284
- await screenSetVariable(
285
- route,
286
- screenStateStore,
287
- { entry: context?.entry, options: action.options },
288
- action
289
- );
290
-
291
- return Promise.resolve(ActionResult.Success);
292
- }
90
+ localStorageToggleFlagAction
293
91
  );
294
92
 
295
- actionExecutor.registerAction(
296
- "screenToggleFlag",
297
- async (
298
- action: ActionType,
299
- context?: Record<string, any>
300
- ): Promise<ActionResult> => {
301
- const screenRoute = context?.screenRoute;
302
- const screenStateStore = context?.screenStateStore;
303
-
304
- await screenToggleFlag(
305
- screenRoute,
306
- screenStateStore,
307
- { entry: context?.entry, options: action.options },
308
- action
309
- );
310
-
311
- return Promise.resolve(ActionResult.Success);
312
- }
313
- );
93
+ actionExecutor.registerAction("screenSetVariable", screenSetVariableAction);
94
+ actionExecutor.registerAction("screenToggleFlag", screenToggleFlagAction);
95
+ actionExecutor.registerAction("openBottomSheet", openBottomSheetAction);
96
+ actionExecutor.registerAction("dismissBottomSheet", dismissBottomSheetAction);
97
+ actionExecutor.registerAction("showToast", showToastAction);
314
98
  };
315
99
 
316
100
  export const ActionExecutorContext =
@@ -321,7 +105,7 @@ export function withActionExecutor(Component) {
321
105
 
322
106
  return function ActionExecutorComponent(props: Props) {
323
107
  const navigator = useNavigation();
324
- const { rivers } = usePickFromState(["rivers"]);
108
+ const rivers = useRivers();
325
109
  const contentTypes = useContentTypes();
326
110
 
327
111
  const handlers = useMemo(() => {
@@ -351,82 +135,7 @@ export function withActionExecutor(Component) {
351
135
  useEffect(() => {
352
136
  return _actionExecutor.registerAction(
353
137
  "navigateToScreen",
354
-
355
- async (action: ActionType, context?: Record<string, any>) => {
356
- const screenType = action.options?.typeMapping;
357
-
358
- if (!screenType) {
359
- log_error("navigateToScreen: typeMapping option is missing");
360
-
361
- return ActionResult.Error;
362
- }
363
-
364
- const navigationAction = action.options?.navigationAction;
365
- const entrySource = action.options?.entry;
366
-
367
- const entry = entrySource
368
- ? entrySource === "@{entry/}"
369
- ? context?.entry
370
- : entrySource
371
- : null;
372
-
373
- if (entry) {
374
- if (typeof entry !== "object") {
375
- log_error(
376
- `navigateToScreen: entry option is not an object, entry: ${entry}`
377
- );
378
-
379
- return ActionResult.Error;
380
- }
381
-
382
- log_info(
383
- `navigateToScreen: navigating to screen type: ${screenType} with entry id: ${entry.id}`
384
- );
385
-
386
- const overriddenEntry = {
387
- ...entry,
388
- type: {
389
- value: screenType,
390
- },
391
- };
392
-
393
- if (navigationAction === "push") {
394
- navigator.push(overriddenEntry);
395
- } else {
396
- navigator.replace(overriddenEntry);
397
- }
398
-
399
- return ActionResult.Success;
400
- }
401
-
402
- const screenId = contentTypes?.[screenType]?.screen_id || null;
403
-
404
- if (!screenId) {
405
- log_error(
406
- `navigateToScreen: can not resolve screen type mapping: ${screenType}`
407
- );
408
-
409
- return ActionResult.Error;
410
- }
411
-
412
- const river = rivers[screenId];
413
-
414
- if (!river) {
415
- log_error("navigateToScreen: can not resolve river");
416
-
417
- return ActionResult.Error;
418
- }
419
-
420
- context?.callback?.({ success: false, error: null, abort: true });
421
-
422
- if (navigationAction === "push") {
423
- navigator.push(river);
424
- } else {
425
- navigator.replace(river);
426
- }
427
-
428
- return ActionResult.Success;
429
- }
138
+ createNavigateToScreenAction(navigator, rivers, contentTypes)
430
139
  );
431
140
  }, [navigator, rivers, contentTypes]);
432
141
 
@@ -0,0 +1,22 @@
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
+ }));
8
+
9
+ describe("dismissBottomSheetAction", () => {
10
+ beforeEach(() => {
11
+ jest.clearAllMocks();
12
+ });
13
+
14
+ it("calls dismissModal and returns ActionResult.Success", async () => {
15
+ const result = await dismissBottomSheetAction({
16
+ type: "dismissBottomSheet",
17
+ });
18
+
19
+ expect(dismissModal).toHaveBeenCalledTimes(1);
20
+ expect(result).toBe(ActionResult.Success);
21
+ });
22
+ });
@@ -0,0 +1,88 @@
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
+ });
@@ -0,0 +1,76 @@
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
+ });