Skip to content

Commit d584391

Browse files
authored
[PM-8223] šŸ’ New device verification continue button enabled at 8 digit (#4802)
1 parent e0d91d7 commit d584391

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

ā€Žapp/src/main/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin/TwoFactorLoginViewModel.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,12 @@ class TwoFactorLoginViewModel @Inject constructor(
189189
* Update the state with the new text and enable or disable the continue button.
190190
*/
191191
private fun handleCodeInputChanged(action: TwoFactorLoginAction.CodeInputChanged) {
192+
@Suppress("MagicNumber")
193+
val minLength = if (state.isNewDeviceVerification) 8 else 6
192194
mutableStateFlow.update {
193195
it.copy(
194196
codeInput = action.input,
195-
isContinueButtonEnabled = action.input.length >= 6,
197+
isContinueButtonEnabled = action.input.length >= minLength,
196198
)
197199
}
198200
}

ā€Žapp/src/test/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin/TwoFactorLoginViewModelTest.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,33 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
310310
)
311311
}
312312

313+
@Test
314+
@Suppress("MaxLineLength")
315+
fun `Continue buttons should only be enabled when code is 8 digit enough on isNewDeviceVerification`() {
316+
val initialState = DEFAULT_STATE.copy(isNewDeviceVerification = true)
317+
val viewModel = createViewModel(initialState)
318+
viewModel.trySendAction(TwoFactorLoginAction.CodeInputChanged("123456"))
319+
320+
// 6 digit should be false when isNewDeviceVerification is true.
321+
assertEquals(
322+
initialState.copy(
323+
codeInput = "123456",
324+
isContinueButtonEnabled = false,
325+
),
326+
viewModel.stateFlow.value,
327+
)
328+
329+
// Set it to true.
330+
viewModel.trySendAction(TwoFactorLoginAction.CodeInputChanged("12345678"))
331+
assertEquals(
332+
initialState.copy(
333+
codeInput = "12345678",
334+
isContinueButtonEnabled = true,
335+
),
336+
viewModel.stateFlow.value,
337+
)
338+
}
339+
313340
@Test
314341
fun `ContinueButtonClick login returns success should update loadingDialogState`() = runTest {
315342
coEvery {

0 commit comments

Comments
Ā (0)