@applicaster/quick-brick-player 16.0.0-alpha.4065452341 → 16.0.0-alpha.4155601029

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.
@@ -0,0 +1,528 @@
1
+ import { appStore } from "@applicaster/zapp-react-native-redux/AppStore";
2
+ import { findPluginByIdentifier } from "@applicaster/zapp-react-native-utils/pluginUtils";
3
+ import { loadFeedEntry } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/OverlayObserver/utils";
4
+ import {
5
+ PlaylistNavigationController,
6
+ RESTART_THRESHOLD_SECONDS,
7
+ } from "../PlaylistNavigationController";
8
+
9
+ jest.mock("@applicaster/zapp-react-native-redux/AppStore", () => ({
10
+ appStore: {
11
+ get: jest.fn(),
12
+ },
13
+ }));
14
+
15
+ jest.mock("@applicaster/zapp-react-native-utils/pluginUtils", () => ({
16
+ findPluginByIdentifier: jest.fn(),
17
+ }));
18
+
19
+ jest.mock(
20
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager/OverlayObserver/utils",
21
+ () => ({
22
+ loadFeedEntry: jest.fn(),
23
+ })
24
+ );
25
+
26
+ const appStoreMock = appStore as unknown as { get: jest.Mock };
27
+ const findPluginByIdentifierMock = findPluginByIdentifier as jest.Mock;
28
+ const loadFeedEntryMock = loadFeedEntry as jest.Mock;
29
+
30
+ const NEXT_URL = "https://feeds/next.json";
31
+ const PREV_URL = "https://feeds/prev.json";
32
+
33
+ const entryWith = (extensions: Record<string, unknown>): ZappEntry =>
34
+ ({
35
+ id: "current",
36
+ title: "Current Track",
37
+ type: { value: "audio" },
38
+ extensions,
39
+ }) as ZappEntry;
40
+
41
+ const stateAt = (
42
+ currentTime: number,
43
+ seekableDuration = 600
44
+ ): QuickBrickPlayer.PlayerState =>
45
+ ({ currentTime, seekableDuration }) as QuickBrickPlayer.PlayerState;
46
+
47
+ const NOT_SEEKABLE = 0;
48
+
49
+ describe("PlaylistNavigationController", () => {
50
+ let player: { seekTo: jest.Mock };
51
+ let navigator: { replaceTop: jest.Mock };
52
+ let mockQueueManager: any;
53
+
54
+ beforeEach(() => {
55
+ player = { seekTo: jest.fn() };
56
+ navigator = { replaceTop: jest.fn() };
57
+ loadFeedEntryMock.mockReset();
58
+
59
+ mockQueueManager = {
60
+ isInitialized: jest.fn().mockReturnValue(false),
61
+ instance: {
62
+ getUpcomingQueue: jest.fn().mockResolvedValue([]),
63
+ getHistoryQueue: jest.fn().mockResolvedValue([]),
64
+ addListener: jest.fn().mockReturnValue(jest.fn()),
65
+ },
66
+ };
67
+
68
+ appStoreMock.get.mockReturnValue([]);
69
+ findPluginByIdentifierMock.mockReturnValue(null);
70
+ });
71
+
72
+ describe("static URL feeds (no queue)", () => {
73
+ it("reports both directions available when both static extensions are present", async () => {
74
+ const entry = entryWith({
75
+ play_next_feed_url: NEXT_URL,
76
+ play_previous_feed_url: PREV_URL,
77
+ });
78
+
79
+ const controller = new PlaylistNavigationController({
80
+ entry,
81
+ player,
82
+ navigator,
83
+ playerState: stateAt(0),
84
+ });
85
+
86
+ await controller.recalculate();
87
+
88
+ expect(controller.hasNext$.getValue()).toBe(true);
89
+ expect(controller.hasPrevious$.getValue()).toBe(true);
90
+
91
+ controller.destroy();
92
+ });
93
+
94
+ it("keeps previous available at head of chain when track is seekable", async () => {
95
+ const entry = entryWith({ play_next_feed_url: NEXT_URL });
96
+
97
+ const controller = new PlaylistNavigationController({
98
+ entry,
99
+ player,
100
+ navigator,
101
+ playerState: stateAt(0),
102
+ });
103
+
104
+ await controller.recalculate();
105
+
106
+ expect(controller.hasNext$.getValue()).toBe(true);
107
+ expect(controller.hasPrevious$.getValue()).toBe(true);
108
+
109
+ controller.destroy();
110
+ });
111
+
112
+ it("reports no previous when track is not seekable and has no previous extension", async () => {
113
+ const entry = entryWith({ play_next_feed_url: NEXT_URL });
114
+
115
+ const controller = new PlaylistNavigationController({
116
+ entry,
117
+ player,
118
+ navigator,
119
+ playerState: stateAt(0, NOT_SEEKABLE),
120
+ });
121
+
122
+ await controller.recalculate();
123
+
124
+ expect(controller.hasNext$.getValue()).toBe(true);
125
+ expect(controller.hasPrevious$.getValue()).toBe(false);
126
+
127
+ controller.destroy();
128
+ });
129
+
130
+ it("fetches and plays next remote feed entry on goNext", async () => {
131
+ const target = { id: "next-track", title: "Next" } as ZappEntry;
132
+ loadFeedEntryMock.mockResolvedValue(target);
133
+
134
+ const entry = entryWith({ play_next_feed_url: NEXT_URL });
135
+
136
+ const controller = new PlaylistNavigationController({
137
+ entry,
138
+ player,
139
+ navigator,
140
+ playerState: stateAt(0),
141
+ });
142
+
143
+ await controller.goNext();
144
+
145
+ expect(loadFeedEntryMock).toHaveBeenCalledWith(NEXT_URL, entry);
146
+ expect(navigator.replaceTop).toHaveBeenCalledWith(target);
147
+
148
+ controller.destroy();
149
+ });
150
+
151
+ it("restarts playback when currentTime > RESTART_THRESHOLD_SECONDS", async () => {
152
+ const entry = entryWith({ play_previous_feed_url: PREV_URL });
153
+
154
+ const controller = new PlaylistNavigationController({
155
+ entry,
156
+ player,
157
+ navigator,
158
+ playerState: stateAt(RESTART_THRESHOLD_SECONDS + 1),
159
+ });
160
+
161
+ await controller.goPrevious();
162
+
163
+ expect(player.seekTo).toHaveBeenCalledWith(0);
164
+ expect(loadFeedEntryMock).not.toHaveBeenCalled();
165
+ expect(navigator.replaceTop).not.toHaveBeenCalled();
166
+
167
+ controller.destroy();
168
+ });
169
+
170
+ it("fetches and plays previous remote feed entry when currentTime <= RESTART_THRESHOLD_SECONDS", async () => {
171
+ const target = { id: "prev-track", title: "Previous" } as ZappEntry;
172
+ loadFeedEntryMock.mockResolvedValue(target);
173
+
174
+ const entry = entryWith({ play_previous_feed_url: PREV_URL });
175
+
176
+ const controller = new PlaylistNavigationController({
177
+ entry,
178
+ player,
179
+ navigator,
180
+ playerState: stateAt(1),
181
+ });
182
+
183
+ await controller.goPrevious();
184
+
185
+ expect(player.seekTo).not.toHaveBeenCalled();
186
+ expect(loadFeedEntryMock).toHaveBeenCalledWith(PREV_URL, entry);
187
+ expect(navigator.replaceTop).toHaveBeenCalledWith(target);
188
+
189
+ controller.destroy();
190
+ });
191
+ });
192
+
193
+ describe("queue navigation (QueueManager active)", () => {
194
+ let queueListener: () => void;
195
+
196
+ beforeEach(() => {
197
+ mockQueueManager.isInitialized.mockReturnValue(true);
198
+
199
+ mockQueueManager.instance.addListener.mockImplementation(
200
+ (cb: () => void) => {
201
+ queueListener = cb;
202
+
203
+ return jest.fn();
204
+ }
205
+ );
206
+
207
+ findPluginByIdentifierMock.mockReturnValue({
208
+ module: { QueueManager: mockQueueManager },
209
+ });
210
+ });
211
+
212
+ it("reports availability based on upcoming and history queues", async () => {
213
+ const upcomingItem = { id: "next_in_queue" } as ZappEntry;
214
+ const historyItem = { id: "prev_in_queue" } as ZappEntry;
215
+
216
+ mockQueueManager.instance.getUpcomingQueue.mockResolvedValue([
217
+ upcomingItem,
218
+ ]);
219
+
220
+ mockQueueManager.instance.getHistoryQueue.mockResolvedValue([
221
+ historyItem,
222
+ ]);
223
+
224
+ const controller = new PlaylistNavigationController({
225
+ entry: entryWith({}),
226
+ player,
227
+ navigator,
228
+ playerState: stateAt(0, NOT_SEEKABLE),
229
+ });
230
+
231
+ await controller.recalculate();
232
+
233
+ expect(controller.hasNext$.getValue()).toBe(true);
234
+ expect(controller.hasPrevious$.getValue()).toBe(true);
235
+
236
+ controller.destroy();
237
+ });
238
+
239
+ it("navigates directly to upcoming item on goNext without Pipes roundtrip", async () => {
240
+ const nextQueueItem = {
241
+ id: "queue_item_2",
242
+ title: "Second Track",
243
+ } as ZappEntry;
244
+
245
+ mockQueueManager.instance.getUpcomingQueue.mockResolvedValue([
246
+ nextQueueItem,
247
+ ]);
248
+
249
+ const controller = new PlaylistNavigationController({
250
+ entry: entryWith({}),
251
+ player,
252
+ navigator,
253
+ playerState: stateAt(0),
254
+ });
255
+
256
+ await controller.goNext();
257
+
258
+ expect(loadFeedEntryMock).not.toHaveBeenCalled();
259
+ expect(navigator.replaceTop).toHaveBeenCalledWith(nextQueueItem);
260
+
261
+ controller.destroy();
262
+ });
263
+
264
+ it("navigates directly to history item on goPrevious without Pipes roundtrip when <= 3s", async () => {
265
+ const prevQueueItem = {
266
+ id: "queue_item_0",
267
+ title: "Zero Track",
268
+ } as ZappEntry;
269
+
270
+ mockQueueManager.instance.getHistoryQueue.mockResolvedValue([
271
+ prevQueueItem,
272
+ ]);
273
+
274
+ const controller = new PlaylistNavigationController({
275
+ entry: entryWith({}),
276
+ player,
277
+ navigator,
278
+ playerState: stateAt(1),
279
+ });
280
+
281
+ await controller.goPrevious();
282
+
283
+ expect(player.seekTo).not.toHaveBeenCalled();
284
+ expect(loadFeedEntryMock).not.toHaveBeenCalled();
285
+ expect(navigator.replaceTop).toHaveBeenCalledWith(prevQueueItem);
286
+
287
+ controller.destroy();
288
+ });
289
+
290
+ it("recalculates streams when QueueManager listener fires", async () => {
291
+ mockQueueManager.instance.getUpcomingQueue.mockResolvedValue([]);
292
+ mockQueueManager.instance.getHistoryQueue.mockResolvedValue([]);
293
+
294
+ const controller = new PlaylistNavigationController({
295
+ entry: entryWith({}),
296
+ player,
297
+ navigator,
298
+ playerState: stateAt(0, NOT_SEEKABLE),
299
+ });
300
+
301
+ await controller.recalculate();
302
+ expect(controller.hasNext$.getValue()).toBe(false);
303
+
304
+ // Simulate item enqueued
305
+ mockQueueManager.instance.getUpcomingQueue.mockResolvedValue([
306
+ { id: "new_item" },
307
+ ]);
308
+
309
+ queueListener();
310
+
311
+ // Wait a tick for async recalculate
312
+ await new Promise((resolve) => setTimeout(resolve, 10));
313
+
314
+ expect(controller.hasNext$.getValue()).toBe(true);
315
+
316
+ controller.destroy();
317
+ });
318
+
319
+ it("prevents duplicate navigation calls while in-flight", async () => {
320
+ const target = { id: "next-track" } as ZappEntry;
321
+ let resolvePromise: (value: ZappEntry) => void;
322
+
323
+ loadFeedEntryMock.mockReturnValue(
324
+ new Promise((resolve) => {
325
+ resolvePromise = resolve;
326
+ })
327
+ );
328
+
329
+ const entry = entryWith({ play_next_feed_url: NEXT_URL });
330
+
331
+ const controller = new PlaylistNavigationController({
332
+ entry,
333
+ player,
334
+ navigator,
335
+ playerState: stateAt(0),
336
+ });
337
+
338
+ // First tap starts flight
339
+ const firstTap = controller.goNext();
340
+ // Second tap while in-flight
341
+ const secondTap = controller.goNext();
342
+
343
+ resolvePromise!(target);
344
+ await Promise.all([firstTap, secondTap]);
345
+
346
+ expect(loadFeedEntryMock).toHaveBeenCalledTimes(1);
347
+ expect(navigator.replaceTop).toHaveBeenCalledTimes(1);
348
+
349
+ controller.destroy();
350
+ });
351
+
352
+ it("prevents duplicate goPrevious calls while in-flight", async () => {
353
+ const target = { id: "prev-track" } as ZappEntry;
354
+ let resolvePromise: (value: ZappEntry) => void;
355
+
356
+ loadFeedEntryMock.mockReturnValue(
357
+ new Promise((resolve) => {
358
+ resolvePromise = resolve;
359
+ })
360
+ );
361
+
362
+ const entry = entryWith({ play_previous_feed_url: PREV_URL });
363
+
364
+ const controller = new PlaylistNavigationController({
365
+ entry,
366
+ player,
367
+ navigator,
368
+ playerState: stateAt(1),
369
+ });
370
+
371
+ const firstTap = controller.goPrevious();
372
+ const secondTap = controller.goPrevious();
373
+
374
+ resolvePromise!(target);
375
+ await Promise.all([firstTap, secondTap]);
376
+
377
+ expect(loadFeedEntryMock).toHaveBeenCalledTimes(1);
378
+ expect(navigator.replaceTop).toHaveBeenCalledTimes(1);
379
+
380
+ controller.destroy();
381
+ });
382
+
383
+ it("prioritizes queue navigation over static feed URLs even when entry is not from queue", async () => {
384
+ const queueNextItem = { id: "queue_next" } as ZappEntry;
385
+ const queuePrevItem = { id: "queue_prev" } as ZappEntry;
386
+ const staticNextTarget = { id: "static_next" } as ZappEntry;
387
+ const staticPrevTarget = { id: "static_prev" } as ZappEntry;
388
+
389
+ mockQueueManager.instance.getUpcomingQueue.mockResolvedValue([
390
+ queueNextItem,
391
+ ]);
392
+
393
+ mockQueueManager.instance.getHistoryQueue.mockResolvedValue([
394
+ queuePrevItem,
395
+ ]);
396
+
397
+ loadFeedEntryMock.mockImplementation((url) =>
398
+ Promise.resolve(url === NEXT_URL ? staticNextTarget : staticPrevTarget)
399
+ );
400
+
401
+ const entry = entryWith({
402
+ play_next_feed_url: NEXT_URL,
403
+ play_previous_feed_url: PREV_URL,
404
+ });
405
+
406
+ const controller = new PlaylistNavigationController({
407
+ entry,
408
+ player,
409
+ navigator,
410
+ playerState: stateAt(1),
411
+ });
412
+
413
+ await controller.goNext();
414
+ expect(loadFeedEntryMock).not.toHaveBeenCalled();
415
+ expect(navigator.replaceTop).toHaveBeenCalledWith(queueNextItem);
416
+
417
+ await controller.goPrevious();
418
+ expect(loadFeedEntryMock).not.toHaveBeenCalled();
419
+ expect(navigator.replaceTop).toHaveBeenCalledWith(queuePrevItem);
420
+
421
+ controller.destroy();
422
+ });
423
+
424
+ it("falls back to static feed URLs when queue is empty", async () => {
425
+ const staticNextTarget = { id: "static_next" } as ZappEntry;
426
+ const staticPrevTarget = { id: "static_prev" } as ZappEntry;
427
+
428
+ mockQueueManager.instance.getUpcomingQueue.mockResolvedValue([]);
429
+ mockQueueManager.instance.getHistoryQueue.mockResolvedValue([]);
430
+
431
+ loadFeedEntryMock.mockImplementation((url) =>
432
+ Promise.resolve(url === NEXT_URL ? staticNextTarget : staticPrevTarget)
433
+ );
434
+
435
+ const entry = entryWith({
436
+ play_next_feed_url: NEXT_URL,
437
+ play_previous_feed_url: PREV_URL,
438
+ });
439
+
440
+ const controller = new PlaylistNavigationController({
441
+ entry,
442
+ player,
443
+ navigator,
444
+ playerState: stateAt(1),
445
+ });
446
+
447
+ await controller.goNext();
448
+ expect(loadFeedEntryMock).toHaveBeenCalledWith(NEXT_URL, entry);
449
+ expect(navigator.replaceTop).toHaveBeenCalledWith(staticNextTarget);
450
+
451
+ await controller.goPrevious();
452
+ expect(loadFeedEntryMock).toHaveBeenCalledWith(PREV_URL, entry);
453
+ expect(navigator.replaceTop).toHaveBeenCalledWith(staticPrevTarget);
454
+
455
+ controller.destroy();
456
+ });
457
+
458
+ it("ignores stale recalculate resolution when newer recalculate was called", async () => {
459
+ let resolveFirst: (val: any) => void;
460
+
461
+ const firstPromise = new Promise<{
462
+ upcoming: ZappEntry[];
463
+ history: ZappEntry[];
464
+ }>((resolve) => {
465
+ resolveFirst = resolve;
466
+ });
467
+
468
+ const entry = entryWith({});
469
+
470
+ const controller = new PlaylistNavigationController({
471
+ entry,
472
+ player,
473
+ navigator,
474
+ playerState: stateAt(0, NOT_SEEKABLE),
475
+ });
476
+
477
+ // Override getUpcomingQueue to control resolution order
478
+ mockQueueManager.instance.getUpcomingQueue
479
+ .mockReturnValueOnce(firstPromise.then((d) => d.upcoming))
480
+ .mockResolvedValueOnce([{ id: "second_call_item" }]);
481
+
482
+ // First recalculate (will hang until resolveFirst)
483
+ const recalc1 = controller.recalculate();
484
+
485
+ // Second recalculate resolves immediately with hasNext = true
486
+ const recalc2 = controller.recalculate();
487
+ await recalc2;
488
+ expect(controller.hasNext$.getValue()).toBe(true);
489
+
490
+ // Now resolve first with empty array; should NOT overwrite hasNext$ to false
491
+ resolveFirst!({ upcoming: [], history: [] });
492
+ await recalc1;
493
+ expect(controller.hasNext$.getValue()).toBe(true);
494
+
495
+ controller.destroy();
496
+ });
497
+
498
+ it("does not navigate if controller is destroyed while resolving feed entry", async () => {
499
+ let resolvePromise: (value: ZappEntry) => void;
500
+
501
+ loadFeedEntryMock.mockReturnValue(
502
+ new Promise((resolve) => {
503
+ resolvePromise = resolve;
504
+ })
505
+ );
506
+
507
+ const entry = entryWith({
508
+ play_next_feed_url: NEXT_URL,
509
+ play_previous_feed_url: PREV_URL,
510
+ });
511
+
512
+ const controller = new PlaylistNavigationController({
513
+ entry,
514
+ player,
515
+ navigator,
516
+ playerState: stateAt(1),
517
+ });
518
+
519
+ const goNextPromise = controller.goNext();
520
+ controller.destroy();
521
+
522
+ resolvePromise!({ id: "target" } as ZappEntry);
523
+ await goNextPromise;
524
+
525
+ expect(navigator.replaceTop).not.toHaveBeenCalled();
526
+ });
527
+ });
528
+ });
@@ -2,8 +2,12 @@ import { renderHook, act } from "@testing-library/react-native";
2
2
  import { useNavigation } from "@applicaster/zapp-react-native-utils/reactHooks";
