Standardize naming of actions related to account switcher (#363)

This commit is contained in:
Brian Yencho 2023-12-11 11:49:32 -06:00 committed by Álison Fernandes
parent 8855fda026
commit 82d7c307ff
8 changed files with 25 additions and 23 deletions

View file

@ -103,7 +103,7 @@ fun LandingScreen(
{
viewModel.trySendAction(
LandingAction.ConfirmSwitchToMatchingAccountClick(
account = dialog.accountSummary,
accountSummary = dialog.accountSummary,
),
)
}

View file

@ -93,13 +93,13 @@ class LandingViewModel @Inject constructor(
}
private fun handleSwitchAccountClicked(action: LandingAction.SwitchAccountClick) {
authRepository.switchAccount(userId = action.account.userId)
authRepository.switchAccount(userId = action.accountSummary.userId)
}
private fun handleConfirmSwitchToMatchingAccountClicked(
action: LandingAction.ConfirmSwitchToMatchingAccountClick,
) {
authRepository.switchAccount(userId = action.account.userId)
authRepository.switchAccount(userId = action.accountSummary.userId)
}
private fun handleEmailInputUpdated(action: LandingAction.EmailInputChanged) {
@ -248,17 +248,18 @@ sealed class LandingEvent {
*/
sealed class LandingAction {
/**
* Indicates the user has clicked on the given [account] information in order to switch to it.
* Indicates the user has clicked on the given [accountSummary] information in order to switch
* to it.
*/
data class SwitchAccountClick(
val account: AccountSummary,
val accountSummary: AccountSummary,
) : LandingAction()
/**
* Indicates the user has confirmed they would like to switch to the existing [account].
* Indicates the user has confirmed they would like to switch to the existing [accountSummary].
*/
data class ConfirmSwitchToMatchingAccountClick(
val account: AccountSummary,
val accountSummary: AccountSummary,
) : LandingAction()
/**

View file

@ -87,7 +87,7 @@ class LoginViewModel @Inject constructor(
}
private fun handleSwitchAccountClicked(action: LoginAction.SwitchAccountClick) {
authRepository.switchAccount(userId = action.account.userId)
authRepository.switchAccount(userId = action.accountSummary.userId)
}
private fun handleReceiveLoginResult(action: LoginAction.Internal.ReceiveLoginResult) {
@ -235,10 +235,11 @@ sealed class LoginEvent {
*/
sealed class LoginAction {
/**
* Indicates the user has clicked on the given [account] information in order to switch to it.
* Indicates the user has clicked on the given [accountSummary] information in order to switch
* to it.
*/
data class SwitchAccountClick(
val account: AccountSummary,
val accountSummary: AccountSummary,
) : LoginAction()
/**

View file

@ -88,7 +88,7 @@ fun VaultScreen(
{ viewModel.trySendAction(VaultAction.SearchIconClick) }
},
accountSwitchClickAction = remember(viewModel) {
{ viewModel.trySendAction(VaultAction.AccountSwitchClick(it)) }
{ viewModel.trySendAction(VaultAction.SwitchAccountClick(it)) }
},
addAccountClickAction = remember(viewModel) {
{ viewModel.trySendAction(VaultAction.AddAccountClick) }

View file

@ -87,7 +87,7 @@ class VaultViewModel @Inject constructor(
is VaultAction.IdentityGroupClick -> handleIdentityClick()
is VaultAction.LoginGroupClick -> handleLoginClick()
is VaultAction.SearchIconClick -> handleSearchIconClick()
is VaultAction.AccountSwitchClick -> handleAccountSwitchClick(action)
is VaultAction.SwitchAccountClick -> handleSwitchAccountClick(action)
is VaultAction.AddAccountClick -> handleAddAccountClick()
is VaultAction.SecureNoteGroupClick -> handleSecureNoteClick()
is VaultAction.TrashClick -> handleTrashClick()
@ -128,7 +128,7 @@ class VaultViewModel @Inject constructor(
sendEvent(VaultEvent.NavigateToVaultSearchScreen)
}
private fun handleAccountSwitchClick(action: VaultAction.AccountSwitchClick) {
private fun handleSwitchAccountClick(action: VaultAction.SwitchAccountClick) {
val isSwitchingAccounts =
when (authRepository.switchAccount(userId = action.accountSummary.userId)) {
SwitchAccountResult.AccountSwitched -> true
@ -464,7 +464,7 @@ sealed class VaultAction {
/**
* User clicked an account in the account switcher.
*/
data class AccountSwitchClick(
data class SwitchAccountClick(
val accountSummary: AccountSummary,
) : VaultAction()

View file

@ -341,7 +341,7 @@ class LandingScreenTest : BaseComposeTest() {
verify {
viewModel.trySendAction(
LandingAction.ConfirmSwitchToMatchingAccountClick(account = accountSummary),
LandingAction.ConfirmSwitchToMatchingAccountClick(accountSummary = accountSummary),
)
}
}

View file

@ -81,14 +81,14 @@ class VaultScreenTest : BaseComposeTest() {
@Suppress("MaxLineLength")
@Test
fun `account click in the account switcher should send AccountSwitchClick and close switcher`() {
fun `account click in the account switcher should send SwitchAccountClick and close switcher`() {
// Open the Account Switcher
val accountSummaries = DEFAULT_STATE.accountSummaries
composeTestRule.performAccountIconClick()
composeTestRule.performAccountClick(accountSummary = LOCKED_ACCOUNT_SUMMARY)
verify { viewModel.trySendAction(VaultAction.AccountSwitchClick(LOCKED_ACCOUNT_SUMMARY)) }
verify { viewModel.trySendAction(VaultAction.SwitchAccountClick(LOCKED_ACCOUNT_SUMMARY)) }
composeTestRule.assertSwitcherIsNotDisplayed(
accountSummaries = accountSummaries,
)

View file

@ -81,7 +81,7 @@ class VaultViewModelTest : BaseViewModelTest() {
switchAccountResult = SwitchAccountResult.AccountSwitched
val updatedUserId = "lockedUserId"
viewModel.trySendAction(
VaultAction.AccountSwitchClick(
VaultAction.SwitchAccountClick(
accountSummary = mockk() {
every { userId } returns updatedUserId
},
@ -146,13 +146,13 @@ class VaultViewModelTest : BaseViewModelTest() {
@Suppress("MaxLineLength")
@Test
fun `on AccountSwitchClick when result is NoChange should try to switch to the given account and set isSwitchingAccounts to false`() =
fun `on SwitchAccountClick when result is NoChange should try to switch to the given account and set isSwitchingAccounts to false`() =
runTest {
val viewModel = createViewModel()
switchAccountResult = SwitchAccountResult.NoChange
val updatedUserId = "lockedUserId"
viewModel.trySendAction(
VaultAction.AccountSwitchClick(
VaultAction.SwitchAccountClick(
accountSummary = mockk {
every { userId } returns updatedUserId
},
@ -167,13 +167,13 @@ class VaultViewModelTest : BaseViewModelTest() {
@Suppress("MaxLineLength")
@Test
fun `on AccountSwitchClick when result is AccountSwitched should switch to the given account and set isSwitchingAccounts to true`() =
fun `on SwitchAccountClick when result is AccountSwitched should switch to the given account and set isSwitchingAccounts to true`() =
runTest {
val viewModel = createViewModel()
switchAccountResult = SwitchAccountResult.AccountSwitched
val updatedUserId = "lockedUserId"
viewModel.trySendAction(
VaultAction.AccountSwitchClick(
VaultAction.SwitchAccountClick(
accountSummary = mockk {
every { userId } returns updatedUserId
},
@ -312,7 +312,7 @@ class VaultViewModelTest : BaseViewModelTest() {
switchAccountResult = SwitchAccountResult.AccountSwitched
val updatedUserId = "lockedUserId"
viewModel.trySendAction(
VaultAction.AccountSwitchClick(
VaultAction.SwitchAccountClick(
accountSummary = mockk() {
every { userId } returns updatedUserId
},