diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemLoginContent.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemLoginContent.kt index 0bed74395..3bcb8b258 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemLoginContent.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemLoginContent.kt @@ -96,7 +96,7 @@ fun VaultItemLoginContent( item { Spacer(modifier = Modifier.height(8.dp)) TotpField( - isPremiumUser = commonState.isPremiumUser, + isPremiumUser = loginItemState.isPremiumUser, modifier = Modifier .fillMaxWidth() .padding(horizontal = 16.dp), 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 294832f7e..61845dd3d 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 @@ -496,7 +496,6 @@ data class VaultItemState( * @property lastUpdated A formatted date string indicating when the item was last * updated. * @property notes Contains general notes taken by the user. - * @property isPremiumUser Indicates if the user has subscribed to a premium account. * @property customFields A list of custom fields that user has added. * @property requiresReprompt Indicates if a master password prompt is required to view * secure fields. @@ -506,7 +505,6 @@ data class VaultItemState( val name: String, val lastUpdated: String, val notes: String?, - val isPremiumUser: Boolean, val customFields: List, val requiresReprompt: Boolean, ) : Parcelable { @@ -570,8 +568,11 @@ data class VaultItemState( * @property passwordHistoryCount An integer indicating how many times the password * has been changed. * @property uris The URI associated with the login item. - * @property passwordRevisionDate - * @property totp + * @property passwordRevisionDate An optional string indicating the last time the + * password was changed. + * @property totp The optional TOTP string value to be displayed. + * @property isPremiumUser Indicates if the user has subscribed to a premium + * account. */ @Parcelize data class Login( @@ -581,6 +582,7 @@ data class VaultItemState( val uris: List, val passwordRevisionDate: String?, val totp: String?, + val isPremiumUser: Boolean, ) : ItemType() { /** 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 89ad06265..c1c1d8b92 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 @@ -32,7 +32,6 @@ fun CipherView.toViewState( VaultItemState.ViewState.Content( common = VaultItemState.ViewState.Content.Common( name = name, - isPremiumUser = isPremiumUser, requiresReprompt = reprompt == CipherRepromptType.PASSWORD, customFields = fields.orEmpty().map { it.toCustomField() }, lastUpdated = dateTimeFormatter.format(revisionDate), @@ -55,6 +54,7 @@ fun CipherView.toViewState( }, passwordHistoryCount = passwordHistory?.count(), totp = loginValues.totp, + isPremiumUser = isPremiumUser, ) } 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 a860c9d45..9b51af5f9 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 @@ -528,6 +528,7 @@ class VaultItemScreenTest : BaseComposeTest() { uris = emptyList(), passwordRevisionDate = null, totp = null, + isPremiumUser = true, ), ), ) @@ -1064,7 +1065,6 @@ private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common = lastUpdated = "12/31/69 06:16 PM", name = "cipher", notes = "Lots of notes", - isPremiumUser = true, customFields = listOf( VaultItemState.ViewState.Content.Common.Custom.TextField( name = "text", @@ -1102,6 +1102,7 @@ private val DEFAULT_LOGIN: VaultItemState.ViewState.Content.ItemType.Login = ), passwordRevisionDate = "4/14/83 3:56 PM", totp = "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example", + isPremiumUser = true, ) private val DEFAULT_IDENTITY: VaultItemState.ViewState.Content.ItemType.Identity = @@ -1122,7 +1123,6 @@ private val EMPTY_COMMON: VaultItemState.ViewState.Content.Common = name = "cipher", lastUpdated = "12/31/69 06:16 PM", notes = null, - isPremiumUser = true, customFields = emptyList(), requiresReprompt = true, ) @@ -1135,6 +1135,7 @@ private val EMPTY_LOGIN_TYPE: VaultItemState.ViewState.Content.ItemType.Login = uris = emptyList(), passwordRevisionDate = null, totp = null, + isPremiumUser = true, ) private val EMPTY_IDENTITY_TYPE: VaultItemState.ViewState.Content.ItemType.Identity = 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 0971c463d..bfc1c5d0a 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 @@ -681,6 +681,7 @@ class VaultItemViewModelTest : BaseViewModelTest() { passwordRevisionDate = "12/31/69 06:16 PM", totp = "otpauth://totp/Example:alice@google.com" + "?secret=JBSWY3DPEHPK3PXP&issuer=Example", + isPremiumUser = true, ) private val DEFAULT_COMMON: VaultItemState.ViewState.Content.Common = @@ -688,7 +689,6 @@ class VaultItemViewModelTest : BaseViewModelTest() { name = "login cipher", lastUpdated = "12/31/69 06:16 PM", notes = "Lots of notes", - isPremiumUser = true, customFields = listOf( VaultItemState.ViewState.Content.Common.Custom.TextField( name = "text", 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 2b1f2f590..fd4a331ce 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 @@ -45,8 +45,8 @@ class CipherViewExtensionsTest { assertEquals( VaultItemState.ViewState.Content( - common = createCommonContent(isEmpty = false).copy(isPremiumUser = isPremiumUser), - type = createLoginContent(isEmpty = false), + common = createCommonContent(isEmpty = false), + type = createLoginContent(isEmpty = false).copy(isPremiumUser = isPremiumUser), ), viewState, ) @@ -66,9 +66,8 @@ class CipherViewExtensionsTest { ) } - @Suppress("MaxLineLength") @Test - fun `toViewState should transform full CipherView into ViewState Identity Content with premium`() { + fun `toViewState should transform full CipherView into ViewState Identity Content`() { val viewState = createCipherView(type = CipherType.IDENTITY, isEmpty = false) .toViewState(isPremiumUser = true) @@ -81,22 +80,6 @@ class CipherViewExtensionsTest { ) } - @Suppress("MaxLineLength") - @Test - fun `toViewState should transform full CipherView into ViewState Identity Content without premium`() { - val isPremiumUser = false - val viewState = createCipherView(type = CipherType.IDENTITY, isEmpty = false) - .toViewState(isPremiumUser = isPremiumUser) - - assertEquals( - VaultItemState.ViewState.Content( - common = createCommonContent(isEmpty = false).copy(isPremiumUser = isPremiumUser), - type = createIdentityContent(isEmpty = false), - ), - viewState, - ) - } - @Test fun `toViewState should transform empty CipherView into ViewState Identity Content`() { val viewState = createCipherView(type = CipherType.IDENTITY, isEmpty = true) @@ -171,9 +154,8 @@ class CipherViewExtensionsTest { ) } - @Suppress("MaxLineLength") @Test - fun `toViewState should transform full CipherView into ViewState Secure Note Content with premium`() { + fun `toViewState should transform full CipherView into ViewState Secure Note Content`() { val viewState = createCipherView(type = CipherType.SECURE_NOTE, isEmpty = false) .toViewState(isPremiumUser = true) @@ -193,7 +175,7 @@ class CipherViewExtensionsTest { .toViewState(isPremiumUser = true) val expectedState = VaultItemState.ViewState.Content( - common = createCommonContent(isEmpty = true).copy(isPremiumUser = true), + common = createCommonContent(isEmpty = true), type = VaultItemState.ViewState.Content.ItemType.SecureNote, ) 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 8ccbbd8c0..29815686a 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 @@ -137,7 +137,6 @@ fun createCommonContent(isEmpty: Boolean): VaultItemState.ViewState.Content.Comm name = "mockName", lastUpdated = "1/1/70 12:16 AM", notes = null, - isPremiumUser = true, customFields = emptyList(), requiresReprompt = true, ) @@ -146,7 +145,6 @@ fun createCommonContent(isEmpty: Boolean): VaultItemState.ViewState.Content.Comm name = "mockName", lastUpdated = "1/1/70 12:16 AM", notes = "Lots of notes", - isPremiumUser = true, customFields = listOf( VaultItemState.ViewState.Content.Common.Custom.TextField( name = "text", @@ -199,6 +197,7 @@ fun createLoginContent(isEmpty: Boolean): VaultItemState.ViewState.Content.ItemT passwordRevisionDate = "1/1/70 12:16 AM".takeUnless { isEmpty }, totp = "otpauth://totp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&issuer=Example" .takeUnless { isEmpty }, + isPremiumUser = true, ) fun createIdentityContent(