mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-72: Adding UI and navigation for the master password hint screen (#720)
This commit is contained in:
committed by
Álison Fernandes
parent
fa0b71df75
commit
427299eddf
@@ -45,6 +45,7 @@ class LoginScreenTest : BaseComposeTest() {
|
||||
every { startCustomTabsActivity(any()) } returns Unit
|
||||
}
|
||||
private var onNavigateBackCalled = false
|
||||
private var onNavigateToMasterPasswordHintCalled = false
|
||||
private var onNavigateToEnterpriseSignOnCalled = false
|
||||
private var onNavigateToLoginWithDeviceCalled = false
|
||||
private val mutableEventFlow = bufferedMutableSharedFlow<LoginEvent>()
|
||||
@@ -59,6 +60,7 @@ class LoginScreenTest : BaseComposeTest() {
|
||||
composeTestRule.setContent {
|
||||
LoginScreen(
|
||||
onNavigateBack = { onNavigateBackCalled = true },
|
||||
onNavigateToMasterPasswordHint = { onNavigateToMasterPasswordHintCalled = true },
|
||||
onNavigateToEnterpriseSignOn = { onNavigateToEnterpriseSignOnCalled = true },
|
||||
onNavigateToLoginWithDevice = { onNavigateToLoginWithDeviceCalled = true },
|
||||
viewModel = viewModel,
|
||||
@@ -279,6 +281,12 @@ class LoginScreenTest : BaseComposeTest() {
|
||||
verify { intentManager.startCustomTabsActivity(mockUri) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `NavigateToMasterPasswordHint should call onNavigateToMasterPasswordHint`() {
|
||||
mutableEventFlow.tryEmit(LoginEvent.NavigateToMasterPasswordHint("email"))
|
||||
assertTrue(onNavigateToMasterPasswordHintCalled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `NavigateToEnterpriseSignOn should call onNavigateToEnterpriseSignOn`() {
|
||||
mutableEventFlow.tryEmit(LoginEvent.NavigateToEnterpriseSignOn)
|
||||
|
||||
@@ -336,13 +336,13 @@ class LoginViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `MasterPasswordHintClick should emit ShowToast`() = runTest {
|
||||
fun `MasterPasswordHintClick should emit NavigateToMasterPasswordHint`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(LoginAction.MasterPasswordHintClick)
|
||||
assertEquals(DEFAULT_STATE, viewModel.stateFlow.value)
|
||||
assertEquals(
|
||||
LoginEvent.ShowToast("Not yet implemented."),
|
||||
LoginEvent.NavigateToMasterPasswordHint("test@gmail.com"),
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.x8bit.bitwarden.ui.auth.feature.masterpasswordhint
|
||||
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performTextReplacement
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
class MasterPasswordHintScreenTest : BaseComposeTest() {
|
||||
|
||||
private var onNavigateBackCalled = false
|
||||
private val mutableEventFlow = bufferedMutableSharedFlow<MasterPasswordHintEvent>()
|
||||
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
|
||||
private val viewModel = mockk<MasterPasswordHintViewModel>(relaxed = true) {
|
||||
every { eventFlow } returns mutableEventFlow
|
||||
every { stateFlow } returns mutableStateFlow
|
||||
}
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
composeTestRule.setContent {
|
||||
MasterPasswordHintScreen(
|
||||
onNavigateBack = { onNavigateBackCalled = true },
|
||||
viewModel = viewModel,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `email input change should send EmailInputChange action`() {
|
||||
val emailInput = "newEmail"
|
||||
composeTestRule.onNodeWithText("currentEmail").performTextReplacement(emailInput)
|
||||
verify {
|
||||
viewModel.trySendAction(MasterPasswordHintAction.EmailInputChange(emailInput))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `NavigateBack should call onNavigateBack`() {
|
||||
mutableEventFlow.tryEmit(MasterPasswordHintEvent.NavigateBack)
|
||||
assertTrue(onNavigateBackCalled)
|
||||
}
|
||||
}
|
||||
|
||||
private val DEFAULT_STATE =
|
||||
MasterPasswordHintState(
|
||||
emailInput = "currentEmail",
|
||||
)
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package com.x8bit.bitwarden.ui.auth.feature.masterpasswordhint
|
||||
|
||||
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 MasterPasswordHintViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `initial state should be correct`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(DEFAULT_STATE, awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on CloseClick should emit NavigateBack`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(MasterPasswordHintAction.CloseClick)
|
||||
assertEquals(MasterPasswordHintEvent.NavigateBack, awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
private fun createViewModel(
|
||||
state: MasterPasswordHintState? = DEFAULT_STATE,
|
||||
): MasterPasswordHintViewModel = MasterPasswordHintViewModel(
|
||||
savedStateHandle = SavedStateHandle().apply { set("state", state) },
|
||||
)
|
||||
}
|
||||
|
||||
private val DEFAULT_STATE: MasterPasswordHintState = MasterPasswordHintState(
|
||||
emailInput = "email",
|
||||
)
|
||||
Reference in New Issue
Block a user