mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 23:21:59 +01:00
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:
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user