@applicaster/zapp-react-native-utils 16.0.0-alpha.1052711356 → 16.0.0-alpha.1054344748

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 (120) hide show
  1. package/actionsExecutor/ActionExecutor.ts +50 -3
  2. package/actionsExecutor/ActionExecutorContext.tsx +97 -19
  3. package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
  4. package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
  5. package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +3 -0
  6. package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
  7. package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
  8. package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
  9. package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +300 -0
  10. package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
  11. package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
  12. package/actionsExecutor/actions/__tests__/showToast.test.ts +29 -4
  13. package/actionsExecutor/actions/dismissBottomSheet.ts +2 -1
  14. package/actionsExecutor/actions/goBack.ts +60 -0
  15. package/actionsExecutor/actions/goHome.ts +31 -0
  16. package/actionsExecutor/actions/index.ts +8 -0
  17. package/actionsExecutor/actions/navigateToScreen.ts +18 -4
  18. package/actionsExecutor/actions/openBottomSheet.ts +51 -31
  19. package/actionsExecutor/actions/presentScreen.ts +78 -0
  20. package/actionsExecutor/actions/sendCloudEvent.ts +5 -8
  21. package/actionsExecutor/actions/showAlert.ts +51 -0
  22. package/actionsExecutor/actions/showToast.ts +62 -6
  23. package/actionsExecutor/consts.ts +27 -0
  24. package/actionsExecutor/feedDecorator.ts +6 -6
  25. package/analyticsUtils/PlayerAnalyticsManager.ts +1 -1
  26. package/appUtils/HooksManager/index.ts +9 -0
  27. package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
  28. package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
  29. package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
  30. package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
  31. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
  32. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
  33. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
  34. package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
  35. package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
  36. package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
  37. package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
  38. package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
  39. package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
  40. package/appUtils/playerManager/__tests__/playerToolbox.test.ts +97 -0
  41. package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
  42. package/appUtils/playerManager/{conts.ts → const.ts} +33 -0
  43. package/appUtils/playerManager/index.ts +3 -1
  44. package/appUtils/playerManager/player.ts +125 -3
  45. package/appUtils/playerManager/playerFactory.ts +1 -1
  46. package/appUtils/playerManager/playerNative.ts +28 -4
  47. package/appUtils/playerManager/playerNativeCommand.ts +3 -6
  48. package/appUtils/playerManager/playerToolbox.ts +192 -0
  49. package/appUtils/playerManager/usePlayerContent.tsx +43 -0
  50. package/appUtils/playerManager/usePlayerControllerSetup.tsx +1 -1
  51. package/appUtils/playerManager/userLanguagePreference.ts +1 -1
  52. package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
  53. package/arrayUtils/index.ts +62 -0
  54. package/cellUtils/index.ts +30 -3
  55. package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
  56. package/configurationUtils/__tests__/modalBlocksParser.test.ts +269 -0
  57. package/configurationUtils/manifestKeyParser.ts +50 -10
  58. package/configurationUtils/modalBlocksParser.ts +214 -0
  59. package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
  60. package/entryActions/aliasPresentation.ts +108 -0
  61. package/entryActions/buildEntryActions.ts +167 -0
  62. package/entryActions/index.ts +15 -0
  63. package/entryActions/types.ts +39 -0
  64. package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
  65. package/manifestUtils/_internals/index.js +8 -3
  66. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  67. package/manifestUtils/defaultManifestConfigurations/player.js +330 -1
  68. package/manifestUtils/index.js +3 -0
  69. package/manifestUtils/modalBlocks.js +304 -0
  70. package/modalState/ContentViewModel.ts +2 -0
  71. package/modalState/ModalOrchestrator.ts +23 -9
  72. package/modalState/RemoteEditableCollection.ts +77 -31
  73. package/modalState/__tests__/ContentViewModel.test.ts +3 -3
  74. package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +35 -0
  75. package/modalState/__tests__/RemoteEditableCollection.test.ts +157 -1
  76. package/modalState/__tests__/index.test.ts +30 -1
  77. package/modalState/__tests__/useBottomSheetContent.test.ts +0 -23
  78. package/modalState/__tests__/useModalStoreState.test.ts +142 -0
  79. package/modalState/index.ts +6 -1
  80. package/modalState/store.ts +9 -2
  81. package/modalState/types.ts +56 -4
  82. package/modalState/useBottomSheetContent.ts +37 -26
  83. package/package.json +2 -2
  84. package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
  85. package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
  86. package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
  87. package/playerUtils/contentDataKeys.ts +134 -0
  88. package/playerUtils/index.ts +37 -16
  89. package/playerUtils/isAudioItem.ts +26 -0
  90. package/playerUtils/resolvePlayerActions.ts +71 -0
  91. package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
  92. package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
  93. package/pluginUtils/index.ts +29 -0
  94. package/reactHooks/actions/index.ts +67 -2
  95. package/reactHooks/cell-click/__tests__/index.test.js +64 -0
  96. package/reactHooks/cell-click/index.ts +21 -14
  97. package/reactHooks/connection/index.tsx +8 -5
  98. package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
  99. package/reactHooks/feed/useMarkPipesDataStale.ts +68 -23
  100. package/reactHooks/index.ts +2 -0
  101. package/reactHooks/layout/index.ts +1 -1
  102. package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
  103. package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
  104. package/reactHooks/navigation/index.ts +2 -0
  105. package/reactHooks/navigation/usePresentScreen.ts +157 -0
  106. package/reactHooks/navigation/useRoute.ts +22 -5
  107. package/reactHooks/usePluginConfiguration.ts +4 -1
  108. package/reactHooks/utils/__tests__/index.test.js +22 -2
  109. package/reactHooks/utils/index.ts +11 -1
  110. package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
  111. package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
  112. package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
  113. package/uiActionsRegistrator/index.ts +25 -203
  114. package/uiActionsRegistrator/registry.ts +351 -0
  115. package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
  116. package/uiActionsRegistrator/usableActionItems.ts +66 -0
  117. package/zappFrameworkUtils/localStorageHelper.ts +10 -2
  118. package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
  119. package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
  120. package/playerUtils/getPlayerActionButtons.ts +0 -17
