mirror of
https://github.com/bitwarden/android.git
synced 2025-02-18 13:00:01 +03:00
BIT-1234: Add Account button should appear in switcher on Login (#402)
This commit is contained in:
parent
6f85d80f9f
commit
fb7bc78d95
4 changed files with 42 additions and 4 deletions
|
@ -152,11 +152,10 @@ fun LoginScreen(
|
||||||
onLogoutAccountClick = remember(viewModel) {
|
onLogoutAccountClick = remember(viewModel) {
|
||||||
{ viewModel.trySendAction(LoginAction.LogoutAccountClick(it)) }
|
{ viewModel.trySendAction(LoginAction.LogoutAccountClick(it)) }
|
||||||
},
|
},
|
||||||
onAddAccountClick = {
|
onAddAccountClick = remember(viewModel) {
|
||||||
// Not available
|
{ viewModel.trySendAction(LoginAction.AddAccountClick) }
|
||||||
},
|
},
|
||||||
onDismissRequest = { isAccountMenuVisible = false },
|
onDismissRequest = { isAccountMenuVisible = false },
|
||||||
isAddAccountAvailable = false,
|
|
||||||
topAppBarScrollBehavior = scrollBehavior,
|
topAppBarScrollBehavior = scrollBehavior,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(innerPadding)
|
.padding(innerPadding)
|
||||||
|
|
|
@ -70,6 +70,7 @@ class LoginViewModel @Inject constructor(
|
||||||
|
|
||||||
override fun handleAction(action: LoginAction) {
|
override fun handleAction(action: LoginAction) {
|
||||||
when (action) {
|
when (action) {
|
||||||
|
LoginAction.AddAccountClick -> handleAddAccountClicked()
|
||||||
is LoginAction.LockAccountClick -> handleLockAccountClicked(action)
|
is LoginAction.LockAccountClick -> handleLockAccountClicked(action)
|
||||||
is LoginAction.LogoutAccountClick -> handleLogoutAccountClicked(action)
|
is LoginAction.LogoutAccountClick -> handleLogoutAccountClicked(action)
|
||||||
is LoginAction.SwitchAccountClick -> handleSwitchAccountClicked(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) {
|
private fun handleLockAccountClicked(action: LoginAction.LockAccountClick) {
|
||||||
vaultRepository.lockVaultIfNecessary(userId = action.accountSummary.userId)
|
vaultRepository.lockVaultIfNecessary(userId = action.accountSummary.userId)
|
||||||
}
|
}
|
||||||
|
@ -247,6 +253,11 @@ sealed class LoginEvent {
|
||||||
*/
|
*/
|
||||||
sealed class LoginAction {
|
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
|
* Indicates the user has clicked on the given [accountSummary] information in order to lock
|
||||||
* the associated account's vault.
|
* the associated account's vault.
|
||||||
|
|
|
@ -26,6 +26,7 @@ import com.x8bit.bitwarden.ui.util.assertSwitcherIsNotDisplayed
|
||||||
import com.x8bit.bitwarden.ui.util.performAccountClick
|
import com.x8bit.bitwarden.ui.util.performAccountClick
|
||||||
import com.x8bit.bitwarden.ui.util.performAccountIconClick
|
import com.x8bit.bitwarden.ui.util.performAccountIconClick
|
||||||
import com.x8bit.bitwarden.ui.util.performAccountLongClick
|
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.performLockAccountClick
|
||||||
import com.x8bit.bitwarden.ui.util.performLogoutAccountClick
|
import com.x8bit.bitwarden.ui.util.performLogoutAccountClick
|
||||||
import com.x8bit.bitwarden.ui.util.performLogoutAccountConfirmationClick
|
import com.x8bit.bitwarden.ui.util.performLogoutAccountConfirmationClick
|
||||||
|
@ -86,7 +87,6 @@ class LoginScreenTest : BaseComposeTest() {
|
||||||
|
|
||||||
composeTestRule.assertSwitcherIsDisplayed(
|
composeTestRule.assertSwitcherIsDisplayed(
|
||||||
accountSummaries = accountSummaries,
|
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")
|
@Suppress("MaxLineLength")
|
||||||
@Test
|
@Test
|
||||||
fun `account long click in the account switcher should show the lock-or-logout dialog and close the switcher`() {
|
fun `account long click in the account switcher should show the lock-or-logout dialog and close the switcher`() {
|
||||||
|
|
|
@ -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
|
@Test
|
||||||
fun `LockAccountClick should call lockVaultIfNecessary for the given account`() {
|
fun `LockAccountClick should call lockVaultIfNecessary for the given account`() {
|
||||||
val accountUserId = "userId"
|
val accountUserId = "userId"
|
||||||
|
|
Loading…
Add table
Reference in a new issue