@applicaster/zapp-react-native-utils 16.0.0-alpha.4004661200 → 16.0.0-alpha.4065452341

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 (35) hide show
  1. package/actionsExecutor/ActionExecutorContext.tsx +10 -1
  2. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +3 -0
  3. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +113 -1
  4. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  5. package/actionsExecutor/actions/__tests__/showToast.test.ts +2 -2
  6. package/actionsExecutor/actions/dismissBottomSheet.ts +2 -1
  7. package/actionsExecutor/actions/index.ts +2 -0
  8. package/actionsExecutor/actions/openBottomSheet.ts +20 -11
  9. package/actionsExecutor/actions/presentScreen.ts +78 -0
  10. package/actionsExecutor/actions/showToast.ts +2 -2
  11. package/actionsExecutor/consts.ts +1 -0
  12. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  13. package/configurationUtils/__tests__/modalBlocksParser.test.ts +153 -0
  14. package/configurationUtils/manifestKeyParser.ts +12 -1
  15. package/configurationUtils/modalBlocksParser.ts +118 -0
  16. package/entryActions/__tests__/buildEntryActions.test.ts +39 -0
  17. package/entryActions/buildEntryActions.ts +1 -0
  18. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  19. package/modalState/ModalOrchestrator.ts +21 -9
  20. package/modalState/RemoteEditableCollection.ts +9 -1
  21. package/modalState/__tests__/RemoteEditableCollection.test.ts +90 -1
  22. package/modalState/__tests__/index.test.ts +30 -1
  23. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  24. package/modalState/index.ts +6 -1
  25. package/modalState/store.ts +9 -2
  26. package/modalState/types.ts +29 -2
  27. package/modalState/useBottomSheetContent.ts +24 -17
  28. package/package.json +2 -2
  29. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  30. package/reactHooks/cell-click/index.ts +21 -14
  31. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  32. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  33. package/reactHooks/navigation/index.ts +2 -0
  34. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  35. package/reactHooks/navigation/useRoute.ts +22 -5
@@ -104,4 +104,157 @@ describe("parseModalBlocksConfiguration", () => {
104
104
  expect(result.button.title).toEqual({ default: {} });
105
105
  expect(result.action.leadingIcon).toEqual({ default: {} });
106
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
+ });
107
260
  });
@@ -11,11 +11,17 @@ const currentPlatform = platformSelect({
11
11
  android_tv: "android",
12
12
  });
13
13
 
14
- // Do not change the order, focused_selected should be first
14
+ // Do not change the order: focused_selected must be first, and "focus" must
15
+ // come *after* "focused". Matching uses startsWith(state + "_"), so putting
16
+ // "focus" first would steal focused_* / focused_selected_* keys. Adding
17
+ // "focus" here affects every getAllSpecificStyles consumer (not only modals);
18
+ // property names that themselves start with focus_ (e.g. focus_font_color as
19
+ // a non-state style) would also be classified as the focus state.
15
20
  const states = [
16
21
  "focused_selected",
17
22
  "pressed",
18
23
  "focused",
24
+ "focus",
19
25
  "selected",
20
26
  "default",
21
27
  ];
