Skip to content

Commit

Permalink
Add test for moving to song methods
Browse files Browse the repository at this point in the history
Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Apr 14, 2024
1 parent 8ac107a commit 36f2d74
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions HarmonyTests/PlayerQueueTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -397,4 +397,35 @@ final class PlayerQueueTests: XCTestCase {
playerQueue.loadNextPageIfNeeded(song: playerQueue.futureSongs.first!)
XCTAssertNotEqual(longSongResults.last, playerQueue.futureSongs.last?.song)
}

@MainActor func testMoveToSong_FindsAndSetsSongAsCurrent() async {
var insertedBasicSongResultsCount = 0
playerQueue.addCurrentSong(basicSongResults.first!, parentResults: basicSongResults)
insertedBasicSongResultsCount += basicSongResults.count

playerQueue.moveToFutureSong(instanceId: playerQueue.futureSongs.first!.id)
XCTAssertEqual(playerQueue.currentSong?.song, basicSongResults[1])
XCTAssertEqual(playerQueue.pastSongs.first?.song, basicSongResults.first)

// Test moving to play next. Should move to play next before future songs, as expected, with
// play next moved into past songs. When moving into the future songs, this should also
// behave as expected
basicSongResults.forEach { playerQueue.insertNextSong($0) }
insertedBasicSongResultsCount += basicSongResults.count
playerQueue.moveToPlayNextSong(instanceId: playerQueue.playNextSongs.last!.id)
XCTAssertEqual(playerQueue.currentSong?.song, basicSongResults.last)
XCTAssertEqual( // Second to last song, because the last song was set to the current song
playerQueue.pastSongs.last?.song, basicSongResults[basicSongResults.count - 2]
)
XCTAssertTrue(playerQueue.playNextSongs.isEmpty)

let pastSongIndex = 2
let pastSongTarget = playerQueue.pastSongs[pastSongIndex]
playerQueue.moveToPastSong(instanceId: pastSongTarget.id)
XCTAssertEqual(playerQueue.currentSong?.song, pastSongTarget.song)
XCTAssertEqual(playerQueue.pastSongs.count, pastSongIndex)
XCTAssertEqual(
playerQueue.futureSongs.count, insertedBasicSongResultsCount - pastSongIndex - 1
)
}
}

0 comments on commit 36f2d74

Please sign in to comment.