From 9d19a73fd64d234fd4f1ecc22658e0016c9adc78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bispo?= Date: Mon, 30 Sep 2024 08:20:45 +0100 Subject: [PATCH] [PM-9755] Change error message from a toast to a dialog (#3963) --- .../twofactorlogin/TwoFactorLoginViewModel.kt | 17 +++++++++---- .../TwoFactorLoginViewModelTest.kt | 24 +++++++++++++------ 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin/TwoFactorLoginViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin/TwoFactorLoginViewModel.kt index 4f474c56d..14afa3136 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin/TwoFactorLoginViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin/TwoFactorLoginViewModel.kt @@ -205,11 +205,18 @@ class TwoFactorLoginViewModel @Inject constructor( -> { val authUrl = authRepository.twoFactorResponse.twoFactorDuoAuthUrl // The url should not be empty unless the environment is somehow not supported. - sendEvent( - event = authUrl - ?.let { TwoFactorLoginEvent.NavigateToDuo(uri = Uri.parse(it)) } - ?: TwoFactorLoginEvent.ShowToast(R.string.error_connecting_with_the_duo_service_use_a_different_two_step_login_method_or_contact_duo_for_assistance.asText()), - ) + authUrl + ?.let { + sendEvent(event = TwoFactorLoginEvent.NavigateToDuo(uri = Uri.parse(it))) + } + ?: mutableStateFlow.update { + it.copy( + dialogState = TwoFactorLoginState.DialogState.Error( + title = R.string.an_error_has_occurred.asText(), + message = R.string.error_connecting_with_the_duo_service_use_a_different_two_step_login_method_or_contact_duo_for_assistance.asText(), + ), + ) + } } TwoFactorAuthMethod.WEB_AUTH -> { diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin/TwoFactorLoginViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin/TwoFactorLoginViewModelTest.kt index aceec027d..6787d7b76 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin/TwoFactorLoginViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin/TwoFactorLoginViewModelTest.kt @@ -362,7 +362,7 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() { @Suppress("MaxLineLength") @Test - fun `ContinueButtonClick login should emit ShowToast when auth method is Duo and authUrl is null`() = + fun `ContinueButtonClick login should show a dialog when auth method is Duo and authUrl is null`() = runTest { val authMethodsData = mapOf( TwoFactorAuthMethod.DUO to JsonObject( @@ -376,15 +376,25 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() { twoFactorProviders = null, ) every { authRepository.twoFactorResponse } returns response - val viewModel = createViewModel( - state = DEFAULT_STATE.copy( - authMethod = TwoFactorAuthMethod.DUO, - ), + val state = DEFAULT_STATE.copy( + authMethod = TwoFactorAuthMethod.DUO, ) - viewModel.eventFlow.test { + val viewModel = createViewModel( + state = state, + ) + viewModel.stateFlow.test { + assertEquals( + state, + awaitItem(), + ) viewModel.trySendAction(TwoFactorLoginAction.ContinueButtonClick) assertEquals( - TwoFactorLoginEvent.ShowToast(R.string.error_connecting_with_the_duo_service_use_a_different_two_step_login_method_or_contact_duo_for_assistance.asText()), + state.copy( + dialogState = TwoFactorLoginState.DialogState.Error( + title = R.string.an_error_has_occurred.asText(), + message = R.string.error_connecting_with_the_duo_service_use_a_different_two_step_login_method_or_contact_duo_for_assistance.asText(), + ), + ), awaitItem(), ) }