mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 23:21:59 +01:00
address review: cancellation-safe star, one star handler, focus logic tested
- setStar no longer treats cancellation as a rejection: rethrow CancellationException instead of toasting/rolling back, and roll back under NonCancellable on a real failure - serialise setStar so overlapping toggles cannot clobber each other's rollback - the menu star item reverts its label when the request fails (setStar now returns the result), so the open menu cannot drift from the row - ContextMenuHost.dismiss clears the actions so a popped screen's ViewModel is released - one shared setStar from the app shell instead of five per-ViewModel copies - extract the nav-focus decision into focusPops and unit-test it
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package com.subtracks.ui
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Test
|
||||
|
||||
class FocusPopsTest {
|
||||
private val library = BackStackKey("library", null)
|
||||
private val artistA = BackStackKey("artist/{artistId}?coverArt={coverArt}", "ar1")
|
||||
private val albumA = BackStackKey("album/{albumId}?coverArt={coverArt}", "al1")
|
||||
private val albumB = BackStackKey("album/{albumId}?coverArt={coverArt}", "al2")
|
||||
|
||||
@Test
|
||||
fun anAbsentTargetNavigates() {
|
||||
assertNull(focusPops(listOf(library, albumA), "artist/{artistId}?coverArt={coverArt}", "ar1"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun anEmptyStackNavigates() {
|
||||
assertNull(focusPops(emptyList(), "album/{albumId}?coverArt={coverArt}", "al1"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aTargetAlreadyOnTopNeedsNoPops() {
|
||||
assertEquals(0, focusPops(listOf(library, artistA), "artist/{artistId}?coverArt={coverArt}", "ar1"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aTargetUnderTheTopPopsDownToIt() {
|
||||
assertEquals(1, focusPops(listOf(library, artistA, albumA), "artist/{artistId}?coverArt={coverArt}", "ar1"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theMatchingEntryIsChosenNotJustTheDestination() {
|
||||
val stack = listOf(library, albumA, artistA, albumB)
|
||||
assertEquals(2, focusPops(stack, "album/{albumId}?coverArt={coverArt}", "al1"))
|
||||
assertEquals(0, focusPops(stack, "album/{albumId}?coverArt={coverArt}", "al2"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user