Skip to content

Commit

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

Playlog tests: Add missing tests
  • Loading branch information
ceciliasaraiva committed Aug 5, 2024
2 parents dd447e6 + a222884 commit 3c02f4c
Showing 1 changed file with 169 additions and 0 deletions.
169 changes: 169 additions & 0 deletions Tests/PlayerTests/Playlog/PlayLogTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,175 @@ extension PlayLogTests {
)
assertPlayLogEvent(actualPlayLogEvent: playLogEvent2, expectedPlayLogEvent: expectedPlayLogEvent2)
}

func test_load_and_play_and_resetPlayerEngine_and_setUpANewPlayerEngine_and_load_and_play_another_track_and_reset() {
// GIVEN
// First we load the media product and then proceed to play it.
uuid = "uuid1"
let shortAudioFile = shortAudioFile
setAudioFileResponseToURLProtocol(audioFile: shortAudioFile)
let mediaProduct1 = shortAudioFile.mediaProduct
playerEngine.load(mediaProduct1, timestamp: timestamp)

optimizedWait {
playerEngine.currentItem != nil
}
guard let currentItem = playerEngine.currentItem else {
XCTFail("Expected for the currentItem to be set up!")
return
}

playerEngine.play(timestamp: timestamp)

// Wait for the track to reach 2 seconds
let loadSecondMediaProductAssetPosition: Double = 2
wait(for: currentItem, toReach: loadSecondMediaProductAssetPosition)

// Simulate Player.load() is called.
// This is in order to simulate the following scenario: load and play a track, load and play another track.
playerEngine.notificationsHandler = nil
playerEngine.resetOrUnload()
setUpPlayerEngine()

// Now we load the second media product and then proceed to play it.
uuid = "uuid2"
let longAudioFile = longAudioFile
setAudioFileResponseToURLProtocol(audioFile: longAudioFile)
let mediaProduct2 = longAudioFile.mediaProduct
playerEngine.load(mediaProduct2, timestamp: timestamp)

optimizedWait {
playerEngine.currentItem != nil
}
guard let nextCurrentItem = playerEngine.currentItem else {
XCTFail("Expected for the currentItem to be set up!")
return
}

playerEngine.play(timestamp: timestamp)

// Wait for the track to reach 1 second
let resetAssetPosition: Double = 1
wait(for: nextCurrentItem, toReach: resetAssetPosition)

playerEngine.reset()

// THEN
optimizedWait(timeout: shortAudioFile.duration) {
playerEventSender.playLogEvents.count == 2
}

let playLogEvent1 = playerEventSender.playLogEvents[0]
let expectedPlayLogEvent1 = PlayLogEvent.mock(
startAssetPosition: 0,
requestedProductId: mediaProduct1.productId,
actualProductId: mediaProduct1.productId,
actualQuality: AudioQuality.LOSSLESS.rawValue,
sourceType: Constants.PlayLogSource.short.sourceType,
sourceId: Constants.PlayLogSource.short.sourceId,
actions: [],
endTimestamp: timestamp,
endAssetPosition: loadSecondMediaProductAssetPosition
)
assertPlayLogEvent(actualPlayLogEvent: playLogEvent1, expectedPlayLogEvent: expectedPlayLogEvent1)

let playLogEvent2 = playerEventSender.playLogEvents[1]
let expectedPlayLogEvent2 = PlayLogEvent.mock(
startAssetPosition: 0,
requestedProductId: mediaProduct2.productId,
actualProductId: mediaProduct2.productId,
actualQuality: AudioQuality.LOSSLESS.rawValue,
sourceType: Constants.PlayLogSource.long.sourceType,
sourceId: Constants.PlayLogSource.long.sourceId,
actions: [],
endTimestamp: timestamp,
endAssetPosition: resetAssetPosition
)
assertPlayLogEvent(actualPlayLogEvent: playLogEvent2, expectedPlayLogEvent: expectedPlayLogEvent2)
}

func test_load_and_play_and_resetPlayerEngine_and_setUpANewPlayerEngine_and_load_and_play_same_track_and_reset() {
// GIVEN
// First we load the media product and then proceed to play it.
uuid = "uuid1"
let shortAudioFile = shortAudioFile
setAudioFileResponseToURLProtocol(audioFile: shortAudioFile)
let mediaProduct1 = shortAudioFile.mediaProduct
playerEngine.load(mediaProduct1, timestamp: timestamp)

optimizedWait {
playerEngine.currentItem != nil
}
guard let currentItem = playerEngine.currentItem else {
XCTFail("Expected for the currentItem to be set up!")
return
}

playerEngine.play(timestamp: timestamp)

// Wait for the track to reach 2 seconds
let loadSecondTimeAssetPosition: Double = 2
wait(for: currentItem, toReach: loadSecondTimeAssetPosition)

// Simulate Player.load() is called.
// This is in order to simulate the following scenario: load and play a track, load and play another track.
playerEngine.notificationsHandler = nil
playerEngine.resetOrUnload()
setUpPlayerEngine()

// Now we load the same media product and then proceed to play it.
let mediaProduct2 = shortAudioFile.mediaProduct
playerEngine.load(mediaProduct2, timestamp: timestamp)

optimizedWait {
playerEngine.currentItem != nil
}
guard let nextCurrentItem = playerEngine.currentItem else {
XCTFail("Expected for the currentItem to be set up!")
return
}

playerEngine.play(timestamp: timestamp)

// Wait for the track to reach 1 second
let resetAssetPosition: Double = 1
wait(for: nextCurrentItem, toReach: resetAssetPosition)

playerEngine.reset()

// THEN
optimizedWait(timeout: shortAudioFile.duration) {
playerEventSender.playLogEvents.count == 2
}

let playLogEvent1 = playerEventSender.playLogEvents[0]
let expectedPlayLogEvent1 = PlayLogEvent.mock(
startAssetPosition: 0,
requestedProductId: mediaProduct1.productId,
actualProductId: mediaProduct1.productId,
actualQuality: AudioQuality.LOSSLESS.rawValue,
sourceType: Constants.PlayLogSource.short.sourceType,
sourceId: Constants.PlayLogSource.short.sourceId,
actions: [],
endTimestamp: timestamp,
endAssetPosition: loadSecondTimeAssetPosition
)
assertPlayLogEvent(actualPlayLogEvent: playLogEvent1, expectedPlayLogEvent: expectedPlayLogEvent1)

let playLogEvent2 = playerEventSender.playLogEvents[1]
let expectedPlayLogEvent2 = PlayLogEvent.mock(
startAssetPosition: 0,
requestedProductId: mediaProduct2.productId,
actualProductId: mediaProduct2.productId,
actualQuality: AudioQuality.LOSSLESS.rawValue,
sourceType: Constants.PlayLogSource.short.sourceType,
sourceId: Constants.PlayLogSource.short.sourceId,
actions: [],
endTimestamp: timestamp,
endAssetPosition: resetAssetPosition
)
assertPlayLogEvent(actualPlayLogEvent: playLogEvent2, expectedPlayLogEvent: expectedPlayLogEvent2)
}
}

// MARK: - Assertion Helpers
Expand Down

0 comments on commit 3c02f4c

Please sign in to comment.