@@ -0,0 +1,300 @@
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("opens an empty inline collection when dynamic collection options are present", async () => {
81
+ const result = await openBottomSheetAction({
82
+ type: "openBottomSheet",
83
+ options: {
84
+ header: { title: "Queue" },
85
+ content: {
86
+ items: [],
87
+ emptyMessage: "Queued items will be added here",
88
+ dynamicCollection: {
89
+ operations: ["remove"],
90
+ provider: "@{provider/queue}",
91
+ },
92
+ },
93
+ },
94
+ } as any);
95
+
96
+ expect(result).toBe(ActionResult.Success);
97
+
98
+ const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
99
+
100
+ expect(menu.content.items).toEqual([]);
101
+ expect(menu.content.emptyMessage).toBe("Queued items will be added here");
102
+
103
+ expect(menu.content.dynamicCollection).toMatchObject({
104
+ operations: ["remove"],
105
+ provider: "@{provider/queue}",
106
+ });
107
+ });
108
+
109
+ it("accepts empty inline items when dynamic_collection_options live on extensions", async () => {
110
+ const result = await openBottomSheetAction({
111
+ type: "openBottomSheet",
112
+ options: {
113
+ content: {
114
+ items: [],
115
+ extensions: {
116
+ dynamic_collection_options: {
117
+ operations: "remove,reorder",
118
+ provider: "@{provider/offline}",
119
+ },
120
+ },
121
+ },
122
+ },
123
+ } as any);
124
+
125
+ expect(result).toBe(ActionResult.Success);
126
+
127
+ const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
128
+
129
+ expect(menu.content.items).toEqual([]);
130
+
131
+ expect(menu.content.dynamicCollection).toMatchObject({
132
+ operations: ["remove", "reorder"],
133
+ provider: "@{provider/offline}",
134
+ });
135
+ });
136
+
137
+ it("returns an error for an empty items array with no source", async () => {
138
+ const result = await openBottomSheetAction({
139
+ type: "openBottomSheet",
140
+ options: {
141
+ content: { items: [] },
142
+ },
143
+ } as any);
144
+
145
+ expect(result).toBe(ActionResult.Error);
146
+ expect(modalOrchestrator.open).not.toHaveBeenCalled();
147
+ });
148
+
149
+ it("forwards content.emptyMessage onto the menu", async () => {
150
+ const result = await openBottomSheetAction({
151
+ type: "openBottomSheet",
152
+ options: {
153
+ header: { title: "Queue" },
154
+ content: {
155
+ items: [{ id: "t1", title: "Track 1" }],
156
+ emptyMessage: "Queued items will be added here",
157
+ },
158
+ },
159
+ } as any);
160
+
161
+ expect(result).toBe(ActionResult.Success);
162
+
163
+ const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
164
+
165
+ expect(menu.content.emptyMessage).toBe("Queued items will be added here");
166
+ });
167
+
168
+ it("pushes a new sheet by default even when another sheet is already open", async () => {
169
+ (modalOrchestrator as any).stackSize = 1;
170
+
171
+ await openBottomSheetAction(speedSheetAction);
172
+
173
+ expect(modalOrchestrator.open).toHaveBeenCalledTimes(1);
174
+ expect(modalOrchestrator.replace).not.toHaveBeenCalled();
175
+ });
176
+
177
+ it("replaces the current sheet when options.replace is true", async () => {
178
+ (modalOrchestrator as any).stackSize = 1;
179
+
180
+ await openBottomSheetAction({
181
+ ...speedSheetAction,
182
+ options: { ...speedSheetAction.options, replace: true },
183
+ });
184
+
185
+ expect(modalOrchestrator.replace).toHaveBeenCalledTimes(1);
186
+ expect(modalOrchestrator.open).not.toHaveBeenCalled();
187
+ });
188
+
189
+ it("executes all actions in tap_actions when onItemPress is called", async () => {
190
+ const multiActionSheet = {
191
+ type: "openBottomSheet",
192
+ options: {
193
+ header: { title: "Target Playlists" },
194
+ content: {
195
+ role: "collection_selector",
196
+ behavior: { selectMode: "none", currentSelection: [] },
197
+ items: [
198
+ {
199
+ id: "playlist-1",
200
+ title: "My Playlist",
201
+ extensions: {
202
+ tap_actions: {
203
+ actions: [
204
+ {
205
+ type: "sendCloudEvent",
206
+ options: { subject: "add_collection_to_collection" },
207
+ },
208
+ {
209
+ type: "showToast",
210
+ options: { message: "Added to playlist" },
211
+ },
212
+ { type: "dismissBottomSheet", options: {} },
213
+ ],
214
+ },
215
+ },
216
+ },
217
+ ],
218
+ },
219
+ },
220
+ } as any;
221
+
222
+ await openBottomSheetAction(multiActionSheet);
223
+
224
+ const [menu, onItemPress] = (modalOrchestrator.open as jest.Mock).mock
225
+ .calls[0];
226
+
227
+ expect(menu.content.items[0].actions).toHaveLength(3);
228
+
229
+ const handleActionsSpy = jest
230
+ .spyOn(actionExecutor, "handleActions")
231
+ .mockResolvedValue(ActionResult.Success);
232
+
233
+ await onItemPress(menu.content.items[0]);
234
+
235
+ expect(handleActionsSpy).toHaveBeenCalledWith(
236
+ [
237
+ {
238
+ type: "sendCloudEvent",
239
+ options: { subject: "add_collection_to_collection" },
240
+ },
241
+ {
242
+ type: "showToast",
243
+ options: { message: "Added to playlist" },
244
+ },
245
+ { type: "dismissBottomSheet", options: {} },
246
+ ],
247
+ expect.objectContaining({
248
+ entry: menu.content.items[0],
249
+ })
250
+ );
251
+
252
+ handleActionsSpy.mockRestore();
253
+ });
254
+
255
+ it("executes preceding actions and excludes presentSubMenu from actionExecutor", async () => {
256
+ const subMenuSheet = {
257
+ type: "openBottomSheet",
258
+ options: {
259
+ header: { title: "Menu" },
260
+ content: {
261
+ items: [
262
+ {
263
+ id: "item-with-submenu",
264
+ title: "More Options",
265
+ extensions: {
266
+ tap_actions: {
267
+ actions: [
268
+ { type: "sendAnalytics", options: { event: "click_more" } },
269
+ {
270
+ type: "presentSubMenu",
271
+ menu: { content: { title: "Sub Options", items: [] } },
272
+ },
273
+ ],
274
+ },
275
+ },
276
+ },
277
+ ],
278
+ },
279
+ },
280
+ } as any;
281
+
282
+ await openBottomSheetAction(subMenuSheet);
283
+
284
+ const [menu, onItemPress] = (modalOrchestrator.open as jest.Mock).mock
285
+ .calls[0];
286
+
287
+ const handleActionsSpy = jest
288
+ .spyOn(actionExecutor, "handleActions")
289
+ .mockResolvedValue(ActionResult.Success);
290
+
291
+ await onItemPress(menu.content.items[0]);
292
+
293
+ expect(handleActionsSpy).toHaveBeenCalledWith(
294
+ [{ type: "sendAnalytics", options: { event: "click_more" } }],
295
+ expect.objectContaining({ entry: menu.content.items[0] })
296
+ );
297
+
298
+ handleActionsSpy.mockRestore();
299
+ });
300
+ });
@@ -0,0 +1,127 @@
1
+ import { createPresentScreenAction } from "../presentScreen";
2
+ import { ActionResult } from "../../ActionExecutor";
3
+
4
+ const contextEntry = { id: "context-entry" } as any;
5
+
6
+ const succeeded = { success: true, cancelled: false };
7
+
8
+ const cancelled = { success: false, cancelled: true };
9
+
10
+ describe("presentScreenAction", () => {
11
+ let presentScreen: jest.Mock;
12
+ let presentScreenAction: ReturnType<typeof createPresentScreenAction>;
13
+
14
+ beforeEach(() => {
15
+ presentScreen = jest.fn().mockResolvedValue(succeeded);
16
+ presentScreenAction = createPresentScreenAction(presentScreen);
17
+ });
18
+
19
+ it("presents the screen named by typeMapping", async () => {
20
+ await presentScreenAction({
21
+ type: "presentScreen",
22
+ options: { typeMapping: "parent_lock" },
23
+ });
24
+
25
+ expect(presentScreen).toHaveBeenCalledWith({
26
+ typeMapping: "parent_lock",
27
+ entry: undefined,
28
+ });
29
+ });
30
+
31
+ it("fails without presenting anything when typeMapping is missing", async () => {
32
+ const result = await presentScreenAction({
33
+ type: "presentScreen",
34
+ options: {},
35
+ });
36
+
37
+ expect(result).toBe(ActionResult.Error);
38
+ expect(presentScreen).not.toHaveBeenCalled();
39
+ });
40
+
41
+ it("resolves the '@{entry/}' token to the entry from the execution context", async () => {
42
+ await presentScreenAction(
43
+ {
44
+ type: "presentScreen",
45
+ options: { typeMapping: "parent_lock", entry: "@{entry/}" },
46
+ },
47
+ { entry: contextEntry }
48
+ );
49
+
50
+ expect(presentScreen).toHaveBeenCalledWith({
51
+ typeMapping: "parent_lock",
52
+ entry: contextEntry,
53
+ });
54
+ });
55
+
56
+ it("presents an entry supplied inline in the options", async () => {
57
+ const inlineEntry = { id: "inline-entry" } as any;
58
+
59
+ await presentScreenAction({
60
+ type: "presentScreen",
61
+ options: { typeMapping: "parent_lock", entry: inlineEntry },
62
+ });
63
+
64
+ expect(presentScreen).toHaveBeenCalledWith({
65
+ typeMapping: "parent_lock",
66
+ entry: inlineEntry,
67
+ });
68
+ });
69
+
70
+ it("fails without presenting anything when the entry option is not an object", async () => {
71
+ const result = await presentScreenAction({
72
+ type: "presentScreen",
73
+ options: { typeMapping: "parent_lock", entry: "not-an-entry" as any },
74
+ });
75
+
76
+ expect(result).toBe(ActionResult.Error);
77
+ expect(presentScreen).not.toHaveBeenCalled();
78
+ });
79
+
80
+ it("succeeds when the presented screen reports success", async () => {
81
+ presentScreen.mockResolvedValue(succeeded);
82
+
83
+ const result = await presentScreenAction({
84
+ type: "presentScreen",
85
+ options: { typeMapping: "parent_lock" },
86
+ });
87
+
88
+ expect(result).toBe(ActionResult.Success);
89
+ });
90
+
91
+ it("cancels the action chain when the presented screen is cancelled", async () => {
92
+ presentScreen.mockResolvedValue(cancelled);
93
+
94
+ const result = await presentScreenAction({
95
+ type: "presentScreen",
96
+ options: { typeMapping: "parent_lock" },
97
+ });
98
+
99
+ expect(result).toBe(ActionResult.Cancel);
100
+ });
101
+
102
+ it("cancels the action chain when the presented screen reports failure", async () => {
103
+ presentScreen.mockResolvedValue({ success: false, cancelled: false });
104
+
105
+ const result = await presentScreenAction({
106
+ type: "presentScreen",
107
+ options: { typeMapping: "parent_lock" },
108
+ });
109
+
110
+ expect(result).toBe(ActionResult.Cancel);
111
+ });
112
+
113
+ it("errors when the screen could not be presented at all", async () => {
114
+ presentScreen.mockResolvedValue({
115
+ success: false,
116
+ cancelled: false,
117
+ error: "can not resolve screen type mapping: parent_lock",
118
+ });
119
+
120
+ const result = await presentScreenAction({
121
+ type: "presentScreen",
122
+ options: { typeMapping: "parent_lock" },
123
+ });
124
+
125
+ expect(result).toBe(ActionResult.Error);
126
+ });
127
+ });
@@ -0,0 +1,49 @@
1
+ import { showAlertAction } from "../showAlert";
2
+ import { ActionResult } from "../../ActionExecutor";
3
+ import { showAlertDialog } from "../../../alertUtils";
4
+
5
+ jest.mock("../../../alertUtils", () => ({
6
+ showAlertDialog: jest.fn(),
7
+ }));
8
+
9
+ const dialog = showAlertDialog as jest.Mock;
10
+
11
+ const dismiss = () => dialog.mock.calls[0][0].completion();
12
+
13
+ describe("showAlert", () => {
14
+ beforeEach(() => dialog.mockReset());
15
+
16
+ it("shows the notice and resolves once it is dismissed", async () => {
17
+ const result = showAlertAction({
18
+ type: "showAlert",
19
+ options: { title: "Locked", message: "Ask the account owner." },
20
+ });
21
+
22
+ expect(dialog).toHaveBeenCalledWith(
23
+ expect.objectContaining({
24
+ title: "Locked",
25
+ message: "Ask the account owner.",
26
+ okButtonText: "OK",
27
+ })
28
+ );
29
+
30
+ dismiss();
31
+
32
+ // Dismissing a notice is not a cancellation: the chain carries on.
33
+ await expect(result).resolves.toBe(ActionResult.Success);
34
+ });
35
+
36
+ it("takes the dismiss label from the action", async () => {
37
+ const result = showAlertAction({
38
+ type: "showAlert",
39
+ options: { title: "Locked", okButtonText: "Got it" },
40
+ });
41
+
42
+ expect(dialog).toHaveBeenCalledWith(
43
+ expect.objectContaining({ okButtonText: "Got it" })
44
+ );
45
+
46
+ dismiss();
47
+ await result;
48
+ });
49
+ });
@@ -11,14 +11,13 @@ describe("showToastAction", () => {
11
11
  jest.clearAllMocks();
12
12
  });
