Skip to content

Commit

Permalink
More realistic, failing BackstackTransitionsTest
Browse files Browse the repository at this point in the history
`BackstackTransitionsTest` now uses a map, to expose problems hidden when key and content are the same thing. As a result we crash when popping.

Reproduces #63.
  • Loading branch information
rjrjr committed Aug 26, 2022
1 parent 82429b4 commit 0c115e4
Showing 1 changed file with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class BackstackTransitionsTest {
assertInitialStateWithMultipleScreens(Crossfade)
}

@Test
fun transition_noop_forward() {
assertTransition(null, forward = true)
}

@Test
fun transition_slide_forward() {
assertTransition(Slide, forward = true)
Expand All @@ -53,6 +58,11 @@ class BackstackTransitionsTest {
assertTransition(Crossfade, forward = true)
}

@Test
fun transition_noop_backward() {
assertTransition(null, forward = false)
}

@Test
fun transition_slide_backward() {
assertTransition(Slide, forward = false)
Expand Down Expand Up @@ -82,19 +92,29 @@ class BackstackTransitionsTest {
compose.onNodeWithText("one").assertDoesNotExist()
}

private fun assertTransition(transition: BackstackTransition, forward: Boolean) {
val firstBackstack = listOf("one")
val secondBackstack = listOf("one", "two")
private fun assertTransition(transition: BackstackTransition?, forward: Boolean) {
val firstBackstack = mapOf(1 to "one")
val secondBackstack = mapOf(1 to "one", 2 to "two")
var backstack by mutableStateOf(if (forward) firstBackstack else secondBackstack)
compose.mainClock.autoAdvance = false
compose.setContent {
Backstack(
backstack,
frameController = rememberTransitionController(
animationSpec = animation,
transition = transition
)
) { BasicText(it) }

if (transition != null) {
compose.setContent {
Backstack(
backstack.keys.toList(),
frameController = rememberTransitionController(
animationSpec = animation,
transition = transition
)
) { BasicText(backstack.getValue(it)) }
}
} else {
compose.setContent {
Backstack(
backstack.keys.toList(),
frameController = NoopFrameController()
) { BasicText(backstack.getValue(it)) }
}
}
val initialText = if (forward) "one" else "two"
val newText = if (forward) "two" else "one"
Expand Down

0 comments on commit 0c115e4

Please sign in to comment.