[PM-9755] Change error message from a toast to a dialog (#3963)

This commit is contained in:
André Bispo 2024-09-30 08:20:45 +01:00 committed by GitHub
parent 72cb9918ac
commit 9d19a73fd6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 12 deletions

View file

@ -205,11 +205,18 @@ class TwoFactorLoginViewModel @Inject constructor(
-> { -> {
val authUrl = authRepository.twoFactorResponse.twoFactorDuoAuthUrl val authUrl = authRepository.twoFactorResponse.twoFactorDuoAuthUrl
// The url should not be empty unless the environment is somehow not supported. // The url should not be empty unless the environment is somehow not supported.
sendEvent( authUrl
event = authUrl ?.let {
?.let { TwoFactorLoginEvent.NavigateToDuo(uri = Uri.parse(it)) } sendEvent(event = 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()), }
) ?: 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 -> { TwoFactorAuthMethod.WEB_AUTH -> {

View file

@ -362,7 +362,7 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
@Suppress("MaxLineLength") @Suppress("MaxLineLength")
@Test @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 { runTest {
val authMethodsData = mapOf( val authMethodsData = mapOf(
TwoFactorAuthMethod.DUO to JsonObject( TwoFactorAuthMethod.DUO to JsonObject(
@ -376,15 +376,25 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
twoFactorProviders = null, twoFactorProviders = null,
) )
every { authRepository.twoFactorResponse } returns response every { authRepository.twoFactorResponse } returns response
val viewModel = createViewModel( val state = DEFAULT_STATE.copy(
state = DEFAULT_STATE.copy( authMethod = TwoFactorAuthMethod.DUO,
authMethod = TwoFactorAuthMethod.DUO,
),
) )
viewModel.eventFlow.test { val viewModel = createViewModel(
state = state,
)
viewModel.stateFlow.test {
assertEquals(
state,
awaitItem(),
)
viewModel.trySendAction(TwoFactorLoginAction.ContinueButtonClick) viewModel.trySendAction(TwoFactorLoginAction.ContinueButtonClick)
assertEquals( 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(), awaitItem(),
) )
} }