|
@@ -0,0 +1,40 @@
|
|
|
|
|
+import { describe, expect, it } from '@ohos/hypium'
|
|
|
|
|
+import { PlaybackStateBridge } from '../../../main/ets/controller/PlaybackStateBridge'
|
|
|
|
|
+import { VideoItem } from '../../../main/ets/viewmodel/VideoItem'
|
|
|
|
|
+
|
|
|
|
|
+export default function playbackStateBridgeTest() {
|
|
|
|
|
+ describe('PlaybackStateBridgeTest', () => {
|
|
|
|
|
+ it('replaceQueueSyncsCurrentSongAndIndex', 0, () => {
|
|
|
|
|
+ const bridge = PlaybackStateBridge.getInstance()
|
|
|
|
|
+ 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')
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ bridge.reset()
|
|
|
|
|
+ bridge.replaceQueue(songs, 99)
|
|
|
|
|
+
|
|
|
|
|
+ const snapshot = bridge.getSnapshot()
|
|
|
|
|
+ expect(snapshot.queue.length).assertEqual(2)
|
|
|
|
|
+ expect(snapshot.currentIndex).assertEqual(1)
|
|
|
|
|
+ expect(snapshot.currentSong?.filePath ?? '').assertEqual('/music/b.flac')
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ it('updatePlaybackStateDoesNotDropQueue', 0, () => {
|
|
|
|
|
+ const bridge = PlaybackStateBridge.getInstance()
|
|
|
|
|
+ const songs: VideoItem[] = [
|
|
|
|
|
+ new VideoItem('Song A', '1', '/music/a.flac', 0, 0, '2026-04-02')
|
|
|
|
|
+ ]
|
|
|
|
|
+
|
|
|
|
|
+ bridge.reset()
|
|
|
|
|
+ bridge.replaceQueue(songs, 0)
|
|
|
|
|
+ bridge.updatePlaybackState(true, 1350, 4200)
|
|
|
|
|
+
|
|
|
|
|
+ const snapshot = bridge.getSnapshot()
|
|
|
|
|
+ expect(snapshot.isPlaying).assertTrue()
|
|
|
|
|
+ expect(snapshot.positionMs).assertEqual(1350)
|
|
|
|
|
+ expect(snapshot.durationMs).assertEqual(4200)
|
|
|
|
|
+ expect(snapshot.currentSong?.filePath ?? '').assertEqual('/music/a.flac')
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+}
|