File tree 2 files changed +30
-1
lines changed
main/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin
test/java/com/x8bit/bitwarden/ui/auth/feature/twofactorlogin
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -189,10 +189,12 @@ class TwoFactorLoginViewModel @Inject constructor(
189
189
* Update the state with the new text and enable or disable the continue button.
190
190
*/
191
191
private fun handleCodeInputChanged (action : TwoFactorLoginAction .CodeInputChanged ) {
192
+ @Suppress(" MagicNumber" )
193
+ val minLength = if (state.isNewDeviceVerification) 8 else 6
192
194
mutableStateFlow.update {
193
195
it.copy(
194
196
codeInput = action.input,
195
- isContinueButtonEnabled = action.input.length >= 6 ,
197
+ isContinueButtonEnabled = action.input.length >= minLength ,
196
198
)
197
199
}
198
200
}
Original file line number Diff line number Diff line change @@ -310,6 +310,33 @@ class TwoFactorLoginViewModelTest : BaseViewModelTest() {
310
310
)
311
311
}
312
312
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
+
313
340
@Test
314
341
fun `ContinueButtonClick login returns success should update loadingDialogState` () = runTest {
315
342
coEvery {
You can’t perform that action at this time.
0 commit comments