From fb7bc78d955fc714e1671b4495e071ff52c3b9c2 Mon Sep 17 00:00:00 2001 From: Brian Yencho Date: Fri, 15 Dec 2023 13:48:06 -0600 Subject: [PATCH] BIT-1234: Add Account button should appear in switcher on Login (#402) --- .../ui/auth/feature/login/LoginScreen.kt | 5 ++--- .../ui/auth/feature/login/LoginViewModel.kt | 11 ++++++++++ .../ui/auth/feature/login/LoginScreenTest.kt | 20 ++++++++++++++++++- .../auth/feature/login/LoginViewModelTest.kt | 10 ++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreen.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreen.kt index 62cb42f13..275d991d6 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreen.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreen.kt @@ -152,11 +152,10 @@ fun LoginScreen( onLogoutAccountClick = remember(viewModel) { { viewModel.trySendAction(LoginAction.LogoutAccountClick(it)) } }, - onAddAccountClick = { - // Not available + onAddAccountClick = remember(viewModel) { + { viewModel.trySendAction(LoginAction.AddAccountClick) } }, onDismissRequest = { isAccountMenuVisible = false }, - isAddAccountAvailable = false, topAppBarScrollBehavior = scrollBehavior, modifier = Modifier .padding(innerPadding) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModel.kt index 0ca727efb..887a7c7ad 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModel.kt @@ -70,6 +70,7 @@ class LoginViewModel @Inject constructor( override fun handleAction(action: LoginAction) { when (action) { + LoginAction.AddAccountClick -> handleAddAccountClicked() is LoginAction.LockAccountClick -> handleLockAccountClicked(action) is LoginAction.LogoutAccountClick -> handleLogoutAccountClicked(action) is LoginAction.SwitchAccountClick -> handleSwitchAccountClicked(action) @@ -90,6 +91,11 @@ class LoginViewModel @Inject constructor( } } + private fun handleAddAccountClicked() { + // Since we are already in the login flow we can just go back to the Landing Screen + sendEvent(LoginEvent.NavigateBack) + } + private fun handleLockAccountClicked(action: LoginAction.LockAccountClick) { vaultRepository.lockVaultIfNecessary(userId = action.accountSummary.userId) } @@ -247,6 +253,11 @@ sealed class LoginEvent { */ sealed class LoginAction { + /** + * The user has clicked the add account button. + */ + data object AddAccountClick : LoginAction() + /** * Indicates the user has clicked on the given [accountSummary] information in order to lock * the associated account's vault. diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreenTest.kt index 13f6db35f..36cbc7731 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginScreenTest.kt @@ -26,6 +26,7 @@ import com.x8bit.bitwarden.ui.util.assertSwitcherIsNotDisplayed import com.x8bit.bitwarden.ui.util.performAccountClick import com.x8bit.bitwarden.ui.util.performAccountIconClick import com.x8bit.bitwarden.ui.util.performAccountLongClick +import com.x8bit.bitwarden.ui.util.performAddAccountClick import com.x8bit.bitwarden.ui.util.performLockAccountClick import com.x8bit.bitwarden.ui.util.performLogoutAccountClick import com.x8bit.bitwarden.ui.util.performLogoutAccountConfirmationClick @@ -86,7 +87,6 @@ class LoginScreenTest : BaseComposeTest() { composeTestRule.assertSwitcherIsDisplayed( accountSummaries = accountSummaries, - isAddAccountButtonVisible = false, ) } @@ -110,6 +110,24 @@ class LoginScreenTest : BaseComposeTest() { ) } + @Suppress("MaxLineLength") + @Test + fun `add account click in the account switcher should send AddAccountClick and close switcher`() { + // Open the Account Switcher + val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY) + mutableStateFlow.update { + it.copy(accountSummaries = accountSummaries) + } + composeTestRule.performAccountIconClick() + + composeTestRule.performAddAccountClick() + + verify { viewModel.trySendAction(LoginAction.AddAccountClick) } + composeTestRule.assertSwitcherIsNotDisplayed( + accountSummaries = accountSummaries, + ) + } + @Suppress("MaxLineLength") @Test fun `account long click in the account switcher should show the lock-or-logout dialog and close the switcher`() { diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModelTest.kt index e4e423aa6..3e8868c1a 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/login/LoginViewModelTest.kt @@ -149,6 +149,16 @@ class LoginViewModelTest : BaseViewModelTest() { } } + @Suppress("MaxLineLength") + @Test + fun `on AddAccountClick should send NavigateBack`() = runTest { + val viewModel = createViewModel() + viewModel.eventFlow.test { + viewModel.trySendAction(LoginAction.AddAccountClick) + assertEquals(LoginEvent.NavigateBack, awaitItem()) + } + } + @Test fun `LockAccountClick should call lockVaultIfNecessary for the given account`() { val accountUserId = "userId"