3
3
  import { usePlayer } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer";
4
4
  import { loadFeedEntry } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/OverlayObserver/utils";
5
+ import { RemoteCommand } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/const";
5
6
 
6
- import { usePlaylistNavigation } from "../usePlaylistNavigation";
7
+ import {
8
+ getTransportControls,
9
+ usePlaylistNavigation,
10
+ } from "../usePlaylistNavigation";
7
11
 
8
12
  jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => ({
9
13
  useNavigation: jest.fn(),
@@ -24,6 +28,13 @@ jest.mock(
24
28
  })
25
29
  );
26
30
 
31
+ jest.mock(
32
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager/playerNativeCommand",
33
+ () => ({
34
+ PlayerNativeCommandTypes: { setPlayerControls: "setPlayerControls" },
35
+ })
36
+ );
37
+
27
38
  const useNavigationMock = useNavigation as jest.Mock;
28
39
  const loadFeedEntryMock = loadFeedEntry as jest.Mock;
29
40
  const usePlayerMock = usePlayer as jest.Mock;
@@ -384,4 +395,145 @@ describe("usePlaylistNavigation", () => {
384
395
  expect(loadFeedEntryMock).not.toHaveBeenCalled();
385
396
  });
386
397
  });
398
+
399
+ describe("remote commands", () => {
400
+ let listeners: Record<string, QuickBrickPlayer.SharedPlayerCallBacks>;
401
+ const command = jest.fn();
402
+
403
+ const remote = (id: RemoteCommand) =>
404
+ act(async () => {
405
+ Object.values(listeners).forEach((l) => l.onRemoteCommand?.({ id }));
406
+ });
407
+
408
+ beforeEach(() => {
409
+ listeners = {};
410
+ command.mockClear();
411
+
412
+ usePlayerMock.mockReturnValue({
413
+ playerId: "player-1",
414
+ command,
415
+ seekTo,
416
+ addListener: ({ id, listener }) => {
417
+ listeners[id] = listener;
418
+
419
+ return () => delete listeners[id];
420
+ },
421
+ });
422
+ });
423
+
424
+ it("plays next when the lock screen / CarPlay next button is pressed", async () => {
425
+ const target = { id: "next" } as ZappEntry;
426
+ loadFeedEntryMock.mockResolvedValue(target);
427
+
428
+ await renderPlaylistNavigation(
429
+ entryWith({ play_next_feed_url: NEXT_URL }),
430
+ stateAt(0)
431
+ );
432
+
433
+ await remote(RemoteCommand.NextTrack);
434
+
435
+ expect(replaceTop).toHaveBeenCalledWith(target);
436
+ });
437
+
438
+ it("restarts the track on remote previous past the threshold", async () => {
439
+ await renderPlaylistNavigation(entryWith({}), stateAt(10));
440
+
441
+ await remote(RemoteCommand.PreviousTrack);
442
+
443
+ expect(seekTo).toHaveBeenCalledWith(0);
444
+ });
445
+
446
+ it("ignores commands native handles itself", async () => {
447
+ await renderPlaylistNavigation(
448
+ entryWith({ play_next_feed_url: NEXT_URL }),
449
+ stateAt(10)
450
+ );
451
+
452
+ await remote(RemoteCommand.Pause);
453
+
454
+ expect(replaceTop).not.toHaveBeenCalled();
455
+ expect(seekTo).not.toHaveBeenCalled();
456
+ });
457
+
458
+ it("sends native the controls snapshot to show", async () => {
459
+ await renderPlaylistNavigation(
460
+ entryWith({ play_next_feed_url: NEXT_URL }),
461
+ stateAt(0, NOT_SEEKABLE)
462
+ );
463
+
464
+ expect(command).toHaveBeenLastCalledWith("setPlayerControls", {
465
+ transport: [
466
+ RemoteCommand.Play,
467
+ RemoteCommand.Pause,
468
+ RemoteCommand.SkipBackward,
469
+ RemoteCommand.NextTrack,
470
+ ],
471
+ });
472
+ });
473
+
474
+ it("stops listening once unmounted", async () => {
475
+ const { unmount } = await renderPlaylistNavigation(
476
+ entryWith({ play_next_feed_url: NEXT_URL }),
477
+ stateAt(0)
478
+ );
479
+
480
+ unmount();
481
+
482
+ expect(listeners).toEqual({});
483
+ });
484
+ });
485
+ });
486
+
487
+ describe("getTransportControls", () => {
488
+ it("falls back to skip backward and leaves next out when there is no playlist", () => {
489
+ expect(
490
+ getTransportControls({
491
+ hasNext: false,
492
+ hasPrevious: false,
493
+ isLive: false,
494
+ })
495
+ ).toEqual([
496
+ RemoteCommand.Play,
497
+ RemoteCommand.Pause,
498
+ RemoteCommand.SkipBackward,
499
+ ]);
500
+ });
501
+
502
+ it("leaves next out without a next item, so it shows disabled", () => {
503
+ expect(
504
+ getTransportControls({ hasNext: false, hasPrevious: true, isLive: false })
505
+ ).toEqual([
506
+ RemoteCommand.Play,
507
+ RemoteCommand.Pause,
508
+ RemoteCommand.PreviousTrack,
509
+ ]);
510
+ });
511
+
512
+ it("puts track buttons in place of skip ones", () => {
513
+ expect(
514
+ getTransportControls({ hasNext: true, hasPrevious: true, isLive: false })
515
+ ).toEqual([
516
+ RemoteCommand.Play,
517
+ RemoteCommand.Pause,
518
+ RemoteCommand.PreviousTrack,
519
+ RemoteCommand.NextTrack,
520
+ ]);
521
+ });
522
+
523
+ it("uses stop and never skips on live", () => {
524
+ expect(
525
+ getTransportControls({ hasNext: false, hasPrevious: false, isLive: true })
526
+ ).toEqual([RemoteCommand.Play, RemoteCommand.Stop]);
527
+ });
528
+
529
+ it("keeps track buttons on live, e.g. a list of radio stations", () => {
530
+ expect(
531
+ getTransportControls({ hasNext: true, hasPrevious: true, isLive: true })
532
+ ).toEqual([
533
+ RemoteCommand.Play,
534
+ RemoteCommand.Stop,
535
+ RemoteCommand.PreviousTrack,
536
+ RemoteCommand.NextTrack,
537
+ ]);
538
+ });
387
539
  });