mirror of
https://github.com/bitwarden/android.git
synced 2026-05-08 04:16:40 -05:00
[PM-32810] test: Cover Bank Account vault, listing, and search surfaces (#6881)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
@file:OmitFromCoverage
|
||||
|
||||
package com.x8bit.bitwarden.ui.platform.feature.search
|
||||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
@@ -5,6 +7,7 @@ import androidx.navigation.NavController
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.NavOptions
|
||||
import androidx.navigation.toRoute
|
||||
import com.bitwarden.annotation.OmitFromCoverage
|
||||
import com.bitwarden.ui.platform.base.util.composableWithSlideTransitions
|
||||
import com.x8bit.bitwarden.ui.platform.feature.search.model.SearchType
|
||||
import com.x8bit.bitwarden.ui.tools.feature.send.addedit.AddEditSendRoute
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
@file:OmitFromCoverage
|
||||
|
||||
package com.x8bit.bitwarden.ui.vault.feature.itemlisting
|
||||
|
||||
import android.os.Parcelable
|
||||
@@ -6,6 +8,7 @@ import androidx.navigation.NavController
|
||||
import androidx.navigation.NavGraphBuilder
|
||||
import androidx.navigation.NavOptions
|
||||
import androidx.navigation.toRoute
|
||||
import com.bitwarden.annotation.OmitFromCoverage
|
||||
import com.bitwarden.ui.platform.base.util.composableWithPushTransitions
|
||||
import com.bitwarden.ui.platform.base.util.composableWithStayTransitions
|
||||
import com.bitwarden.ui.platform.util.ParcelableRouteSerializer
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.time.temporal.TemporalAccessor
|
||||
|
||||
private const val DEFAULT_FORMATTED_DATE_TIME = "Oct 27, 2023, 12:00 PM"
|
||||
|
||||
@Suppress("LargeClass")
|
||||
class SearchTypeDataExtensionsTest {
|
||||
|
||||
private val clock: Clock = Clock.fixed(
|
||||
@@ -240,6 +241,19 @@ class SearchTypeDataExtensionsTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `updateWithAdditionalDataIfNecessary should return the searchTypeData unchanged for Vault BankAccounts`() {
|
||||
val searchTypeData = SearchTypeData.Vault.BankAccounts
|
||||
assertEquals(
|
||||
searchTypeData,
|
||||
searchTypeData.updateWithAdditionalDataIfNecessary(
|
||||
folderList = listOf(),
|
||||
collectionList = emptyList(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `updateWithAdditionalDataIfNecessary should return the searchTypeData unchanged for Vault VerificationCodes`() {
|
||||
@@ -360,6 +374,27 @@ class SearchTypeDataExtensionsTest {
|
||||
assertEquals(listOf(match1, match3), result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `CipherViews filterAndOrganize should return list with only bank account items`() {
|
||||
val match1 = createMockCipherListView(
|
||||
number = 1,
|
||||
type = CipherListViewType.BankAccount,
|
||||
name = "match1",
|
||||
)
|
||||
val match2 = createMockCipherListView(number = 2, name = "match2")
|
||||
val match3 = createMockCipherListView(
|
||||
number = 3,
|
||||
type = CipherListViewType.BankAccount,
|
||||
name = "match3",
|
||||
)
|
||||
val ciphers = listOf(match1, match2, match3)
|
||||
val result = ciphers.filterAndOrganize(
|
||||
searchTypeData = SearchTypeData.Vault.BankAccounts,
|
||||
searchTerm = "match",
|
||||
)
|
||||
assertEquals(listOf(match1, match3), result)
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `CipherViews toViewState should return empty state with no message when search term is blank`() {
|
||||
|
||||
@@ -398,6 +398,38 @@ class VaultItemListingDataExtensionsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MaxLineLength")
|
||||
fun `determineListingPredicate should return the correct predicate for a non trash BankAccount cipherView`() {
|
||||
val cipherView = createMockCipherListView(
|
||||
number = 1,
|
||||
isDeleted = false,
|
||||
type = CipherListViewType.BankAccount,
|
||||
)
|
||||
|
||||
mapOf(
|
||||
VaultItemListingState.ItemListingType.Vault.Login to false,
|
||||
VaultItemListingState.ItemListingType.Vault.Card to false,
|
||||
VaultItemListingState.ItemListingType.Vault.SecureNote to false,
|
||||
VaultItemListingState.ItemListingType.Vault.Identity to false,
|
||||
VaultItemListingState.ItemListingType.Vault.Archive to false,
|
||||
VaultItemListingState.ItemListingType.Vault.Trash to false,
|
||||
VaultItemListingState.ItemListingType.Vault.SshKey to false,
|
||||
VaultItemListingState.ItemListingType.Vault.BankAccount to true,
|
||||
VaultItemListingState.ItemListingType.Vault.Folder(folderId = "mockId-1") to true,
|
||||
VaultItemListingState.ItemListingType.Vault.Collection(collectionId = "mockId-1") to true,
|
||||
)
|
||||
.forEach { (type, expected) ->
|
||||
val result = cipherView.determineListingPredicate(
|
||||
itemListingType = type,
|
||||
)
|
||||
assertEquals(
|
||||
expected,
|
||||
result,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MaxLineLength")
|
||||
fun `determineListingPredicate should return the correct predicate for item not in a folder`() {
|
||||
@@ -877,6 +909,27 @@ class VaultItemListingDataExtensionsTest {
|
||||
),
|
||||
)
|
||||
|
||||
// Bank accounts
|
||||
assertEquals(
|
||||
VaultItemListingState.ViewState.NoItems(
|
||||
message = BitwardenString.no_bank_accounts.asText(),
|
||||
shouldShowAddButton = false,
|
||||
buttonText = BitwardenString.new_bank_account.asText(),
|
||||
),
|
||||
vaultData.toViewState(
|
||||
itemListingType = VaultItemListingState.ItemListingType.Vault.BankAccount,
|
||||
vaultFilterType = VaultFilterType.AllVaults,
|
||||
hasMasterPassword = true,
|
||||
baseIconUrl = Environment.Us.environmentUrlData.baseIconUrl,
|
||||
isIconLoadingDisabled = false,
|
||||
autofillSelectionData = null,
|
||||
createCredentialRequestData = null,
|
||||
totpData = null,
|
||||
isPremiumUser = true,
|
||||
restrictItemTypesPolicyOrgIds = emptyList(),
|
||||
),
|
||||
)
|
||||
|
||||
// Other ciphers
|
||||
// Login Type
|
||||
assertEquals(
|
||||
@@ -1255,6 +1308,15 @@ class VaultItemListingDataExtensionsTest {
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
VaultItemListingState.ItemListingType.Vault.BankAccount,
|
||||
VaultItemListingState.ItemListingType.Vault.BankAccount
|
||||
.updateWithAdditionalDataIfNecessary(
|
||||
folderList = folderViewList,
|
||||
collectionList = collectionViewList,
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
VaultItemListingState.ItemListingType.Vault.Card,
|
||||
VaultItemListingState.ItemListingType.Vault.Card
|
||||
|
||||
@@ -132,6 +132,16 @@ class VaultItemListingStateExtensionsTest {
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toSearchType should return BankAccounts when item type is BankAccount`() {
|
||||
val expected = SearchType.Vault.BankAccounts
|
||||
val itemType = VaultItemListingState.ItemListingType.Vault.BankAccount
|
||||
|
||||
val result = itemType.toSearchType()
|
||||
|
||||
assertEquals(expected, result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toVaultItemCipherType should return the correct response`() {
|
||||
val itemListingTypes = listOf(
|
||||
@@ -141,6 +151,7 @@ class VaultItemListingStateExtensionsTest {
|
||||
VaultItemListingState.ItemListingType.Vault.Login,
|
||||
VaultItemListingState.ItemListingType.Vault.Collection(collectionId = "mockId"),
|
||||
VaultItemListingState.ItemListingType.Vault.SshKey,
|
||||
VaultItemListingState.ItemListingType.Vault.BankAccount,
|
||||
VaultItemListingState.ItemListingType.Vault.Folder(folderId = "mockId"),
|
||||
)
|
||||
|
||||
@@ -154,6 +165,7 @@ class VaultItemListingStateExtensionsTest {
|
||||
VaultItemCipherType.LOGIN,
|
||||
VaultItemCipherType.LOGIN,
|
||||
VaultItemCipherType.SSH_KEY,
|
||||
VaultItemCipherType.BANK_ACCOUNT,
|
||||
VaultItemCipherType.LOGIN,
|
||||
),
|
||||
result,
|
||||
|
||||
Reference in New Issue
Block a user