mirror of
https://github.com/bitwarden/android.git
synced 2026-08-02 02:32:04 -05:00
Chore: Account Summaries list in UI should be immutable (#7147)
This commit is contained in:
@@ -55,7 +55,6 @@ import com.bitwarden.ui.platform.resource.BitwardenDrawable
|
||||
import com.bitwarden.ui.platform.resource.BitwardenString
|
||||
import com.bitwarden.ui.platform.theme.BitwardenTheme
|
||||
import com.x8bit.bitwarden.ui.platform.components.dropdown.EnvironmentSelector
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
/**
|
||||
* The top level composable for the Landing screen.
|
||||
@@ -139,7 +138,7 @@ fun LandingScreen(
|
||||
overlay = {
|
||||
BitwardenAccountSwitcher(
|
||||
isVisible = isAccountMenuVisible,
|
||||
accountSummaries = state.accountSummaries.toImmutableList(),
|
||||
accountSummaries = state.accountSummaries,
|
||||
onSwitchAccountClick = {
|
||||
viewModel.trySendAction(LandingAction.SwitchAccountClick(it))
|
||||
},
|
||||
|
||||
+10
-8
@@ -55,7 +55,12 @@ class LandingViewModel @Inject constructor(
|
||||
selectedEnvironmentType = environmentRepository.environment.type,
|
||||
selectedEnvironmentLabel = environmentRepository.environment.label,
|
||||
dialog = null,
|
||||
accountSummaries = authRepository.userStateFlow.value?.toAccountSummaries().orEmpty(),
|
||||
accountSummaries = authRepository
|
||||
.userStateFlow
|
||||
.value
|
||||
?.toAccountSummaries()
|
||||
.orEmpty()
|
||||
.toImmutableList(),
|
||||
isFedRampEnabled = featureFlagManager.getFeatureFlag(FlagKey.FedRamp),
|
||||
),
|
||||
) {
|
||||
@@ -68,12 +73,9 @@ class LandingViewModel @Inject constructor(
|
||||
get() {
|
||||
val currentEmail = state.emailInput
|
||||
val currentEnvironmentLabel = state.selectedEnvironmentLabel
|
||||
val accountSummaries = state.accountSummaries
|
||||
return accountSummaries
|
||||
.find {
|
||||
it.email == currentEmail &&
|
||||
it.environmentLabel == currentEnvironmentLabel
|
||||
}
|
||||
return state
|
||||
.accountSummaries
|
||||
.find { it.email == currentEmail && it.environmentLabel == currentEnvironmentLabel }
|
||||
?.takeUnless { !it.isLoggedIn }
|
||||
}
|
||||
|
||||
@@ -299,7 +301,7 @@ data class LandingState(
|
||||
val selectedEnvironmentType: Environment.Type,
|
||||
val selectedEnvironmentLabel: String,
|
||||
val dialog: DialogState?,
|
||||
val accountSummaries: List<AccountSummary>,
|
||||
val accountSummaries: ImmutableList<AccountSummary>,
|
||||
val isFedRampEnabled: Boolean,
|
||||
) : Parcelable {
|
||||
/**
|
||||
|
||||
@@ -50,7 +50,6 @@ import com.bitwarden.ui.platform.resource.BitwardenString
|
||||
import com.bitwarden.ui.platform.theme.BitwardenTheme
|
||||
import com.x8bit.bitwarden.R
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
/**
|
||||
* The top level composable for the Login screen.
|
||||
@@ -134,7 +133,7 @@ fun LoginScreen(
|
||||
overlay = {
|
||||
BitwardenAccountSwitcher(
|
||||
isVisible = isAccountMenuVisible,
|
||||
accountSummaries = state.accountSummaries.toImmutableList(),
|
||||
accountSummaries = state.accountSummaries,
|
||||
onSwitchAccountClick = {
|
||||
viewModel.trySendAction(LoginAction.SwitchAccountClick(it))
|
||||
},
|
||||
|
||||
@@ -20,6 +20,8 @@ import com.x8bit.bitwarden.data.platform.util.toUriOrNull
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.toAccountSummaries
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.parcelize.IgnoredOnParcel
|
||||
@@ -52,7 +54,8 @@ class LoginViewModel @Inject constructor(
|
||||
.userStateFlow
|
||||
.value
|
||||
?.toAccountSummaries()
|
||||
.orEmpty(),
|
||||
.orEmpty()
|
||||
.toImmutableList(),
|
||||
shouldShowLoginWithDevice = false,
|
||||
)
|
||||
},
|
||||
@@ -296,7 +299,7 @@ data class LoginState(
|
||||
val environmentLabel: String,
|
||||
val isLoginButtonEnabled: Boolean,
|
||||
val dialogState: DialogState?,
|
||||
val accountSummaries: List<AccountSummary>,
|
||||
val accountSummaries: ImmutableList<AccountSummary>,
|
||||
val shouldShowLoginWithDevice: Boolean,
|
||||
) : Parcelable {
|
||||
/**
|
||||
|
||||
+1
-2
@@ -64,7 +64,6 @@ import com.x8bit.bitwarden.ui.platform.composition.LocalBiometricsManager
|
||||
import com.x8bit.bitwarden.ui.platform.composition.LocalCredentialProviderCompletionManager
|
||||
import com.x8bit.bitwarden.ui.platform.manager.biometrics.BiometricsManager
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.coroutines.delay
|
||||
import javax.crypto.Cipher
|
||||
|
||||
@@ -222,7 +221,7 @@ fun VaultUnlockScreen(
|
||||
overlay = {
|
||||
BitwardenAccountSwitcher(
|
||||
isVisible = accountMenuVisible,
|
||||
accountSummaries = state.accountSummaries.toImmutableList(),
|
||||
accountSummaries = state.accountSummaries,
|
||||
onSwitchAccountClick = {
|
||||
viewModel.trySendAction(VaultUnlockAction.SwitchAccountClick(it))
|
||||
},
|
||||
|
||||
+4
-2
@@ -36,6 +36,8 @@ import com.x8bit.bitwarden.ui.vault.feature.vault.util.toAccountSummaries
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.toAccountSummary
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.toActiveAccountSummary
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.update
|
||||
@@ -71,7 +73,7 @@ class VaultUnlockViewModel @Inject constructor(
|
||||
// get us out of here.
|
||||
UserState.EMPTY_ACCOUNT
|
||||
}
|
||||
val accountSummaries = userState?.toAccountSummaries().orEmpty()
|
||||
val accountSummaries = userState?.toAccountSummaries().orEmpty().toImmutableList()
|
||||
val activeAccountSummary = activeAccount.toAccountSummary(isActive = true)
|
||||
val vaultUnlockType = activeAccount.vaultUnlockType
|
||||
val hasNoMasterPassword = !activeAccount.hasMasterPassword
|
||||
@@ -445,7 +447,7 @@ class VaultUnlockViewModel @Inject constructor(
|
||||
*/
|
||||
@Parcelize
|
||||
data class VaultUnlockState(
|
||||
val accountSummaries: List<AccountSummary>,
|
||||
val accountSummaries: ImmutableList<AccountSummary>,
|
||||
private val avatarColorString: String,
|
||||
val hideInput: Boolean,
|
||||
val initials: String,
|
||||
|
||||
+1
-2
@@ -68,7 +68,6 @@ import com.x8bit.bitwarden.ui.vault.feature.itemlisting.handlers.VaultItemListin
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultAddEditType
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultItemListingType
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
|
||||
/**
|
||||
* Displays the vault item listing screen.
|
||||
@@ -501,7 +500,7 @@ private fun VaultItemListingScaffold(
|
||||
overlay = {
|
||||
BitwardenAccountSwitcher(
|
||||
isVisible = isAccountMenuVisible,
|
||||
accountSummaries = state.accountSummaries.toImmutableList(),
|
||||
accountSummaries = state.accountSummaries,
|
||||
onSwitchAccountClick = vaultItemListingHandlers.switchAccountClick,
|
||||
onLockAccountClick = vaultItemListingHandlers.lockAccountClick,
|
||||
onLogoutAccountClick = vaultItemListingHandlers.logoutAccountClick,
|
||||
|
||||
+1
-1
@@ -2933,7 +2933,7 @@ class VaultItemListingViewModel @Inject constructor(
|
||||
data class VaultItemListingState(
|
||||
val itemListingType: ItemListingType,
|
||||
val activeAccountSummary: AccountSummary,
|
||||
val accountSummaries: List<AccountSummary>,
|
||||
val accountSummaries: ImmutableList<AccountSummary>,
|
||||
val viewState: ViewState,
|
||||
val vaultFilterType: VaultFilterType,
|
||||
val baseWebSendUrl: String,
|
||||
|
||||
@@ -310,7 +310,7 @@ private fun VaultScreenScaffold(
|
||||
overlay = {
|
||||
BitwardenAccountSwitcher(
|
||||
isVisible = accountMenuVisible,
|
||||
accountSummaries = state.accountSummaries.toImmutableList(),
|
||||
accountSummaries = state.accountSummaries,
|
||||
onSwitchAccountClick = vaultHandlers.accountSwitchClickAction,
|
||||
onLockAccountClick = vaultHandlers.accountLockClickAction,
|
||||
onLogoutAccountClick = vaultHandlers.accountLogoutClickAction,
|
||||
|
||||
@@ -127,7 +127,7 @@ class VaultViewModel @Inject constructor(
|
||||
) : BaseViewModel<VaultState, VaultEvent, VaultAction>(
|
||||
initialState = run {
|
||||
val userState = authRepository.userStateFlow.value
|
||||
val accountSummaries = userState?.toAccountSummaries().orEmpty()
|
||||
val accountSummaries = userState?.toAccountSummaries().orEmpty().toImmutableList()
|
||||
val activeAccount = userState?.activeAccount ?: run {
|
||||
// We use this empty account to avoid a crash that can occur during a race condition.
|
||||
// The state-based navigation brought us here but the UserState has now been set to
|
||||
@@ -1756,7 +1756,7 @@ data class VaultState(
|
||||
val appBarTitle: Text,
|
||||
private val avatarColorString: String,
|
||||
val initials: String,
|
||||
val accountSummaries: List<AccountSummary>,
|
||||
val accountSummaries: ImmutableList<AccountSummary>,
|
||||
val vaultFilterData: VaultFilterData? = null,
|
||||
val viewState: ViewState,
|
||||
val dialog: DialogState? = null,
|
||||
|
||||
+6
-6
@@ -4,17 +4,17 @@ import com.bitwarden.ui.platform.components.account.model.AccountSummary
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.UserState
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterData
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterType
|
||||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import java.util.Locale
|
||||
|
||||
/**
|
||||
* Converts the given [UserState] to a list of [AccountSummary].
|
||||
*/
|
||||
fun UserState.toAccountSummaries(): List<AccountSummary> =
|
||||
accounts.map { account ->
|
||||
account.toAccountSummary(
|
||||
isActive = this.activeUserId == account.userId,
|
||||
)
|
||||
}
|
||||
fun UserState.toAccountSummaries(): ImmutableList<AccountSummary> =
|
||||
accounts
|
||||
.map { it.toAccountSummary(isActive = this.activeUserId == it.userId) }
|
||||
.toImmutableList()
|
||||
|
||||
/**
|
||||
* Converts the given [UserState] to an [AccountSummary] with a [AccountSummary.status] of
|
||||
|
||||
+11
-10
@@ -38,6 +38,7 @@ import com.x8bit.bitwarden.ui.platform.base.BitwardenComposeTest
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import org.junit.Before
|
||||
@@ -80,7 +81,7 @@ class LandingScreenTest : BitwardenComposeTest() {
|
||||
composeTestRule.onNodeWithContentDescription("Account").assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY))
|
||||
it.copy(accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY))
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithContentDescription("Account").assertIsDisplayed()
|
||||
@@ -88,7 +89,7 @@ class LandingScreenTest : BitwardenComposeTest() {
|
||||
|
||||
@Test
|
||||
fun `account menu icon click should show the account switcher`() {
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -105,7 +106,7 @@ class LandingScreenTest : BitwardenComposeTest() {
|
||||
@Test
|
||||
fun `account click in the account switcher should send SwitchAccountClick and close switcher`() {
|
||||
// Show the account switcher
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -125,7 +126,7 @@ class LandingScreenTest : BitwardenComposeTest() {
|
||||
@Test
|
||||
fun `account long click in the account switcher should show the lock-or-logout dialog and close the switcher`() {
|
||||
// Show the account switcher
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -145,7 +146,7 @@ class LandingScreenTest : BitwardenComposeTest() {
|
||||
@Test
|
||||
fun `lock button click in the lock-or-logout dialog should send LockAccountClick action and close the dialog`() {
|
||||
// Show the lock-or-logout dialog
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -162,7 +163,7 @@ class LandingScreenTest : BitwardenComposeTest() {
|
||||
@Test
|
||||
fun `logout button click in the lock-or-logout dialog should show the logout confirmation dialog and hide the lock-or-logout dialog`() {
|
||||
// Show the lock-or-logout dialog
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -180,7 +181,7 @@ class LandingScreenTest : BitwardenComposeTest() {
|
||||
@Test
|
||||
fun `logout button click in the logout confirmation dialog should send LogoutAccountClick action and close the dialog`() {
|
||||
// Show the logout confirmation dialog
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -200,7 +201,7 @@ class LandingScreenTest : BitwardenComposeTest() {
|
||||
// Show the lock-or-logout dialog
|
||||
val activeAccountSummary = ACTIVE_ACCOUNT_SUMMARY.copy(isLoggedIn = false)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = listOf(activeAccountSummary))
|
||||
it.copy(accountSummaries = persistentListOf(activeAccountSummary))
|
||||
}
|
||||
composeTestRule.performAccountIconClick()
|
||||
composeTestRule.performAccountLongClick(activeAccountSummary)
|
||||
@@ -216,7 +217,7 @@ class LandingScreenTest : BitwardenComposeTest() {
|
||||
// Show the remove account confirmation dialog
|
||||
val activeAccountSummary = ACTIVE_ACCOUNT_SUMMARY.copy(isLoggedIn = false)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = listOf(activeAccountSummary))
|
||||
it.copy(accountSummaries = persistentListOf(activeAccountSummary))
|
||||
}
|
||||
composeTestRule.performAccountIconClick()
|
||||
composeTestRule.performAccountLongClick(activeAccountSummary)
|
||||
@@ -522,6 +523,6 @@ private val DEFAULT_STATE = LandingState(
|
||||
selectedEnvironmentType = Environment.Type.US,
|
||||
selectedEnvironmentLabel = Environment.Us.label,
|
||||
dialog = null,
|
||||
accountSummaries = emptyList(),
|
||||
accountSummaries = persistentListOf(),
|
||||
isFedRampEnabled = true,
|
||||
)
|
||||
|
||||
+2
-1
@@ -28,6 +28,7 @@ import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import io.mockk.runs
|
||||
import io.mockk.verify
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
@@ -659,6 +660,6 @@ private val DEFAULT_STATE = LandingState(
|
||||
selectedEnvironmentType = Environment.Type.US,
|
||||
selectedEnvironmentLabel = Environment.Us.label,
|
||||
dialog = null,
|
||||
accountSummaries = emptyList(),
|
||||
accountSummaries = persistentListOf(),
|
||||
isFedRampEnabled = true,
|
||||
)
|
||||
|
||||
@@ -37,6 +37,7 @@ import io.mockk.mockk
|
||||
import io.mockk.runs
|
||||
import io.mockk.verify
|
||||
import junit.framework.TestCase.assertTrue
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import org.junit.Before
|
||||
@@ -83,7 +84,7 @@ class LoginScreenTest : BitwardenComposeTest() {
|
||||
composeTestRule.onNodeWithContentDescription("Account").assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY))
|
||||
it.copy(accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY))
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithContentDescription("Account").assertIsDisplayed()
|
||||
@@ -91,7 +92,7 @@ class LoginScreenTest : BitwardenComposeTest() {
|
||||
|
||||
@Test
|
||||
fun `account menu icon click should show the account switcher`() {
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -107,7 +108,7 @@ class LoginScreenTest : BitwardenComposeTest() {
|
||||
@Test
|
||||
fun `account click in the account switcher should send SwitchAccountClick and close switcher`() {
|
||||
// Show the account switcher
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -127,7 +128,7 @@ class LoginScreenTest : BitwardenComposeTest() {
|
||||
@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)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -145,7 +146,7 @@ class LoginScreenTest : BitwardenComposeTest() {
|
||||
@Test
|
||||
fun `account long click in the account switcher should show the lock-or-logout dialog and close the switcher`() {
|
||||
// Show the account switcher
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -165,7 +166,7 @@ class LoginScreenTest : BitwardenComposeTest() {
|
||||
@Test
|
||||
fun `lock button click in the lock-or-logout dialog should send LockAccountClick action and close the dialog`() {
|
||||
// Show the lock-or-logout dialog
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -182,7 +183,7 @@ class LoginScreenTest : BitwardenComposeTest() {
|
||||
@Test
|
||||
fun `logout button click in the lock-or-logout dialog should show the logout confirmation dialog and hide the lock-or-logout dialog`() {
|
||||
// Show the lock-or-logout dialog
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -200,7 +201,7 @@ class LoginScreenTest : BitwardenComposeTest() {
|
||||
@Test
|
||||
fun `logout button click in the logout confirmation dialog should send LogoutAccountClick action and close the dialog`() {
|
||||
// Show the logout confirmation dialog
|
||||
val accountSummaries = listOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
val accountSummaries = persistentListOf(ACTIVE_ACCOUNT_SUMMARY)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = accountSummaries)
|
||||
}
|
||||
@@ -220,7 +221,7 @@ class LoginScreenTest : BitwardenComposeTest() {
|
||||
// Show the lock-or-logout dialog
|
||||
val activeAccountSummary = ACTIVE_ACCOUNT_SUMMARY.copy(isLoggedIn = false)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = listOf(activeAccountSummary))
|
||||
it.copy(accountSummaries = persistentListOf(activeAccountSummary))
|
||||
}
|
||||
composeTestRule.performAccountIconClick()
|
||||
composeTestRule.performAccountLongClick(activeAccountSummary)
|
||||
@@ -236,7 +237,7 @@ class LoginScreenTest : BitwardenComposeTest() {
|
||||
// Show the remove account confirmation dialog
|
||||
val activeAccountSummary = ACTIVE_ACCOUNT_SUMMARY.copy(isLoggedIn = false)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = listOf(activeAccountSummary))
|
||||
it.copy(accountSummaries = persistentListOf(activeAccountSummary))
|
||||
}
|
||||
composeTestRule.performAccountIconClick()
|
||||
composeTestRule.performAccountLongClick(activeAccountSummary)
|
||||
@@ -355,6 +356,6 @@ private val DEFAULT_STATE =
|
||||
passwordInput = "",
|
||||
environmentLabel = "",
|
||||
dialogState = null,
|
||||
accountSummaries = emptyList(),
|
||||
accountSummaries = persistentListOf(),
|
||||
shouldShowLoginWithDevice = false,
|
||||
)
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.mockk.mockkStatic
|
||||
import io.mockk.runs
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.AfterEach
|
||||
@@ -721,7 +722,7 @@ class LoginViewModelTest : BaseViewModelTest() {
|
||||
isLoginButtonEnabled = false,
|
||||
environmentLabel = Environment.Us.label,
|
||||
dialogState = null,
|
||||
accountSummaries = emptyList(),
|
||||
accountSummaries = persistentListOf(),
|
||||
shouldShowLoginWithDevice = false,
|
||||
)
|
||||
}
|
||||
|
||||
+4
-3
@@ -49,6 +49,7 @@ import io.mockk.mockk
|
||||
import io.mockk.runs
|
||||
import io.mockk.slot
|
||||
import io.mockk.verify
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.test.runTest
|
||||
@@ -344,7 +345,7 @@ class VaultUnlockScreenTest : BitwardenComposeTest() {
|
||||
// Show the lock-or-logout dialog
|
||||
val activeAccountSummary = ACTIVE_ACCOUNT_SUMMARY.copy(isLoggedIn = false)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = listOf(activeAccountSummary))
|
||||
it.copy(accountSummaries = persistentListOf(activeAccountSummary))
|
||||
}
|
||||
composeTestRule.performAccountIconClick()
|
||||
composeTestRule.performAccountLongClick(activeAccountSummary)
|
||||
@@ -360,7 +361,7 @@ class VaultUnlockScreenTest : BitwardenComposeTest() {
|
||||
// Show the remove account confirmation dialog
|
||||
val activeAccountSummary = ACTIVE_ACCOUNT_SUMMARY.copy(isLoggedIn = false)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = listOf(activeAccountSummary))
|
||||
it.copy(accountSummaries = persistentListOf(activeAccountSummary))
|
||||
}
|
||||
composeTestRule.performAccountIconClick()
|
||||
composeTestRule.performAccountLongClick(activeAccountSummary)
|
||||
@@ -628,7 +629,7 @@ private val LOCKED_ACCOUNT_SUMMARY = AccountSummary(
|
||||
isVaultUnlocked = false,
|
||||
)
|
||||
|
||||
private val ACCOUNT_SUMMARIES = listOf(
|
||||
private val ACCOUNT_SUMMARIES = persistentListOf(
|
||||
ACTIVE_ACCOUNT_SUMMARY,
|
||||
LOCKED_ACCOUNT_SUMMARY,
|
||||
)
|
||||
|
||||
+19
-13
@@ -36,6 +36,7 @@ import io.mockk.mockkStatic
|
||||
import io.mockk.runs
|
||||
import io.mockk.unmockkStatic
|
||||
import io.mockk.verify
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.update
|
||||
@@ -119,7 +120,7 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
|
||||
val viewModel = createViewModel()
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
accountSummaries = emptyList(),
|
||||
accountSummaries = persistentListOf(),
|
||||
avatarColorString = "#ff000000",
|
||||
initials = "",
|
||||
email = "",
|
||||
@@ -326,7 +327,7 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
|
||||
avatarColorString = "#00aaaa",
|
||||
initials = "OU",
|
||||
email = "active+test@bitwarden.com",
|
||||
accountSummaries = listOf(
|
||||
accountSummaries = persistentListOf(
|
||||
AccountSummary(
|
||||
userId = "activeUserId",
|
||||
name = "Other User",
|
||||
@@ -349,8 +350,9 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
|
||||
val password = "abc1234"
|
||||
val initialState = DEFAULT_STATE.copy(
|
||||
input = password,
|
||||
accountSummaries = listOf(
|
||||
DEFAULT_ACCOUNT.copy(isVaultUnlocked = false)
|
||||
accountSummaries = persistentListOf(
|
||||
DEFAULT_ACCOUNT
|
||||
.copy(isVaultUnlocked = false)
|
||||
.toAccountSummary(true),
|
||||
),
|
||||
)
|
||||
@@ -379,8 +381,9 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
|
||||
val mockFido2GetCredentialsRequest = createMockGetCredentialsRequest(number = 1)
|
||||
val initialState = DEFAULT_STATE.copy(
|
||||
getCredentialsRequest = mockFido2GetCredentialsRequest,
|
||||
accountSummaries = listOf(
|
||||
DEFAULT_ACCOUNT.copy(isVaultUnlocked = false)
|
||||
accountSummaries = persistentListOf(
|
||||
DEFAULT_ACCOUNT
|
||||
.copy(isVaultUnlocked = false)
|
||||
.toAccountSummary(isActive = true),
|
||||
),
|
||||
)
|
||||
@@ -412,8 +415,9 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
val initialState = DEFAULT_STATE.copy(
|
||||
getCredentialsRequest = mockFido2GetCredentialsRequest,
|
||||
accountSummaries = listOf(
|
||||
DEFAULT_ACCOUNT.copy(isVaultUnlocked = false)
|
||||
accountSummaries = persistentListOf(
|
||||
DEFAULT_ACCOUNT
|
||||
.copy(isVaultUnlocked = false)
|
||||
.toAccountSummary(isActive = true),
|
||||
),
|
||||
userId = mockFido2GetCredentialsRequest.userId,
|
||||
@@ -444,8 +448,9 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
|
||||
createMockFido2CredentialAssertionRequest(number = 1)
|
||||
val initialState = DEFAULT_STATE.copy(
|
||||
fido2CredentialAssertionRequest = mockFido2CredentialAssertionRequest,
|
||||
accountSummaries = listOf(
|
||||
DEFAULT_ACCOUNT.copy(isVaultUnlocked = false)
|
||||
accountSummaries = persistentListOf(
|
||||
DEFAULT_ACCOUNT
|
||||
.copy(isVaultUnlocked = false)
|
||||
.toAccountSummary(isActive = true),
|
||||
),
|
||||
)
|
||||
@@ -478,8 +483,9 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
val initialState = DEFAULT_STATE.copy(
|
||||
fido2CredentialAssertionRequest = mockFido2CredentialAssertionRequest,
|
||||
accountSummaries = listOf(
|
||||
DEFAULT_ACCOUNT.copy(isVaultUnlocked = false)
|
||||
accountSummaries = persistentListOf(
|
||||
DEFAULT_ACCOUNT
|
||||
.copy(isVaultUnlocked = false)
|
||||
.toAccountSummary(isActive = true),
|
||||
),
|
||||
userId = mockFido2CredentialAssertionRequest.userId,
|
||||
@@ -1365,7 +1371,7 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
|
||||
private val CIPHER = mockk<Cipher>()
|
||||
private const val USER_ID: String = "activeUserId"
|
||||
private val DEFAULT_STATE: VaultUnlockState = VaultUnlockState(
|
||||
accountSummaries = listOf(
|
||||
accountSummaries = persistentListOf(
|
||||
AccountSummary(
|
||||
userId = "activeUserId",
|
||||
name = "Active User",
|
||||
|
||||
+3
-3
@@ -372,7 +372,7 @@ class VaultItemListingScreenTest : BitwardenComposeTest() {
|
||||
val activeAccountSummary = ACTIVE_ACCOUNT_SUMMARY.copy(isLoggedIn = false)
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
accountSummaries = listOf(activeAccountSummary),
|
||||
accountSummaries = persistentListOf(activeAccountSummary),
|
||||
autofillSelectionData = AUTOFILL_SELECTION_DATA,
|
||||
)
|
||||
}
|
||||
@@ -391,7 +391,7 @@ class VaultItemListingScreenTest : BitwardenComposeTest() {
|
||||
val activeAccountSummary = ACTIVE_ACCOUNT_SUMMARY.copy(isLoggedIn = false)
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
accountSummaries = listOf(activeAccountSummary),
|
||||
accountSummaries = persistentListOf(activeAccountSummary),
|
||||
autofillSelectionData = AUTOFILL_SELECTION_DATA,
|
||||
)
|
||||
}
|
||||
@@ -2651,7 +2651,7 @@ private val LOCKED_ACCOUNT_SUMMARY = AccountSummary(
|
||||
isVaultUnlocked = false,
|
||||
)
|
||||
|
||||
private val ACCOUNT_SUMMARIES = listOf(
|
||||
private val ACCOUNT_SUMMARIES = persistentListOf(
|
||||
ACTIVE_ACCOUNT_SUMMARY,
|
||||
LOCKED_ACCOUNT_SUMMARY,
|
||||
)
|
||||
|
||||
@@ -384,7 +384,7 @@ class VaultScreenTest : BitwardenComposeTest() {
|
||||
// Show the lock-or-logout dialog
|
||||
val activeAccountSummary = ACTIVE_ACCOUNT_SUMMARY.copy(isLoggedIn = false)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = listOf(activeAccountSummary))
|
||||
it.copy(accountSummaries = persistentListOf(activeAccountSummary))
|
||||
}
|
||||
composeTestRule.performAccountIconClick()
|
||||
composeTestRule.performAccountLongClick(activeAccountSummary)
|
||||
@@ -400,7 +400,7 @@ class VaultScreenTest : BitwardenComposeTest() {
|
||||
// Show the remove account confirmation dialog
|
||||
val activeAccountSummary = ACTIVE_ACCOUNT_SUMMARY.copy(isLoggedIn = false)
|
||||
mutableStateFlow.update {
|
||||
it.copy(accountSummaries = listOf(activeAccountSummary))
|
||||
it.copy(accountSummaries = persistentListOf(activeAccountSummary))
|
||||
}
|
||||
composeTestRule.performAccountIconClick()
|
||||
composeTestRule.performAccountLongClick(activeAccountSummary)
|
||||
|
||||
+4
-4
@@ -265,7 +265,7 @@ class VaultViewModelTest : BaseViewModelTest() {
|
||||
val viewModel = createViewModel()
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
accountSummaries = emptyList(),
|
||||
accountSummaries = persistentListOf(),
|
||||
avatarColorString = "#ff000000",
|
||||
initials = "",
|
||||
showImportActionCard = false,
|
||||
@@ -681,7 +681,7 @@ class VaultViewModelTest : BaseViewModelTest() {
|
||||
appBarTitle = BitwardenString.vaults.asText(),
|
||||
avatarColorString = "#00aaaa",
|
||||
initials = "OU",
|
||||
accountSummaries = listOf(
|
||||
accountSummaries = persistentListOf(
|
||||
AccountSummary(
|
||||
userId = "activeUserId",
|
||||
name = "Other User",
|
||||
@@ -768,7 +768,7 @@ class VaultViewModelTest : BaseViewModelTest() {
|
||||
appBarTitle = BitwardenString.vaults.asText(),
|
||||
avatarColorString = "#00aaaa",
|
||||
initials = "OU",
|
||||
accountSummaries = listOf(
|
||||
accountSummaries = persistentListOf(
|
||||
AccountSummary(
|
||||
userId = "activeUserId",
|
||||
name = "Other User",
|
||||
@@ -4735,7 +4735,7 @@ private fun createMockVaultState(
|
||||
appBarTitle = BitwardenString.my_vault.asText(),
|
||||
avatarColorString = "#aa00aa",
|
||||
initials = "AU",
|
||||
accountSummaries = listOf(
|
||||
accountSummaries = persistentListOf(
|
||||
AccountSummary(
|
||||
userId = "activeUserId",
|
||||
name = "Active User",
|
||||
|
||||
Reference in New Issue
Block a user