@@ -112,6 +118,11 @@ export const getAllSpecificStyles = ({
112
118
  state = defaultKey;
113
119
  }
114
120
 
121
+ // Normalize Studio "focus" keys onto the runtime "focused" state bucket.
122
+ if (state === "focus") {
123
+ state = "focused";
124
+ }
125
+
115
126
  if (!styleName) return;
116
127
 
117
128
  const camelCaseKey = toCamelCase(styleName);
@@ -25,6 +25,10 @@ export type ModalBlocksConfig = {
25
25
  buttonsContainer: Record<string, any>;
26
26
  button1: Record<string, any>;
27
27
  button2: Record<string, any>;
28
+ /** Studio item.checkbox_asset / item.checked_checkbox_asset */
29
+ checkbox?: Record<string, any>;
30
+ /** Studio reorder/remove icons for Edit Order rows */
31
+ actionButtons?: Record<string, any>;
28
32
  };
29
33
  nowPlayingItem?: {
30
34
  background: Record<string, any>;
@@ -37,6 +41,8 @@ export type ModalBlocksConfig = {
37
41
  buttonsContainer: Record<string, any>;
38
42
  button1: Record<string, any>;
39
43
  button2: Record<string, any>;
44
+ checkbox?: Record<string, any>;
45
+ actionButtons?: Record<string, any>;
40
46
  };
41
47
  button: {
42
48
  background: Record<string, any>;
@@ -75,6 +81,8 @@ export const parseModalBlocksConfiguration = (
75
81
  buttonsContainer: {},
76
82
  button1: {},
77
83
  button2: {},
84
+ checkbox: {},
85
+ actionButtons: {},
78
86
  },
79
87
  nowPlayingItem: {
80
88
  background: {},
@@ -87,6 +95,8 @@ export const parseModalBlocksConfiguration = (
87
95
  buttonsContainer: {},
88
96
  button1: {},
89
97
  button2: {},
98
+ checkbox: {},
99
+ actionButtons: {},
90
100
  },
91
101
  button: {
92
102
  background: {},
@@ -152,8 +162,12 @@ export const parseModalBlocksConfiguration = (
152
162
  "now_playing_container",
153
163
  "now_playing_asset",
154
164
  "now_playing_label",
165
+ // Underscored form (QB convention) and Studio/manifest-generator form
166
+ // without the underscore before the digit (text_label1).
155
167
  "text_label_1",
156
168
  "text_label_2",
169
+ "text_label1",
170
+ "text_label2",
157
171
  "buttons_container",
158
172
  "button_1",
159
173
  "button_2",
@@ -167,6 +181,8 @@ export const parseModalBlocksConfiguration = (
167
181
  "now_playing_label",
168
182
  "text_label_1",
169
183
  "text_label_2",
184
+ "text_label1",
185
+ "text_label2",
170
186
  "buttons_container",
171
187
  "button_1",
172
188
  "button_2",
@@ -174,5 +190,107 @@ export const parseModalBlocksConfiguration = (
174
190
 
175
191
  parseBlock("button", ["background", "title", "icons", "leading_icon"]);
176
192
 
193
+ // Playlist-experience Studio keys live in this shared parser because modal
194
+ // blocks are themed by themePluginId. Gate them so other plugins are not
195
+ // affected by playlist-only asset names.
196
+ const isPlaylistExperience =
197
+ normalizedComponentName === "playlist_experience";
198
+
199
+ // Studio uploads Create New icon as button.create_new_playlist_asset (not
200
+ // button.leading_icon.asset). Map it onto leadingIcon so AudioPlayerButton
201
+ // can override the hardcoded action-type asset.
202
+ const createNewPlaylistAsset = isPlaylistExperience
203
+ ? configuration["button.create_new_playlist_asset"] ||
204
+ configuration[
205
+ `${normalizedComponentName}_button_create_new_playlist_asset`
206
+ ]
207
+ : undefined;
208
+
209
+ if (createNewPlaylistAsset) {
210
+ if (!result.button.leadingIcon.default) {
211
+ result.button.leadingIcon.default = {};
212
+ }
213
+
214
+ result.button.leadingIcon.default.asset = createNewPlaylistAsset;
215
+ }
216
+
217
+ // Studio checkbox assets are top-level item.* keys (not a parseBlock
218
+ // sub-component). Map onto item.checkbox so multiSelect can render them.
219
+ const checkboxAsset =
220
+ configuration["item.checkbox_asset"] ||
221
+ configuration[`${normalizedComponentName}_item_checkbox_asset`];
222
+
223
+ const checkedCheckboxAsset =
224
+ configuration["item.checked_checkbox_asset"] ||
225
+ configuration[`${normalizedComponentName}_item_checked_checkbox_asset`];
226
+
227
+ if (checkboxAsset || checkedCheckboxAsset) {
228
+ if (!result.item.checkbox.default) {
229
+ result.item.checkbox.default = {};
230
+ }
231
+
232
+ if (checkboxAsset) {
233
+ result.item.checkbox.default.asset = checkboxAsset;
234
+ }
235
+
236
+ if (checkedCheckboxAsset) {
237
+ result.item.checkbox.default.checkedAsset = checkedCheckboxAsset;
238
+ }
239
+ }
240
+
241
+ // Edit Order row icons: prefer reorder_playlist_item.*, then flavor1, then
242
+ // flavor2 playlist_experience_assets_* (playlist-experience theme only).
243
+ const removeAsset = isPlaylistExperience
244
+ ? configuration["reorder_playlist_item.remove_from_playlist_asset"] ||
245
+ configuration[
246
+ `${normalizedComponentName}_reorder_playlist_item_remove_from_playlist_asset`
247
+ ] ||
248
+ configuration[
249
+ "playlist_experience_assets_flavor1.remove_from_playlist_asset"
250
+ ] ||
251
+ configuration[
252
+ `${normalizedComponentName}_assets_flavor1_remove_from_playlist_asset`
253
+ ] ||
254
+ configuration[
255
+ "playlist_experience_assets_flavor2.remove_from_playlist_asset"
256
+ ] ||
257
+ configuration[
258
+ `${normalizedComponentName}_assets_flavor2_remove_from_playlist_asset`
259
+ ]
260
+ : undefined;
261
+
262
+ const dragAsset = isPlaylistExperience
263
+ ? configuration["reorder_playlist_item.reorder_handle_asset"] ||
264
+ configuration[
265
+ `${normalizedComponentName}_reorder_playlist_item_reorder_handle_asset`
266
+ ] ||
267
+ configuration[
268
+ "playlist_experience_assets_flavor1.reorder_handle_asset"
269
+ ] ||
270
+ configuration[
271
+ `${normalizedComponentName}_assets_flavor1_reorder_handle_asset`
272
+ ] ||
273
+ configuration[
274
+ "playlist_experience_assets_flavor2.reorder_handle_asset"
275
+ ] ||
276
+ configuration[
277
+ `${normalizedComponentName}_assets_flavor2_reorder_handle_asset`
278
+ ]
279
+ : undefined;
280
+
281
+ if (removeAsset || dragAsset) {
282
+ if (!result.item.actionButtons.default) {
283
+ result.item.actionButtons.default = {};
284
+ }
285
+
286
+ if (removeAsset) {
287
+ result.item.actionButtons.default.removeAsset = removeAsset;
288
+ }
289
+
290
+ if (dragAsset) {
291
+ result.item.actionButtons.default.dragAsset = dragAsset;
292
+ }
293
+ }
294
+
177
295
  return result;
178
296
  };
@@ -154,3 +154,42 @@ describe("buildEntryActions - alias & label resolution", () => {
154
154
  });
155
155
  });
156
156
  });
157
+
158
+ describe("buildEntryActions - invokeAction execution context", () => {
159
+ it("forwards the List component from invoke options into handleActions", async () => {
160
+ const handleActions = jest.fn();
161
+
162
+ const component = {
163
+ id: "list-1",
164
+ data: { source: "https://example.com/user/collections/abc" },
165
+ };
166
+
167
+ const deps = {
168
+ actionExecutor: { handleActions } as any,
169
+ actionContext: { screenData: { id: "playlist-screen" } },
170
+ };
171
+
172
+ const entry = {
173
+ id: "entry-1",
174
+ extensions: {
175
+ entry_action: [
176
+ {
177
+ button: { title: "Edit Name" },
178
+ actions: [{ type: "refreshComponent" }],
179
+ },
180
+ ],
181
+ },
182
+ };
183
+
184
+ const [action] = buildEntryActions(entry as any, deps);
185
+
186
+ await action.action.invokeAction(entry as any, { component });
187
+
188
+ expect(handleActions).toHaveBeenCalledWith([{ type: "refreshComponent" }], {
189
+ entry,
190
+ entryContext: entry,
191
+ screenData: { id: "playlist-screen" },
192
+ component,
193
+ });
194
+ });
195
+ });
@@ -105,6 +105,7 @@ function createEntryAction(
105
105
  entry: invokedEntry,
106
106
  entryContext: invokedEntry,
107
107
  ...deps.actionContext,
108
+ ...(options.component ? { component: options.component } : {}),
108
109
  } as ActionExecutionContext);
109
110
  } catch (error) {
110
111
  log_error(
@@ -12,6 +12,12 @@ const generalContent = () => ({
12
12
  label: "Navigation Bar",
13
13
  placeholder: "Choose Nav Bar",
14
14
  },
15
+ {
16
+ key: "hide_menu",
17
+ type: "switch",
18
+ label: "Hide Menu",
19
+ initial_value: false,
20
+ },
15
21
  ],
16
22
  },
17
23
  styles: {
@@ -1,10 +1,16 @@
1
1
  import { dismissModal, modalStore, openBottomSheetModal } from "./store";
2
- import { isPresentSubMenuAction, Menu, MenuItem } from "./types";
2
+ import {
3
+ getMenuItemActions,
4
+ isPresentSubMenuAction,
5
+ Menu,
6
+ MenuItem,
7
+ PresentSubMenuAction,
8
+ } from "./types";
3
9
  import { ContentViewModel } from "./ContentViewModel";
4
10
 
5
11
  export type { Menu, MenuItem };
6
12
 
7
- export { isPresentSubMenuAction };
13
+ export { isPresentSubMenuAction, getMenuItemActions };
8
14
 
9
15
  /**
10
16
  * Converts a Menu model into the props expected by BottomSheetModalContent.
@@ -136,15 +142,21 @@ class ModalOrchestrator {
136
142
  private _buildOnPress(
137
143
  onItemPress?: (item: MenuItem) => void | Promise<void>
138
144
  ): (item: MenuItem) => void | Promise<void> {
139
- return (item: MenuItem) => {
140
- if (isPresentSubMenuAction(item.action)) {
141
- // Navigate deeper into the sub-menu
142
- this.open(item.action.menu, onItemPress);
143
-
144
- return;
145
+ return async (item: MenuItem) => {
146
+ if (onItemPress) {
147
+ await onItemPress(item);
145
148
  }
146
149
 
147
- return onItemPress?.(item);
150
+ const actions = getMenuItemActions(item);
151
+
152
+ const subMenuAction = actions.find(isPresentSubMenuAction) as
153
+ | PresentSubMenuAction
154
+ | undefined;
155
+
156
+ if (subMenuAction) {
157
+ // Navigate deeper into the sub-menu
158
+ this.open(subMenuAction.menu, onItemPress);
159
+ }
148
160
  };
149
161
  }
150
162
 
@@ -123,7 +123,14 @@ export class RemoteEditableCollection implements EditableCollection {
123
123
 
124
124
  try {
125
125
  for (const action of addEvents) {
126
- await actionExecutor.handleAction(action as any);
126
+ if (this.content.context) {
127
+ await actionExecutor.handleAction(
128
+ action as any,
129
+ this.content.context
130
+ );
131
+ } else {
132
+ await actionExecutor.handleAction(action as any);
133
+ }
127
134
  }
128
135
  } catch (e) {
129
136
  actionFailed = true;
@@ -219,6 +226,7 @@ export class RemoteEditableCollection implements EditableCollection {
219
226
  await actionExecutor.handleAction(
220
227
  actionToExecute as any,
221
228
  {
229
+ ...this.content.context,
222
230
  entry: item as any,
223
231
  } as any
224
232
  );
@@ -34,16 +34,26 @@ const itemPlain: MenuItem = { id: "2", title: "B" };
34
34
  function makeCollection(
35
35
  items: MenuItem[],
36
36
  refetch = jest.fn().mockResolvedValue(undefined),
37
- operations = ["remove", "reorder"]
37
+ operations = ["remove", "reorder"],
38
+ context?: Record<string, unknown>
38
39
  ) {
39
40
  const content = {
40
41
  items,
42
+ context,
41
43
  dynamicCollection: { operations, postUrl: "https://x/cloud-events" },
42
44
  } as unknown as Content;
43
45
 
44
46
  return { col: new RemoteEditableCollection(content, refetch), refetch };
45
47
  }
46
48
 
49
+ const openingContext = {
50
+ component: {
51
+ id: "list-1",
52
+ data: { source: "https://example.com/user/collections/abc" },
53
+ },
54
+ screenData: { id: "playlist-screen" },
55
+ };
56
+
47
57
  describe("RemoteEditableCollection", () => {
48
58
  beforeEach(() => jest.clearAllMocks());
49
59
 
@@ -118,6 +128,24 @@ describe("RemoteEditableCollection", () => {
118
128
  expect(refetch).toHaveBeenCalledTimes(1);
119
129
  expect(currentItems(col)).toEqual([itemWithRemove]);
120
130
  });
131
+
132
+ it("forwards stored sheet context plus the removed item as entry", async () => {
133
+ handleAction.mockResolvedValue("success");
134
+
135
+ const { col } = makeCollection(
136
+ [itemWithRemove, itemPlain],
137
+ jest.fn().mockResolvedValue(undefined),
138
+ ["remove", "reorder"],
139
+ openingContext
140
+ );
141
+
142
+ await col.remove(0);
143
+
144
+ expect(handleAction).toHaveBeenCalledWith(removeAction, {
145
+ ...openingContext,
146
+ entry: itemWithRemove,
147
+ });
148
+ });
121
149
  });
122
150
 
123
151
  describe("move", () => {
@@ -164,6 +192,35 @@ describe("RemoteEditableCollection", () => {
164
192
  expect(refetch).toHaveBeenCalledTimes(1);
165
193
  });
166
194
 
195
+ it("forwards stored sheet context plus the moved item as entry", async () => {
196
+ handleAction.mockResolvedValue("success");
197
+
198
+ const itemA: MenuItem = {
199
+ id: "2",
200
+ title: "B",
201
+ entryActions: [
202
+ { button: { alias: "reorder_item" }, actions: [removeAction] },
203
+ ],
204
+ };
205
+
206
+ const { col } = makeCollection(
207
+ [itemA],
208
+ jest.fn().mockResolvedValue(undefined),
209
+ ["remove", "reorder"],
210
+ openingContext
211
+ );
212
+
213
+ await col.move(["2"]);
214
+
215
+ expect(handleAction).toHaveBeenCalledWith(
216
+ expect.objectContaining({ type: "sendCloudEvent" }),
217
+ {
218
+ ...openingContext,
219
+ entry: itemA,
220
+ }
221
+ );
222
+ });
223
+
167
224
  it("rolls back on failure", async () => {
168
225
  handleAction.mockRejectedValue(new Error("nope"));
169
226
 
@@ -322,5 +379,37 @@ describe("RemoteEditableCollection", () => {
322
379
  expect(handleAction).toHaveBeenCalledWith(addAction);
323
380
  expect(refetch).toHaveBeenCalledTimes(1);
324
381
  });
382
+
383
+ it("forwards stored sheet context into events.add actions", async () => {
384
+ handleAction.mockResolvedValue("success");
385
+
386
+ const addAction = {
387
+ type: "showTextInput",
388
+ options: {
389
+ headerTitle: "Create Playlist",
390
+ buttonLabel: "Create",
391
+ actions: [{ type: "sendCloudEvent" }],
392
+ },
393
+ };
394
+
395
+ const content = {
396
+ items: [],
397
+ context: openingContext,
398
+ dynamicCollection: {
399
+ operations: ["add"],
400
+ postUrl: "https://x/cloud-events",
401
+ events: {
402
+ add: [addAction],
403
+ },
404
+ },
405
+ } as any;
406
+
407
+ const refetch = jest.fn().mockResolvedValue(undefined);
408
+ const col = new RemoteEditableCollection(content, refetch);
409
+
410
+ await col.add();
411
+
412
+ expect(handleAction).toHaveBeenCalledWith(addAction, openingContext);
413
+ });
325
414
  });
326
415
  });
@@ -1,4 +1,4 @@
1
- import { modalStore } from "../";
1
+ import { modalStore, getMenuItemActions } from "../";
2
2
 
3
3
  describe("Modal State", () => {
4
4
  it("should have initial state", () => {
@@ -48,4 +48,33 @@ describe("Modal State", () => {
48
48
  });
49
49
  });
50
50
  });
51
+
52
+ describe("getMenuItemActions", () => {
53
+ it("returns actions array when actions is provided", () => {
54
+ const actions = [{ type: "action1" }, { type: "action2" }];
55
+ const item = { id: "1", title: "Item", actions };
56
+
57
+ expect(getMenuItemActions(item)).toEqual(actions);
58
+ });
59
+
60
+ it("returns [action] when single action is provided", () => {
61
+ const action = { type: "action1" };
62
+ const item = { id: "1", title: "Item", action };
63
+
64
+ expect(getMenuItemActions(item)).toEqual([action]);
65
+ });
66
+
67
+ it("returns action when action is passed as an array", () => {
68
+ const actions = [{ type: "action1" }];
69
+ const item = { id: "1", title: "Item", action: actions as any };
70
+
71
+ expect(getMenuItemActions(item)).toEqual(actions);
72
+ });
73
+
74
+ it("returns empty array when no action or actions are provided", () => {
75
+ expect(getMenuItemActions({ id: "1", title: "Item" })).toEqual([]);
76
+ expect(getMenuItemActions(null)).toEqual([]);
77
+ expect(getMenuItemActions(undefined)).toEqual([]);
78
+ });
79
+ });
51
80
  });