diff --git a/app/src/main/kotlin/com/wire/android/ui/authentication/login/email/LoginEmailViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/authentication/login/email/LoginEmailViewModel.kt index 5b8b8a99704..b69c9b39331 100644 --- a/app/src/main/kotlin/com/wire/android/ui/authentication/login/email/LoginEmailViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/authentication/login/email/LoginEmailViewModel.kt @@ -161,12 +161,12 @@ class LoginEmailViewModel @Inject constructor( private suspend fun handleAuthenticationFailure(it: AuthenticationResult.Failure, authScope: AuthenticationScope) { when (it) { is AuthenticationResult.Failure.InvalidCredentials.Missing2FA -> { - loginState = loginState.updateEmailLoginEnabled() + loginState = loginState.copy(emailLoginLoading = false).updateEmailLoginEnabled() request2FACode(authScope) } is AuthenticationResult.Failure.InvalidCredentials.Invalid2FA -> { - loginState = loginState.updateEmailLoginEnabled() + loginState = loginState.copy(emailLoginLoading = false).updateEmailLoginEnabled() secondFactorVerificationCodeState = secondFactorVerificationCodeState.copy(isCurrentCodeInvalid = true) } diff --git a/app/src/test/kotlin/com/wire/android/ui/authentication/login/email/LoginEmailViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/authentication/login/email/LoginEmailViewModelTest.kt index 8986a43c1b3..e930939ae61 100644 --- a/app/src/test/kotlin/com/wire/android/ui/authentication/login/email/LoginEmailViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/authentication/login/email/LoginEmailViewModelTest.kt @@ -66,6 +66,8 @@ import io.mockk.impl.annotations.MockK import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flowOf +import kotlinx.coroutines.test.StandardTestDispatcher +import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.advanceUntilIdle import kotlinx.coroutines.test.runTest import kotlinx.datetime.Instant @@ -126,6 +128,10 @@ class LoginEmailViewModelTest { private val userId: QualifiedID = QualifiedID("userId", "domain") + private val dispatcherProvider = TestDispatcherProvider(StandardTestDispatcher()) + + private fun runTest(test: suspend TestScope.() -> Unit) = runTest(dispatcherProvider.main(), testBody = test) + @BeforeEach fun setup() { MockKAnnotations.init(this) @@ -152,7 +158,7 @@ class LoginEmailViewModelTest { authServerConfigProvider, userDataStoreProvider, coreLogic, - TestDispatcherProvider() + dispatcherProvider ) } @@ -333,6 +339,21 @@ class LoginEmailViewModelTest { coVerify(exactly = 1) { requestSecondFactorCodeUseCase(email, VerifiableAction.LOGIN_OR_CLIENT_REGISTRATION) } } + @Test + fun `given missing 2fa, when logging in, then email should be enabled and not loading`() = runTest { + val email = "some.email@example.org" + coEvery { loginUseCase(any(), any(), any(), any(), any()) } returns AuthenticationResult.Failure.InvalidCredentials.Missing2FA + coEvery { requestSecondFactorCodeUseCase(any(), any()) } returns RequestSecondFactorVerificationCodeUseCase.Result.Success + + loginViewModel.onUserIdentifierChange(TextFieldValue(email)) + loginViewModel.onPasswordChange(TextFieldValue("somePassword")) + loginViewModel.login(onSuccess) + advanceUntilIdle() + + loginViewModel.loginState.emailLoginLoading shouldBe false + loginViewModel.loginState.emailLoginEnabled shouldBe true + } + @Test fun `given login fails with 2fa missing and 2fa request succeeds, when logging in, then should request user input`() = runTest { val email = "some.email@example.org"