mirror of
https://github.com/bitwarden/android.git
synced 2025-12-11 22:52:20 -06:00
Fixed and added tests to skip account selection on cxp
This commit is contained in:
parent
b2716cd7d2
commit
44a784fbd5
@ -25,6 +25,7 @@ import com.x8bit.bitwarden.ui.tools.feature.send.model.SendItemType
|
|||||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditMode
|
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditMode
|
||||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditRoute
|
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditRoute
|
||||||
import com.x8bit.bitwarden.ui.vault.feature.exportitems.ExportItemsGraphRoute
|
import com.x8bit.bitwarden.ui.vault.feature.exportitems.ExportItemsGraphRoute
|
||||||
|
import com.x8bit.bitwarden.ui.vault.feature.exportitems.verifypassword.VerifyPasswordRoute
|
||||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.ItemListingType
|
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.ItemListingType
|
||||||
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.VaultItemListingRoute
|
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.VaultItemListingRoute
|
||||||
import com.x8bit.bitwarden.ui.vault.model.VaultItemCipherType
|
import com.x8bit.bitwarden.ui.vault.model.VaultItemCipherType
|
||||||
@ -450,6 +451,26 @@ class RootNavScreenTest : BitwardenComposeTest() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Make sure navigating to export items graph works as expected:
|
||||||
|
rootNavStateFlow.value = RootNavState.CredentialExchangeExportSkipAccountSelection(
|
||||||
|
userId = "activeUserId",
|
||||||
|
)
|
||||||
|
composeTestRule.runOnIdle {
|
||||||
|
verify {
|
||||||
|
mockNavHostController.navigate(
|
||||||
|
route = ExportItemsGraphRoute,
|
||||||
|
navOptions = expectedNavOptions,
|
||||||
|
)
|
||||||
|
|
||||||
|
mockNavHostController.navigate(
|
||||||
|
route = VerifyPasswordRoute(
|
||||||
|
userId = "activeUserId",
|
||||||
|
),
|
||||||
|
navOptions = expectedNavOptions,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1441,7 +1441,7 @@ class RootNavViewModelTest : BaseViewModelTest() {
|
|||||||
requestJson = "mockRequestJson",
|
requestJson = "mockRequestJson",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
mutableUserStateFlow.tryEmit(MOCK_VAULT_UNLOCKED_USER_STATE)
|
mutableUserStateFlow.tryEmit(MOCK_VAULT_UNLOCKED_USER_MULTIPLE_ACCOUNTS_STATE)
|
||||||
val viewModel = createViewModel()
|
val viewModel = createViewModel()
|
||||||
assertEquals(
|
assertEquals(
|
||||||
RootNavState.CredentialExchangeExport,
|
RootNavState.CredentialExchangeExport,
|
||||||
@ -1449,6 +1449,26 @@ class RootNavViewModelTest : BaseViewModelTest() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("MaxLineLength")
|
||||||
|
@Test
|
||||||
|
fun `when SpecialCircumstance is CredentialExchangeExport and only has 1 account, the nav state should be CredentialExchangeExportSkipAccountSelection`() {
|
||||||
|
specialCircumstanceManager.specialCircumstance =
|
||||||
|
SpecialCircumstance.CredentialExchangeExport(
|
||||||
|
data = ImportCredentialsRequestData(
|
||||||
|
uri = mockk(),
|
||||||
|
requestJson = "mockRequestJson",
|
||||||
|
),
|
||||||
|
)
|
||||||
|
mutableUserStateFlow.tryEmit(MOCK_VAULT_UNLOCKED_USER_STATE)
|
||||||
|
val viewModel = createViewModel()
|
||||||
|
assertEquals(
|
||||||
|
RootNavState.CredentialExchangeExportSkipAccountSelection(
|
||||||
|
userId = "activeUserId",
|
||||||
|
),
|
||||||
|
viewModel.stateFlow.value,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun createViewModel(): RootNavViewModel =
|
private fun createViewModel(): RootNavViewModel =
|
||||||
RootNavViewModel(
|
RootNavViewModel(
|
||||||
authRepository = authRepository,
|
authRepository = authRepository,
|
||||||
@ -1487,3 +1507,48 @@ private val MOCK_VAULT_UNLOCKED_USER_STATE = UserState(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
private val MOCK_VAULT_UNLOCKED_USER_MULTIPLE_ACCOUNTS_STATE = UserState(
|
||||||
|
activeUserId = "activeUserId",
|
||||||
|
accounts = listOf(
|
||||||
|
UserState.Account(
|
||||||
|
userId = "activeUserId",
|
||||||
|
name = "name",
|
||||||
|
email = "email",
|
||||||
|
avatarColorHex = "avatarColorHex",
|
||||||
|
environment = Environment.Us,
|
||||||
|
isPremium = true,
|
||||||
|
isLoggedIn = true,
|
||||||
|
isVaultUnlocked = true,
|
||||||
|
needsPasswordReset = false,
|
||||||
|
isBiometricsEnabled = false,
|
||||||
|
organizations = emptyList(),
|
||||||
|
needsMasterPassword = false,
|
||||||
|
trustedDevice = null,
|
||||||
|
hasMasterPassword = true,
|
||||||
|
isUsingKeyConnector = false,
|
||||||
|
firstTimeState = FirstTimeState(false),
|
||||||
|
onboardingStatus = OnboardingStatus.COMPLETE,
|
||||||
|
),
|
||||||
|
|
||||||
|
UserState.Account(
|
||||||
|
userId = "activeUserTwoId",
|
||||||
|
name = "name two",
|
||||||
|
email = "email two",
|
||||||
|
avatarColorHex = "avatarColorHex",
|
||||||
|
environment = Environment.Us,
|
||||||
|
isPremium = true,
|
||||||
|
isLoggedIn = true,
|
||||||
|
isVaultUnlocked = true,
|
||||||
|
needsPasswordReset = false,
|
||||||
|
isBiometricsEnabled = false,
|
||||||
|
organizations = emptyList(),
|
||||||
|
needsMasterPassword = false,
|
||||||
|
trustedDevice = null,
|
||||||
|
hasMasterPassword = true,
|
||||||
|
isUsingKeyConnector = false,
|
||||||
|
firstTimeState = FirstTimeState(false),
|
||||||
|
onboardingStatus = OnboardingStatus.COMPLETE,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|||||||
@ -262,4 +262,5 @@ private val DEFAULT_STATE = VerifyPasswordState(
|
|||||||
accountSummaryListItem = DEFAULT_ACCOUNT_SELECTION_LIST_ITEM,
|
accountSummaryListItem = DEFAULT_ACCOUNT_SELECTION_LIST_ITEM,
|
||||||
input = "",
|
input = "",
|
||||||
dialog = null,
|
dialog = null,
|
||||||
|
hasOtherAccounts = true,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -86,6 +86,7 @@ class VerifyPasswordViewModelTest : BaseViewModelTest() {
|
|||||||
isItemRestricted = false,
|
isItemRestricted = false,
|
||||||
initials = DEFAULT_USER_STATE.activeAccount.initials,
|
initials = DEFAULT_USER_STATE.activeAccount.initials,
|
||||||
),
|
),
|
||||||
|
hasOtherAccounts = true,
|
||||||
),
|
),
|
||||||
it.stateFlow.value,
|
it.stateFlow.value,
|
||||||
)
|
)
|
||||||
@ -108,6 +109,7 @@ class VerifyPasswordViewModelTest : BaseViewModelTest() {
|
|||||||
.also {
|
.also {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
VerifyPasswordState(
|
VerifyPasswordState(
|
||||||
|
hasOtherAccounts = true,
|
||||||
accountSummaryListItem = DEFAULT_ACCOUNT_SELECTION_LIST_ITEM
|
accountSummaryListItem = DEFAULT_ACCOUNT_SELECTION_LIST_ITEM
|
||||||
.copy(isItemRestricted = true),
|
.copy(isItemRestricted = true),
|
||||||
),
|
),
|
||||||
@ -571,6 +573,36 @@ private val DEFAULT_USER_STATE = UserState(
|
|||||||
onboardingStatus = OnboardingStatus.COMPLETE,
|
onboardingStatus = OnboardingStatus.COMPLETE,
|
||||||
firstTimeState = FirstTimeState(showImportLoginsCard = true),
|
firstTimeState = FirstTimeState(showImportLoginsCard = true),
|
||||||
),
|
),
|
||||||
|
|
||||||
|
UserState.Account(
|
||||||
|
userId = "activeUserId2",
|
||||||
|
name = "Active User Two",
|
||||||
|
email = "active+two@bitwarden.com",
|
||||||
|
avatarColorHex = "#aa00aa",
|
||||||
|
environment = Environment.Us,
|
||||||
|
isPremium = true,
|
||||||
|
isLoggedIn = true,
|
||||||
|
isVaultUnlocked = true,
|
||||||
|
needsPasswordReset = false,
|
||||||
|
isBiometricsEnabled = false,
|
||||||
|
organizations = listOf(
|
||||||
|
Organization(
|
||||||
|
id = DEFAULT_ORGANIZATION_ID,
|
||||||
|
name = "Organization User Two",
|
||||||
|
shouldUseKeyConnector = false,
|
||||||
|
shouldManageResetPassword = false,
|
||||||
|
role = OrganizationType.USER,
|
||||||
|
keyConnectorUrl = null,
|
||||||
|
userIsClaimedByOrganization = false,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
needsMasterPassword = false,
|
||||||
|
trustedDevice = null,
|
||||||
|
hasMasterPassword = true,
|
||||||
|
isUsingKeyConnector = false,
|
||||||
|
onboardingStatus = OnboardingStatus.COMPLETE,
|
||||||
|
firstTimeState = FirstTimeState(showImportLoginsCard = true),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
private val DEFAULT_ACCOUNT_SELECTION_LIST_ITEM = AccountSelectionListItem(
|
private val DEFAULT_ACCOUNT_SELECTION_LIST_ITEM = AccountSelectionListItem(
|
||||||
@ -581,6 +613,7 @@ private val DEFAULT_ACCOUNT_SELECTION_LIST_ITEM = AccountSelectionListItem(
|
|||||||
initials = DEFAULT_USER_STATE.activeAccount.initials,
|
initials = DEFAULT_USER_STATE.activeAccount.initials,
|
||||||
)
|
)
|
||||||
private val DEFAULT_STATE = VerifyPasswordState(
|
private val DEFAULT_STATE = VerifyPasswordState(
|
||||||
|
hasOtherAccounts = true,
|
||||||
accountSummaryListItem = DEFAULT_ACCOUNT_SELECTION_LIST_ITEM,
|
accountSummaryListItem = DEFAULT_ACCOUNT_SELECTION_LIST_ITEM,
|
||||||
input = "",
|
input = "",
|
||||||
dialog = null,
|
dialog = null,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user