Unit tests for PlaybackViewModel & several services (#1592)
## Description This PR contains only tests, there are no user facing changes. Adds tests for playback covering: - Playing next, previous, or within the queue - Media segments (intro/credit) - Playing intros before media Adds basic unit tests for track selection. This uses a new "test track" builder which can model various files and build them as represented (differently) by the server, ExoPlayer, and MPV. In future, this will allow for testing of more complex files. Also add unit tests for services covering things like: - Fetching extras - Deleting media - Server/user management & auth ### Related issues Will help with testing/verifying some issues like #1475, #1548 ### Testing Ran the unit tests! ## Screenshots N/A ## AI or LLM usage None
This commit is contained in:
parent
2afac3a1a5
commit
8e0798ee16
14 changed files with 2313 additions and 63 deletions
|
|
@ -192,14 +192,18 @@ class PlaybackViewModel
|
|||
|
||||
val currentUserDto = serverRepository.currentUserDtoFlow
|
||||
|
||||
// Exposed for testing
|
||||
val initJob: Job
|
||||
|
||||
init {
|
||||
viewModelScope.launchIO {
|
||||
addCloseable {
|
||||
screensaverService.keepScreenOn(false)
|
||||
disconnectPlayer()
|
||||
initJob =
|
||||
viewModelScope.launchIO {
|
||||
addCloseable {
|
||||
screensaverService.keepScreenOn(false)
|
||||
disconnectPlayer()
|
||||
}
|
||||
init()
|
||||
}
|
||||
init()
|
||||
}
|
||||
}
|
||||
|
||||
private fun disconnectPlayer() {
|
||||
|
|
@ -269,10 +273,7 @@ class PlaybackViewModel
|
|||
player,
|
||||
preferences.appPreferences.playbackPreferences,
|
||||
)
|
||||
mediaSession =
|
||||
MediaSession
|
||||
.Builder(context, sessionPlayer)
|
||||
.build()
|
||||
mediaSession = playerFactory.createMediaSession(sessionPlayer)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1054,7 +1055,8 @@ class PlaybackViewModel
|
|||
}
|
||||
|
||||
// Variables for tracking segment state
|
||||
private var segmentJob: Job? = null
|
||||
// Exposed for testing
|
||||
internal var segmentJob: Job? = null
|
||||
private val autoSkippedSegments = mutableSetOf<UUID>()
|
||||
private val outroShownSegments = mutableSetOf<UUID>()
|
||||
|
||||
|
|
@ -1269,7 +1271,7 @@ class PlaybackViewModel
|
|||
}
|
||||
}
|
||||
} else {
|
||||
Timber.w("Attempting to play next, but there are no more items")
|
||||
Timber.w("Attempting to play previous, but there is none")
|
||||
return@launchDefault
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue