From 35483408b2cfdc736637501ae3740784a1c15978 Mon Sep 17 00:00:00 2001 From: Andrew Haisting <142518658+ahaisting-livefront@users.noreply.github.com> Date: Thu, 21 Sep 2023 11:47:28 -0500 Subject: [PATCH] BIT-589 Prevent crash on Landing when navigating with empty input (#59) --- .../ui/auth/feature/landing/LandingViewModel.kt | 4 ++++ .../ui/auth/feature/landing/LandingViewModelTest.kt | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/landing/LandingViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/landing/LandingViewModel.kt index 3fc102986..a9ca61bff 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/landing/LandingViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/landing/LandingViewModel.kt @@ -49,6 +49,10 @@ class LandingViewModel @Inject constructor( } private fun handleContinueButtonClicked() { + // TODO: add actual validation here: BIT-193 + if (mutableStateFlow.value.emailInput.isBlank()) { + return + } sendEvent(LandingEvent.NavigateToLogin(mutableStateFlow.value.emailInput)) } diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/landing/LandingViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/landing/LandingViewModelTest.kt index 8710b097c..9b58e254f 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/landing/LandingViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/landing/LandingViewModelTest.kt @@ -34,15 +34,24 @@ class LandingViewModelTest : BaseViewModelTest() { @Test fun `ContinueButtonClick should emit NavigateToLogin`() = runTest { val viewModel = LandingViewModel(SavedStateHandle()) + viewModel.trySendAction(LandingAction.EmailInputChanged("input")) viewModel.eventFlow.test { viewModel.actionChannel.trySend(LandingAction.ContinueButtonClick) assertEquals( - LandingEvent.NavigateToLogin(""), + LandingEvent.NavigateToLogin("input"), awaitItem(), ) } } + @Test + fun `ContinueButtonClick with empty input should do nothing`() = runTest { + val viewModel = LandingViewModel(SavedStateHandle()) + viewModel.eventFlow.test { + viewModel.actionChannel.trySend(LandingAction.ContinueButtonClick) + } + } + @Test fun `CreateAccountClick should emit NavigateToCreateAccount`() = runTest { val viewModel = LandingViewModel(SavedStateHandle())