From 5c8a055975b111274b53b37021ee7ba62734b507 Mon Sep 17 00:00:00 2001 From: mpbw2 <59324545+mpbw2@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:27:36 -0500 Subject: [PATCH 1/5] [PM-13349] Hide edit button unless item is in at least one non-readOnly collection --- .../vault/feature/item/VaultItemViewModel.kt | 17 +- .../feature/item/model/VaultItemStateData.kt | 2 + .../feature/item/util/CipherViewExtensions.kt | 2 + .../feature/util/CollectionViewExtensions.kt | 17 ++ .../vault/feature/item/VaultItemScreenTest.kt | 2 + .../feature/item/VaultItemViewModelTest.kt | 145 +++++++++++++++--- .../item/util/CipherViewExtensionsTest.kt | 13 ++ .../feature/item/util/VaultItemTestUtil.kt | 2 + .../util/CollectionViewExtensionsTest.kt | 62 ++++++++ 9 files changed, 240 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt index c6ba8363f38..cce848fd2df 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt @@ -31,6 +31,7 @@ import com.x8bit.bitwarden.ui.vault.feature.item.model.VaultItemStateData import com.x8bit.bitwarden.ui.vault.feature.item.util.toViewState import com.x8bit.bitwarden.ui.vault.feature.util.canAssignToCollections import com.x8bit.bitwarden.ui.vault.feature.util.hasDeletePermissionInAtLeastOneCollection +import com.x8bit.bitwarden.ui.vault.feature.util.hasEditPermissionInAtLeastOneCollection import com.x8bit.bitwarden.ui.vault.model.VaultCardBrand import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType import dagger.hilt.android.lifecycle.HiltViewModel @@ -116,11 +117,18 @@ class VaultItemViewModel @Inject constructor( .data .canAssignToCollections(cipherViewState.data?.collectionIds) + val canEdit = collectionsState + .data + .hasEditPermissionInAtLeastOneCollection( + cipherViewState.data?.collectionIds, + ) + VaultItemStateData( cipher = cipherViewState.data, totpCodeItemData = totpCodeData, canDelete = canDelete, canAssociateToCollections = canAssignToCollections, + canEdit = canEdit, ) }, ) @@ -1040,6 +1048,7 @@ class VaultItemViewModel @Inject constructor( totpCodeItemData = this.data?.totpCodeItemData, canDelete = this.data?.canDelete == true, canAssignToCollections = this.data?.canAssociateToCollections == true, + canEdit = this.data?.canEdit == true, ) } ?: VaultItemState.ViewState.Error(message = errorText) @@ -1277,11 +1286,16 @@ data class VaultItemState( ?.currentCipher ?.deletedDate != null + private val isCipherEditable: Boolean + get() = viewState.asContentOrNull() + ?.common + ?.canEdit == true + /** * Whether or not the fab is visible. */ val isFabVisible: Boolean - get() = viewState is ViewState.Content && !isCipherDeleted + get() = viewState is ViewState.Content && !isCipherDeleted && isCipherEditable /** * Whether or not the cipher is in a collection. @@ -1377,6 +1391,7 @@ data class VaultItemState( val attachments: List?, val canDelete: Boolean, val canAssignToCollections: Boolean, + val canEdit: Boolean, ) : Parcelable { /** diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt index 5554c56b0c1..f89e0f93f20 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt @@ -9,10 +9,12 @@ import com.bitwarden.vault.CipherView * @property totpCodeItemData The data for the totp code. * @property canDelete Whether the item can be deleted. * @property canAssociateToCollections Whether the item can be associated to a collection. + * @property canEdit Whether the item can be edited. */ data class VaultItemStateData( val cipher: CipherView?, val totpCodeItemData: TotpCodeItemData?, val canDelete: Boolean, val canAssociateToCollections: Boolean, + val canEdit: Boolean, ) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt index 55b95dc90a8..e0b842f6c5b 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt @@ -41,6 +41,7 @@ fun CipherView.toViewState( clock: Clock = Clock.systemDefaultZone(), canDelete: Boolean, canAssignToCollections: Boolean, + canEdit: Boolean, ): VaultItemState.ViewState = VaultItemState.ViewState.Content( common = VaultItemState.ViewState.Content.Common( @@ -83,6 +84,7 @@ fun CipherView.toViewState( .orEmpty(), canDelete = canDelete, canAssignToCollections = canAssignToCollections, + canEdit = canEdit, ), type = when (type) { CipherType.LOGIN -> { diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt index b75b186bed6..d2cff4d23ba 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt @@ -122,3 +122,20 @@ fun List?.canAssignToCollections(currentCollectionIds: List?.hasEditPermissionInAtLeastOneCollection( + collectionIds: List?, +): Boolean { + if (this.isNullOrEmpty() || collectionIds.isNullOrEmpty()) return true + return this + .any { collectionView -> + collectionIds + .contains(collectionView.id) + .let { isInCollection -> isInCollection && !collectionView.readOnly } + } +} diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt index 3cfe234bea3..067dd347cd5 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt @@ -2698,6 +2698,7 @@ private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common = ), canDelete = true, canAssignToCollections = true, + canEdit = true, ) private val DEFAULT_PASSKEY = R.string.created_xy.asText( @@ -2781,6 +2782,7 @@ private val EMPTY_COMMON: VaultItemState.ViewState.Content.Common = attachments = emptyList(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) private val EMPTY_LOGIN_TYPE: VaultItemState.ViewState.Content.ItemType.Login = diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt index 81a3ac8c989..7588ec54dd3 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt @@ -170,6 +170,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -195,6 +196,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -214,6 +216,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginState @@ -258,6 +261,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginState @@ -291,6 +295,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -335,6 +340,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -382,6 +388,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -421,6 +428,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -455,6 +463,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -493,6 +502,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -534,6 +544,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -584,6 +595,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -617,6 +629,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -635,6 +648,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } assertEquals( @@ -660,7 +674,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState @@ -722,7 +738,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState @@ -776,7 +794,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState @@ -841,7 +861,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -865,7 +887,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -880,7 +904,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns createViewState(common = DEFAULT_COMMON.copy(requiresReprompt = false)) every { clipboardManager.setText(text = field) } just runs @@ -898,7 +924,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) organizationEventManager.trackEvent( event = OrganizationEvent.CipherClientCopiedHiddenField( @@ -937,7 +965,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -969,7 +999,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1004,6 +1036,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1035,7 +1068,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) organizationEventManager.trackEvent( event = OrganizationEvent.CipherClientToggledHiddenFieldVisible( @@ -1055,7 +1090,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1079,7 +1116,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1098,7 +1137,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1132,7 +1173,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1158,7 +1201,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1181,7 +1226,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1229,7 +1276,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1253,7 +1302,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1272,7 +1323,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1303,7 +1356,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1327,7 +1382,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1347,6 +1404,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1390,6 +1448,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1447,6 +1506,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1513,6 +1573,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1681,6 +1742,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE @@ -1719,6 +1781,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns DEFAULT_VIEW_STATE @@ -1760,6 +1823,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1779,6 +1843,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns DEFAULT_VIEW_STATE @@ -1807,6 +1872,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1822,6 +1888,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns createViewState(common = DEFAULT_COMMON.copy(requiresReprompt = false)) @@ -1842,6 +1909,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1884,6 +1952,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns createViewState(common = DEFAULT_COMMON.copy(requiresReprompt = false)) @@ -1904,6 +1973,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -1929,6 +1999,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1955,6 +2026,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -1971,6 +2043,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } .returns( @@ -1999,6 +2072,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2016,6 +2090,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2046,6 +2121,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2066,6 +2142,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2099,6 +2176,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) organizationEventManager.trackEvent( event = OrganizationEvent.CipherClientToggledPasswordVisible( @@ -2134,6 +2212,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2161,6 +2240,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2176,6 +2256,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2197,6 +2278,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2213,6 +2295,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2240,6 +2323,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2255,6 +2339,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2282,6 +2367,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2298,6 +2384,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2325,6 +2412,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2340,6 +2428,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2361,6 +2450,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2377,6 +2467,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2404,6 +2495,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2419,6 +2511,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2446,6 +2539,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2475,6 +2569,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2504,6 +2599,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2540,6 +2636,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2573,6 +2670,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns IDENTITY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2722,6 +2820,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2763,6 +2862,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2802,6 +2902,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2838,6 +2939,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -3066,6 +3168,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { ), canDelete = true, canAssignToCollections = true, + canEdit = true, ) private val DEFAULT_VIEW_STATE: VaultItemState.ViewState.Content = diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt index 4bb7186bd15..a9b2d277f25 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt @@ -47,6 +47,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -84,6 +85,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -114,6 +116,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -144,6 +147,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -180,6 +184,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -206,6 +211,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -230,6 +236,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -253,6 +260,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -286,6 +294,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -324,6 +333,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -364,6 +374,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -388,6 +399,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) val expectedState = VaultItemState.ViewState.Content( @@ -410,6 +422,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( VaultItemState.ViewState.Content( diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt index 3d86e753a29..f3fb2d16a6f 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt @@ -172,6 +172,7 @@ fun createCommonContent( attachments = emptyList(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } else { VaultItemState.ViewState.Content.Common( @@ -217,6 +218,7 @@ fun createCommonContent( ), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt index 50538d7bdda..73e37e4a11e 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt @@ -166,4 +166,66 @@ class CollectionViewExtensionsTest { ) assertTrue(collectionList.canAssignToCollections(null)) } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return true if the item is in at least one non-readOnly collection`() { + val collectionList: List = listOf( + createMockCollectionView(number = 1, readOnly = true), + createMockCollectionView(number = 2, readOnly = false), + ) + + val collectionIds = listOf("mockId-1", "mockId-2") + + assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(collectionIds)) + } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return false if the item isn't in at least one non-readOnly collection`() { + val collectionList: List = listOf( + createMockCollectionView(number = 1, readOnly = true), + createMockCollectionView(number = 2, readOnly = true), + ) + val collectionIds = listOf("mockId-1", "mockId-2") + assertFalse(collectionList.hasEditPermissionInAtLeastOneCollection(collectionIds)) + } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionView list is null`() { + val collectionIds = listOf("mockId-1", "mockId-2") + assertTrue(null.hasEditPermissionInAtLeastOneCollection(collectionIds)) + } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionIds list is null`() { + val collectionList: List = listOf( + createMockCollectionView(number = 1, readOnly = true), + createMockCollectionView(number = 2, readOnly = false), + ) + assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(null)) + } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionIds list is empty`() { + val collectionList: List = listOf( + createMockCollectionView(number = 1, readOnly = true), + createMockCollectionView(number = 2, readOnly = false), + ) + assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(emptyList())) + } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionView list is empty`() { + val collectionIds = listOf("mockId-1", "mockId-2") + assertTrue( + emptyList().hasEditPermissionInAtLeastOneCollection( + collectionIds, + ), + ) + } } From 7ea095236c2ca5e665ff34299a1e07b39a796eba Mon Sep 17 00:00:00 2001 From: mpbw2 <59324545+mpbw2@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:08:29 -0500 Subject: [PATCH 2/5] use SDK provided state instead --- .../vault/feature/item/VaultItemViewModel.kt | 13 +- .../feature/item/model/VaultItemStateData.kt | 2 - .../feature/item/util/CipherViewExtensions.kt | 2 - .../feature/util/CollectionViewExtensions.kt | 17 -- .../vault/feature/item/VaultItemScreenTest.kt | 2 - .../feature/item/VaultItemViewModelTest.kt | 145 +++--------------- .../item/util/CipherViewExtensionsTest.kt | 13 -- .../feature/item/util/VaultItemTestUtil.kt | 2 - .../util/CollectionViewExtensionsTest.kt | 62 -------- 9 files changed, 23 insertions(+), 235 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt index cce848fd2df..81dc401f729 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt @@ -31,7 +31,6 @@ import com.x8bit.bitwarden.ui.vault.feature.item.model.VaultItemStateData import com.x8bit.bitwarden.ui.vault.feature.item.util.toViewState import com.x8bit.bitwarden.ui.vault.feature.util.canAssignToCollections import com.x8bit.bitwarden.ui.vault.feature.util.hasDeletePermissionInAtLeastOneCollection -import com.x8bit.bitwarden.ui.vault.feature.util.hasEditPermissionInAtLeastOneCollection import com.x8bit.bitwarden.ui.vault.model.VaultCardBrand import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType import dagger.hilt.android.lifecycle.HiltViewModel @@ -117,18 +116,11 @@ class VaultItemViewModel @Inject constructor( .data .canAssignToCollections(cipherViewState.data?.collectionIds) - val canEdit = collectionsState - .data - .hasEditPermissionInAtLeastOneCollection( - cipherViewState.data?.collectionIds, - ) - VaultItemStateData( cipher = cipherViewState.data, totpCodeItemData = totpCodeData, canDelete = canDelete, canAssociateToCollections = canAssignToCollections, - canEdit = canEdit, ) }, ) @@ -1048,7 +1040,6 @@ class VaultItemViewModel @Inject constructor( totpCodeItemData = this.data?.totpCodeItemData, canDelete = this.data?.canDelete == true, canAssignToCollections = this.data?.canAssociateToCollections == true, - canEdit = this.data?.canEdit == true, ) } ?: VaultItemState.ViewState.Error(message = errorText) @@ -1289,7 +1280,8 @@ data class VaultItemState( private val isCipherEditable: Boolean get() = viewState.asContentOrNull() ?.common - ?.canEdit == true + ?.currentCipher + ?.edit == true /** * Whether or not the fab is visible. @@ -1391,7 +1383,6 @@ data class VaultItemState( val attachments: List?, val canDelete: Boolean, val canAssignToCollections: Boolean, - val canEdit: Boolean, ) : Parcelable { /** diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt index f89e0f93f20..5554c56b0c1 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt @@ -9,12 +9,10 @@ import com.bitwarden.vault.CipherView * @property totpCodeItemData The data for the totp code. * @property canDelete Whether the item can be deleted. * @property canAssociateToCollections Whether the item can be associated to a collection. - * @property canEdit Whether the item can be edited. */ data class VaultItemStateData( val cipher: CipherView?, val totpCodeItemData: TotpCodeItemData?, val canDelete: Boolean, val canAssociateToCollections: Boolean, - val canEdit: Boolean, ) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt index e0b842f6c5b..55b95dc90a8 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt @@ -41,7 +41,6 @@ fun CipherView.toViewState( clock: Clock = Clock.systemDefaultZone(), canDelete: Boolean, canAssignToCollections: Boolean, - canEdit: Boolean, ): VaultItemState.ViewState = VaultItemState.ViewState.Content( common = VaultItemState.ViewState.Content.Common( @@ -84,7 +83,6 @@ fun CipherView.toViewState( .orEmpty(), canDelete = canDelete, canAssignToCollections = canAssignToCollections, - canEdit = canEdit, ), type = when (type) { CipherType.LOGIN -> { diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt index d2cff4d23ba..b75b186bed6 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt @@ -122,20 +122,3 @@ fun List?.canAssignToCollections(currentCollectionIds: List?.hasEditPermissionInAtLeastOneCollection( - collectionIds: List?, -): Boolean { - if (this.isNullOrEmpty() || collectionIds.isNullOrEmpty()) return true - return this - .any { collectionView -> - collectionIds - .contains(collectionView.id) - .let { isInCollection -> isInCollection && !collectionView.readOnly } - } -} diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt index 067dd347cd5..3cfe234bea3 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt @@ -2698,7 +2698,6 @@ private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common = ), canDelete = true, canAssignToCollections = true, - canEdit = true, ) private val DEFAULT_PASSKEY = R.string.created_xy.asText( @@ -2782,7 +2781,6 @@ private val EMPTY_COMMON: VaultItemState.ViewState.Content.Common = attachments = emptyList(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) private val EMPTY_LOGIN_TYPE: VaultItemState.ViewState.Content.ItemType.Login = diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt index 7588ec54dd3..81a3ac8c989 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt @@ -170,7 +170,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -196,7 +195,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -216,7 +214,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns loginState @@ -261,7 +258,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns loginState @@ -295,7 +291,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -340,7 +335,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -388,7 +382,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -428,7 +421,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -463,7 +455,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns viewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -502,7 +493,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -544,7 +534,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -595,7 +584,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -629,7 +617,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -648,7 +635,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } assertEquals( @@ -674,9 +660,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns loginViewState @@ -738,9 +722,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns loginViewState @@ -794,9 +776,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns loginViewState @@ -861,9 +841,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -887,9 +865,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } } @@ -904,9 +880,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns createViewState(common = DEFAULT_COMMON.copy(requiresReprompt = false)) every { clipboardManager.setText(text = field) } just runs @@ -924,9 +898,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) organizationEventManager.trackEvent( event = OrganizationEvent.CipherClientCopiedHiddenField( @@ -965,9 +937,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -999,9 +969,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } } @@ -1036,7 +1004,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1068,9 +1035,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) organizationEventManager.trackEvent( event = OrganizationEvent.CipherClientToggledHiddenFieldVisible( @@ -1090,9 +1055,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1116,9 +1079,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } } @@ -1137,9 +1098,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1173,9 +1132,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1201,9 +1158,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } } @@ -1226,9 +1181,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1276,9 +1229,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1302,9 +1253,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } } @@ -1323,9 +1272,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1356,9 +1303,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1382,9 +1327,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, - canEdit = true, - totpCodeItemData = null, + canAssignToCollections = true, totpCodeItemData = null, ) } } @@ -1404,7 +1347,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, - canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1448,7 +1390,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, - canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1506,7 +1447,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, - canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1573,7 +1513,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, - canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1742,7 +1681,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns DEFAULT_VIEW_STATE @@ -1781,7 +1719,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, - canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns DEFAULT_VIEW_STATE @@ -1823,7 +1760,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, - canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1843,7 +1779,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, - canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns DEFAULT_VIEW_STATE @@ -1872,7 +1807,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, - canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1888,7 +1822,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, - canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns createViewState(common = DEFAULT_COMMON.copy(requiresReprompt = false)) @@ -1909,7 +1842,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, - canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1952,7 +1884,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, - canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns createViewState(common = DEFAULT_COMMON.copy(requiresReprompt = false)) @@ -1973,7 +1904,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -1999,7 +1929,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2026,7 +1955,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -2043,7 +1971,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } .returns( @@ -2072,7 +1999,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -2090,7 +2016,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2121,7 +2046,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -2142,7 +2066,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2176,7 +2099,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) organizationEventManager.trackEvent( event = OrganizationEvent.CipherClientToggledPasswordVisible( @@ -2212,7 +2134,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2240,7 +2161,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -2256,7 +2176,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2278,7 +2197,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -2295,7 +2213,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2323,7 +2240,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -2339,7 +2255,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2367,7 +2282,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -2384,7 +2298,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2412,7 +2325,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -2428,7 +2340,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2450,7 +2361,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -2467,7 +2377,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2495,7 +2404,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -2511,7 +2419,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2539,7 +2446,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } } @@ -2569,7 +2475,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2599,7 +2504,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2636,7 +2540,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2670,7 +2573,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns IDENTITY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2820,7 +2722,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2862,7 +2763,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2902,7 +2802,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2939,7 +2838,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, - canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -3168,7 +3066,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { ), canDelete = true, canAssignToCollections = true, - canEdit = true, ) private val DEFAULT_VIEW_STATE: VaultItemState.ViewState.Content = diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt index a9b2d277f25..4bb7186bd15 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt @@ -47,7 +47,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( @@ -85,7 +84,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( @@ -116,7 +114,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( @@ -147,7 +144,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( @@ -184,7 +180,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( @@ -211,7 +206,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( @@ -236,7 +230,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( @@ -260,7 +253,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( @@ -294,7 +286,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( @@ -333,7 +324,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( @@ -374,7 +364,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( @@ -399,7 +388,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) val expectedState = VaultItemState.ViewState.Content( @@ -422,7 +410,6 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, - canEdit = true, ) assertEquals( VaultItemState.ViewState.Content( diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt index f3fb2d16a6f..3d86e753a29 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt @@ -172,7 +172,6 @@ fun createCommonContent( attachments = emptyList(), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } else { VaultItemState.ViewState.Content.Common( @@ -218,7 +217,6 @@ fun createCommonContent( ), canDelete = true, canAssignToCollections = true, - canEdit = true, ) } diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt index 73e37e4a11e..50538d7bdda 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt @@ -166,66 +166,4 @@ class CollectionViewExtensionsTest { ) assertTrue(collectionList.canAssignToCollections(null)) } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return true if the item is in at least one non-readOnly collection`() { - val collectionList: List = listOf( - createMockCollectionView(number = 1, readOnly = true), - createMockCollectionView(number = 2, readOnly = false), - ) - - val collectionIds = listOf("mockId-1", "mockId-2") - - assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(collectionIds)) - } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return false if the item isn't in at least one non-readOnly collection`() { - val collectionList: List = listOf( - createMockCollectionView(number = 1, readOnly = true), - createMockCollectionView(number = 2, readOnly = true), - ) - val collectionIds = listOf("mockId-1", "mockId-2") - assertFalse(collectionList.hasEditPermissionInAtLeastOneCollection(collectionIds)) - } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionView list is null`() { - val collectionIds = listOf("mockId-1", "mockId-2") - assertTrue(null.hasEditPermissionInAtLeastOneCollection(collectionIds)) - } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionIds list is null`() { - val collectionList: List = listOf( - createMockCollectionView(number = 1, readOnly = true), - createMockCollectionView(number = 2, readOnly = false), - ) - assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(null)) - } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionIds list is empty`() { - val collectionList: List = listOf( - createMockCollectionView(number = 1, readOnly = true), - createMockCollectionView(number = 2, readOnly = false), - ) - assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(emptyList())) - } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionView list is empty`() { - val collectionIds = listOf("mockId-1", "mockId-2") - assertTrue( - emptyList().hasEditPermissionInAtLeastOneCollection( - collectionIds, - ), - ) - } } From 65447750ea1958b663ce43760e068fcb8a7eee02 Mon Sep 17 00:00:00 2001 From: mpbw2 <59324545+mpbw2@users.noreply.github.com> Date: Fri, 20 Dec 2024 12:45:18 -0500 Subject: [PATCH 3/5] Revert "use SDK provided state instead" This reverts commit 7ea095236c2ca5e665ff34299a1e07b39a796eba. --- .../vault/feature/item/VaultItemViewModel.kt | 13 +- .../feature/item/model/VaultItemStateData.kt | 2 + .../feature/item/util/CipherViewExtensions.kt | 2 + .../feature/util/CollectionViewExtensions.kt | 17 ++ .../vault/feature/item/VaultItemScreenTest.kt | 2 + .../feature/item/VaultItemViewModelTest.kt | 145 +++++++++++++++--- .../item/util/CipherViewExtensionsTest.kt | 13 ++ .../feature/item/util/VaultItemTestUtil.kt | 2 + .../util/CollectionViewExtensionsTest.kt | 62 ++++++++ 9 files changed, 235 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt index 81dc401f729..cce848fd2df 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt @@ -31,6 +31,7 @@ import com.x8bit.bitwarden.ui.vault.feature.item.model.VaultItemStateData import com.x8bit.bitwarden.ui.vault.feature.item.util.toViewState import com.x8bit.bitwarden.ui.vault.feature.util.canAssignToCollections import com.x8bit.bitwarden.ui.vault.feature.util.hasDeletePermissionInAtLeastOneCollection +import com.x8bit.bitwarden.ui.vault.feature.util.hasEditPermissionInAtLeastOneCollection import com.x8bit.bitwarden.ui.vault.model.VaultCardBrand import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType import dagger.hilt.android.lifecycle.HiltViewModel @@ -116,11 +117,18 @@ class VaultItemViewModel @Inject constructor( .data .canAssignToCollections(cipherViewState.data?.collectionIds) + val canEdit = collectionsState + .data + .hasEditPermissionInAtLeastOneCollection( + cipherViewState.data?.collectionIds, + ) + VaultItemStateData( cipher = cipherViewState.data, totpCodeItemData = totpCodeData, canDelete = canDelete, canAssociateToCollections = canAssignToCollections, + canEdit = canEdit, ) }, ) @@ -1040,6 +1048,7 @@ class VaultItemViewModel @Inject constructor( totpCodeItemData = this.data?.totpCodeItemData, canDelete = this.data?.canDelete == true, canAssignToCollections = this.data?.canAssociateToCollections == true, + canEdit = this.data?.canEdit == true, ) } ?: VaultItemState.ViewState.Error(message = errorText) @@ -1280,8 +1289,7 @@ data class VaultItemState( private val isCipherEditable: Boolean get() = viewState.asContentOrNull() ?.common - ?.currentCipher - ?.edit == true + ?.canEdit == true /** * Whether or not the fab is visible. @@ -1383,6 +1391,7 @@ data class VaultItemState( val attachments: List?, val canDelete: Boolean, val canAssignToCollections: Boolean, + val canEdit: Boolean, ) : Parcelable { /** diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt index 5554c56b0c1..f89e0f93f20 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/model/VaultItemStateData.kt @@ -9,10 +9,12 @@ import com.bitwarden.vault.CipherView * @property totpCodeItemData The data for the totp code. * @property canDelete Whether the item can be deleted. * @property canAssociateToCollections Whether the item can be associated to a collection. + * @property canEdit Whether the item can be edited. */ data class VaultItemStateData( val cipher: CipherView?, val totpCodeItemData: TotpCodeItemData?, val canDelete: Boolean, val canAssociateToCollections: Boolean, + val canEdit: Boolean, ) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt index 55b95dc90a8..e0b842f6c5b 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensions.kt @@ -41,6 +41,7 @@ fun CipherView.toViewState( clock: Clock = Clock.systemDefaultZone(), canDelete: Boolean, canAssignToCollections: Boolean, + canEdit: Boolean, ): VaultItemState.ViewState = VaultItemState.ViewState.Content( common = VaultItemState.ViewState.Content.Common( @@ -83,6 +84,7 @@ fun CipherView.toViewState( .orEmpty(), canDelete = canDelete, canAssignToCollections = canAssignToCollections, + canEdit = canEdit, ), type = when (type) { CipherType.LOGIN -> { diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt index b75b186bed6..d2cff4d23ba 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt @@ -122,3 +122,20 @@ fun List?.canAssignToCollections(currentCollectionIds: List?.hasEditPermissionInAtLeastOneCollection( + collectionIds: List?, +): Boolean { + if (this.isNullOrEmpty() || collectionIds.isNullOrEmpty()) return true + return this + .any { collectionView -> + collectionIds + .contains(collectionView.id) + .let { isInCollection -> isInCollection && !collectionView.readOnly } + } +} diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt index 3cfe234bea3..067dd347cd5 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemScreenTest.kt @@ -2698,6 +2698,7 @@ private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common = ), canDelete = true, canAssignToCollections = true, + canEdit = true, ) private val DEFAULT_PASSKEY = R.string.created_xy.asText( @@ -2781,6 +2782,7 @@ private val EMPTY_COMMON: VaultItemState.ViewState.Content.Common = attachments = emptyList(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) private val EMPTY_LOGIN_TYPE: VaultItemState.ViewState.Content.ItemType.Login = diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt index 81a3ac8c989..7588ec54dd3 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt @@ -170,6 +170,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -195,6 +196,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -214,6 +216,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginState @@ -258,6 +261,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginState @@ -291,6 +295,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -335,6 +340,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -382,6 +388,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -421,6 +428,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -455,6 +463,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -493,6 +502,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -534,6 +544,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -584,6 +595,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -617,6 +629,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -635,6 +648,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } assertEquals( @@ -660,7 +674,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState @@ -722,7 +738,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState @@ -776,7 +794,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState @@ -841,7 +861,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -865,7 +887,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -880,7 +904,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns createViewState(common = DEFAULT_COMMON.copy(requiresReprompt = false)) every { clipboardManager.setText(text = field) } just runs @@ -898,7 +924,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) organizationEventManager.trackEvent( event = OrganizationEvent.CipherClientCopiedHiddenField( @@ -937,7 +965,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -969,7 +999,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1004,6 +1036,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1035,7 +1068,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) organizationEventManager.trackEvent( event = OrganizationEvent.CipherClientToggledHiddenFieldVisible( @@ -1055,7 +1090,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1079,7 +1116,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1098,7 +1137,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1132,7 +1173,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1158,7 +1201,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1181,7 +1226,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1229,7 +1276,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1253,7 +1302,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1272,7 +1323,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1303,7 +1356,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1327,7 +1382,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1347,6 +1404,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1390,6 +1448,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1447,6 +1506,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1513,6 +1573,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1681,6 +1742,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE @@ -1719,6 +1781,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns DEFAULT_VIEW_STATE @@ -1760,6 +1823,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1779,6 +1843,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns DEFAULT_VIEW_STATE @@ -1807,6 +1872,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1822,6 +1888,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns createViewState(common = DEFAULT_COMMON.copy(requiresReprompt = false)) @@ -1842,6 +1909,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1884,6 +1952,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns createViewState(common = DEFAULT_COMMON.copy(requiresReprompt = false)) @@ -1904,6 +1973,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -1929,6 +1999,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1955,6 +2026,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -1971,6 +2043,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } .returns( @@ -1999,6 +2072,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2016,6 +2090,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2046,6 +2121,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2066,6 +2142,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2099,6 +2176,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) organizationEventManager.trackEvent( event = OrganizationEvent.CipherClientToggledPasswordVisible( @@ -2134,6 +2212,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2161,6 +2240,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2176,6 +2256,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2197,6 +2278,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2213,6 +2295,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2240,6 +2323,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2255,6 +2339,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2282,6 +2367,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2298,6 +2384,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2325,6 +2412,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2340,6 +2428,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2361,6 +2450,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2377,6 +2467,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2404,6 +2495,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2419,6 +2511,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2446,6 +2539,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2475,6 +2569,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2504,6 +2599,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2540,6 +2636,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2573,6 +2670,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns IDENTITY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2722,6 +2820,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2763,6 +2862,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2802,6 +2902,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2838,6 +2939,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -3066,6 +3168,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { ), canDelete = true, canAssignToCollections = true, + canEdit = true, ) private val DEFAULT_VIEW_STATE: VaultItemState.ViewState.Content = diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt index 4bb7186bd15..a9b2d277f25 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/CipherViewExtensionsTest.kt @@ -47,6 +47,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -84,6 +85,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -114,6 +116,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -144,6 +147,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -180,6 +184,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -206,6 +211,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -230,6 +236,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -253,6 +260,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -286,6 +294,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -324,6 +333,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -364,6 +374,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( @@ -388,6 +399,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) val expectedState = VaultItemState.ViewState.Content( @@ -410,6 +422,7 @@ class CipherViewExtensionsTest { clock = fixedClock, canDelete = true, canAssignToCollections = true, + canEdit = true, ) assertEquals( VaultItemState.ViewState.Content( diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt index 3d86e753a29..f3fb2d16a6f 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/util/VaultItemTestUtil.kt @@ -172,6 +172,7 @@ fun createCommonContent( attachments = emptyList(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } else { VaultItemState.ViewState.Content.Common( @@ -217,6 +218,7 @@ fun createCommonContent( ), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt index 50538d7bdda..73e37e4a11e 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt @@ -166,4 +166,66 @@ class CollectionViewExtensionsTest { ) assertTrue(collectionList.canAssignToCollections(null)) } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return true if the item is in at least one non-readOnly collection`() { + val collectionList: List = listOf( + createMockCollectionView(number = 1, readOnly = true), + createMockCollectionView(number = 2, readOnly = false), + ) + + val collectionIds = listOf("mockId-1", "mockId-2") + + assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(collectionIds)) + } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return false if the item isn't in at least one non-readOnly collection`() { + val collectionList: List = listOf( + createMockCollectionView(number = 1, readOnly = true), + createMockCollectionView(number = 2, readOnly = true), + ) + val collectionIds = listOf("mockId-1", "mockId-2") + assertFalse(collectionList.hasEditPermissionInAtLeastOneCollection(collectionIds)) + } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionView list is null`() { + val collectionIds = listOf("mockId-1", "mockId-2") + assertTrue(null.hasEditPermissionInAtLeastOneCollection(collectionIds)) + } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionIds list is null`() { + val collectionList: List = listOf( + createMockCollectionView(number = 1, readOnly = true), + createMockCollectionView(number = 2, readOnly = false), + ) + assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(null)) + } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionIds list is empty`() { + val collectionList: List = listOf( + createMockCollectionView(number = 1, readOnly = true), + createMockCollectionView(number = 2, readOnly = false), + ) + assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(emptyList())) + } + + @Suppress("MaxLineLength") + @Test + fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionView list is empty`() { + val collectionIds = listOf("mockId-1", "mockId-2") + assertTrue( + emptyList().hasEditPermissionInAtLeastOneCollection( + collectionIds, + ), + ) + } } From 4d76e26729e50ab29b012cfc717250fb275b606f Mon Sep 17 00:00:00 2001 From: mpbw2 <59324545+mpbw2@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:54:33 -0500 Subject: [PATCH 4/5] retain view testability while using SDK state --- .../vault/feature/item/VaultItemViewModel.kt | 7 +-- .../feature/util/CollectionViewExtensions.kt | 17 ----- .../feature/item/VaultItemViewModelTest.kt | 1 + .../util/CollectionViewExtensionsTest.kt | 62 ------------------- 4 files changed, 2 insertions(+), 85 deletions(-) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt index cce848fd2df..0a1d4cb8fd6 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModel.kt @@ -31,7 +31,6 @@ import com.x8bit.bitwarden.ui.vault.feature.item.model.VaultItemStateData import com.x8bit.bitwarden.ui.vault.feature.item.util.toViewState import com.x8bit.bitwarden.ui.vault.feature.util.canAssignToCollections import com.x8bit.bitwarden.ui.vault.feature.util.hasDeletePermissionInAtLeastOneCollection -import com.x8bit.bitwarden.ui.vault.feature.util.hasEditPermissionInAtLeastOneCollection import com.x8bit.bitwarden.ui.vault.model.VaultCardBrand import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType import dagger.hilt.android.lifecycle.HiltViewModel @@ -117,11 +116,7 @@ class VaultItemViewModel @Inject constructor( .data .canAssignToCollections(cipherViewState.data?.collectionIds) - val canEdit = collectionsState - .data - .hasEditPermissionInAtLeastOneCollection( - cipherViewState.data?.collectionIds, - ) + val canEdit = cipherViewState.data?.edit == true VaultItemStateData( cipher = cipherViewState.data, diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt index d2cff4d23ba..b75b186bed6 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensions.kt @@ -122,20 +122,3 @@ fun List?.canAssignToCollections(currentCollectionIds: List?.hasEditPermissionInAtLeastOneCollection( - collectionIds: List?, -): Boolean { - if (this.isNullOrEmpty() || collectionIds.isNullOrEmpty()) return true - return this - .any { collectionView -> - collectionIds - .contains(collectionView.id) - .let { isInCollection -> isInCollection && !collectionView.readOnly } - } -} diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt index 7588ec54dd3..6cfe06d2758 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt @@ -80,6 +80,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { } private val mockCipherView = mockk { every { collectionIds } returns emptyList() + every { edit } returns true } @BeforeEach diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt index 73e37e4a11e..50538d7bdda 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/util/CollectionViewExtensionsTest.kt @@ -166,66 +166,4 @@ class CollectionViewExtensionsTest { ) assertTrue(collectionList.canAssignToCollections(null)) } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return true if the item is in at least one non-readOnly collection`() { - val collectionList: List = listOf( - createMockCollectionView(number = 1, readOnly = true), - createMockCollectionView(number = 2, readOnly = false), - ) - - val collectionIds = listOf("mockId-1", "mockId-2") - - assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(collectionIds)) - } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return false if the item isn't in at least one non-readOnly collection`() { - val collectionList: List = listOf( - createMockCollectionView(number = 1, readOnly = true), - createMockCollectionView(number = 2, readOnly = true), - ) - val collectionIds = listOf("mockId-1", "mockId-2") - assertFalse(collectionList.hasEditPermissionInAtLeastOneCollection(collectionIds)) - } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionView list is null`() { - val collectionIds = listOf("mockId-1", "mockId-2") - assertTrue(null.hasEditPermissionInAtLeastOneCollection(collectionIds)) - } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionIds list is null`() { - val collectionList: List = listOf( - createMockCollectionView(number = 1, readOnly = true), - createMockCollectionView(number = 2, readOnly = false), - ) - assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(null)) - } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionIds list is empty`() { - val collectionList: List = listOf( - createMockCollectionView(number = 1, readOnly = true), - createMockCollectionView(number = 2, readOnly = false), - ) - assertTrue(collectionList.hasEditPermissionInAtLeastOneCollection(emptyList())) - } - - @Suppress("MaxLineLength") - @Test - fun `hasEditPermissionInAtLeastOneCollection should return true if the collectionView list is empty`() { - val collectionIds = listOf("mockId-1", "mockId-2") - assertTrue( - emptyList().hasEditPermissionInAtLeastOneCollection( - collectionIds, - ), - ) - } } From 23e4a9e5c07be3e05df16c9659d49524723da399 Mon Sep 17 00:00:00 2001 From: mpbw2 <59324545+mpbw2@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:09:18 -0500 Subject: [PATCH 5/5] fix test --- .../bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt index 6ec840f03c9..d7980d31c02 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt @@ -2601,6 +2601,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns sshKeyViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2630,6 +2631,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2676,6 +2678,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } }