|
|
@@ -0,0 +1,68 @@
|
|
|
+import { describe, expect, it } from '@ohos/hypium'
|
|
|
+import { PlaybackCoordinator, PlaybackRuntime } from '../../../main/ets/controller/PlaybackCoordinator'
|
|
|
+import { PlaybackStateBridge } from '../../../main/ets/controller/PlaybackStateBridge'
|
|
|
+import { VideoItem } from '../../../main/ets/viewmodel/VideoItem'
|
|
|
+
|
|
|
+export default function playbackCoordinatorTest() {
|
|
|
+ describe('PlaybackCoordinatorTest', () => {
|
|
|
+ it('playQueueCallsRuntimeAndUpdatesState', 0, async () => {
|
|
|
+ const bridge = PlaybackStateBridge.getInstance()
|
|
|
+ const coordinator = PlaybackCoordinator.getInstance()
|
|
|
+ const calls: string[] = []
|
|
|
+ const songs: VideoItem[] = [
|
|
|
+ new VideoItem('Song A', '1', '/music/a.flac', 0, 0, '2026-04-02'),
|
|
|
+ new VideoItem('Song B', '2', '/music/b.flac', 0, 0, '2026-04-02')
|
|
|
+ ]
|
|
|
+
|
|
|
+ const runtime: PlaybackRuntime = {
|
|
|
+ playQueue: async (_queue, startIndex, source) => {
|
|
|
+ calls.push(`playQueue:${startIndex}:${source}`)
|
|
|
+ },
|
|
|
+ playOrPause: async () => {
|
|
|
+ calls.push('playOrPause')
|
|
|
+ },
|
|
|
+ playNext: async () => {
|
|
|
+ calls.push('playNext')
|
|
|
+ },
|
|
|
+ playPrevious: async () => {
|
|
|
+ calls.push('playPrevious')
|
|
|
+ },
|
|
|
+ seekTo: async (value, source) => {
|
|
|
+ calls.push(`seekTo:${value}:${source ?? ''}`)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ bridge.reset()
|
|
|
+ coordinator.clearRuntime()
|
|
|
+ coordinator.setRuntime(runtime)
|
|
|
+
|
|
|
+ await coordinator.playQueue(songs, 1, 'charts-count')
|
|
|
+
|
|
|
+ const snapshot = bridge.getSnapshot()
|
|
|
+ expect(snapshot.currentIndex).assertEqual(1)
|
|
|
+ expect(snapshot.currentSong?.filePath ?? '').assertEqual('/music/b.flac')
|
|
|
+ expect(calls.join(',')).assertEqual('playQueue:1:charts-count')
|
|
|
+ coordinator.clearRuntime()
|
|
|
+ })
|
|
|
+
|
|
|
+ it('playSongWrapsSingleSongQueue', 0, async () => {
|
|
|
+ const coordinator = PlaybackCoordinator.getInstance()
|
|
|
+ let queueLength = 0
|
|
|
+
|
|
|
+ coordinator.clearRuntime()
|
|
|
+ coordinator.setRuntime({
|
|
|
+ playQueue: async (queue) => {
|
|
|
+ queueLength = queue.length
|
|
|
+ },
|
|
|
+ playOrPause: async () => {},
|
|
|
+ playNext: async () => {},
|
|
|
+ playPrevious: async () => {},
|
|
|
+ seekTo: async () => {}
|
|
|
+ })
|
|
|
+
|
|
|
+ await coordinator.playSong(new VideoItem('Song A', '1', '/music/a.flac', 0, 0, '2026-04-02'), 'playlist-detail')
|
|
|
+ expect(queueLength).assertEqual(1)
|
|
|
+ coordinator.clearRuntime()
|
|
|
+ })
|
|
|
+ })
|
|
|
+}
|