Skip to content

Commit

Permalink
Merge pull request #43 from tidal-music/cecilia/BITS-2951/add-tests-f…
Browse files Browse the repository at this point in the history
…or-playlog

Playlog tests: Align skipToNext behavior with Android: don't do anything when there's no nextItem set up
  • Loading branch information
ceciliasaraiva authored Aug 2, 2024
2 parents b20ff37 + 8195376 commit 5043c70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
7 changes: 2 additions & 5 deletions Sources/Player/PlaybackEngine/PlayerEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,10 @@ final class PlayerEngine {

func skipToNext(timestamp: UInt64) {
queue.dispatch {
let playerItem = self.nextItem
self.currentItem?.unloadFromPlayer()

guard let playerItem else {
self.reset(to: .IDLE)
guard let playerItem = self.nextItem else {
return
}
self.currentItem?.unloadFromPlayer()

// The order is important due to logic for emitting events in didSet of the items.
self.currentItem = playerItem
Expand Down
14 changes: 7 additions & 7 deletions Tests/PlayerTests/Player/PlaybackEngine/PlayerEngineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ extension PlayerEngineTests {

// THEN
// Make sure it's idle, and items remain nil
XCTAssertEqual(playerEngine.getState(), .IDLE)
XCTAssertEqual(playerEngine.getState(), .NOT_PLAYING)
XCTAssertEqual(playerEngine.currentItem, nil)
XCTAssertEqual(playerEngine.nextItem, nil)

Expand Down Expand Up @@ -618,17 +618,17 @@ extension PlayerEngineTests {
assertGenericPlayer(assets: [asset], playCount: 2, pauseCount: 0)

// WHEN
// skipToNext() should unload the current one, set the previously next as current, and nextItem should become nil.
// skipToNext() should not do anything when next item is not set up.
// If still playing, it will continue till it ends.
playerEngine.skipToNext(timestamp: timestamp)

// Since setNext was not called, meaning there's no nextItem set up, then both currentItem and nextItem are nil, reset is
// called, and set to IDLE state.
assertItem(item: playerEngine.currentItem, expectedItem: nil, shouldBeLoaded: nil)
// Since setNext was not called and skipToNext didn't do anything, everything remains.
assertItem(item: playerEngine.currentItem, expectedItem: expectedPlayerItem1, shouldBeLoaded: true)
assertItem(item: playerEngine.nextItem, expectedItem: nil, shouldBeLoaded: nil)
XCTAssertEqual(playerEngine.getState(), .IDLE)
XCTAssertEqual(playerEngine.getState(), .PLAYING)

// Same as above
assertGenericPlayer(assets: [], playCount: 2, pauseCount: 0)
assertGenericPlayer(assets: [asset], playCount: 2, pauseCount: 0)
assertPlayerLoader(trackPlaybackInfos: [trackPlaybackInfo1])
}

Expand Down

0 comments on commit 5043c70

Please sign in to comment.