@applicaster/zapp-react-native-utils 16.0.0-alpha.1593888345 → 16.0.0-alpha.1701179921
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 +10 -1
- package/actionsExecutor/ActionExecutorContext.tsx +3 -0
- package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +88 -0
- package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
- package/actionsExecutor/actions/__tests__/showToast.test.ts +2 -2
- package/actionsExecutor/actions/index.ts +2 -0
- package/actionsExecutor/actions/openBottomSheet.ts +19 -6
- package/actionsExecutor/actions/showAlert.ts +51 -0
- package/actionsExecutor/actions/showToast.ts +2 -2
- package/actionsExecutor/consts.ts +1 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +4 -11
- package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +9 -2
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +15 -2
- package/appUtils/playerManager/OverlayObserver/utils.ts +2 -5
- package/appUtils/playerManager/__tests__/playerNative.test.ts +76 -0
- package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
- package/appUtils/playerManager/const.ts +13 -0
- package/appUtils/playerManager/player.ts +10 -0
- package/appUtils/playerManager/playerNative.ts +22 -0
- package/appUtils/playerManager/playerNativeCommand.ts +3 -6
- package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
- package/arrayUtils/index.ts +26 -43
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +78 -69
- package/configurationUtils/modalBlocksParser.ts +24 -106
- package/entryActions/__tests__/buildEntryActions.test.ts +97 -18
- package/entryActions/aliasPresentation.ts +26 -42
- package/entryActions/buildEntryActions.ts +1 -0
- package/entryActions/index.ts +0 -2
- package/modalState/ModalOrchestrator.ts +1 -0
- package/modalState/RemoteEditableCollection.ts +9 -1
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +16 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +90 -1
- package/modalState/__tests__/useModalStoreState.test.ts +142 -0
- package/modalState/store.ts +9 -2
- package/modalState/types.ts +3 -0
- package/modalState/useBottomSheetContent.ts +17 -12
- package/package.json +2 -2
- package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
- package/pluginUtils/index.ts +29 -0
- package/reactHooks/cell-click/__tests__/index.test.js +64 -0
- package/reactHooks/cell-click/index.ts +21 -14
- package/reactHooks/navigation/__tests__/index.test.tsx +128 -1
- package/reactHooks/navigation/useRoute.ts +8 -4
|
@@ -60,7 +60,7 @@ describe("buildEntryActions - alias & label resolution", () => {
|
|
|
60
60
|
expect(state.label).toBe("Label Property Action");
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
-
it("
|
|
63
|
+
it("humanizes an un-overridden alias and falls back to the placeholder asset", () => {
|
|
64
64
|
const entry = {
|
|
65
65
|
id: "entry-3",
|
|
66
66
|
extensions: {
|
|
@@ -71,11 +71,7 @@ describe("buildEntryActions - alias & label resolution", () => {
|
|
|
71
71
|
dismiss_on_action: true,
|
|
72
72
|
},
|
|
73
73
|
{
|
|
74
|
-
button: { alias: "
|
|
75
|
-
actions: [{ type: "test" }],
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
button: { alias: "delete_collection" },
|
|
74
|
+
button: { alias: "custom_unknown_action" },
|
|
79
75
|
actions: [{ type: "test" }],
|
|
80
76
|
},
|
|
81
77
|
],
|
|
@@ -84,42 +80,86 @@ describe("buildEntryActions - alias & label resolution", () => {
|
|
|
84
80
|
|
|
85
81
|
const actions = resolveEntryActions(entry as any);
|
|
86
82
|
|
|
87
|
-
expect(actions).toHaveLength(
|
|
83
|
+
expect(actions).toHaveLength(2);
|
|
88
84
|
|
|
85
|
+
// No built-in alias vocabulary any more: underscores become spaces and
|
|
86
|
+
// only the first letter is capitalized, so "queue" stays lowercase.
|
|
89
87
|
expect(actions[0].action.initialEntryState(entry as any)).toMatchObject({
|
|
90
88
|
state: 0,
|
|
91
|
-
label: "Add all to
|
|
89
|
+
label: "Add all to queue",
|
|
92
90
|
});
|
|
93
91
|
|
|
94
92
|
expect(actions[1].action.initialEntryState(entry as any)).toMatchObject({
|
|
95
93
|
state: 0,
|
|
96
|
-
label: "
|
|
94
|
+
label: "Custom unknown action",
|
|
97
95
|
});
|
|
98
96
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
97
|
+
// The asset has no such fallback: without an override it is the red-box
|
|
98
|
+
// placeholder, so a missing Studio icon is visible rather than absent.
|
|
99
|
+
for (const action of actions) {
|
|
100
|
+
expect(action.action.initialEntryState(entry as any)).toMatchObject({
|
|
101
|
+
asset: expect.stringMatching(/^data:image\/png;base64,/),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
103
104
|
});
|
|
104
105
|
|
|
105
|
-
it("
|
|
106
|
+
it("prefers aliasPresentation overrides over the humanized fallbacks", () => {
|
|
107
|
+
const deps = {
|
|
108
|
+
actionExecutor: { handleActions: jest.fn() } as any,
|
|
109
|
+
actionContext: {},
|
|
110
|
+
aliasPresentation: {
|
|
111
|
+
labels: { add_all_to_queue: "Add all to Queue" },
|
|
112
|
+
assets: { add_all_to_queue: "http://example.com/queue.png" },
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
|
|
106
116
|
const entry = {
|
|
107
117
|
id: "entry-4",
|
|
108
118
|
extensions: {
|
|
109
119
|
entry_action: [
|
|
110
120
|
{
|
|
111
|
-
button: { alias: "
|
|
121
|
+
button: { alias: "add_all_to_queue" },
|
|
122
|
+
actions: [{ type: "test" }],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
button: { alias: "not_overridden" },
|
|
112
126
|
actions: [{ type: "test" }],
|
|
113
127
|
},
|
|
114
128
|
],
|
|
115
129
|
},
|
|
116
130
|
};
|
|
117
131
|
|
|
118
|
-
const actions =
|
|
132
|
+
const actions = buildEntryActions(entry as any, deps);
|
|
119
133
|
|
|
120
|
-
expect(actions).
|
|
134
|
+
expect(actions[0].action.initialEntryState(entry as any)).toMatchObject({
|
|
135
|
+
label: "Add all to Queue",
|
|
136
|
+
asset: "http://example.com/queue.png",
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
// Overrides are per-alias, so an alias absent from the map still humanizes.
|
|
140
|
+
expect(actions[1].action.initialEntryState(entry as any)).toMatchObject({
|
|
141
|
+
label: "Not overridden",
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("returns no asset when the button has neither iconURL nor alias", () => {
|
|
146
|
+
const entry = {
|
|
147
|
+
id: "entry-5",
|
|
148
|
+
extensions: {
|
|
149
|
+
entry_action: [
|
|
150
|
+
{
|
|
151
|
+
button: { label: "Plain Label" },
|
|
152
|
+
actions: [{ type: "test" }],
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
const actions = resolveEntryActions(entry as any);
|
|
121
159
|
const state = actions[0].action.initialEntryState(entry as any);
|
|
122
|
-
|
|
160
|
+
|
|
161
|
+
expect(state.label).toBe("Plain Label");
|
|
162
|
+
expect(state.asset).toBeUndefined();
|
|
123
163
|
});
|
|
124
164
|
|
|
125
165
|
it("uses actionExecutor.getActionState for plugin-provided label and asset", () => {
|
|
@@ -154,3 +194,42 @@ describe("buildEntryActions - alias & label resolution", () => {
|
|
|
154
194
|
});
|
|
155
195
|
});
|
|
156
196
|
});
|
|
197
|
+
|
|
198
|
+
describe("buildEntryActions - invokeAction execution context", () => {
|
|
199
|
+
it("forwards the List component from invoke options into handleActions", async () => {
|
|
200
|
+
const handleActions = jest.fn();
|
|
201
|
+
|
|
202
|
+
const component = {
|
|
203
|
+
id: "list-1",
|
|
204
|
+
data: { source: "https://example.com/user/collections/abc" },
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
const deps = {
|
|
208
|
+
actionExecutor: { handleActions } as any,
|
|
209
|
+
actionContext: { screenData: { id: "playlist-screen" } },
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const entry = {
|
|
213
|
+
id: "entry-1",
|
|
214
|
+
extensions: {
|
|
215
|
+
entry_action: [
|
|
216
|
+
{
|
|
217
|
+
button: { title: "Edit Name" },
|
|
218
|
+
actions: [{ type: "refreshComponent" }],
|
|
219
|
+
},
|
|
220
|
+
],
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const [action] = buildEntryActions(entry as any, deps);
|
|
225
|
+
|
|
226
|
+
await action.action.invokeAction(entry as any, { component });
|
|
227
|
+
|
|
228
|
+
expect(handleActions).toHaveBeenCalledWith([{ type: "refreshComponent" }], {
|
|
229
|
+
entry,
|
|
230
|
+
entryContext: entry,
|
|
231
|
+
screenData: { id: "playlist-screen" },
|
|
232
|
+
component,
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
});
|
|
@@ -1,52 +1,29 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Presentation
|
|
2
|
+
* Presentation fallbacks for backend action aliases.
|
|
3
3
|
*
|
|
4
4
|
* Entries may declare an action by `alias` alone, without a label or an icon.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* There is no built-in alias vocabulary: a label falls back to a humanized
|
|
6
|
+
* version of the alias itself, and an icon falls back to an inline placeholder
|
|
7
|
+
* that is deliberately conspicuous, so a missing asset reads as unconfigured
|
|
8
|
+
* rather than as a deliberate blank.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
9
|
-
* alias vocabulary
|
|
10
|
-
*
|
|
10
|
+
* Both are last resorts, not a framework guarantee: an app that speaks its own
|
|
11
|
+
* alias vocabulary or needs other languages passes labels and assets through
|
|
12
|
+
* `EntryActionDeps.aliasPresentation`, which is consulted per alias.
|
|
11
13
|
*/
|
|
12
14
|
|
|
13
15
|
import { EntryAction } from "./types";
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
"https://assets-secure.applicaster.com/zapp/assets/app_family/1710/906728572617/playlist_add_24dp_FFFFFF_FILL0_wght400_GRAD0_opsz24.png";
|
|
17
|
-
|
|
18
|
-
const REMOVE_ICON =
|
|
19
|
-
"https://assets-secure.applicaster.com/zapp/assets/app_family/1710/372097240191/remove_24dp_EA3323_FILL0_wght400_GRAD0_opsz24.png";
|
|
20
|
-
|
|
21
|
-
const EDIT_ICON =
|
|
22
|
-
"https://upload.wikimedia.org/wikipedia/commons/b/b6/Edit-icon.png";
|
|
23
|
-
|
|
24
|
-
/** Known backend action alias labels. */
|
|
25
|
-
export const ALIAS_LABELS: Record<string, string> = {
|
|
26
|
-
add_to_playlist: "Add to Playlist",
|
|
27
|
-
add_to_queue: "Add to Queue",
|
|
28
|
-
add_all_to_queue: "Add all to Queue",
|
|
29
|
-
play_all: "Play All",
|
|
30
|
-
remove_item: "Remove item",
|
|
31
|
-
delete_collection: "Delete collection",
|
|
32
|
-
create_collection: "Create collection",
|
|
33
|
-
edit: "Edit",
|
|
34
|
-
edit_name: "Edit Name & Details",
|
|
35
|
-
};
|
|
17
|
+
import { createLogger } from "@applicaster/zapp-react-native-utils/logger";
|
|
36
18
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
remove_item: REMOVE_ICON,
|
|
44
|
-
delete_collection: REMOVE_ICON,
|
|
45
|
-
edit: EDIT_ICON,
|
|
46
|
-
edit_name: EDIT_ICON,
|
|
47
|
-
};
|
|
19
|
+
const logger = createLogger({
|
|
20
|
+
category: "zapp-react-native-utils:aliasPresentation",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const PLACEHOLDER_RED_BOX =
|
|
24
|
+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAAJ0lEQVR4nO3NMQEAAAjDsIF/z2ACvlRAU5NMHuvPOQAAAAAAAMBdC/07Ai5sNw+CAAAAAElFTkSuQmCC";
|
|
48
25
|
|
|
49
|
-
/** Per-app
|
|
26
|
+
/** Per-app labels and icons, keyed by alias, that outrank the fallbacks. */
|
|
50
27
|
export type AliasPresentation = {
|
|
51
28
|
labels?: Record<string, string>;
|
|
52
29
|
assets?: Record<string, string>;
|
|
@@ -56,7 +33,7 @@ function formatAliasLabel(
|
|
|
56
33
|
alias: string,
|
|
57
34
|
overrides?: AliasPresentation
|
|
58
35
|
): string {
|
|
59
|
-
const label = overrides?.labels?.[alias]
|
|
36
|
+
const label = overrides?.labels?.[alias];
|
|
60
37
|
|
|
61
38
|
if (label) {
|
|
62
39
|
return label;
|
|
@@ -107,7 +84,7 @@ export function resolveButtonLabel(
|
|
|
107
84
|
return "";
|
|
108
85
|
}
|
|
109
86
|
|
|
110
|
-
/** Icon to show for an entry action: explicit iconURL,
|
|
87
|
+
/** Icon to show for an entry action: explicit iconURL, matching alias asset or fallback to red box. */
|
|
111
88
|
export function resolveButtonAsset(
|
|
112
89
|
button: EntryAction["button"],
|
|
113
90
|
overrides?: AliasPresentation
|
|
@@ -120,5 +97,12 @@ export function resolveButtonAsset(
|
|
|
120
97
|
return undefined;
|
|
121
98
|
}
|
|
122
99
|
|
|
123
|
-
|
|
100
|
+
if (!overrides?.assets?.[button.alias]) {
|
|
101
|
+
logger.log_warning(
|
|
102
|
+
`Entry action alias '${button.alias}' was not resolved by any plugin feedDecorator or app override. Falling back to placeholder red box.`,
|
|
103
|
+
{ data: { button } }
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return overrides?.assets?.[button.alias] ?? PLACEHOLDER_RED_BOX;
|
|
124
108
|
}
|
package/entryActions/index.ts
CHANGED
|
@@ -123,7 +123,14 @@ export class RemoteEditableCollection implements EditableCollection {
|
|
|
123
123
|
|
|
124
124
|
try {
|
|
125
125
|
for (const action of addEvents) {
|
|
126
|
-
|
|
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
|
);
|
|
@@ -44,4 +44,20 @@ describe("ModalOrchestrator phase 3", () => {
|
|
|
44
44
|
expect(props.title).toBe("Sleep Timer");
|
|
45
45
|
expect(props.summary).toBe("remaining");
|
|
46
46
|
});
|
|
47
|
+
|
|
48
|
+
it("forwards the queue empty message onto the sheet props", () => {
|
|
49
|
+
modalOrchestrator.open({
|
|
50
|
+
header: { title: "Queue" },
|
|
51
|
+
content: {
|
|
52
|
+
title: "Queue",
|
|
53
|
+
items: [],
|
|
54
|
+
emptyMessage: "Queued items will be added here",
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const props = (modalStore.getState().modalState.screen as any)
|
|
59
|
+
?.modalBottomSheetContentProps;
|
|
60
|
+
|
|
61
|
+
expect(props.emptyMessage).toBe("Queued items will be added here");
|
|
62
|
+
});
|
|
47
63
|
});
|
|
@@ -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
|
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { act, renderHook } from "@testing-library/react-native";
|
|
2
|
+
|
|
3
|
+
import { modalStore, useModalStoreState } from "../";
|
|
4
|
+
|
|
5
|
+
const item = { id: "river-general", name: "Test Modal" };
|
|
6
|
+
const props = { entry: { id: "modal-entry-1" } };
|
|
7
|
+
|
|
8
|
+
const openModal = () =>
|
|
9
|
+
act(() => {
|
|
10
|
+
modalStore.getState().openModal({ item, props } as any);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Counts every render of the hook so the tests can assert on subscription
|
|
14
|
+
// behaviour, not just on the returned value.
|
|
15
|
+
const renderModalStoreState = (skipSubscription?: boolean) => {
|
|
16
|
+
const renders = { count: 0 };
|
|
17
|
+
|
|
18
|
+
const view = renderHook(() => {
|
|
19
|
+
renders.count += 1;
|
|
20
|
+
|
|
21
|
+
return skipSubscription === undefined
|
|
22
|
+
? useModalStoreState()
|
|
23
|
+
: useModalStoreState(skipSubscription);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return { ...view, renders };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
describe("useModalStoreState", () => {
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
act(() => {
|
|
32
|
+
modalStore.getState().dismissModal();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("when subscribed (default)", () => {
|
|
37
|
+
it("returns the live modal state when called without arguments", () => {
|
|
38
|
+
const { result } = renderModalStoreState();
|
|
39
|
+
|
|
40
|
+
expect(result.current.visible).toBe(false);
|
|
41
|
+
|
|
42
|
+
openModal();
|
|
43
|
+
|
|
44
|
+
expect(result.current.visible).toBe(true);
|
|
45
|
+
expect(result.current.screen).toBe(item);
|
|
46
|
+
expect(result.current.props).toBe(props);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("re-renders the consumer when the modal state changes", () => {
|
|
50
|
+
const { renders } = renderModalStoreState(false);
|
|
51
|
+
|
|
52
|
+
const rendersBeforeOpen = renders.count;
|
|
53
|
+
|
|
54
|
+
openModal();
|
|
55
|
+
|
|
56
|
+
expect(renders.count).toBeGreaterThan(rendersBeforeOpen);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Counterpart to "returns a stable reference across store updates": an open
|
|
60
|
+
// modal is the one point where a live subscription and a skipped one hold
|
|
61
|
+
// different references, which is what makes that assertion meaningful.
|
|
62
|
+
it("returns a new reference while the modal is open", () => {
|
|
63
|
+
const { result } = renderModalStoreState(false);
|
|
64
|
+
|
|
65
|
+
const firstValue = result.current;
|
|
66
|
+
|
|
67
|
+
openModal();
|
|
68
|
+
|
|
69
|
+
expect(result.current).not.toBe(firstValue);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("when subscription is skipped", () => {
|
|
74
|
+
it("reports an empty modal state even while a modal is open", () => {
|
|
75
|
+
openModal();
|
|
76
|
+
|
|
77
|
+
expect(modalStore.getState().modalState.visible).toBe(true);
|
|
78
|
+
|
|
79
|
+
const { result } = renderModalStoreState(true);
|
|
80
|
+
|
|
81
|
+
expect(result.current).toMatchObject({
|
|
82
|
+
visible: false,
|
|
83
|
+
screen: null,
|
|
84
|
+
options: {},
|
|
85
|
+
props: {},
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("does not re-render the consumer when the modal state changes", () => {
|
|
90
|
+
const { renders } = renderModalStoreState(true);
|
|
91
|
+
|
|
92
|
+
const rendersBeforeOpen = renders.count;
|
|
93
|
+
|
|
94
|
+
openModal();
|
|
95
|
+
|
|
96
|
+
expect(renders.count).toBe(rendersBeforeOpen);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// The skipped branch has to hand back a module-level constant. Returning a
|
|
100
|
+
// fresh object would fail zustand's Object.is check and re-render on every
|
|
101
|
+
// store notification - the opposite of what skipping is for.
|
|
102
|
+
it("returns a stable reference across store updates", () => {
|
|
103
|
+
const { result } = renderModalStoreState(true);
|
|
104
|
+
|
|
105
|
+
const firstValue = result.current;
|
|
106
|
+
|
|
107
|
+
openModal();
|
|
108
|
+
|
|
109
|
+
// Asserted while the modal is open: dismissing resets the store to the
|
|
110
|
+
// very same initialModalState object, so an end-to-end round trip would
|
|
111
|
+
// hold this identity even for a live subscription.
|
|
112
|
+
expect(result.current).toBe(firstValue);
|
|
113
|
+
|
|
114
|
+
act(() => {
|
|
115
|
+
modalStore.getState().dismissModal();
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
expect(result.current).toBe(firstValue);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("picks up the current modal state when it starts subscribing", () => {
|
|
123
|
+
let skipSubscription = true;
|
|
124
|
+
|
|
125
|
+
const { result, rerender } = renderHook(() =>
|
|
126
|
+
useModalStoreState(skipSubscription)
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
openModal();
|
|
130
|
+
|
|
131
|
+
expect(result.current.visible).toBe(false);
|
|
132
|
+
|
|
133
|
+
skipSubscription = false;
|
|
134
|
+
|
|
135
|
+
act(() => {
|
|
136
|
+
rerender(undefined);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
expect(result.current.visible).toBe(true);
|
|
140
|
+
expect(result.current.screen).toBe(item);
|
|
141
|
+
});
|
|
142
|
+
});
|
package/modalState/store.ts
CHANGED
|
@@ -98,5 +98,12 @@ export const openBottomSheetModal = ({
|
|
|
98
98
|
});
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
|
|
102
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Pass `skipSubscription` from callers that render outside of a modal: the
|
|
103
|
+
* selector then returns the stable `initialModalState` reference, so the
|
|
104
|
+
* component is never re-rendered by modal state it does not read.
|
|
105
|
+
*/
|
|
106
|
+
export const useModalStoreState = (skipSubscription = false): ModalState =>
|
|
107
|
+
useModalStore<ModalState>((state) =>
|
|
108
|
+
skipSubscription ? initialModalState : state.modalState
|
|
109
|
+
);
|
package/modalState/types.ts
CHANGED
|
@@ -118,6 +118,9 @@ export interface Content {
|
|
|
118
118
|
dynamicCollection?: DynamicCollectionOptions;
|
|
119
119
|
themePluginId?: string;
|
|
120
120
|
styleOverrides?: Record<string, any>;
|
|
121
|
+
/** Shown under Next Up when the queue sheet has no upcoming items. */
|
|
122
|
+
emptyMessage?: string;
|
|
123
|
+
context?: Record<string, any>;
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
export interface Menu {
|