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 4b04861e406..7f2e76f967e 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 @@ -116,11 +116,14 @@ class VaultItemViewModel @Inject constructor( .data .canAssignToCollections(cipherViewState.data?.collectionIds) + val canEdit = cipherViewState.data?.edit == true + VaultItemStateData( cipher = cipherViewState.data, totpCodeItemData = totpCodeData, canDelete = canDelete, canAssociateToCollections = canAssignToCollections, + canEdit = canEdit, ) }, ) @@ -1050,6 +1053,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) @@ -1287,11 +1291,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. @@ -1387,6 +1396,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/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 9eb5496eeba..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 @@ -80,6 +80,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { } private val mockCipherView = mockk { every { collectionIds } returns emptyList() + every { edit } returns true } @BeforeEach @@ -170,6 +171,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -195,6 +197,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -214,6 +217,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginState @@ -258,6 +262,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginState @@ -291,6 +296,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -335,6 +341,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -382,6 +389,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -421,6 +429,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -455,6 +464,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -493,6 +503,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -534,6 +545,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -584,6 +596,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -617,6 +630,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -635,6 +649,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } assertEquals( @@ -660,7 +675,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState @@ -722,7 +739,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState @@ -776,7 +795,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } returns loginViewState @@ -841,7 +862,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 +888,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -880,7 +905,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 +925,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 +966,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 +1000,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1004,6 +1037,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1035,7 +1069,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 +1091,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 +1117,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1098,7 +1138,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 +1174,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 +1202,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1181,7 +1227,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 +1277,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 +1303,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1272,7 +1324,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 +1357,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 +1383,9 @@ class VaultItemViewModelTest : BaseViewModelTest() { isPremiumUser = true, hasMasterPassword = true, canDelete = true, - canAssignToCollections = true, totpCodeItemData = null, + canAssignToCollections = true, + canEdit = true, + totpCodeItemData = null, ) } } @@ -1347,6 +1405,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1390,6 +1449,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1447,6 +1507,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1513,6 +1574,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = null, ) } returns loginViewState @@ -1681,6 +1743,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE @@ -1719,6 +1782,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns DEFAULT_VIEW_STATE @@ -1760,6 +1824,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1779,6 +1844,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns DEFAULT_VIEW_STATE @@ -1807,6 +1873,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1822,6 +1889,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns createViewState(common = DEFAULT_COMMON.copy(requiresReprompt = false)) @@ -1842,6 +1910,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } @@ -1884,6 +1953,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { hasMasterPassword = true, canDelete = true, canAssignToCollections = true, + canEdit = true, totpCodeItemData = createTotpCodeData(), ) } returns createViewState(common = DEFAULT_COMMON.copy(requiresReprompt = false)) @@ -1904,6 +1974,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -1929,6 +2000,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -1955,6 +2027,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -1971,6 +2044,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } .returns( @@ -1999,6 +2073,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2016,6 +2091,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns DEFAULT_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2046,6 +2122,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2066,6 +2143,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns loginViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2099,6 +2177,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = createTotpCodeData(), canDelete = true, canAssignToCollections = true, + canEdit = true, ) organizationEventManager.trackEvent( event = OrganizationEvent.CipherClientToggledPasswordVisible( @@ -2134,6 +2213,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2161,6 +2241,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2176,6 +2257,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2197,6 +2279,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2213,6 +2296,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2240,6 +2324,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2255,6 +2340,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2282,6 +2368,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2298,6 +2385,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2325,6 +2413,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2340,6 +2429,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2361,6 +2451,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2377,6 +2468,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns CARD_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2404,6 +2496,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2419,6 +2512,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns createViewState( common = DEFAULT_COMMON.copy(requiresReprompt = false), @@ -2446,6 +2540,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2475,6 +2570,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2505,6 +2601,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns sshKeyViewState mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2534,6 +2631,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2551,6 +2649,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2579,6 +2678,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } } @@ -2594,6 +2694,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns SSH_KEY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2627,6 +2728,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns IDENTITY_VIEW_STATE mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView) @@ -2776,6 +2878,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2817,6 +2920,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2856,6 +2960,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -2892,6 +2997,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { totpCodeItemData = null, canDelete = true, canAssignToCollections = true, + canEdit = true, ) } returns viewState val viewModel = createViewModel(state = null) @@ -3120,6 +3226,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, ) }