mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 18:58:59 +03:00
Disable login button when password is blank (#441)
This commit is contained in:
parent
492038f163
commit
e92c85005b
2 changed files with 50 additions and 13 deletions
|
@ -42,7 +42,7 @@ class LoginViewModel @Inject constructor(
|
|||
initialState = savedStateHandle[KEY_STATE]
|
||||
?: LoginState(
|
||||
emailAddress = LoginArgs(savedStateHandle).emailAddress,
|
||||
isLoginButtonEnabled = true,
|
||||
isLoginButtonEnabled = false,
|
||||
passwordInput = "",
|
||||
environmentLabel = environmentRepository.environment.label,
|
||||
loadingDialogState = LoadingDialogState.Hidden,
|
||||
|
@ -208,7 +208,12 @@ class LoginViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun handlePasswordInputChanged(action: LoginAction.PasswordInputChanged) {
|
||||
mutableStateFlow.update { it.copy(passwordInput = action.input) }
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
passwordInput = action.input,
|
||||
isLoginButtonEnabled = action.input.isNotBlank(),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -343,17 +343,49 @@ class LoginViewModelTest : BaseViewModelTest() {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `PasswordInputChanged should update password input`() = runTest {
|
||||
val input = "input"
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(LoginAction.PasswordInputChanged(input))
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(passwordInput = input),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
fun `PasswordInputChanged should update input and enable button if password is not blank`() =
|
||||
runTest {
|
||||
val input = "input"
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(LoginAction.PasswordInputChanged(input))
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
passwordInput = input,
|
||||
isLoginButtonEnabled = true,
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `PasswordInputChanged should update input and disable button if password is blank`() =
|
||||
runTest {
|
||||
val input = "input"
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
// set isLoginButtonEnabled to true
|
||||
viewModel.actionChannel.trySend(LoginAction.PasswordInputChanged(input))
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
passwordInput = input,
|
||||
isLoginButtonEnabled = true,
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
|
||||
// set isLoginButtonEnabled to false
|
||||
viewModel.actionChannel.trySend(LoginAction.PasswordInputChanged(""))
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
passwordInput = "",
|
||||
isLoginButtonEnabled = false,
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `captchaTokenFlow success update should trigger a login`() = runTest {
|
||||
|
@ -383,7 +415,7 @@ class LoginViewModelTest : BaseViewModelTest() {
|
|||
private val DEFAULT_STATE = LoginState(
|
||||
emailAddress = "test@gmail.com",
|
||||
passwordInput = "",
|
||||
isLoginButtonEnabled = true,
|
||||
isLoginButtonEnabled = false,
|
||||
environmentLabel = Environment.Us.label,
|
||||
loadingDialogState = LoadingDialogState.Hidden,
|
||||
errorDialogState = BasicDialogState.Hidden,
|
||||
|
|
Loading…
Add table
Reference in a new issue