mirror of
https://github.com/bitwarden/android.git
synced 2025-02-17 20:40:00 +03:00
PM-9017 updated the continue button state when switching 2FA method (#3530)
This commit is contained in:
parent
58937d4e20
commit
721c69619e
2 changed files with 32 additions and 4 deletions
|
@ -465,7 +465,7 @@ class TwoFactorLoginViewModel @Inject constructor(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mutableStateFlow.update { it.copy(authMethod = action.authMethod) }
|
updateAuthMethodRelatedState(action.authMethod)
|
||||||
}
|
}
|
||||||
|
|
||||||
TwoFactorAuthMethod.AUTHENTICATOR_APP,
|
TwoFactorAuthMethod.AUTHENTICATOR_APP,
|
||||||
|
@ -476,11 +476,20 @@ class TwoFactorLoginViewModel @Inject constructor(
|
||||||
TwoFactorAuthMethod.DUO_ORGANIZATION,
|
TwoFactorAuthMethod.DUO_ORGANIZATION,
|
||||||
TwoFactorAuthMethod.WEB_AUTH,
|
TwoFactorAuthMethod.WEB_AUTH,
|
||||||
-> {
|
-> {
|
||||||
mutableStateFlow.update { it.copy(authMethod = action.authMethod) }
|
updateAuthMethodRelatedState(action.authMethod)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateAuthMethodRelatedState(authMethod: TwoFactorAuthMethod) {
|
||||||
|
mutableStateFlow.update {
|
||||||
|
it.copy(
|
||||||
|
authMethod = authMethod,
|
||||||
|
isContinueButtonEnabled = authMethod.isContinueButtonEnabled,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify the input and attempt to authenticate with the code.
|
* Verify the input and attempt to authenticate with the code.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -680,14 +680,33 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
|
||||||
@Test
|
@Test
|
||||||
fun `SelectAuthMethod with other method should update the state`() {
|
fun `SelectAuthMethod with other method should update the state`() {
|
||||||
val viewModel = createViewModel()
|
val viewModel = createViewModel()
|
||||||
|
|
||||||
|
// To method with continue button enabled by default
|
||||||
viewModel.trySendAction(
|
viewModel.trySendAction(
|
||||||
TwoFactorLoginAction.SelectAuthMethod(
|
TwoFactorLoginAction.SelectAuthMethod(
|
||||||
TwoFactorAuthMethod.AUTHENTICATOR_APP,
|
TwoFactorAuthMethod.DUO,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
DEFAULT_STATE.copy(
|
DEFAULT_STATE.copy(
|
||||||
authMethod = TwoFactorAuthMethod.AUTHENTICATOR_APP,
|
authMethod = TwoFactorAuthMethod.DUO,
|
||||||
|
isContinueButtonEnabled = true,
|
||||||
|
),
|
||||||
|
viewModel.stateFlow.value,
|
||||||
|
)
|
||||||
|
|
||||||
|
// To method with continue button disabled by default
|
||||||
|
viewModel.trySendAction(
|
||||||
|
TwoFactorLoginAction.SelectAuthMethod(
|
||||||
|
TwoFactorAuthMethod.YUBI_KEY,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
assertEquals(
|
||||||
|
DEFAULT_STATE.copy(
|
||||||
|
authMethod = TwoFactorAuthMethod.YUBI_KEY,
|
||||||
|
isContinueButtonEnabled = false,
|
||||||
),
|
),
|
||||||
viewModel.stateFlow.value,
|
viewModel.stateFlow.value,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue