BIT-267 make sure root navigation state doesn't get blown away after … (#32)

This commit is contained in:
Andrew Haisting
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent 7ba13a771f
commit 9ce88e2222
5 changed files with 103 additions and 27 deletions
@@ -1,24 +1,33 @@
package com.x8bit.bitwarden.ui.platform.feature.rootnav
import androidx.lifecycle.SavedStateHandle
import app.cash.turbine.test
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
class RootNavViewModelTest : BaseViewModelTest() {
@Test
fun `initial state should be splash`() {
val viewModel = RootNavViewModel()
assert(viewModel.stateFlow.value is RootNavState.Splash)
val viewModel = RootNavViewModel(SavedStateHandle())
assertEquals(viewModel.stateFlow.value, RootNavState.Splash)
}
@Test
fun `initial state should be the state in savedStateHandle`() {
val handle = SavedStateHandle(mapOf(("nav_state" to RootNavState.VaultUnlocked)))
val viewModel = RootNavViewModel(handle)
assertEquals(viewModel.stateFlow.value, RootNavState.VaultUnlocked)
}
@Test
fun `state should move from splash to auth`() = runTest {
val viewModel = RootNavViewModel()
val viewModel = RootNavViewModel(SavedStateHandle())
viewModel.stateFlow.test {
assert(awaitItem() is RootNavState.Splash)
assert(awaitItem() is RootNavState.Auth)
assertEquals(awaitItem(), RootNavState.Splash)
assertEquals(awaitItem(), RootNavState.Auth)
}
}
}