mirror of
https://github.com/bitwarden/android.git
synced 2026-11-20 11:37:52 -06:00
BIT-1563: Handle POST auth-requests error on Login with Device (#828)
This commit is contained in:
committed by
Álison Fernandes
parent
ab0cfdfdc2
commit
fa551fa6ab
+24
-25
@@ -1,13 +1,15 @@
|
||||
package com.x8bit.bitwarden.ui.auth.feature.loginwithdevice
|
||||
|
||||
import androidx.compose.ui.test.assert
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.hasAnyAncestor
|
||||
import androidx.compose.ui.test.isDialog
|
||||
import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performScrollTo
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.util.isProgressBar
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
@@ -45,6 +47,26 @@ class LoginWithDeviceScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `dismissing error dialog should send ErrorDialogDismiss`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = LoginWithDeviceState.ViewState.Content(
|
||||
fingerprintPhrase = "",
|
||||
isResendNotificationLoading = false,
|
||||
shouldShowErrorDialog = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
composeTestRule
|
||||
.onNodeWithText("Ok")
|
||||
.assert(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
verify {
|
||||
viewModel.trySendAction(LoginWithDeviceAction.ErrorDialogDismiss)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `resend notification click should send ResendNotificationClick action`() {
|
||||
composeTestRule.onNodeWithText("Resend notification").performClick()
|
||||
@@ -74,36 +96,12 @@ class LoginWithDeviceScreenTest : BaseComposeTest() {
|
||||
}
|
||||
composeTestRule.onNode(isProgressBar).assertIsDisplayed()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = LoginWithDeviceState.ViewState.Error("Failure".asText()))
|
||||
}
|
||||
composeTestRule.onNode(isProgressBar).assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = DEFAULT_STATE.viewState)
|
||||
}
|
||||
composeTestRule.onNode(isProgressBar).assertDoesNotExist()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `error should be displayed according to state`() {
|
||||
val errorMessage = "error"
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = LoginWithDeviceState.ViewState.Loading)
|
||||
}
|
||||
composeTestRule.onNodeWithText(errorMessage).assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = LoginWithDeviceState.ViewState.Error(errorMessage.asText()))
|
||||
}
|
||||
composeTestRule.onNodeWithText(errorMessage).assertIsDisplayed()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(viewState = DEFAULT_STATE.viewState)
|
||||
}
|
||||
composeTestRule.onNodeWithText(errorMessage).assertDoesNotExist()
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val EMAIL = "test@gmail.com"
|
||||
private val DEFAULT_STATE = LoginWithDeviceState(
|
||||
@@ -111,6 +109,7 @@ class LoginWithDeviceScreenTest : BaseComposeTest() {
|
||||
viewState = LoginWithDeviceState.ViewState.Content(
|
||||
fingerprintPhrase = "alabster-drinkable-mystified-rapping-irrigate",
|
||||
isResendNotificationLoading = false,
|
||||
shouldShowErrorDialog = false,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
+9
-5
@@ -2,12 +2,10 @@ package com.x8bit.bitwarden.ui.auth.feature.loginwithdevice
|
||||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.AuthRequest
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.AuthRequestResult
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.every
|
||||
@@ -46,6 +44,7 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
viewState = LoginWithDeviceState.ViewState.Content(
|
||||
fingerprintPhrase = FINGERPRINT,
|
||||
isResendNotificationLoading = false,
|
||||
shouldShowErrorDialog = false,
|
||||
),
|
||||
)
|
||||
val viewModel = createViewModel(state)
|
||||
@@ -82,6 +81,7 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
viewState = LoginWithDeviceState.ViewState.Content(
|
||||
fingerprintPhrase = newFingerprint,
|
||||
isResendNotificationLoading = false,
|
||||
shouldShowErrorDialog = false,
|
||||
),
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
@@ -120,6 +120,7 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
viewState = LoginWithDeviceState.ViewState.Content(
|
||||
fingerprintPhrase = newFingerprint,
|
||||
isResendNotificationLoading = false,
|
||||
shouldShowErrorDialog = false,
|
||||
),
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
@@ -127,7 +128,7 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on fingerprint result failure received should show error`() = runTest {
|
||||
fun `on fingerprint result failure received should show error dialog`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
assertEquals(DEFAULT_STATE, viewModel.stateFlow.value)
|
||||
viewModel.actionChannel.trySend(
|
||||
@@ -137,8 +138,10 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
viewState = LoginWithDeviceState.ViewState.Error(
|
||||
message = R.string.generic_error_message.asText(),
|
||||
viewState = LoginWithDeviceState.ViewState.Content(
|
||||
fingerprintPhrase = "",
|
||||
isResendNotificationLoading = false,
|
||||
shouldShowErrorDialog = true,
|
||||
),
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
@@ -161,6 +164,7 @@ class LoginWithDeviceViewModelTest : BaseViewModelTest() {
|
||||
viewState = LoginWithDeviceState.ViewState.Content(
|
||||
fingerprintPhrase = FINGERPRINT,
|
||||
isResendNotificationLoading = false,
|
||||
shouldShowErrorDialog = false,
|
||||
),
|
||||
)
|
||||
private val AUTH_REQUEST = AuthRequest(
|
||||
|
||||
Reference in New Issue
Block a user