mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-267 make sure root navigation state doesn't get blown away after … (#32)
This commit is contained in:
committed by
Álison Fernandes
parent
7ba13a771f
commit
9ce88e2222
+14
-5
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user