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(), ) }