From fc78037fb0f90e99feb63c3a8fde3638ab0a3ede Mon Sep 17 00:00:00 2001 From: David Perez Date: Wed, 26 Jun 2024 11:34:39 -0500 Subject: [PATCH] BIT-2433: Filter trash from search results (#3361) --- .../search/util/SearchTypeDataExtensions.kt | 21 ++++++++------- .../util/SearchTypeDataExtensionsTest.kt | 26 +++++++++++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/search/util/SearchTypeDataExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/search/util/SearchTypeDataExtensions.kt index 0ebc880b2..399886049 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/search/util/SearchTypeDataExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/search/util/SearchTypeDataExtensions.kt @@ -102,15 +102,18 @@ private fun CipherView.filterBySearchType( searchTypeData: SearchTypeData.Vault, ): Boolean = when (searchTypeData) { - SearchTypeData.Vault.All -> true - is SearchTypeData.Vault.Cards -> type == CipherType.CARD - is SearchTypeData.Vault.Collection -> searchTypeData.collectionId in this.collectionIds - is SearchTypeData.Vault.Folder -> folderId == searchTypeData.folderId - SearchTypeData.Vault.NoFolder -> folderId == null - is SearchTypeData.Vault.Identities -> type == CipherType.IDENTITY - is SearchTypeData.Vault.Logins -> type == CipherType.LOGIN - is SearchTypeData.Vault.SecureNotes -> type == CipherType.SECURE_NOTE - is SearchTypeData.Vault.VerificationCodes -> login?.totp != null + SearchTypeData.Vault.All -> deletedDate == null + is SearchTypeData.Vault.Cards -> type == CipherType.CARD && deletedDate == null + is SearchTypeData.Vault.Collection -> { + searchTypeData.collectionId in this.collectionIds && deletedDate == null + } + + is SearchTypeData.Vault.Folder -> folderId == searchTypeData.folderId && deletedDate == null + SearchTypeData.Vault.NoFolder -> folderId == null && deletedDate == null + is SearchTypeData.Vault.Identities -> type == CipherType.IDENTITY && deletedDate == null + is SearchTypeData.Vault.Logins -> type == CipherType.LOGIN && deletedDate == null + is SearchTypeData.Vault.SecureNotes -> type == CipherType.SECURE_NOTE && deletedDate == null + is SearchTypeData.Vault.VerificationCodes -> login?.totp != null && deletedDate == null is SearchTypeData.Vault.Trash -> deletedDate != null } diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/search/util/SearchTypeDataExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/search/util/SearchTypeDataExtensionsTest.kt index 778627615..fdaa4e6c5 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/search/util/SearchTypeDataExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/search/util/SearchTypeDataExtensionsTest.kt @@ -257,6 +257,32 @@ class SearchTypeDataExtensionsTest { assertEquals(listOf(match1, match2), result) } + @Test + fun `CipherViews filterAndOrganize should return list without deleted items`() { + val match1 = createMockCipherView(number = 1, isDeleted = true).copy(name = "match1") + val match2 = createMockCipherView(number = 2).copy(name = "match2") + val match3 = createMockCipherView(number = 3, isDeleted = true).copy(name = "match3") + val ciphers = listOf(match1, match2, match3) + val result = ciphers.filterAndOrganize( + searchTypeData = SearchTypeData.Vault.Logins, + searchTerm = "match", + ) + assertEquals(listOf(match2), result) + } + + @Test + fun `CipherViews filterAndOrganize should return list with only deleted items`() { + val match1 = createMockCipherView(number = 1, isDeleted = true).copy(name = "match1") + val match2 = createMockCipherView(number = 2).copy(name = "match2") + val match3 = createMockCipherView(number = 3, isDeleted = true).copy(name = "match3") + val ciphers = listOf(match1, match2, match3) + val result = ciphers.filterAndOrganize( + searchTypeData = SearchTypeData.Vault.Trash, + 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`() {