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:
Damontecres 2026-06-19 11:06:35 -04:00 • committed by GitHub
parent 2afac3a1a5
commit 8e0798ee16
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 2313 additions and 63 deletions

View file

@ -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
}
}