[PM-8223] 🍒 New device verification continue button enabled at 8 digit (#4802)

This commit is contained in:
aj-rosado
2025-02-27 19:48:24 +00:00
committed by GitHub
parent e0d91d7682
commit d584391843
2 changed files with 30 additions and 1 deletions

View File

@@ -189,10 +189,12 @@ class TwoFactorLoginViewModel @Inject constructor(
* Update the state with the new text and enable or disable the continue button.
*/
private fun handleCodeInputChanged(action: TwoFactorLoginAction.CodeInputChanged) {
@Suppress("MagicNumber")
val minLength = if (state.isNewDeviceVerification) 8 else 6
mutableStateFlow.update {
it.copy(
codeInput = action.input,
isContinueButtonEnabled = action.input.length >= 6,
isContinueButtonEnabled = action.input.length >= minLength,
)
}
}

View File

@@ -310,6 +310,33 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
)
}
@Test
@Suppress("MaxLineLength")
fun `Continue buttons should only be enabled when code is 8 digit enough on isNewDeviceVerification`() {
val initialState = DEFAULT_STATE.copy(isNewDeviceVerification = true)
val viewModel = createViewModel(initialState)
viewModel.trySendAction(TwoFactorLoginAction.CodeInputChanged("123456"))
// 6 digit should be false when isNewDeviceVerification is true.
assertEquals(
initialState.copy(
codeInput = "123456",
isContinueButtonEnabled = false,
),
viewModel.stateFlow.value,
)
// Set it to true.
viewModel.trySendAction(TwoFactorLoginAction.CodeInputChanged("12345678"))
assertEquals(
initialState.copy(
codeInput = "12345678",
isContinueButtonEnabled = true,
),
viewModel.stateFlow.value,
)
}
@Test
fun `ContinueButtonClick login returns success should update loadingDialogState`() = runTest {
coEvery {