13
13
 
14
- it("calls postEvent with showToast payload and returns ActionResult.Success", async () => {
14
+ it("calls postEvent with confirmation source, default timeout, and returns Success", async () => {
15
15
  const action = {
16
16
  type: "showToast",
17
17
  options: {
18
18
  id: "toast-1",
19
19
  message: "Added to queue",
20
20
  extraMessage: "Extra info",
21
- timeout: 3000,
22
21
  },
23
22
  };
24
23
 
@@ -32,13 +31,38 @@ describe("showToastAction", () => {
32
31
  message: "Added to queue",
33
32
  extraMessage: "Extra info",
34
33
  style: undefined,
35
- timeout: 3000,
34
+ timeout: 5000,
35
+ source: "confirmation",
36
36
  },
37
37
  ]);
38
38
 
39
39
  expect(result).toBe(ActionResult.Success);
40
40
  });
41
41
 
42
+ it("preserves an explicit timeout and style override", async () => {
43
+ const action = {
44
+ type: "showToast",
45
+ options: {
46
+ message: "Playlist created",
47
+ timeout: 3000,
48
+ style: { backgroundColor: "#00FF00" },
49
+ },
50
+ };
51
+
52
+ await showToastAction(action);
53
+
54
+ expect(postEvent).toHaveBeenCalledWith("showToast", [
55
+ {
56
+ id: undefined,
57
+ message: "Playlist created",
58
+ extraMessage: undefined,
59
+ style: { backgroundColor: "#00FF00" },
60
+ timeout: 3000,
61
+ source: "confirmation",
62
+ },
63
+ ]);
64
+ });
65
+
42
66
  it("handles missing or empty options without throwing", async () => {
43
67
  const action = {
44
68
  type: "showToast",
@@ -54,7 +78,8 @@ describe("showToastAction", () => {
54
78
  message: undefined,
55
79
  extraMessage: undefined,
56
80
  style: undefined,
57
- timeout: undefined,
81
+ timeout: 5000,
82
+ source: "confirmation",
58
83
  },
59
84
  ]);
60
85
 
@@ -1,5 +1,5 @@
1
1
  /// <reference types="@applicaster/applicaster-types" />
2
- import { dismissModal } from "../../modalState";
2
+ import { dismissModal, modalOrchestrator } from "../../modalState";
3
3
  import { ActionResult } from "../ActionExecutor";
4
4
  import { ActionHandler } from "../types";
5
5
  import { createLogger } from "../../logger";
@@ -16,6 +16,7 @@ export const dismissBottomSheetAction: ActionHandler<
16
16
  any
17
17
  > = async (): Promise<ActionResult> => {
18
18
  log_info("handleAction: dismissBottomSheet");
19
+ modalOrchestrator.close();
19
20
  dismissModal();
20
21
 
21
22
  return ActionResult.Success;
@@ -0,0 +1,60 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler } from "../types";
4
+ import { createLogger } from "../../logger";
5
+
6
+ const { log_info } = createLogger({
7
+ subsystem: "ActionExecutorContext",
8
+ category: "General",
9
+ });
10
+
11
+ /**
12
+ * Options for the goBack action.
13
+ */
14
+ export interface GoBackOptions {
15
+ /**
16
+ * Navigate to the home screen when there is no screen to go back to.
17
+ * Defaults to true.
18
+ */
19
+ fallbackToHome?: boolean;
20
+
21
+ /**
22
+ * Go back to the first screen of the stack instead of the previous one.
23
+ * Defaults to false.
24
+ */
25
+ backToTop?: boolean;
26
+ }
27
+
28
+ /**
29
+ * Creates a go back action handler with the provided dependencies.
30
+ * This factory pattern allows the action to access navigation state at runtime.
31
+ *
32
+ * @param navigator - The app navigator performing the back navigation
33
+ * @returns An action handler that navigates back
34
+ */
35
+ export function createGoBackAction(
36
+ navigator: QuickBrickAppNavigator
37
+ ): ActionHandler<GoBackOptions> {
38
+ return async function goBackAction(action): Promise<ActionResult> {
39
+ const fallbackToHome = action.options?.fallbackToHome ?? true;
40
+ const backToTop = action.options?.backToTop ?? false;
41
+
42
+ // With fallbackToHome on, the navigator goes home on an empty stack by
43
+ // itself. The guard only matters when the caller opted out of that.
44
+ if (!fallbackToHome && !navigator.canGoBack()) {
45
+ log_info(
46
+ "goBack: no screen to go back to and fallbackToHome is disabled, ignoring"
47
+ );
48
+
49
+ return ActionResult.Error;
50
+ }
51
+
52
+ log_info(
53
+ `goBack: navigating back, fallbackToHome: ${fallbackToHome}, backToTop: ${backToTop}`
54
+ );
55
+
56
+ navigator.goBack(fallbackToHome, false, backToTop);
57
+
58
+ return ActionResult.Success;
59
+ };
60
+ }
@@ -0,0 +1,31 @@
1
+ /// <reference types="@applicaster/applicaster-types" />
2
+ import { ActionResult } from "../ActionExecutor";
3
+ import { ActionHandler } from "../types";
4
+ import { createLogger } from "../../logger";
5
+
6
+ const { log_info } = createLogger({
7
+ subsystem: "ActionExecutorContext",
8
+ category: "General",
9
+ });
10
+
11
+ /**
12
+ * Creates a go home action handler with the provided dependencies.
13
+ * This factory pattern allows the action to access navigation state at runtime.
14
+ *
15
+ * The navigator's `initialLaunch` flag is intentionally not exposed: it selects
16
+ * the offline home river during app bootstrap and is not a per-action choice.
17
+ *
18
+ * @param navigator - The app navigator performing the navigation
19
+ * @returns An action handler that navigates to the home screen
20
+ */
21
+ export function createGoHomeAction(
22
+ navigator: QuickBrickAppNavigator
23
+ ): ActionHandler {
24
+ return async function goHomeAction(): Promise<ActionResult> {
25
+ log_info("goHome: navigating to the home screen");
26
+
27
+ navigator.goHome();
28
+
29
+ return ActionResult.Success;
30
+ };
31
+ }
@@ -15,6 +15,8 @@ export { appRestartAction } from "./appRestart";
15
15
 
16
16
  export { confirmDialogAction } from "./confirmDialog";
17
17
 
18
+ export { showAlertAction } from "./showAlert";
19
+
18
20
  export { sendCloudEventAction } from "./sendCloudEvent";
19
21
 
20
22
  export { sessionStorageToggleFlagAction } from "./sessionStorageToggleFlag";
@@ -27,6 +29,12 @@ export { screenToggleFlagAction } from "./screenToggleFlag";
27
29
 
28
30
  export { createNavigateToScreenAction } from "./navigateToScreen";
29
31
 
32
+ export { createPresentScreenAction } from "./presentScreen";
33
+
34
+ export { createGoBackAction } from "./goBack";
35
+
36
+ export { createGoHomeAction } from "./goHome";
37
+
30
38
  export { showToastAction } from "./showToast";
31
39
 
32
40
  export { openBottomSheetAction } from "./openBottomSheet";