mirror of
https://github.com/bitwarden/android.git
synced 2026-06-03 19:27:07 -05:00
Use a DialogState in LandingState (#341)
This commit is contained in:
@@ -21,7 +21,6 @@ import androidx.test.core.app.ApplicationProvider
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.Environment
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.components.BasicDialogState
|
||||
import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
@@ -236,8 +235,7 @@ class LandingScreenTest : BaseComposeTest() {
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
errorDialogState = BasicDialogState.Shown(
|
||||
title = "Error dialog title".asText(),
|
||||
dialog = LandingState.DialogState.Error(
|
||||
message = "Error dialog message".asText(),
|
||||
),
|
||||
)
|
||||
@@ -246,7 +244,7 @@ class LandingScreenTest : BaseComposeTest() {
|
||||
composeTestRule.onNode(isDialog()).assertIsDisplayed()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Error dialog title")
|
||||
.onNodeWithText("An error has occurred.")
|
||||
.assert(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
composeTestRule
|
||||
@@ -260,11 +258,10 @@ class LandingScreenTest : BaseComposeTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `error dialog OK click should send ErrorDialogDismiss action`() {
|
||||
fun `error dialog OK click should send DialogDismiss action`() {
|
||||
mutableStateFlow.update {
|
||||
DEFAULT_STATE.copy(
|
||||
errorDialogState = BasicDialogState.Shown(
|
||||
title = "title".asText(),
|
||||
dialog = LandingState.DialogState.Error(
|
||||
message = "message".asText(),
|
||||
),
|
||||
)
|
||||
@@ -274,7 +271,7 @@ class LandingScreenTest : BaseComposeTest() {
|
||||
.onAllNodesWithText("Ok")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
verify { viewModel.trySendAction(LandingAction.ErrorDialogDismiss) }
|
||||
verify { viewModel.trySendAction(LandingAction.DialogDismiss) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,6 +288,6 @@ private val DEFAULT_STATE = LandingState(
|
||||
isContinueButtonEnabled = true,
|
||||
isRememberMeEnabled = false,
|
||||
selectedEnvironmentType = Environment.Type.US,
|
||||
errorDialogState = BasicDialogState.Hidden,
|
||||
dialog = null,
|
||||
accountSummaries = emptyList(),
|
||||
)
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.x8bit.bitwarden.data.platform.repository.model.Environment
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.FakeEnvironmentRepository
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.components.BasicDialogState
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.toAccountSummaries
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
@@ -112,8 +111,7 @@ class LandingViewModelTest : BaseViewModelTest() {
|
||||
viewModel.actionChannel.trySend(LandingAction.ContinueButtonClick)
|
||||
assertEquals(
|
||||
initialState.copy(
|
||||
errorDialogState = BasicDialogState.Shown(
|
||||
title = R.string.an_error_has_occurred.asText(),
|
||||
dialog = LandingState.DialogState.Error(
|
||||
message = R.string.invalid_email.asText(),
|
||||
),
|
||||
),
|
||||
@@ -134,6 +132,27 @@ class LandingViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `DialogDismiss should clear the active dialog`() {
|
||||
val initialState = DEFAULT_STATE.copy(
|
||||
dialog = LandingState.DialogState.Error(
|
||||
message = "Error".asText(),
|
||||
),
|
||||
)
|
||||
val viewModel = createViewModel(initialState = initialState)
|
||||
assertEquals(
|
||||
initialState,
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
|
||||
viewModel.trySendAction(LandingAction.DialogDismiss)
|
||||
|
||||
assertEquals(
|
||||
initialState.copy(dialog = null),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `RememberMeToggle should update value of isRememberMeToggled`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
@@ -206,9 +225,12 @@ class LandingViewModelTest : BaseViewModelTest() {
|
||||
//region Helper methods
|
||||
|
||||
private fun createViewModel(
|
||||
initialState: LandingState? = null,
|
||||
rememberedEmail: String? = null,
|
||||
userState: UserState? = null,
|
||||
savedStateHandle: SavedStateHandle = SavedStateHandle(),
|
||||
savedStateHandle: SavedStateHandle = SavedStateHandle(
|
||||
initialState = mapOf("state" to initialState),
|
||||
),
|
||||
): LandingViewModel = LandingViewModel(
|
||||
authRepository = mockk(relaxed = true) {
|
||||
every { rememberedEmailAddress } returns rememberedEmail
|
||||
@@ -226,7 +248,7 @@ class LandingViewModelTest : BaseViewModelTest() {
|
||||
isContinueButtonEnabled = false,
|
||||
isRememberMeEnabled = false,
|
||||
selectedEnvironmentType = Environment.Type.US,
|
||||
errorDialogState = BasicDialogState.Hidden,
|
||||
dialog = null,
|
||||
accountSummaries = emptyList(),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user