@applicaster/quick-brick-player 16.0.0-rc.6 → 16.0.0-rc.61
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/package.json +6 -6
- package/src/Player/AudioLayer/AudioDescription.tsx +46 -11
- package/src/Player/AudioLayer/AudioPlayerWrapper.tsx +38 -48
- package/src/Player/AudioLayer/Layout/Controls/__tests__/utils.test.ts +66 -0
- package/src/Player/AudioLayer/Layout/Controls/index.tsx +34 -14
- package/src/Player/AudioLayer/Layout/Controls/utils.ts +26 -0
- package/src/Player/AudioLayer/Layout/DockedControls/index.tsx +1 -13
- package/src/Player/AudioLayer/Layout/MobileLayout.tsx +0 -4
- package/src/Player/AudioLayer/Layout/TabletLandscapeLayout.tsx +0 -4
- package/src/Player/AudioLayer/Layout/TabletPortraitLayout.tsx +0 -4
- package/src/Player/AudioLayer/SleepTimerManager.ts +5 -1
- package/src/Player/AudioLayer/SpeedManager.ts +4 -0
- package/src/Player/AudioLayer/__tests__/AudioDescription.test.tsx +147 -0
- package/src/Player/AudioLayer/__tests__/AudioPlayerWrapper.test.tsx +130 -0
- package/src/Player/AudioLayer/__tests__/SleepTimerManager.test.ts +78 -0
- package/src/Player/AudioLayer/__tests__/SpeedManager.test.ts +57 -0
- package/src/Player/AudioLayer/__tests__/playerActions.test.ts +351 -0
- package/src/Player/AudioLayer/__tests__/usePlaylistNavigation.test.ts +387 -0
- package/src/Player/AudioLayer/components/SleepTimerModalHeader/SleepTimerModalHeader.tsx +9 -8
- package/src/Player/AudioLayer/components/SleepTimerModalHeader/__tests__/SleepTimerModalHeader.test.tsx +53 -0
- package/src/Player/AudioLayer/playerActions.ts +280 -0
- package/src/Player/AudioLayer/usePlaylistNavigation.ts +134 -0
- package/src/Player/AudioLayer/useSleepTimerModal.ts +20 -57
- package/src/Player/__tests__/getNativeProps.test.ts +115 -0
- package/src/Player/__tests__/toNativeMetadata.test.ts +77 -0
- package/src/Player/index.tsx +72 -27
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { playerManager } from "@applicaster/zapp-react-native-utils/appUtils";
|
|
2
|
+
import {
|
|
3
|
+
actionExecutor,
|
|
4
|
+
ActionResult,
|
|
5
|
+
} from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutor";
|
|
6
|
+
import { uiActionsRegistry } from "@applicaster/zapp-react-native-utils/uiActionsRegistrator";
|
|
7
|
+
import { modalOrchestrator } from "@applicaster/zapp-react-native-utils/modalState/ModalOrchestrator";
|
|
8
|
+
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
9
|
+
import { firstValueFrom } from "rxjs";
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
PLAYER_ACTION_IDENTIFIERS,
|
|
13
|
+
PLAYER_ACTION_TYPES,
|
|
14
|
+
registerPlayerActions,
|
|
15
|
+
} from "../playerActions";
|
|
16
|
+
import { SpeedController } from "../SpeedManager";
|
|
17
|
+
import { SleepTimerController } from "../SleepTimerManager";
|
|
18
|
+
import { SleepTimerModalHeader } from "../components/SleepTimerModalHeader";
|
|
19
|
+
|
|
20
|
+
jest.mock("../components/SleepTimerModalHeader", () => ({
|
|
21
|
+
SleepTimerModalHeader: function SleepTimerModalHeader() {
|
|
22
|
+
return null;
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
jest.mock("../../Const/sleepTimerOptions", () => ({
|
|
27
|
+
getSleepTimerOptions: (offLabel: string, sleepTimerValue: number | null) => [
|
|
28
|
+
sleepTimerValue ? { label: offLabel, value: 0 } : null,
|
|
29
|
+
{ label: "5 minutes", value: 5 },
|
|
30
|
+
{ label: "15 minutes", value: 15 },
|
|
31
|
+
],
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
jest.mock("@applicaster/zapp-react-native-utils/appUtils", () => ({
|
|
35
|
+
playerManager: {
|
|
36
|
+
getActivePlayer: jest.fn(),
|
|
37
|
+
},
|
|
38
|
+
}));
|
|
39
|
+
|
|
40
|
+
jest.mock(
|
|
41
|
+
"@applicaster/zapp-react-native-utils/modalState/ModalOrchestrator",
|
|
42
|
+
() => ({
|
|
43
|
+
modalOrchestrator: {
|
|
44
|
+
close: jest.fn(),
|
|
45
|
+
stackSize: 0,
|
|
46
|
+
},
|
|
47
|
+
})
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
jest.mock(
|
|
51
|
+
"@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage",
|
|
52
|
+
() => ({
|
|
53
|
+
localStorage: {
|
|
54
|
+
getItem: jest.fn(),
|
|
55
|
+
setItem: jest.fn(),
|
|
56
|
+
removeItem: jest.fn(),
|
|
57
|
+
},
|
|
58
|
+
})
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
describe("playerActions", () => {
|
|
62
|
+
const openedSheets: ActionType[] = [];
|
|
63
|
+
|
|
64
|
+
let player: {
|
|
65
|
+
getConfig: () => Record<string, string>;
|
|
66
|
+
setPlaybackRate: jest.Mock;
|
|
67
|
+
startSleepTimer: jest.Mock;
|
|
68
|
+
cancelSleepTimer: jest.Mock;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
let speedController: SpeedController;
|
|
72
|
+
let sleepController: SleepTimerController;
|
|
73
|
+
let unregisterPlayerActions: () => void;
|
|
74
|
+
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
openedSheets.length = 0;
|
|
77
|
+
jest.clearAllMocks();
|
|
78
|
+
(localStorage.setItem as jest.Mock).mockResolvedValue(undefined);
|
|
79
|
+
(localStorage.removeItem as jest.Mock).mockResolvedValue(undefined);
|
|
80
|
+
|
|
81
|
+
player = {
|
|
82
|
+
getConfig: () => ({
|
|
83
|
+
playback_speed_title: "Playback Speed",
|
|
84
|
+
playback_sleep_title: "Sleep Timer",
|
|
85
|
+
playback_sleep_off_label: "Off",
|
|
86
|
+
sleep_timer: "sleep_timer",
|
|
87
|
+
sleep_timer_active: "sleep_timer_active",
|
|
88
|
+
}),
|
|
89
|
+
setPlaybackRate: jest.fn(),
|
|
90
|
+
startSleepTimer: jest.fn(),
|
|
91
|
+
cancelSleepTimer: jest.fn(),
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
(playerManager.getActivePlayer as jest.Mock).mockReturnValue(player);
|
|
95
|
+
speedController = new SpeedController(player as any);
|
|
96
|
+
sleepController = new SleepTimerController(player as any);
|
|
97
|
+
|
|
98
|
+
[
|
|
99
|
+
"openBottomSheet",
|
|
100
|
+
PLAYER_ACTION_TYPES.OPEN_PLAYBACK_SPEED,
|
|
101
|
+
PLAYER_ACTION_TYPES.OPEN_SLEEP_TIMER,
|
|
102
|
+
PLAYER_ACTION_TYPES.SET_PLAYBACK_SPEED,
|
|
103
|
+
PLAYER_ACTION_TYPES.SET_SLEEP_TIMER,
|
|
104
|
+
].forEach((type) => actionExecutor.unregisterAction(type));
|
|
105
|
+
|
|
106
|
+
actionExecutor.registerAction("openBottomSheet", async (action) => {
|
|
107
|
+
openedSheets.push(action);
|
|
108
|
+
|
|
109
|
+
return ActionResult.Success;
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
unregisterPlayerActions = registerPlayerActions({
|
|
113
|
+
speedController,
|
|
114
|
+
sleepController,
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
afterEach(() => {
|
|
119
|
+
unregisterPlayerActions?.();
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("does not register actions until a player controller is provided", async () => {
|
|
123
|
+
unregisterPlayerActions();
|
|
124
|
+
unregisterPlayerActions = registerPlayerActions({});
|
|
125
|
+
|
|
126
|
+
const result = await actionExecutor.handleAction({
|
|
127
|
+
type: PLAYER_ACTION_TYPES.SET_PLAYBACK_SPEED,
|
|
128
|
+
options: { value: 1.5, dismissSheet: true },
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
expect(result).toBeUndefined();
|
|
132
|
+
expect(player.setPlaybackRate).not.toHaveBeenCalled();
|
|
133
|
+
|
|
134
|
+
expect(
|
|
135
|
+
uiActionsRegistry.getAction(PLAYER_ACTION_IDENTIFIERS.PLAYBACK_SPEED)
|
|
136
|
+
).toBeUndefined();
|
|
137
|
+
|
|
138
|
+
expect(
|
|
139
|
+
uiActionsRegistry.getAction(PLAYER_ACTION_IDENTIFIERS.SLEEP_TIMER)
|
|
140
|
+
).toBeUndefined();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("unregisters player actions when the player goes away", async () => {
|
|
144
|
+
unregisterPlayerActions();
|
|
145
|
+
|
|
146
|
+
expect(
|
|
147
|
+
uiActionsRegistry.getAction(PLAYER_ACTION_IDENTIFIERS.PLAYBACK_SPEED)
|
|
148
|
+
).toBeUndefined();
|
|
149
|
+
|
|
150
|
+
const result = await actionExecutor.handleAction({
|
|
151
|
+
type: PLAYER_ACTION_TYPES.SET_PLAYBACK_SPEED,
|
|
152
|
+
options: { value: 1.5 },
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
expect(result).toBeUndefined();
|
|
156
|
+
expect(player.setPlaybackRate).not.toHaveBeenCalled();
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("opens playback speed through openBottomSheet with the current speed selected", async () => {
|
|
160
|
+
await speedController.setPlaybackSpeed({
|
|
161
|
+
asset: "speed_1",
|
|
162
|
+
value: 1,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
const result = await actionExecutor.handleAction({
|
|
166
|
+
type: PLAYER_ACTION_TYPES.OPEN_PLAYBACK_SPEED,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
expect(result).toBe(ActionResult.Success);
|
|
170
|
+
|
|
171
|
+
const sheet = openedSheets[0];
|
|
172
|
+
|
|
173
|
+
expect(sheet.options.replace).toBe(true);
|
|
174
|
+
expect(sheet.options.header.title).toBe("Playback Speed");
|
|
175
|
+
expect(sheet.options.content.role).toBe("collection_selector");
|
|
176
|
+
expect(sheet.options.content.behavior.currentSelection).toEqual(["1"]);
|
|
177
|
+
|
|
178
|
+
expect(sheet.options.content.items.map((item) => item.title)).toEqual([
|
|
179
|
+
"0.8x",
|
|
180
|
+
"1x",
|
|
181
|
+
"1.2x",
|
|
182
|
+
"1.5x",
|
|
183
|
+
"2x",
|
|
184
|
+
]);
|
|
185
|
+
|
|
186
|
+
expect(
|
|
187
|
+
sheet.options.content.items[0].extensions.tap_actions.actions[0].options
|
|
188
|
+
.dismissSheet
|
|
189
|
+
).toBe(true);
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("opens sleep timer with the ticking countdown header", async () => {
|
|
193
|
+
const timerDate = Date.now() + 15 * 60 * 1000;
|
|
194
|
+
|
|
195
|
+
await sleepController.setSleepTimer(
|
|
196
|
+
{ label: "15 minutes", value: 15 },
|
|
197
|
+
timerDate
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
const result = await actionExecutor.handleAction({
|
|
201
|
+
type: PLAYER_ACTION_TYPES.OPEN_SLEEP_TIMER,
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
expect(result).toBe(ActionResult.Success);
|
|
205
|
+
|
|
206
|
+
const sheet = openedSheets[0];
|
|
207
|
+
|
|
208
|
+
expect(sheet.options.replace).toBe(true);
|
|
209
|
+
expect(sheet.options.header.title).toBe("Sleep Timer");
|
|
210
|
+
expect(sheet.options.header.component).toBe(SleepTimerModalHeader);
|
|
211
|
+
expect(sheet.options.header.componentProps.timerDate).toBe(timerDate);
|
|
212
|
+
expect(sheet.options.header.subtitle).toBeUndefined();
|
|
213
|
+
expect(sheet.options.content.behavior.currentSelection).toEqual(["15"]);
|
|
214
|
+
|
|
215
|
+
expect(
|
|
216
|
+
sheet.options.content.items[0].extensions.tap_actions.actions[0].type
|
|
217
|
+
).toBe(PLAYER_ACTION_TYPES.SET_SLEEP_TIMER);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("setPlaybackSpeed applies the rate and closes the sheet when opened from the picker", async () => {
|
|
221
|
+
const result = await actionExecutor.handleAction({
|
|
222
|
+
type: PLAYER_ACTION_TYPES.SET_PLAYBACK_SPEED,
|
|
223
|
+
options: { value: 1.5, dismissSheet: true },
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
expect(result).toBe(ActionResult.Success);
|
|
227
|
+
expect(player.setPlaybackRate).toHaveBeenCalledWith(1.5);
|
|
228
|
+
expect(localStorage.setItem).toHaveBeenCalled();
|
|
229
|
+
expect(modalOrchestrator.close).toHaveBeenCalled();
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("setSleepTimer starts the timer, writes storage, and closes the sheet", async () => {
|
|
233
|
+
const result = await actionExecutor.handleAction({
|
|
234
|
+
type: PLAYER_ACTION_TYPES.SET_SLEEP_TIMER,
|
|
235
|
+
options: { value: 15, label: "15 minutes", dismissSheet: true },
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
expect(result).toBe(ActionResult.Success);
|
|
239
|
+
expect(player.startSleepTimer).toHaveBeenCalled();
|
|
240
|
+
expect(localStorage.setItem).toHaveBeenCalled();
|
|
241
|
+
expect(modalOrchestrator.close).toHaveBeenCalled();
|
|
242
|
+
expect(sleepController.currentState.timer.value).toBe(15);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
it("setSleepTimer with value 0 cancels the timer", async () => {
|
|
246
|
+
await sleepController.setSleepTimer({
|
|
247
|
+
label: "15 minutes",
|
|
248
|
+
value: 15,
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
player.cancelSleepTimer.mockClear();
|
|
252
|
+
(localStorage.removeItem as jest.Mock).mockClear();
|
|
253
|
+
(modalOrchestrator.close as jest.Mock).mockClear();
|
|
254
|
+
|
|
255
|
+
const result = await actionExecutor.handleAction({
|
|
256
|
+
type: PLAYER_ACTION_TYPES.SET_SLEEP_TIMER,
|
|
257
|
+
options: { value: 0, label: "Off", dismissSheet: true },
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
expect(result).toBe(ActionResult.Success);
|
|
261
|
+
expect(player.cancelSleepTimer).toHaveBeenCalled();
|
|
262
|
+
expect(localStorage.removeItem).toHaveBeenCalled();
|
|
263
|
+
expect(sleepController.currentState.timer.value).toBe(0);
|
|
264
|
+
expect(modalOrchestrator.close).toHaveBeenCalled();
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it.each([undefined, "foo"])(
|
|
268
|
+
"rejects invalid setPlaybackSpeed value %p",
|
|
269
|
+
async (value) => {
|
|
270
|
+
player.setPlaybackRate.mockClear();
|
|
271
|
+
(localStorage.setItem as jest.Mock).mockClear();
|
|
272
|
+
|
|
273
|
+
const result = await actionExecutor.handleAction({
|
|
274
|
+
type: PLAYER_ACTION_TYPES.SET_PLAYBACK_SPEED,
|
|
275
|
+
options: { value, dismissSheet: true },
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
expect(result).toBe(ActionResult.Error);
|
|
279
|
+
expect(player.setPlaybackRate).not.toHaveBeenCalled();
|
|
280
|
+
expect(localStorage.setItem).not.toHaveBeenCalled();
|
|
281
|
+
expect(modalOrchestrator.close).not.toHaveBeenCalled();
|
|
282
|
+
}
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
it.each([undefined, "foo"])(
|
|
286
|
+
"rejects invalid setSleepTimer value %p",
|
|
287
|
+
async (value) => {
|
|
288
|
+
const result = await actionExecutor.handleAction({
|
|
289
|
+
type: PLAYER_ACTION_TYPES.SET_SLEEP_TIMER,
|
|
290
|
+
options: { value, dismissSheet: true },
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
expect(result).toBe(ActionResult.Error);
|
|
294
|
+
expect(player.startSleepTimer).not.toHaveBeenCalled();
|
|
295
|
+
expect(localStorage.setItem).not.toHaveBeenCalled();
|
|
296
|
+
expect(modalOrchestrator.close).not.toHaveBeenCalled();
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
|
|
300
|
+
it("does not close an unrelated sheet when setPlaybackSpeed is invoked standalone", async () => {
|
|
301
|
+
const result = await actionExecutor.handleAction({
|
|
302
|
+
type: PLAYER_ACTION_TYPES.SET_PLAYBACK_SPEED,
|
|
303
|
+
options: { value: 1.5 },
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
expect(result).toBe(ActionResult.Success);
|
|
307
|
+
expect(player.setPlaybackRate).toHaveBeenCalledWith(1.5);
|
|
308
|
+
expect(modalOrchestrator.close).not.toHaveBeenCalled();
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("initialEntryState for sleep-timer reflects an active timer", async () => {
|
|
312
|
+
await sleepController.setSleepTimer({
|
|
313
|
+
label: "15 minutes",
|
|
314
|
+
value: 15,
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
const action = uiActionsRegistry.getAction(
|
|
318
|
+
PLAYER_ACTION_IDENTIFIERS.SLEEP_TIMER
|
|
319
|
+
);
|
|
320
|
+
|
|
321
|
+
expect(action.initialEntryState({} as ZappEntry)).toMatchObject({
|
|
322
|
+
state: 1,
|
|
323
|
+
asset: "sleep_timer_active",
|
|
324
|
+
label: "Sleep Timer",
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
const observed = await firstValueFrom(
|
|
328
|
+
action.observeEntryState({} as ZappEntry)
|
|
329
|
+
);
|
|
330
|
+
|
|
331
|
+
expect(observed).toMatchObject({
|
|
332
|
+
state: 1,
|
|
333
|
+
asset: "sleep_timer_active",
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it("registers UI action identifiers that open the matching sheets", async () => {
|
|
338
|
+
await uiActionsRegistry
|
|
339
|
+
.getAction(PLAYER_ACTION_IDENTIFIERS.PLAYBACK_SPEED)
|
|
340
|
+
.invokeAction({} as ZappEntry);
|
|
341
|
+
|
|
342
|
+
await uiActionsRegistry
|
|
343
|
+
.getAction(PLAYER_ACTION_IDENTIFIERS.SLEEP_TIMER)
|
|
344
|
+
.invokeAction({} as ZappEntry);
|
|
345
|
+
|
|
346
|
+
expect(openedSheets.map((action) => action.options.header.title)).toEqual([
|
|
347
|
+
"Playback Speed",
|
|
348
|
+
"Sleep Timer",
|
|
349
|
+
]);
|
|
350
|
+
});
|
|
351
|
+
});
|