react to active source changes

The active source becomes one immutable id+source pair, so cover art and
stream/download URLs can no longer read a torn state mid-switch. The root
navigation watches the active source id and, on a real switch, closes the
overlays and pops an open album/artist/playlist detail back to the library.
This commit is contained in:
austinried
2026-10-04 00:30:05 +00:00
parent d4f3b54574
commit fa5595db30
3 changed files with 139 additions and 17 deletions
@@ -0,0 +1,86 @@
package com.subtracks.ui
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class SourceSwitchResetTest {
private var nowPlayingClosed = false
private var queueClosed = false
private var detailPopped = false
private fun reset(
previous: Long?,
current: Long?,
route: String?,
) {
nowPlayingClosed = false
queueClosed = false
detailPopped = false
resetOnSourceSwitch(
previousSourceId = previous,
currentSourceId = current,
route = route,
closeNowPlaying = { nowPlayingClosed = true },
closeQueue = { queueClosed = true },
popDetail = { detailPopped = true },
)
}
@Test
fun theFirstSourceResetsNothing() {
reset(previous = null, current = 1L, route = "album/{albumId}?coverArt={coverArt}")
assertFalse(nowPlayingClosed)
assertFalse(queueClosed)
assertFalse(detailPopped)
}
@Test
fun reselectingTheSameSourceResetsNothing() {
reset(previous = 1L, current = 1L, route = "settings")
assertFalse(nowPlayingClosed)
assertFalse(queueClosed)
assertFalse(detailPopped)
}
@Test
fun losingTheSourceResetsNothing() {
reset(previous = 1L, current = null, route = "settings")
assertFalse(nowPlayingClosed)
assertFalse(queueClosed)
assertFalse(detailPopped)
}
@Test
fun aSwitchClosesTheOverlays() {
reset(previous = 1L, current = 2L, route = "settings")
assertTrue(nowPlayingClosed)
assertTrue(queueClosed)
assertFalse(detailPopped)
}
@Test
fun aSwitchOnADetailPopsIt() {
reset(previous = 1L, current = 2L, route = "album/{albumId}?coverArt={coverArt}")
assertTrue(nowPlayingClosed)
assertTrue(queueClosed)
assertTrue(detailPopped)
}
@Test
fun everyDetailRoutePopsOnASwitch() {
listOf(
"album/{albumId}?coverArt={coverArt}",
"artist/{artistId}?coverArt={coverArt}",
"playlist/{playlistId}",
).forEach { route ->
reset(previous = 1L, current = 2L, route = route)
assertTrue("$route should be dismissed", detailPopped)
}
}
}