From 4601f84140748c6d9805518342af7e70f3f8ed63 Mon Sep 17 00:00:00 2001 From: David Perez Date: Wed, 3 Jan 2024 09:06:04 -0600 Subject: [PATCH] Rename additem to addedit (#474) --- .../vaultunlocked/VaultUnlockedNavigation.kt | 12 +- .../VaultAddEditCustomField.kt} | 16 +- .../VaultAddEditCustomFieldsButton.kt} | 6 +- .../{additem => addedit}/VaultAddEditError.kt | 6 +- .../VaultAddEditIdentityItems.kt} | 28 +- .../VaultAddEditItemContent.kt} | 50 +- .../VaultAddEditLoading.kt | 6 +- .../VaultAddEditLoginItems.kt} | 20 +- .../VaultAddEditNavigation.kt} | 14 +- .../VaultAddEditScreen.kt} | 50 +- .../VaultAddEditSecureNotesItems.kt} | 16 +- .../VaultAddEditViewModel.kt} | 336 ++++++------- .../handlers/VaultAddEditCommonHandlers.kt} | 40 +- .../VaultAddEditIdentityTypeHandlers.kt} | 56 +-- .../VaultAddEditLoginTypeHandlers.kt} | 40 +- .../model/CustomFieldType.kt | 16 +- .../util/CipherViewExtensions.kt | 34 +- .../vault/util/VaultAddItemStateExtensions.kt | 46 +- .../VaultAddEditScreenTest.kt} | 234 ++++----- .../VaultAddEditViewModelTest.kt} | 464 +++++++++--------- .../model/CustomFieldTypeTests.kt | 12 +- .../util/CipherViewExtensionsTest.kt | 58 +-- .../util/VaultAddItemStateExtensionsTest.kt | 64 +-- 23 files changed, 804 insertions(+), 820 deletions(-) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/AddEditCustomField.kt => addedit/VaultAddEditCustomField.kt} (95%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/AddEditCustomFieldsButton.kt => addedit/VaultAddEditCustomFieldsButton.kt} (94%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem => addedit}/VaultAddEditError.kt (87%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/AddEditIdentityItems.kt => addedit/VaultAddEditIdentityItems.kt} (94%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/AddEditItemContent.kt => addedit/VaultAddEditItemContent.kt} (73%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem => addedit}/VaultAddEditLoading.kt (83%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/AddEditLoginItems.kt => addedit/VaultAddEditLoginItems.kt} (95%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/VaultAddEditItemNavigation.kt => addedit/VaultAddEditNavigation.kt} (86%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/VaultAddItemScreen.kt => addedit/VaultAddEditScreen.kt} (78%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/AddEditSecureNotesItems.kt => addedit/VaultAddEditSecureNotesItems.kt} (93%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/VaultAddItemViewModel.kt => addedit/VaultAddEditViewModel.kt} (80%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/handlers/VaultAddItemCommonHandlers.kt => addedit/handlers/VaultAddEditCommonHandlers.kt} (72%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/handlers/VaultAddIdentityItemTypeHandlers.kt => addedit/handlers/VaultAddEditIdentityTypeHandlers.kt} (79%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem/handlers/VaultAddLoginItemTypeHandlers.kt => addedit/handlers/VaultAddEditLoginTypeHandlers.kt} (72%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem => addedit}/model/CustomFieldType.kt (79%) rename app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/{additem => addedit}/util/CipherViewExtensions.kt (76%) rename app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/{additem/VaultAddItemScreenTest.kt => addedit/VaultAddEditScreenTest.kt} (87%) rename app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/{additem/VaultAddItemViewModelTest.kt => addedit/VaultAddEditViewModelTest.kt} (75%) rename app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/{additem => addedit}/model/CustomFieldTypeTests.kt (83%) rename app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/{additem => addedit}/util/CipherViewExtensionsTest.kt (84%) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/vaultunlocked/VaultUnlockedNavigation.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/vaultunlocked/VaultUnlockedNavigation.kt index 3eeee9c95..a6f806d82 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/vaultunlocked/VaultUnlockedNavigation.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/feature/vaultunlocked/VaultUnlockedNavigation.kt @@ -14,8 +14,8 @@ import com.x8bit.bitwarden.ui.tools.feature.generator.passwordhistory.navigateTo import com.x8bit.bitwarden.ui.tools.feature.generator.passwordhistory.passwordHistoryDestination import com.x8bit.bitwarden.ui.tools.feature.send.addsend.addSendDestination import com.x8bit.bitwarden.ui.tools.feature.send.addsend.navigateToAddSend -import com.x8bit.bitwarden.ui.vault.feature.additem.navigateToVaultAddEditItem -import com.x8bit.bitwarden.ui.vault.feature.additem.vaultAddEditItemDestination +import com.x8bit.bitwarden.ui.vault.feature.addedit.navigateToVaultAddEdit +import com.x8bit.bitwarden.ui.vault.feature.addedit.vaultAddEditDestination import com.x8bit.bitwarden.ui.vault.feature.item.navigateToVaultItem import com.x8bit.bitwarden.ui.vault.feature.item.vaultItemDestination import com.x8bit.bitwarden.ui.vault.feature.qrcodescan.navigateToQrCodeScanScreen @@ -44,18 +44,18 @@ fun NavGraphBuilder.vaultUnlockedGraph( vaultUnlockedNavBarDestination( onNavigateToFolders = { navController.navigateToFolders() }, onNavigateToVaultAddItem = { - navController.navigateToVaultAddEditItem(VaultAddEditType.AddItem) + navController.navigateToVaultAddEdit(VaultAddEditType.AddItem) }, onNavigateToVaultItem = { navController.navigateToVaultItem(it) }, onNavigateToVaultEditItem = { - navController.navigateToVaultAddEditItem(VaultAddEditType.EditItem(it)) + navController.navigateToVaultAddEdit(VaultAddEditType.EditItem(it)) }, onNavigateToAddSend = { navController.navigateToAddSend() }, onNavigateToDeleteAccount = { navController.navigateToDeleteAccount() }, onNavigateToPasswordHistory = { navController.navigateToPasswordHistory() }, ) deleteAccountDestination(onNavigateBack = { navController.popBackStack() }) - vaultAddEditItemDestination( + vaultAddEditDestination( onNavigateToQrCodeScanScreen = { navController.navigateToQrCodeScanScreen() }, @@ -64,7 +64,7 @@ fun NavGraphBuilder.vaultUnlockedGraph( vaultItemDestination( onNavigateBack = { navController.popBackStack() }, onNavigateToVaultEditItem = { - navController.navigateToVaultAddEditItem(VaultAddEditType.EditItem(it)) + navController.navigateToVaultAddEdit(VaultAddEditType.EditItem(it)) }, ) vaultQrCodeScanDestination(onNavigateBack = { navController.popBackStack() }) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditCustomField.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditCustomField.kt similarity index 95% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditCustomField.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditCustomField.kt index d190c8789..800c74ab0 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditCustomField.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditCustomField.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth @@ -33,14 +33,14 @@ import kotlinx.collections.immutable.toImmutableList */ @Composable @Suppress("LongMethod") -fun AddEditCustomField( - customField: VaultAddItemState.Custom, - onCustomFieldValueChange: (VaultAddItemState.Custom) -> Unit, +fun VaultAddEditCustomField( + customField: VaultAddEditState.Custom, + onCustomFieldValueChange: (VaultAddEditState.Custom) -> Unit, modifier: Modifier = Modifier, supportedLinkedTypes: ImmutableList = persistentListOf(), ) { when (customField) { - is VaultAddItemState.Custom.BooleanField -> { + is VaultAddEditState.Custom.BooleanField -> { CustomFieldBoolean( label = customField.name, value = customField.value, @@ -49,7 +49,7 @@ fun AddEditCustomField( ) } - is VaultAddItemState.Custom.HiddenField -> { + is VaultAddEditState.Custom.HiddenField -> { CustomFieldHiddenField( customField.name, customField.value, @@ -60,7 +60,7 @@ fun AddEditCustomField( ) } - is VaultAddItemState.Custom.LinkedField -> { + is VaultAddEditState.Custom.LinkedField -> { CustomFieldLinkedField( selectedOption = customField.vaultLinkedFieldType, supportedLinkedTypes = supportedLinkedTypes, @@ -71,7 +71,7 @@ fun AddEditCustomField( ) } - is VaultAddItemState.Custom.TextField -> { + is VaultAddEditState.Custom.TextField -> { CustomFieldTextField( label = customField.name, value = customField.value, diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditCustomFieldsButton.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditCustomFieldsButton.kt similarity index 94% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditCustomFieldsButton.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditCustomFieldsButton.kt index 43b464f7a..7b2fc0aab 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditCustomFieldsButton.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditCustomFieldsButton.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -12,7 +12,7 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenBasicDialogRow import com.x8bit.bitwarden.ui.platform.components.BitwardenFilledTonalButton import com.x8bit.bitwarden.ui.platform.components.BitwardenSelectionDialog import com.x8bit.bitwarden.ui.platform.components.BitwardenTextEntryDialog -import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType +import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.persistentListOf @@ -24,7 +24,7 @@ import kotlinx.collections.immutable.persistentListOf */ @Suppress("LongMethod") @Composable -fun AddEditCustomFieldsButton( +fun VaultAddEditCustomFieldsButton( onFinishNamingClick: (CustomFieldType, String) -> Unit, modifier: Modifier = Modifier, options: ImmutableList = persistentListOf( diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddEditError.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditError.kt similarity index 87% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddEditError.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditError.kt index 9c750a9d8..d54a350bb 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddEditError.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditError.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -15,11 +15,11 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp /** - * The top level error UI state for the [VaultAddItemScreen]. + * The top level error UI state for the [VaultAddEditScreen]. */ @Composable fun VaultAddEditError( - viewState: VaultAddItemState.ViewState.Error, + viewState: VaultAddEditState.ViewState.Error, modifier: Modifier = Modifier, ) { Column( diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditIdentityItems.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditIdentityItems.kt similarity index 94% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditIdentityItems.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditIdentityItems.kt index d12a6e544..69014577c 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditIdentityItems.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditIdentityItems.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth @@ -21,8 +21,8 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenMultiSelectButton import com.x8bit.bitwarden.ui.platform.components.BitwardenSwitch import com.x8bit.bitwarden.ui.platform.components.BitwardenSwitchWithActions import com.x8bit.bitwarden.ui.platform.components.BitwardenTextField -import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddIdentityItemTypeHandlers -import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddItemCommonHandlers +import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCommonHandlers +import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditIdentityTypeHandlers import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList @@ -31,12 +31,12 @@ import kotlinx.collections.immutable.toImmutableList * The UI for adding and editing an identity cipher. */ @Suppress("LongMethod") -fun LazyListScope.addEditIdentityItems( - commonState: VaultAddItemState.ViewState.Content.Common, - identityState: VaultAddItemState.ViewState.Content.ItemType.Identity, +fun LazyListScope.vaultAddEditIdentityItems( + commonState: VaultAddEditState.ViewState.Content.Common, + identityState: VaultAddEditState.ViewState.Content.ItemType.Identity, isAddItemMode: Boolean, - commonTypeHandlers: VaultAddItemCommonHandlers, - identityItemTypeHandlers: VaultAddIdentityItemTypeHandlers, + commonTypeHandlers: VaultAddEditCommonHandlers, + identityItemTypeHandlers: VaultAddEditIdentityTypeHandlers, ) { item { Spacer(modifier = Modifier.height(8.dp)) @@ -337,7 +337,7 @@ fun LazyListScope.addEditIdentityItems( } items(commonState.customFieldData) { customItem -> - AddEditCustomField( + VaultAddEditCustomField( customItem, onCustomFieldValueChange = commonTypeHandlers.onCustomFieldValueChange, modifier = Modifier @@ -352,7 +352,7 @@ fun LazyListScope.addEditIdentityItems( item { Spacer(modifier = Modifier.height(16.dp)) - AddEditCustomFieldsButton( + VaultAddEditCustomFieldsButton( onFinishNamingClick = commonTypeHandlers.onAddNewCustomFieldClick, modifier = Modifier .fillMaxWidth() @@ -391,21 +391,21 @@ fun LazyListScope.addEditIdentityItems( @Composable private fun TitleMultiSelectButton( - selectedTitle: VaultAddItemState.ViewState.Content.ItemType.Identity.Title, - onTitleSelected: (VaultAddItemState.ViewState.Content.ItemType.Identity.Title) -> Unit, + selectedTitle: VaultAddEditState.ViewState.Content.ItemType.Identity.Title, + onTitleSelected: (VaultAddEditState.ViewState.Content.ItemType.Identity.Title) -> Unit, modifier: Modifier = Modifier, ) { val resources = LocalContext.current.resources BitwardenMultiSelectButton( label = stringResource(id = R.string.title), - options = VaultAddItemState.ViewState.Content.ItemType.Identity.Title + options = VaultAddEditState.ViewState.Content.ItemType.Identity.Title .entries .map { it.value() } .toImmutableList(), selectedOption = selectedTitle.value(), onOptionSelected = { selectedString -> onTitleSelected( - VaultAddItemState.ViewState.Content.ItemType.Identity.Title + VaultAddEditState.ViewState.Content.ItemType.Identity.Title .entries .first { it.value.toString(resources) == selectedString }, ) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditItemContent.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditItemContent.kt similarity index 73% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditItemContent.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditItemContent.kt index f69965b4f..d1f3fb81b 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditItemContent.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditItemContent.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import android.Manifest import androidx.compose.foundation.layout.Spacer @@ -15,35 +15,35 @@ import com.x8bit.bitwarden.R import com.x8bit.bitwarden.ui.platform.base.util.PermissionsManager import com.x8bit.bitwarden.ui.platform.components.BitwardenListHeaderText import com.x8bit.bitwarden.ui.platform.components.BitwardenMultiSelectButton -import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddIdentityItemTypeHandlers -import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddItemCommonHandlers -import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddLoginItemTypeHandlers +import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCommonHandlers +import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditIdentityTypeHandlers +import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditLoginTypeHandlers import kotlinx.collections.immutable.toImmutableList /** - * The top level content UI state for the [VaultAddItemScreen]. + * The top level content UI state for the [VaultAddEditScreen]. */ @Composable @Suppress("LongMethod") -fun AddEditItemContent( - state: VaultAddItemState.ViewState.Content, +fun VaultAddEditContent( + state: VaultAddEditState.ViewState.Content, isAddItemMode: Boolean, - onTypeOptionClicked: (VaultAddItemState.ItemTypeOption) -> Unit, - commonTypeHandlers: VaultAddItemCommonHandlers, - loginItemTypeHandlers: VaultAddLoginItemTypeHandlers, - identityItemTypeHandlers: VaultAddIdentityItemTypeHandlers, + onTypeOptionClicked: (VaultAddEditState.ItemTypeOption) -> Unit, + commonTypeHandlers: VaultAddEditCommonHandlers, + loginItemTypeHandlers: VaultAddEditLoginTypeHandlers, + identityItemTypeHandlers: VaultAddEditIdentityTypeHandlers, modifier: Modifier = Modifier, permissionsManager: PermissionsManager, ) { val launcher = permissionsManager.getLauncher( onResult = { isGranted -> when (state.type) { - is VaultAddItemState.ViewState.Content.ItemType.SecureNotes -> Unit + is VaultAddEditState.ViewState.Content.ItemType.SecureNotes -> Unit // TODO: Create UI for card-type item creation BIT-507 - is VaultAddItemState.ViewState.Content.ItemType.Card -> Unit + is VaultAddEditState.ViewState.Content.ItemType.Card -> Unit // TODO: Create UI for identity-type item creation BIT-667 - is VaultAddItemState.ViewState.Content.ItemType.Identity -> Unit - is VaultAddItemState.ViewState.Content.ItemType.Login -> { + is VaultAddEditState.ViewState.Content.ItemType.Identity -> Unit + is VaultAddEditState.ViewState.Content.ItemType.Login -> { loginItemTypeHandlers.onSetupTotpClick(isGranted) } } @@ -73,8 +73,8 @@ fun AddEditItemContent( } when (state.type) { - is VaultAddItemState.ViewState.Content.ItemType.Login -> { - addEditLoginItems( + is VaultAddEditState.ViewState.Content.ItemType.Login -> { + vaultAddEditLoginItems( commonState = state.common, loginState = state.type, isAddItemMode = isAddItemMode, @@ -90,12 +90,12 @@ fun AddEditItemContent( ) } - is VaultAddItemState.ViewState.Content.ItemType.Card -> { + is VaultAddEditState.ViewState.Content.ItemType.Card -> { // TODO(BIT-507): Create UI for card-type item creation } - is VaultAddItemState.ViewState.Content.ItemType.Identity -> { - addEditIdentityItems( + is VaultAddEditState.ViewState.Content.ItemType.Identity -> { + vaultAddEditIdentityItems( commonState = state.common, identityState = state.type, isAddItemMode = isAddItemMode, @@ -104,8 +104,8 @@ fun AddEditItemContent( ) } - is VaultAddItemState.ViewState.Content.ItemType.SecureNotes -> { - addEditSecureNotesItems( + is VaultAddEditState.ViewState.Content.ItemType.SecureNotes -> { + vaultAddEditSecureNotesItems( commonState = state.common, isAddItemMode = isAddItemMode, commonTypeHandlers = commonTypeHandlers, @@ -121,11 +121,11 @@ fun AddEditItemContent( @Composable private fun TypeOptionsItem( - itemType: VaultAddItemState.ViewState.Content.ItemType, - onTypeOptionClicked: (VaultAddItemState.ItemTypeOption) -> Unit, + itemType: VaultAddEditState.ViewState.Content.ItemType, + onTypeOptionClicked: (VaultAddEditState.ItemTypeOption) -> Unit, modifier: Modifier, ) { - val possibleMainStates = VaultAddItemState.ItemTypeOption.entries.toList() + val possibleMainStates = VaultAddEditState.ItemTypeOption.entries.toList() val optionsWithStrings = possibleMainStates.associateWith { stringResource(id = it.labelRes) } BitwardenMultiSelectButton( diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddEditLoading.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditLoading.kt similarity index 83% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddEditLoading.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditLoading.kt index 6f25319db..0adcef7d5 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddEditLoading.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditLoading.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -10,10 +10,10 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier /** - * The top level loading UI state for the [VaultAddItemScreen]. + * The top level loading UI state for the [VaultAddEditScreen]. */ @Composable -fun VaultAddEditItemLoading( +fun VaultAddEditLoading( modifier: Modifier = Modifier, ) { Column( diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditLoginItems.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditLoginItems.kt similarity index 95% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditLoginItems.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditLoginItems.kt index 990152309..fd6e6515d 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditLoginItems.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditLoginItems.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth @@ -25,8 +25,8 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenSwitchWithActions import com.x8bit.bitwarden.ui.platform.components.BitwardenTextField import com.x8bit.bitwarden.ui.platform.components.BitwardenTextFieldWithActions import com.x8bit.bitwarden.ui.platform.components.model.IconResource -import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddItemCommonHandlers -import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddLoginItemTypeHandlers +import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCommonHandlers +import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditLoginTypeHandlers import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList @@ -35,12 +35,12 @@ import kotlinx.collections.immutable.toImmutableList * The UI for adding and editing a login cipher. */ @Suppress("LongMethod", "LongParameterList") -fun LazyListScope.addEditLoginItems( - commonState: VaultAddItemState.ViewState.Content.Common, - loginState: VaultAddItemState.ViewState.Content.ItemType.Login, +fun LazyListScope.vaultAddEditLoginItems( + commonState: VaultAddEditState.ViewState.Content.Common, + loginState: VaultAddEditState.ViewState.Content.ItemType.Login, isAddItemMode: Boolean, - commonActionHandler: VaultAddItemCommonHandlers, - loginItemTypeHandlers: VaultAddLoginItemTypeHandlers, + commonActionHandler: VaultAddEditCommonHandlers, + loginItemTypeHandlers: VaultAddEditLoginTypeHandlers, onTotpSetupClick: () -> Unit, ) { item { @@ -287,7 +287,7 @@ fun LazyListScope.addEditLoginItems( } items(commonState.customFieldData) { customItem -> - AddEditCustomField( + VaultAddEditCustomField( customItem, onCustomFieldValueChange = commonActionHandler.onCustomFieldValueChange, modifier = Modifier @@ -302,7 +302,7 @@ fun LazyListScope.addEditLoginItems( item { Spacer(modifier = Modifier.height(16.dp)) - AddEditCustomFieldsButton( + VaultAddEditCustomFieldsButton( onFinishNamingClick = commonActionHandler.onAddNewCustomFieldClick, modifier = Modifier .fillMaxWidth() diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddEditItemNavigation.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditNavigation.kt similarity index 86% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddEditItemNavigation.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditNavigation.kt index 7ebd7633f..a8905bdca 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddEditItemNavigation.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditNavigation.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import androidx.lifecycle.SavedStateHandle import androidx.navigation.NavController @@ -24,7 +24,7 @@ private const val ADD_EDIT_ITEM_ROUTE: String = * Class to retrieve vault add & edit arguments from the [SavedStateHandle]. */ @OmitFromCoverage -data class VaultAddEditItemArgs( +data class VaultAddEditArgs( val vaultAddEditType: VaultAddEditType, ) { constructor(savedStateHandle: SavedStateHandle) : this( @@ -37,9 +37,9 @@ data class VaultAddEditItemArgs( } /** - * Add the vault add & edit item screen to the nav graph. + * Add the vault add & edit screen to the nav graph. */ -fun NavGraphBuilder.vaultAddEditItemDestination( +fun NavGraphBuilder.vaultAddEditDestination( onNavigateToQrCodeScanScreen: () -> Unit, onNavigateBack: () -> Unit, ) { @@ -49,14 +49,14 @@ fun NavGraphBuilder.vaultAddEditItemDestination( navArgument(ADD_EDIT_ITEM_TYPE) { type = NavType.StringType }, ), ) { - VaultAddItemScreen(onNavigateBack, onNavigateToQrCodeScanScreen) + VaultAddEditScreen(onNavigateBack, onNavigateToQrCodeScanScreen) } } /** - * Navigate to the vault add & edit item screen. + * Navigate to the vault add & edit screen. */ -fun NavController.navigateToVaultAddEditItem( +fun NavController.navigateToVaultAddEdit( vaultAddEditType: VaultAddEditType, navOptions: NavOptions? = null, ) { diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemScreen.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreen.kt similarity index 78% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemScreen.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreen.kt index c4003da5e..5a98d9437 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemScreen.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreen.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import android.app.Activity import android.widget.Toast @@ -33,9 +33,9 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenScaffold import com.x8bit.bitwarden.ui.platform.components.BitwardenTextButton import com.x8bit.bitwarden.ui.platform.components.BitwardenTopAppBar import com.x8bit.bitwarden.ui.platform.components.LoadingDialogState -import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddIdentityItemTypeHandlers -import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddItemCommonHandlers -import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddLoginItemTypeHandlers +import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCommonHandlers +import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditIdentityTypeHandlers +import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditLoginTypeHandlers /** * Top level composable for the vault add item screen. @@ -43,10 +43,10 @@ import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddLoginItemTy @OptIn(ExperimentalMaterial3Api::class) @Suppress("LongMethod") @Composable -fun VaultAddItemScreen( +fun VaultAddEditScreen( onNavigateBack: () -> Unit, onNavigateToQrCodeScanScreen: () -> Unit, - viewModel: VaultAddItemViewModel = hiltViewModel(), + viewModel: VaultAddEditViewModel = hiltViewModel(), clipboardManager: ClipboardManager = LocalClipboardManager.current, permissionsManager: PermissionsManager = PermissionsManagerImpl(LocalContext.current as Activity), @@ -57,38 +57,38 @@ fun VaultAddItemScreen( EventsEffect(viewModel = viewModel) { event -> when (event) { - is VaultAddItemEvent.NavigateToQrCodeScan -> { + is VaultAddEditEvent.NavigateToQrCodeScan -> { onNavigateToQrCodeScanScreen() } - is VaultAddItemEvent.ShowToast -> { + is VaultAddEditEvent.ShowToast -> { Toast.makeText(context, event.message(resources), Toast.LENGTH_SHORT).show() } - is VaultAddItemEvent.CopyToClipboard -> { + is VaultAddEditEvent.CopyToClipboard -> { clipboardManager.setText(event.text.toAnnotatedString()) } - VaultAddItemEvent.NavigateBack -> onNavigateBack.invoke() + VaultAddEditEvent.NavigateBack -> onNavigateBack.invoke() } } val loginItemTypeHandlers = remember(viewModel) { - VaultAddLoginItemTypeHandlers.create(viewModel = viewModel) + VaultAddEditLoginTypeHandlers.create(viewModel = viewModel) } val commonTypeHandlers = remember(viewModel) { - VaultAddItemCommonHandlers.create(viewModel = viewModel) + VaultAddEditCommonHandlers.create(viewModel = viewModel) } val identityItemTypeHandlers = remember(viewModel) { - VaultAddIdentityItemTypeHandlers.create(viewModel = viewModel) + VaultAddEditIdentityTypeHandlers.create(viewModel = viewModel) } VaultAddEditItemDialogs( dialogState = state.dialog, onDismissRequest = remember(viewModel) { - { viewModel.trySendAction(VaultAddItemAction.Common.DismissDialog) } + { viewModel.trySendAction(VaultAddEditAction.Common.DismissDialog) } }, ) @@ -103,14 +103,14 @@ fun VaultAddItemScreen( navigationIcon = painterResource(id = R.drawable.ic_close), navigationIconContentDescription = stringResource(id = R.string.close), onNavigationIconClick = remember(viewModel) { - { viewModel.trySendAction(VaultAddItemAction.Common.CloseClick) } + { viewModel.trySendAction(VaultAddEditAction.Common.CloseClick) } }, scrollBehavior = scrollBehavior, actions = { BitwardenTextButton( label = stringResource(id = R.string.save), onClick = remember(viewModel) { - { viewModel.trySendAction(VaultAddItemAction.Common.SaveClick) } + { viewModel.trySendAction(VaultAddEditAction.Common.SaveClick) } }, ) }, @@ -118,12 +118,12 @@ fun VaultAddItemScreen( }, ) { innerPadding -> when (val viewState = state.viewState) { - is VaultAddItemState.ViewState.Content -> { - AddEditItemContent( + is VaultAddEditState.ViewState.Content -> { + VaultAddEditContent( state = viewState, isAddItemMode = state.isAddItemMode, onTypeOptionClicked = remember(viewModel) { - { viewModel.trySendAction(VaultAddItemAction.Common.TypeOptionSelect(it)) } + { viewModel.trySendAction(VaultAddEditAction.Common.TypeOptionSelect(it)) } }, loginItemTypeHandlers = loginItemTypeHandlers, commonTypeHandlers = commonTypeHandlers, @@ -136,7 +136,7 @@ fun VaultAddItemScreen( ) } - is VaultAddItemState.ViewState.Error -> { + is VaultAddEditState.ViewState.Error -> { VaultAddEditError( viewState = viewState, modifier = Modifier @@ -145,8 +145,8 @@ fun VaultAddItemScreen( ) } - VaultAddItemState.ViewState.Loading -> { - VaultAddEditItemLoading( + VaultAddEditState.ViewState.Loading -> { + VaultAddEditLoading( modifier = Modifier .padding(innerPadding) .fillMaxSize(), @@ -158,17 +158,17 @@ fun VaultAddItemScreen( @Composable private fun VaultAddEditItemDialogs( - dialogState: VaultAddItemState.DialogState?, + dialogState: VaultAddEditState.DialogState?, onDismissRequest: () -> Unit, ) { when (dialogState) { - is VaultAddItemState.DialogState.Loading -> { + is VaultAddEditState.DialogState.Loading -> { BitwardenLoadingDialog( visibilityState = LoadingDialogState.Shown(dialogState.label), ) } - is VaultAddItemState.DialogState.Error -> BitwardenBasicDialog( + is VaultAddEditState.DialogState.Error -> BitwardenBasicDialog( visibilityState = BasicDialogState.Shown( title = R.string.an_error_has_occurred.asText(), message = dialogState.message, diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditSecureNotesItems.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditSecureNotesItems.kt similarity index 93% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditSecureNotesItems.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditSecureNotesItems.kt index e881bf6a3..d70fa6c37 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/AddEditSecureNotesItems.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditSecureNotesItems.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth @@ -19,8 +19,8 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenMultiSelectButton import com.x8bit.bitwarden.ui.platform.components.BitwardenSwitch import com.x8bit.bitwarden.ui.platform.components.BitwardenSwitchWithActions import com.x8bit.bitwarden.ui.platform.components.BitwardenTextField -import com.x8bit.bitwarden.ui.vault.feature.additem.handlers.VaultAddItemCommonHandlers -import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType +import com.x8bit.bitwarden.ui.vault.feature.addedit.handlers.VaultAddEditCommonHandlers +import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.toImmutableList @@ -28,10 +28,10 @@ import kotlinx.collections.immutable.toImmutableList * The UI for adding and editing a secure notes cipher. */ @Suppress("LongMethod") -fun LazyListScope.addEditSecureNotesItems( - commonState: VaultAddItemState.ViewState.Content.Common, +fun LazyListScope.vaultAddEditSecureNotesItems( + commonState: VaultAddEditState.ViewState.Content.Common, isAddItemMode: Boolean, - commonTypeHandlers: VaultAddItemCommonHandlers, + commonTypeHandlers: VaultAddEditCommonHandlers, ) { item { Spacer(modifier = Modifier.height(8.dp)) @@ -135,7 +135,7 @@ fun LazyListScope.addEditSecureNotesItems( ) } items(commonState.customFieldData) { customItem -> - AddEditCustomField( + VaultAddEditCustomField( customItem, onCustomFieldValueChange = commonTypeHandlers.onCustomFieldValueChange, modifier = Modifier @@ -146,7 +146,7 @@ fun LazyListScope.addEditSecureNotesItems( item { Spacer(modifier = Modifier.height(16.dp)) - AddEditCustomFieldsButton( + VaultAddEditCustomFieldsButton( onFinishNamingClick = commonTypeHandlers.onAddNewCustomFieldClick, options = persistentListOf( CustomFieldType.TEXT, diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt similarity index 80% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemViewModel.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt index 0f87b5bbf..57370035e 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import android.os.Parcelable import androidx.lifecycle.SavedStateHandle @@ -14,9 +14,9 @@ import com.x8bit.bitwarden.ui.platform.base.BaseViewModel import com.x8bit.bitwarden.ui.platform.base.util.Text import com.x8bit.bitwarden.ui.platform.base.util.asText import com.x8bit.bitwarden.ui.platform.base.util.concat -import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType -import com.x8bit.bitwarden.ui.vault.feature.additem.model.toCustomField -import com.x8bit.bitwarden.ui.vault.feature.additem.util.toViewState +import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType +import com.x8bit.bitwarden.ui.vault.feature.addedit.model.toCustomField +import com.x8bit.bitwarden.ui.vault.feature.addedit.util.toViewState import com.x8bit.bitwarden.ui.vault.feature.vault.util.toCipherView import com.x8bit.bitwarden.ui.vault.model.VaultAddEditType import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType @@ -43,23 +43,23 @@ private const val KEY_STATE = "state" */ @HiltViewModel @Suppress("TooManyFunctions", "LargeClass") -class VaultAddItemViewModel @Inject constructor( +class VaultAddEditViewModel @Inject constructor( savedStateHandle: SavedStateHandle, private val vaultRepository: VaultRepository, -) : BaseViewModel( +) : BaseViewModel( // We load the state from the savedStateHandle for testing purposes. initialState = savedStateHandle[KEY_STATE] ?: run { - val vaultAddEditType = VaultAddEditItemArgs(savedStateHandle).vaultAddEditType - VaultAddItemState( + val vaultAddEditType = VaultAddEditArgs(savedStateHandle).vaultAddEditType + VaultAddEditState( vaultAddEditType = vaultAddEditType, viewState = when (vaultAddEditType) { - VaultAddEditType.AddItem -> VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common(), - type = VaultAddItemState.ViewState.Content.ItemType.Login(), + VaultAddEditType.AddItem -> VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common(), + type = VaultAddEditState.ViewState.Content.ItemType.Login(), ) - is VaultAddEditType.EditItem -> VaultAddItemState.ViewState.Loading + is VaultAddEditType.EditItem -> VaultAddEditState.ViewState.Loading }, dialog = null, ) @@ -76,7 +76,7 @@ class VaultAddItemViewModel @Inject constructor( .getVaultItemStateFlow(vaultAddEditType.vaultItemId) // We'll stop getting updates as soon as we get some loaded data. .takeUntilLoaded() - .map { VaultAddItemAction.Internal.VaultDataReceive(it) } + .map { VaultAddEditAction.Internal.VaultDataReceive(it) } .onEach(::sendAction) .launchIn(viewModelScope) } @@ -84,17 +84,17 @@ class VaultAddItemViewModel @Inject constructor( vaultRepository .totpCodeFlow - .map { VaultAddItemAction.Internal.TotpCodeReceive(totpCode = it) } + .map { VaultAddEditAction.Internal.TotpCodeReceive(totpCode = it) } .onEach(::sendAction) .launchIn(viewModelScope) } - override fun handleAction(action: VaultAddItemAction) { + override fun handleAction(action: VaultAddEditAction) { when (action) { - is VaultAddItemAction.Common -> handleCommonActions(action) - is VaultAddItemAction.ItemType.LoginType -> handleAddLoginTypeAction(action) - is VaultAddItemAction.ItemType.IdentityType -> handleIdentityTypeActions(action) - is VaultAddItemAction.Internal -> handleInternalActions(action) + is VaultAddEditAction.Common -> handleCommonActions(action) + is VaultAddEditAction.ItemType.LoginType -> handleAddLoginTypeAction(action) + is VaultAddEditAction.ItemType.IdentityType -> handleIdentityTypeActions(action) + is VaultAddEditAction.Internal -> handleInternalActions(action) } } @@ -102,46 +102,46 @@ class VaultAddItemViewModel @Inject constructor( //region Common Handlers - private fun handleCommonActions(action: VaultAddItemAction.Common) { + private fun handleCommonActions(action: VaultAddEditAction.Common) { when (action) { - is VaultAddItemAction.Common.CustomFieldValueChange -> handleCustomFieldValueChange( + is VaultAddEditAction.Common.CustomFieldValueChange -> handleCustomFieldValueChange( action, ) - is VaultAddItemAction.Common.FolderChange -> handleFolderTextInputChange(action) - is VaultAddItemAction.Common.NameTextChange -> handleNameTextInputChange(action) - is VaultAddItemAction.Common.NotesTextChange -> handleNotesTextInputChange(action) - is VaultAddItemAction.Common.OwnershipChange -> handleOwnershipTextInputChange(action) - is VaultAddItemAction.Common.ToggleFavorite -> handleToggleFavorite(action) - is VaultAddItemAction.Common.ToggleMasterPasswordReprompt -> { + is VaultAddEditAction.Common.FolderChange -> handleFolderTextInputChange(action) + is VaultAddEditAction.Common.NameTextChange -> handleNameTextInputChange(action) + is VaultAddEditAction.Common.NotesTextChange -> handleNotesTextInputChange(action) + is VaultAddEditAction.Common.OwnershipChange -> handleOwnershipTextInputChange(action) + is VaultAddEditAction.Common.ToggleFavorite -> handleToggleFavorite(action) + is VaultAddEditAction.Common.ToggleMasterPasswordReprompt -> { handleToggleMasterPasswordReprompt(action) } - is VaultAddItemAction.Common.CloseClick -> handleCloseClick() - is VaultAddItemAction.Common.DismissDialog -> handleDismissDialog() - is VaultAddItemAction.Common.SaveClick -> handleSaveClick() - is VaultAddItemAction.Common.TypeOptionSelect -> handleTypeOptionSelect(action) - is VaultAddItemAction.Common.AddNewCustomFieldClick -> handleAddNewCustomFieldClick( + is VaultAddEditAction.Common.CloseClick -> handleCloseClick() + is VaultAddEditAction.Common.DismissDialog -> handleDismissDialog() + is VaultAddEditAction.Common.SaveClick -> handleSaveClick() + is VaultAddEditAction.Common.TypeOptionSelect -> handleTypeOptionSelect(action) + is VaultAddEditAction.Common.AddNewCustomFieldClick -> handleAddNewCustomFieldClick( action, ) - is VaultAddItemAction.Common.TooltipClick -> handleTooltipClick() + is VaultAddEditAction.Common.TooltipClick -> handleTooltipClick() } } - private fun handleTypeOptionSelect(action: VaultAddItemAction.Common.TypeOptionSelect) { + private fun handleTypeOptionSelect(action: VaultAddEditAction.Common.TypeOptionSelect) { when (action.typeOption) { - VaultAddItemState.ItemTypeOption.LOGIN -> handleSwitchToAddLoginItem() - VaultAddItemState.ItemTypeOption.CARD -> handleSwitchToAddCardItem() - VaultAddItemState.ItemTypeOption.IDENTITY -> handleSwitchToAddIdentityItem() - VaultAddItemState.ItemTypeOption.SECURE_NOTES -> handleSwitchToAddSecureNotesItem() + VaultAddEditState.ItemTypeOption.LOGIN -> handleSwitchToAddLoginItem() + VaultAddEditState.ItemTypeOption.CARD -> handleSwitchToAddCardItem() + VaultAddEditState.ItemTypeOption.IDENTITY -> handleSwitchToAddIdentityItem() + VaultAddEditState.ItemTypeOption.SECURE_NOTES -> handleSwitchToAddSecureNotesItem() } } private fun handleSwitchToAddLoginItem() { updateContent { currentContent -> currentContent.copy( - type = VaultAddItemState.ViewState.Content.ItemType.Login(), + type = VaultAddEditState.ViewState.Content.ItemType.Login(), ) } } @@ -149,7 +149,7 @@ class VaultAddItemViewModel @Inject constructor( private fun handleSwitchToAddSecureNotesItem() { updateContent { currentContent -> currentContent.copy( - type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes, + type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes, ) } } @@ -157,7 +157,7 @@ class VaultAddItemViewModel @Inject constructor( private fun handleSwitchToAddCardItem() { updateContent { currentContent -> currentContent.copy( - type = VaultAddItemState.ViewState.Content.ItemType.Card, + type = VaultAddEditState.ViewState.Content.ItemType.Card, ) } } @@ -165,7 +165,7 @@ class VaultAddItemViewModel @Inject constructor( private fun handleSwitchToAddIdentityItem() { updateContent { currentContent -> currentContent.copy( - type = VaultAddItemState.ViewState.Content.ItemType.Identity(), + type = VaultAddEditState.ViewState.Content.ItemType.Identity(), ) } } @@ -174,7 +174,7 @@ class VaultAddItemViewModel @Inject constructor( if (content.common.name.isBlank()) { mutableStateFlow.update { it.copy( - dialog = VaultAddItemState.DialogState.Error( + dialog = VaultAddEditState.DialogState.Error( R.string.validation_field_required .asText(R.string.name.asText()), ), @@ -185,7 +185,7 @@ class VaultAddItemViewModel @Inject constructor( mutableStateFlow.update { it.copy( - dialog = VaultAddItemState.DialogState.Loading( + dialog = VaultAddEditState.DialogState.Loading( R.string.saving.asText(), ), ) @@ -195,7 +195,7 @@ class VaultAddItemViewModel @Inject constructor( when (val vaultAddEditType = state.vaultAddEditType) { VaultAddEditType.AddItem -> { val result = vaultRepository.createCipher(cipherView = content.toCipherView()) - sendAction(VaultAddItemAction.Internal.CreateCipherResultReceive(result)) + sendAction(VaultAddEditAction.Internal.CreateCipherResultReceive(result)) } is VaultAddEditType.EditItem -> { @@ -203,7 +203,7 @@ class VaultAddItemViewModel @Inject constructor( cipherId = vaultAddEditType.vaultItemId, cipherView = content.toCipherView(), ) - sendAction(VaultAddItemAction.Internal.UpdateCipherResultReceive(result)) + sendAction(VaultAddEditAction.Internal.UpdateCipherResultReceive(result)) } } } @@ -211,7 +211,7 @@ class VaultAddItemViewModel @Inject constructor( private fun handleCloseClick() { sendEvent( - event = VaultAddItemEvent.NavigateBack, + event = VaultAddEditEvent.NavigateBack, ) } @@ -222,9 +222,9 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleAddNewCustomFieldClick( - action: VaultAddItemAction.Common.AddNewCustomFieldClick, + action: VaultAddEditAction.Common.AddNewCustomFieldClick, ) { - val newCustomData: VaultAddItemState.Custom = + val newCustomData: VaultAddEditState.Custom = action.customFieldType.toCustomField(action.name) updateCommonContent { loginType -> @@ -233,7 +233,7 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleCustomFieldValueChange( - action: VaultAddItemAction.Common.CustomFieldValueChange, + action: VaultAddEditAction.Common.CustomFieldValueChange, ) { updateCommonContent { commonContent -> commonContent.copy( @@ -249,7 +249,7 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleFolderTextInputChange( - action: VaultAddItemAction.Common.FolderChange, + action: VaultAddEditAction.Common.FolderChange, ) { updateCommonContent { commonContent -> commonContent.copy(folderName = action.folder) @@ -257,7 +257,7 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleToggleFavorite( - action: VaultAddItemAction.Common.ToggleFavorite, + action: VaultAddEditAction.Common.ToggleFavorite, ) { updateCommonContent { commonContent -> commonContent.copy(favorite = action.isFavorite) @@ -265,7 +265,7 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleToggleMasterPasswordReprompt( - action: VaultAddItemAction.Common.ToggleMasterPasswordReprompt, + action: VaultAddEditAction.Common.ToggleMasterPasswordReprompt, ) { updateCommonContent { commonContent -> commonContent.copy(masterPasswordReprompt = action.isMasterPasswordReprompt) @@ -273,7 +273,7 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleNotesTextInputChange( - action: VaultAddItemAction.Common.NotesTextChange, + action: VaultAddEditAction.Common.NotesTextChange, ) { updateCommonContent { commonContent -> commonContent.copy(notes = action.notes) @@ -281,7 +281,7 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleOwnershipTextInputChange( - action: VaultAddItemAction.Common.OwnershipChange, + action: VaultAddEditAction.Common.OwnershipChange, ) { updateCommonContent { commonContent -> commonContent.copy(ownership = action.ownership) @@ -289,7 +289,7 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleNameTextInputChange( - action: VaultAddItemAction.Common.NameTextChange, + action: VaultAddEditAction.Common.NameTextChange, ) { updateCommonContent { commonContent -> commonContent.copy(name = action.name) @@ -299,7 +299,7 @@ class VaultAddItemViewModel @Inject constructor( private fun handleTooltipClick() { // TODO Add the text for the prompt (BIT-1079) sendEvent( - event = VaultAddItemEvent.ShowToast( + event = VaultAddEditEvent.ShowToast( message = "Not yet implemented".asText(), ), ) @@ -311,53 +311,53 @@ class VaultAddItemViewModel @Inject constructor( @Suppress("LongMethod") private fun handleAddLoginTypeAction( - action: VaultAddItemAction.ItemType.LoginType, + action: VaultAddEditAction.ItemType.LoginType, ) { when (action) { - is VaultAddItemAction.ItemType.LoginType.UsernameTextChange -> { + is VaultAddEditAction.ItemType.LoginType.UsernameTextChange -> { handleLoginUsernameTextInputChange(action) } - is VaultAddItemAction.ItemType.LoginType.PasswordTextChange -> { + is VaultAddEditAction.ItemType.LoginType.PasswordTextChange -> { handleLoginPasswordTextInputChange(action) } - is VaultAddItemAction.ItemType.LoginType.UriTextChange -> { + is VaultAddEditAction.ItemType.LoginType.UriTextChange -> { handleLoginUriTextInputChange(action) } - is VaultAddItemAction.ItemType.LoginType.OpenUsernameGeneratorClick -> { + is VaultAddEditAction.ItemType.LoginType.OpenUsernameGeneratorClick -> { handleLoginOpenUsernameGeneratorClick() } - is VaultAddItemAction.ItemType.LoginType.PasswordCheckerClick -> { + is VaultAddEditAction.ItemType.LoginType.PasswordCheckerClick -> { handleLoginPasswordCheckerClick() } - is VaultAddItemAction.ItemType.LoginType.OpenPasswordGeneratorClick -> { + is VaultAddEditAction.ItemType.LoginType.OpenPasswordGeneratorClick -> { handleLoginOpenPasswordGeneratorClick() } - is VaultAddItemAction.ItemType.LoginType.SetupTotpClick -> { + is VaultAddEditAction.ItemType.LoginType.SetupTotpClick -> { handleLoginSetupTotpClick(action) } - is VaultAddItemAction.ItemType.LoginType.UriSettingsClick -> { + is VaultAddEditAction.ItemType.LoginType.UriSettingsClick -> { handleLoginUriSettingsClick() } - is VaultAddItemAction.ItemType.LoginType.AddNewUriClick -> { + is VaultAddEditAction.ItemType.LoginType.AddNewUriClick -> { handleLoginAddNewUriClick() } - is VaultAddItemAction.ItemType.LoginType.CopyTotpKeyClick -> { + is VaultAddEditAction.ItemType.LoginType.CopyTotpKeyClick -> { handleLoginCopyTotpKeyText(action) } } } private fun handleLoginUsernameTextInputChange( - action: VaultAddItemAction.ItemType.LoginType.UsernameTextChange, + action: VaultAddEditAction.ItemType.LoginType.UsernameTextChange, ) { updateLoginContent { loginType -> loginType.copy(username = action.username) @@ -365,7 +365,7 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleLoginPasswordTextInputChange( - action: VaultAddItemAction.ItemType.LoginType.PasswordTextChange, + action: VaultAddEditAction.ItemType.LoginType.PasswordTextChange, ) { updateLoginContent { loginType -> loginType.copy(password = action.password) @@ -373,7 +373,7 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleLoginUriTextInputChange( - action: VaultAddItemAction.ItemType.LoginType.UriTextChange, + action: VaultAddEditAction.ItemType.LoginType.UriTextChange, ) { updateLoginContent { loginType -> loginType.copy(uri = action.uri) @@ -383,7 +383,7 @@ class VaultAddItemViewModel @Inject constructor( private fun handleLoginOpenUsernameGeneratorClick() { viewModelScope.launch { sendEvent( - event = VaultAddItemEvent.ShowToast( + event = VaultAddEditEvent.ShowToast( message = "Open Username Generator".asText(), ), ) @@ -393,7 +393,7 @@ class VaultAddItemViewModel @Inject constructor( private fun handleLoginPasswordCheckerClick() { viewModelScope.launch { sendEvent( - event = VaultAddItemEvent.ShowToast( + event = VaultAddEditEvent.ShowToast( message = "Password Checker".asText(), ), ) @@ -403,7 +403,7 @@ class VaultAddItemViewModel @Inject constructor( private fun handleLoginOpenPasswordGeneratorClick() { viewModelScope.launch { sendEvent( - event = VaultAddItemEvent.ShowToast( + event = VaultAddEditEvent.ShowToast( message = "Open Password Generator".asText(), ), ) @@ -411,14 +411,14 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleLoginSetupTotpClick( - action: VaultAddItemAction.ItemType.LoginType.SetupTotpClick, + action: VaultAddEditAction.ItemType.LoginType.SetupTotpClick, ) { if (action.isGranted) { - sendEvent(event = VaultAddItemEvent.NavigateToQrCodeScan) + sendEvent(event = VaultAddEditEvent.NavigateToQrCodeScan) } else { // TODO Add manual QR code entry (BIT-1114) sendEvent( - event = VaultAddItemEvent.ShowToast( + event = VaultAddEditEvent.ShowToast( message = "Permission Not Granted, Manual QR Code Entry Not Implemented".asText(), ), @@ -427,10 +427,10 @@ class VaultAddItemViewModel @Inject constructor( } private fun handleLoginCopyTotpKeyText( - action: VaultAddItemAction.ItemType.LoginType.CopyTotpKeyClick, + action: VaultAddEditAction.ItemType.LoginType.CopyTotpKeyClick, ) { sendEvent( - event = VaultAddItemEvent.CopyToClipboard( + event = VaultAddEditEvent.CopyToClipboard( text = action.totpKey, ), ) @@ -439,7 +439,7 @@ class VaultAddItemViewModel @Inject constructor( private fun handleLoginUriSettingsClick() { viewModelScope.launch { sendEvent( - event = VaultAddItemEvent.ShowToast( + event = VaultAddEditEvent.ShowToast( message = "URI Settings".asText(), ), ) @@ -449,7 +449,7 @@ class VaultAddItemViewModel @Inject constructor( private fun handleLoginAddNewUriClick() { viewModelScope.launch { sendEvent( - event = VaultAddItemEvent.ShowToast( + event = VaultAddEditEvent.ShowToast( message = "Add New URI".asText(), ), ) @@ -459,186 +459,186 @@ class VaultAddItemViewModel @Inject constructor( //endregion Add Login Item Type Handlers //region Identity Type Handlers - private fun handleIdentityTypeActions(action: VaultAddItemAction.ItemType.IdentityType) { + private fun handleIdentityTypeActions(action: VaultAddEditAction.ItemType.IdentityType) { when (action) { - is VaultAddItemAction.ItemType.IdentityType.FirstNameTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.FirstNameTextChange -> { handleIdentityFirstNameTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.Address1TextChange -> { + is VaultAddEditAction.ItemType.IdentityType.Address1TextChange -> { handleIdentityAddress1TextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.Address2TextChange -> { + is VaultAddEditAction.ItemType.IdentityType.Address2TextChange -> { handleIdentityAddress2TextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.Address3TextChange -> { + is VaultAddEditAction.ItemType.IdentityType.Address3TextChange -> { handleIdentityAddress3TextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.CityTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.CityTextChange -> { handleIdentityCityTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.StateTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.StateTextChange -> { handleIdentityStateTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.CompanyTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.CompanyTextChange -> { handleIdentityCompanyTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.CountryTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.CountryTextChange -> { handleIdentityCountryTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.EmailTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.EmailTextChange -> { handleIdentityEmailTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.LastNameTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.LastNameTextChange -> { handleIdentityLastNameTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.LicenseNumberTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.LicenseNumberTextChange -> { handleIdentityLicenseNumberTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.MiddleNameTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.MiddleNameTextChange -> { handleIdentityMiddleNameTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.PassportNumberTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.PassportNumberTextChange -> { handleIdentityPassportNumberTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.PhoneTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.PhoneTextChange -> { handleIdentityPhoneTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.ZipTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.ZipTextChange -> { handleIdentityZipTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.SsnTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.SsnTextChange -> { handleIdentitySsnTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.UsernameTextChange -> { + is VaultAddEditAction.ItemType.IdentityType.UsernameTextChange -> { handleIdentityUsernameTextChange(action) } - is VaultAddItemAction.ItemType.IdentityType.TitleSelected -> { + is VaultAddEditAction.ItemType.IdentityType.TitleSelected -> { handleIdentityTitleSelected(action) } } } private fun handleIdentityAddress1TextChange( - action: VaultAddItemAction.ItemType.IdentityType.Address1TextChange, + action: VaultAddEditAction.ItemType.IdentityType.Address1TextChange, ) { updateIdentityContent { it.copy(address1 = action.address1) } } private fun handleIdentityAddress2TextChange( - action: VaultAddItemAction.ItemType.IdentityType.Address2TextChange, + action: VaultAddEditAction.ItemType.IdentityType.Address2TextChange, ) { updateIdentityContent { it.copy(address2 = action.address2) } } private fun handleIdentityAddress3TextChange( - action: VaultAddItemAction.ItemType.IdentityType.Address3TextChange, + action: VaultAddEditAction.ItemType.IdentityType.Address3TextChange, ) { updateIdentityContent { it.copy(address3 = action.address3) } } private fun handleIdentityCityTextChange( - action: VaultAddItemAction.ItemType.IdentityType.CityTextChange, + action: VaultAddEditAction.ItemType.IdentityType.CityTextChange, ) { updateIdentityContent { it.copy(city = action.city) } } private fun handleIdentityStateTextChange( - action: VaultAddItemAction.ItemType.IdentityType.StateTextChange, + action: VaultAddEditAction.ItemType.IdentityType.StateTextChange, ) { updateIdentityContent { it.copy(state = action.state) } } private fun handleIdentityCompanyTextChange( - action: VaultAddItemAction.ItemType.IdentityType.CompanyTextChange, + action: VaultAddEditAction.ItemType.IdentityType.CompanyTextChange, ) { updateIdentityContent { it.copy(company = action.company) } } private fun handleIdentityCountryTextChange( - action: VaultAddItemAction.ItemType.IdentityType.CountryTextChange, + action: VaultAddEditAction.ItemType.IdentityType.CountryTextChange, ) { updateIdentityContent { it.copy(country = action.country) } } private fun handleIdentityEmailTextChange( - action: VaultAddItemAction.ItemType.IdentityType.EmailTextChange, + action: VaultAddEditAction.ItemType.IdentityType.EmailTextChange, ) { updateIdentityContent { it.copy(email = action.email) } } private fun handleIdentityLastNameTextChange( - action: VaultAddItemAction.ItemType.IdentityType.LastNameTextChange, + action: VaultAddEditAction.ItemType.IdentityType.LastNameTextChange, ) { updateIdentityContent { it.copy(lastName = action.lastName) } } private fun handleIdentityLicenseNumberTextChange( - action: VaultAddItemAction.ItemType.IdentityType.LicenseNumberTextChange, + action: VaultAddEditAction.ItemType.IdentityType.LicenseNumberTextChange, ) { updateIdentityContent { it.copy(licenseNumber = action.licenseNumber) } } private fun handleIdentityMiddleNameTextChange( - action: VaultAddItemAction.ItemType.IdentityType.MiddleNameTextChange, + action: VaultAddEditAction.ItemType.IdentityType.MiddleNameTextChange, ) { updateIdentityContent { it.copy(middleName = action.middleName) } } private fun handleIdentityPassportNumberTextChange( - action: VaultAddItemAction.ItemType.IdentityType.PassportNumberTextChange, + action: VaultAddEditAction.ItemType.IdentityType.PassportNumberTextChange, ) { updateIdentityContent { it.copy(passportNumber = action.passportNumber) } } private fun handleIdentityPhoneTextChange( - action: VaultAddItemAction.ItemType.IdentityType.PhoneTextChange, + action: VaultAddEditAction.ItemType.IdentityType.PhoneTextChange, ) { updateIdentityContent { it.copy(phone = action.phone) } } private fun handleIdentityZipTextChange( - action: VaultAddItemAction.ItemType.IdentityType.ZipTextChange, + action: VaultAddEditAction.ItemType.IdentityType.ZipTextChange, ) { updateIdentityContent { it.copy(zip = action.zip) } } private fun handleIdentitySsnTextChange( - action: VaultAddItemAction.ItemType.IdentityType.SsnTextChange, + action: VaultAddEditAction.ItemType.IdentityType.SsnTextChange, ) { updateIdentityContent { it.copy(ssn = action.ssn) } } private fun handleIdentityUsernameTextChange( - action: VaultAddItemAction.ItemType.IdentityType.UsernameTextChange, + action: VaultAddEditAction.ItemType.IdentityType.UsernameTextChange, ) { updateIdentityContent { it.copy(username = action.username) } } private fun handleIdentityFirstNameTextChange( - action: VaultAddItemAction.ItemType.IdentityType.FirstNameTextChange, + action: VaultAddEditAction.ItemType.IdentityType.FirstNameTextChange, ) { updateIdentityContent { it.copy(firstName = action.firstName) } } private fun handleIdentityTitleSelected( - action: VaultAddItemAction.ItemType.IdentityType.TitleSelected, + action: VaultAddEditAction.ItemType.IdentityType.TitleSelected, ) { updateIdentityContent { it.copy(selectedTitle = action.title) } } @@ -646,23 +646,23 @@ class VaultAddItemViewModel @Inject constructor( //region Internal Type Handlers - private fun handleInternalActions(action: VaultAddItemAction.Internal) { + private fun handleInternalActions(action: VaultAddEditAction.Internal) { when (action) { - is VaultAddItemAction.Internal.CreateCipherResultReceive -> { + is VaultAddEditAction.Internal.CreateCipherResultReceive -> { handleCreateCipherResultReceive(action) } - is VaultAddItemAction.Internal.UpdateCipherResultReceive -> { + is VaultAddEditAction.Internal.UpdateCipherResultReceive -> { handleUpdateCipherResultReceive(action) } - is VaultAddItemAction.Internal.VaultDataReceive -> handleVaultDataReceive(action) - is VaultAddItemAction.Internal.TotpCodeReceive -> handleVaultTotpCodeReceive(action) + is VaultAddEditAction.Internal.TotpCodeReceive -> handleVaultTotpCodeReceive(action) + is VaultAddEditAction.Internal.VaultDataReceive -> handleVaultDataReceive(action) } } private fun handleCreateCipherResultReceive( - action: VaultAddItemAction.Internal.CreateCipherResultReceive, + action: VaultAddEditAction.Internal.CreateCipherResultReceive, ) { mutableStateFlow.update { it.copy(dialog = null) @@ -672,7 +672,7 @@ class VaultAddItemViewModel @Inject constructor( is CreateCipherResult.Error -> { // TODO Display error dialog BIT-501 sendEvent( - event = VaultAddItemEvent.ShowToast( + event = VaultAddEditEvent.ShowToast( message = "Save Item Failure".asText(), ), ) @@ -680,34 +680,34 @@ class VaultAddItemViewModel @Inject constructor( is CreateCipherResult.Success -> { sendEvent( - event = VaultAddItemEvent.NavigateBack, + event = VaultAddEditEvent.NavigateBack, ) } } } private fun handleUpdateCipherResultReceive( - action: VaultAddItemAction.Internal.UpdateCipherResultReceive, + action: VaultAddEditAction.Internal.UpdateCipherResultReceive, ) { mutableStateFlow.update { it.copy(dialog = null) } when (action.updateCipherResult) { is UpdateCipherResult.Error -> { // TODO Display error dialog BIT-501 - sendEvent(VaultAddItemEvent.ShowToast(message = "Save Item Failure".asText())) + sendEvent(VaultAddEditEvent.ShowToast(message = "Save Item Failure".asText())) } is UpdateCipherResult.Success -> { - sendEvent(VaultAddItemEvent.NavigateBack) + sendEvent(VaultAddEditEvent.NavigateBack) } } } - private fun handleVaultDataReceive(action: VaultAddItemAction.Internal.VaultDataReceive) { + private fun handleVaultDataReceive(action: VaultAddEditAction.Internal.VaultDataReceive) { when (val vaultDataState = action.vaultDataState) { is DataState.Error -> { mutableStateFlow.update { it.copy( - viewState = VaultAddItemState.ViewState.Error( + viewState = VaultAddEditState.ViewState.Error( message = R.string.generic_error_message.asText(), ), ) @@ -720,7 +720,7 @@ class VaultAddItemViewModel @Inject constructor( viewState = vaultDataState .data ?.toViewState() - ?: VaultAddItemState.ViewState.Error( + ?: VaultAddEditState.ViewState.Error( message = R.string.generic_error_message.asText(), ), ) @@ -729,14 +729,14 @@ class VaultAddItemViewModel @Inject constructor( DataState.Loading -> { mutableStateFlow.update { - it.copy(viewState = VaultAddItemState.ViewState.Loading) + it.copy(viewState = VaultAddEditState.ViewState.Loading) } } is DataState.NoNetwork -> { mutableStateFlow.update { it.copy( - viewState = VaultAddItemState.ViewState.Error( + viewState = VaultAddEditState.ViewState.Error( message = R.string.internet_connection_required_title .asText() .concat(R.string.internet_connection_required_message.asText()), @@ -751,7 +751,7 @@ class VaultAddItemViewModel @Inject constructor( viewState = vaultDataState .data ?.toViewState() - ?: VaultAddItemState.ViewState.Error( + ?: VaultAddEditState.ViewState.Error( message = R.string.generic_error_message.asText(), ), ) @@ -760,13 +760,13 @@ class VaultAddItemViewModel @Inject constructor( } } - private fun handleVaultTotpCodeReceive(action: VaultAddItemAction.Internal.TotpCodeReceive) { + private fun handleVaultTotpCodeReceive(action: VaultAddEditAction.Internal.TotpCodeReceive) { updateLoginContent { loginType -> loginType.copy(totp = action.totpCode) } sendEvent( - event = VaultAddItemEvent.ShowToast( + event = VaultAddEditEvent.ShowToast( message = R.string.authenticator_key_added.asText(), ), ) @@ -777,26 +777,26 @@ class VaultAddItemViewModel @Inject constructor( //region Utility Functions private inline fun onContent( - crossinline block: (VaultAddItemState.ViewState.Content) -> Unit, + crossinline block: (VaultAddEditState.ViewState.Content) -> Unit, ) { - (state.viewState as? VaultAddItemState.ViewState.Content)?.let(block) + (state.viewState as? VaultAddEditState.ViewState.Content)?.let(block) } private inline fun updateContent( crossinline block: ( - VaultAddItemState.ViewState.Content, - ) -> VaultAddItemState.ViewState.Content?, + VaultAddEditState.ViewState.Content, + ) -> VaultAddEditState.ViewState.Content?, ) { val currentViewState = state.viewState - val updatedContent = (currentViewState as? VaultAddItemState.ViewState.Content) + val updatedContent = (currentViewState as? VaultAddEditState.ViewState.Content) ?.let(block) ?: return mutableStateFlow.update { it.copy(viewState = updatedContent) } } private inline fun updateCommonContent( - crossinline block: (VaultAddItemState.ViewState.Content.Common) -> - VaultAddItemState.ViewState.Content.Common, + crossinline block: (VaultAddEditState.ViewState.Content.Common) -> + VaultAddEditState.ViewState.Content.Common, ) { updateContent { currentContent -> currentContent.copy(common = block(currentContent.common)) @@ -804,21 +804,21 @@ class VaultAddItemViewModel @Inject constructor( } private inline fun updateLoginContent( - crossinline block: (VaultAddItemState.ViewState.Content.ItemType.Login) -> - VaultAddItemState.ViewState.Content.ItemType.Login, + crossinline block: (VaultAddEditState.ViewState.Content.ItemType.Login) -> + VaultAddEditState.ViewState.Content.ItemType.Login, ) { updateContent { currentContent -> - (currentContent.type as? VaultAddItemState.ViewState.Content.ItemType.Login) + (currentContent.type as? VaultAddEditState.ViewState.Content.ItemType.Login) ?.let { currentContent.copy(type = block(it)) } } } private inline fun updateIdentityContent( - crossinline block: (VaultAddItemState.ViewState.Content.ItemType.Identity) -> - VaultAddItemState.ViewState.Content.ItemType.Identity, + crossinline block: (VaultAddEditState.ViewState.Content.ItemType.Identity) -> + VaultAddEditState.ViewState.Content.ItemType.Identity, ) { updateContent { currentContent -> - (currentContent.type as? VaultAddItemState.ViewState.Content.ItemType.Identity) + (currentContent.type as? VaultAddEditState.ViewState.Content.ItemType.Identity) ?.let { currentContent.copy(type = block(it)) } } } @@ -834,7 +834,7 @@ class VaultAddItemViewModel @Inject constructor( * @property dialog the state for the dialogs that can be displayed */ @Parcelize -data class VaultAddItemState( +data class VaultAddEditState( val vaultAddEditType: VaultAddEditType, val viewState: ViewState, val dialog: DialogState?, @@ -867,11 +867,11 @@ data class VaultAddItemState( } /** - * Represents the specific view states for the [VaultAddItemScreen]. + * Represents the specific view states for the [VaultAddEditScreen]. */ sealed class ViewState : Parcelable { /** - * Represents an error state for the [VaultAddItemScreen]. + * Represents an error state for the [VaultAddEditScreen]. */ @Parcelize data class Error( @@ -879,14 +879,14 @@ data class VaultAddItemState( ) : ViewState() /** - * Loading state for the [VaultAddItemScreen], signifying that the content is being + * Loading state for the [VaultAddEditScreen], signifying that the content is being * processed. */ @Parcelize data object Loading : ViewState() /** - * Represents a loaded content state for the [VaultAddItemScreen]. + * Represents a loaded content state for the [VaultAddEditScreen]. */ @Parcelize data class Content( @@ -1119,38 +1119,38 @@ data class VaultAddItemState( * Represents a set of events that can be emitted during the process of adding an item to the vault. * Each subclass of this sealed class denotes a distinct event that can occur. */ -sealed class VaultAddItemEvent { +sealed class VaultAddEditEvent { /** * Shows a toast with the given [message]. */ - data class ShowToast(val message: Text) : VaultAddItemEvent() + data class ShowToast(val message: Text) : VaultAddEditEvent() /** * Copy the given [text] to the clipboard. */ - data class CopyToClipboard(val text: String) : VaultAddItemEvent() + data class CopyToClipboard(val text: String) : VaultAddEditEvent() /** * Navigate back to previous screen. */ - data object NavigateBack : VaultAddItemEvent() + data object NavigateBack : VaultAddEditEvent() /** * Navigate to the QR code scan screen. */ - data object NavigateToQrCodeScan : VaultAddItemEvent() + data object NavigateToQrCodeScan : VaultAddEditEvent() } /** * Represents a set of actions related to the process of adding an item to the vault. * Each subclass of this sealed class denotes a distinct action that can be taken. */ -sealed class VaultAddItemAction { +sealed class VaultAddEditAction { /** * Represents actions common across all item types. */ - sealed class Common : VaultAddItemAction() { + sealed class Common : VaultAddEditAction() { /** * Represents the action when the save button is clicked. @@ -1173,7 +1173,7 @@ sealed class VaultAddItemAction { * @property typeOption The selected type option. */ data class TypeOptionSelect( - val typeOption: VaultAddItemState.ItemTypeOption, + val typeOption: VaultAddEditState.ItemTypeOption, ) : Common() /** @@ -1230,7 +1230,7 @@ sealed class VaultAddItemAction { /** * Fired when the custom field data is changed. */ - data class CustomFieldValueChange(val customField: VaultAddItemState.Custom) : Common() + data class CustomFieldValueChange(val customField: VaultAddEditState.Custom) : Common() /** * Represents the action to open tooltip @@ -1241,7 +1241,7 @@ sealed class VaultAddItemAction { /** * Represents actions specific to an item type. */ - sealed class ItemType : VaultAddItemAction() { + sealed class ItemType : VaultAddEditAction() { /** * Represents actions specific to the Login type. @@ -1439,15 +1439,15 @@ sealed class VaultAddItemAction { * @property title The selected title. */ data class TitleSelected( - val title: VaultAddItemState.ViewState.Content.ItemType.Identity.Title, + val title: VaultAddEditState.ViewState.Content.ItemType.Identity.Title, ) : IdentityType() } } /** - * Models actions that the [VaultAddItemViewModel] itself might send. + * Models actions that the [VaultAddEditViewModel] itself might send. */ - sealed class Internal : VaultAddItemAction() { + sealed class Internal : VaultAddEditAction() { /** * Indicates that the vault totp code has been received. diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/handlers/VaultAddItemCommonHandlers.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/handlers/VaultAddEditCommonHandlers.kt similarity index 72% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/handlers/VaultAddItemCommonHandlers.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/handlers/VaultAddEditCommonHandlers.kt index 8c315c0ef..417045f58 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/handlers/VaultAddItemCommonHandlers.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/handlers/VaultAddEditCommonHandlers.kt @@ -1,10 +1,10 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem.handlers +package com.x8bit.bitwarden.ui.vault.feature.addedit.handlers import com.x8bit.bitwarden.ui.platform.base.util.asText -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemAction -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemViewModel -import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditAction +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditViewModel +import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType /** * A collection of handler functions for managing actions common @@ -23,7 +23,7 @@ import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType * @property onCustomFieldValueChange Handles the action when the field's value changes */ @Suppress("LongParameterList") -class VaultAddItemCommonHandlers( +class VaultAddEditCommonHandlers( val onNameTextChange: (String) -> Unit, val onFolderTextChange: (String) -> Unit, val onToggleFavorite: (Boolean) -> Unit, @@ -32,59 +32,59 @@ class VaultAddItemCommonHandlers( val onOwnershipTextChange: (String) -> Unit, val onTooltipClick: () -> Unit, val onAddNewCustomFieldClick: (CustomFieldType, String) -> Unit, - val onCustomFieldValueChange: (VaultAddItemState.Custom) -> Unit, + val onCustomFieldValueChange: (VaultAddEditState.Custom) -> Unit, ) { companion object { /** - * Creates an instance of [VaultAddItemCommonHandlers] by binding actions - * to the provided [VaultAddItemViewModel]. + * Creates an instance of [VaultAddEditCommonHandlers] by binding actions + * to the provided [VaultAddEditViewModel]. */ @Suppress("LongMethod") - fun create(viewModel: VaultAddItemViewModel): VaultAddItemCommonHandlers { - return VaultAddItemCommonHandlers( + fun create(viewModel: VaultAddEditViewModel): VaultAddEditCommonHandlers { + return VaultAddEditCommonHandlers( onNameTextChange = { newName -> viewModel.trySendAction( - VaultAddItemAction.Common.NameTextChange(newName), + VaultAddEditAction.Common.NameTextChange(newName), ) }, onFolderTextChange = { newFolder -> viewModel.trySendAction( - VaultAddItemAction.Common.FolderChange( + VaultAddEditAction.Common.FolderChange( newFolder.asText(), ), ) }, onToggleFavorite = { isFavorite -> viewModel.trySendAction( - VaultAddItemAction.Common.ToggleFavorite(isFavorite), + VaultAddEditAction.Common.ToggleFavorite(isFavorite), ) }, onToggleMasterPasswordReprompt = { isMasterPasswordReprompt -> viewModel.trySendAction( - VaultAddItemAction.Common.ToggleMasterPasswordReprompt( + VaultAddEditAction.Common.ToggleMasterPasswordReprompt( isMasterPasswordReprompt, ), ) }, onNotesTextChange = { newNotes -> viewModel.trySendAction( - VaultAddItemAction.Common.NotesTextChange(newNotes), + VaultAddEditAction.Common.NotesTextChange(newNotes), ) }, onOwnershipTextChange = { newOwnership -> viewModel.trySendAction( - VaultAddItemAction.Common.OwnershipChange(newOwnership), + VaultAddEditAction.Common.OwnershipChange(newOwnership), ) }, onTooltipClick = { viewModel.trySendAction( - VaultAddItemAction.Common.TooltipClick, + VaultAddEditAction.Common.TooltipClick, ) }, onAddNewCustomFieldClick = { newCustomFieldType, name -> viewModel.trySendAction( - VaultAddItemAction.Common.AddNewCustomFieldClick( + VaultAddEditAction.Common.AddNewCustomFieldClick( newCustomFieldType, name, ), @@ -92,7 +92,7 @@ class VaultAddItemCommonHandlers( }, onCustomFieldValueChange = { newValue -> viewModel.trySendAction( - VaultAddItemAction.Common.CustomFieldValueChange( + VaultAddEditAction.Common.CustomFieldValueChange( newValue, ), ) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/handlers/VaultAddIdentityItemTypeHandlers.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/handlers/VaultAddEditIdentityTypeHandlers.kt similarity index 79% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/handlers/VaultAddIdentityItemTypeHandlers.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/handlers/VaultAddEditIdentityTypeHandlers.kt index 90521f8a2..b3ddea2e9 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/handlers/VaultAddIdentityItemTypeHandlers.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/handlers/VaultAddEditIdentityTypeHandlers.kt @@ -1,8 +1,8 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem.handlers +package com.x8bit.bitwarden.ui.vault.feature.addedit.handlers -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemAction -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemViewModel +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditAction +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditViewModel /** * A collection of handler functions specifically tailored for managing actions @@ -26,8 +26,8 @@ import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemViewModel * @property onCountryTextChange Handles the action when the country text is changed. */ @Suppress("LongParameterList") -class VaultAddIdentityItemTypeHandlers( - val onTitleSelected: (VaultAddItemState.ViewState.Content.ItemType.Identity.Title) -> Unit, +class VaultAddEditIdentityTypeHandlers( + val onTitleSelected: (VaultAddEditState.ViewState.Content.ItemType.Identity.Title) -> Unit, val onFirstNameTextChange: (String) -> Unit, val onMiddleNameTextChange: (String) -> Unit, val onLastNameTextChange: (String) -> Unit, @@ -49,134 +49,134 @@ class VaultAddIdentityItemTypeHandlers( companion object { /** - * Creates an instance of [VaultAddIdentityItemTypeHandlers] by binding actions - * to the provided [VaultAddItemViewModel]. + * Creates an instance of [VaultAddEditIdentityTypeHandlers] by binding actions + * to the provided [VaultAddEditViewModel]. */ @Suppress("LongMethod") - fun create(viewModel: VaultAddItemViewModel): VaultAddIdentityItemTypeHandlers { - return VaultAddIdentityItemTypeHandlers( + fun create(viewModel: VaultAddEditViewModel): VaultAddEditIdentityTypeHandlers { + return VaultAddEditIdentityTypeHandlers( onTitleSelected = { newTitle -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.TitleSelected( + VaultAddEditAction.ItemType.IdentityType.TitleSelected( title = newTitle, ), ) }, onFirstNameTextChange = { newFirstName -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.FirstNameTextChange( + VaultAddEditAction.ItemType.IdentityType.FirstNameTextChange( firstName = newFirstName, ), ) }, onMiddleNameTextChange = { newMiddleName -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.MiddleNameTextChange( + VaultAddEditAction.ItemType.IdentityType.MiddleNameTextChange( middleName = newMiddleName, ), ) }, onLastNameTextChange = { newLastName -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.LastNameTextChange( + VaultAddEditAction.ItemType.IdentityType.LastNameTextChange( lastName = newLastName, ), ) }, onUsernameTextChange = { newUsername -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.UsernameTextChange( + VaultAddEditAction.ItemType.IdentityType.UsernameTextChange( username = newUsername, ), ) }, onCompanyTextChange = { newCompany -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.CompanyTextChange( + VaultAddEditAction.ItemType.IdentityType.CompanyTextChange( company = newCompany, ), ) }, onSsnTextChange = { newSsn -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.SsnTextChange( + VaultAddEditAction.ItemType.IdentityType.SsnTextChange( ssn = newSsn, ), ) }, onPassportNumberTextChange = { newPassportNumber -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.PassportNumberTextChange( + VaultAddEditAction.ItemType.IdentityType.PassportNumberTextChange( passportNumber = newPassportNumber, ), ) }, onLicenseNumberTextChange = { newLicenseNumber -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.LicenseNumberTextChange( + VaultAddEditAction.ItemType.IdentityType.LicenseNumberTextChange( licenseNumber = newLicenseNumber, ), ) }, onEmailTextChange = { newEmail -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.EmailTextChange( + VaultAddEditAction.ItemType.IdentityType.EmailTextChange( email = newEmail, ), ) }, onPhoneTextChange = { newPhone -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.PhoneTextChange( + VaultAddEditAction.ItemType.IdentityType.PhoneTextChange( phone = newPhone, ), ) }, onAddress1TextChange = { newAddress1 -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.Address1TextChange( + VaultAddEditAction.ItemType.IdentityType.Address1TextChange( address1 = newAddress1, ), ) }, onAddress2TextChange = { newAddress2 -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.Address2TextChange( + VaultAddEditAction.ItemType.IdentityType.Address2TextChange( address2 = newAddress2, ), ) }, onAddress3TextChange = { newAddress3 -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.Address3TextChange( + VaultAddEditAction.ItemType.IdentityType.Address3TextChange( address3 = newAddress3, ), ) }, onCityTextChange = { newCity -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.CityTextChange( + VaultAddEditAction.ItemType.IdentityType.CityTextChange( city = newCity, ), ) }, onStateTextChange = { newState -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.StateTextChange( + VaultAddEditAction.ItemType.IdentityType.StateTextChange( state = newState, ), ) }, onZipTextChange = { newZip -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.ZipTextChange( + VaultAddEditAction.ItemType.IdentityType.ZipTextChange( zip = newZip, ), ) }, onCountryTextChange = { newCountry -> viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.CountryTextChange( + VaultAddEditAction.ItemType.IdentityType.CountryTextChange( country = newCountry, ), ) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/handlers/VaultAddLoginItemTypeHandlers.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/handlers/VaultAddEditLoginTypeHandlers.kt similarity index 72% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/handlers/VaultAddLoginItemTypeHandlers.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/handlers/VaultAddEditLoginTypeHandlers.kt index cdedae9a3..3faaa835b 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/handlers/VaultAddLoginItemTypeHandlers.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/handlers/VaultAddEditLoginTypeHandlers.kt @@ -1,7 +1,7 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem.handlers +package com.x8bit.bitwarden.ui.vault.feature.addedit.handlers -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemAction -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemViewModel +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditAction +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditViewModel /** * A collection of handler functions specifically tailored for managing actions @@ -22,7 +22,7 @@ import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemViewModel * @property onAddNewUriClick Handles the action when the add new URI button is clicked. */ @Suppress("LongParameterList") -class VaultAddLoginItemTypeHandlers( +class VaultAddEditLoginTypeHandlers( val onUsernameTextChange: (String) -> Unit, val onPasswordTextChange: (String) -> Unit, val onUriTextChange: (String) -> Unit, @@ -37,59 +37,59 @@ class VaultAddLoginItemTypeHandlers( companion object { /** - * Creates an instance of [VaultAddLoginItemTypeHandlers] by binding actions - * to the provided [VaultAddItemViewModel]. + * Creates an instance of [VaultAddEditLoginTypeHandlers] by binding actions + * to the provided [VaultAddEditViewModel]. * - * @param viewModel The [VaultAddItemViewModel] to which actions will be sent. - * @return A fully initialized [VaultAddLoginItemTypeHandlers] object. + * @param viewModel The [VaultAddEditViewModel] to which actions will be sent. + * @return A fully initialized [VaultAddEditLoginTypeHandlers] object. */ @Suppress("LongMethod") - fun create(viewModel: VaultAddItemViewModel): VaultAddLoginItemTypeHandlers { - return VaultAddLoginItemTypeHandlers( + fun create(viewModel: VaultAddEditViewModel): VaultAddEditLoginTypeHandlers { + return VaultAddEditLoginTypeHandlers( onUsernameTextChange = { newUsername -> viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.UsernameTextChange(newUsername), + VaultAddEditAction.ItemType.LoginType.UsernameTextChange(newUsername), ) }, onPasswordTextChange = { newPassword -> viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.PasswordTextChange(newPassword), + VaultAddEditAction.ItemType.LoginType.PasswordTextChange(newPassword), ) }, onUriTextChange = { newUri -> viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.UriTextChange(newUri), + VaultAddEditAction.ItemType.LoginType.UriTextChange(newUri), ) }, onOpenUsernameGeneratorClick = { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.OpenUsernameGeneratorClick, + VaultAddEditAction.ItemType.LoginType.OpenUsernameGeneratorClick, ) }, onPasswordCheckerClick = { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.PasswordCheckerClick, + VaultAddEditAction.ItemType.LoginType.PasswordCheckerClick, ) }, onOpenPasswordGeneratorClick = { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.OpenPasswordGeneratorClick, + VaultAddEditAction.ItemType.LoginType.OpenPasswordGeneratorClick, ) }, onSetupTotpClick = { isGranted -> viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.SetupTotpClick(isGranted), + VaultAddEditAction.ItemType.LoginType.SetupTotpClick(isGranted), ) }, onUriSettingsClick = { - viewModel.trySendAction(VaultAddItemAction.ItemType.LoginType.UriSettingsClick) + viewModel.trySendAction(VaultAddEditAction.ItemType.LoginType.UriSettingsClick) }, onAddNewUriClick = { - viewModel.trySendAction(VaultAddItemAction.ItemType.LoginType.AddNewUriClick) + viewModel.trySendAction(VaultAddEditAction.ItemType.LoginType.AddNewUriClick) }, onCopyTotpKeyClick = { totpKey -> viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.CopyTotpKeyClick( + VaultAddEditAction.ItemType.LoginType.CopyTotpKeyClick( totpKey, ), ) diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/model/CustomFieldType.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/model/CustomFieldType.kt similarity index 79% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/model/CustomFieldType.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/model/CustomFieldType.kt index 57574c87b..764bd08d3 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/model/CustomFieldType.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/model/CustomFieldType.kt @@ -1,9 +1,9 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem.model +package com.x8bit.bitwarden.ui.vault.feature.addedit.model import com.x8bit.bitwarden.R import com.x8bit.bitwarden.ui.platform.base.util.Text import com.x8bit.bitwarden.ui.platform.base.util.asText -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType import java.util.UUID @@ -18,14 +18,14 @@ enum class CustomFieldType(val typeText: Text) { } /** - * A function that converts [CustomFieldType] and a string to [VaultAddItemState.Custom]. + * A function that converts [CustomFieldType] and a string to [VaultAddEditState.Custom]. */ fun CustomFieldType.toCustomField( name: String, -): VaultAddItemState.Custom { +): VaultAddEditState.Custom { return when (this) { CustomFieldType.BOOLEAN -> { - VaultAddItemState.Custom.BooleanField( + VaultAddEditState.Custom.BooleanField( itemId = UUID.randomUUID().toString(), name = name, value = false, @@ -33,7 +33,7 @@ fun CustomFieldType.toCustomField( } CustomFieldType.LINKED -> { - VaultAddItemState.Custom.LinkedField( + VaultAddEditState.Custom.LinkedField( itemId = UUID.randomUUID().toString(), name = name, vaultLinkedFieldType = VaultLinkedFieldType.USERNAME, @@ -41,7 +41,7 @@ fun CustomFieldType.toCustomField( } CustomFieldType.HIDDEN -> { - VaultAddItemState.Custom.HiddenField( + VaultAddEditState.Custom.HiddenField( itemId = UUID.randomUUID().toString(), name = name, value = "", @@ -49,7 +49,7 @@ fun CustomFieldType.toCustomField( } CustomFieldType.TEXT -> { - VaultAddItemState.Custom.TextField( + VaultAddEditState.Custom.TextField( itemId = UUID.randomUUID().toString(), name = name, value = "", diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/util/CipherViewExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/util/CipherViewExtensions.kt similarity index 76% rename from app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/util/CipherViewExtensions.kt rename to app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/util/CipherViewExtensions.kt index 4eb3e8f6d..c1e9dc98e 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/additem/util/CipherViewExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/util/CipherViewExtensions.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem.util +package com.x8bit.bitwarden.ui.vault.feature.addedit.util import com.bitwarden.core.CipherRepromptType import com.bitwarden.core.CipherType @@ -7,18 +7,18 @@ import com.bitwarden.core.FieldType import com.bitwarden.core.FieldView import com.x8bit.bitwarden.R import com.x8bit.bitwarden.ui.platform.base.util.asText -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType.Companion.fromId import java.util.UUID /** - * Transforms [CipherView] into [VaultAddItemState.ViewState]. + * Transforms [CipherView] into [VaultAddEditState.ViewState]. */ -fun CipherView.toViewState(): VaultAddItemState.ViewState = - VaultAddItemState.ViewState.Content( +fun CipherView.toViewState(): VaultAddEditState.ViewState = + VaultAddEditState.ViewState.Content( type = when (type) { CipherType.LOGIN -> { - VaultAddItemState.ViewState.Content.ItemType.Login( + VaultAddEditState.ViewState.Content.ItemType.Login( username = login?.username.orEmpty(), password = login?.password.orEmpty(), uri = login?.uris?.firstOrNull()?.uri.orEmpty(), @@ -26,9 +26,9 @@ fun CipherView.toViewState(): VaultAddItemState.ViewState = ) } - CipherType.SECURE_NOTE -> VaultAddItemState.ViewState.Content.ItemType.SecureNotes - CipherType.CARD -> VaultAddItemState.ViewState.Content.ItemType.Card - CipherType.IDENTITY -> VaultAddItemState.ViewState.Content.ItemType.Identity( + CipherType.SECURE_NOTE -> VaultAddEditState.ViewState.Content.ItemType.SecureNotes + CipherType.CARD -> VaultAddEditState.ViewState.Content.ItemType.Card + CipherType.IDENTITY -> VaultAddEditState.ViewState.Content.ItemType.Identity( selectedTitle = identity?.title.toTitleOrDefault(), firstName = identity?.firstName.orEmpty(), middleName = identity?.middleName.orEmpty(), @@ -48,7 +48,7 @@ fun CipherView.toViewState(): VaultAddItemState.ViewState = country = identity?.country.orEmpty(), ) }, - common = VaultAddItemState.ViewState.Content.Common( + common = VaultAddEditState.ViewState.Content.Common( originalCipher = this, name = this.name, favorite = this.favorite, @@ -67,25 +67,25 @@ fun CipherView.toViewState(): VaultAddItemState.ViewState = private fun FieldView.toCustomField() = when (this.type) { - FieldType.TEXT -> VaultAddItemState.Custom.TextField( + FieldType.TEXT -> VaultAddEditState.Custom.TextField( itemId = UUID.randomUUID().toString(), name = this.name.orEmpty(), value = this.value.orEmpty(), ) - FieldType.HIDDEN -> VaultAddItemState.Custom.HiddenField( + FieldType.HIDDEN -> VaultAddEditState.Custom.HiddenField( itemId = UUID.randomUUID().toString(), name = this.name.orEmpty(), value = this.value.orEmpty(), ) - FieldType.BOOLEAN -> VaultAddItemState.Custom.BooleanField( + FieldType.BOOLEAN -> VaultAddEditState.Custom.BooleanField( itemId = UUID.randomUUID().toString(), name = this.name.orEmpty(), value = this.value.toBoolean(), ) - FieldType.LINKED -> VaultAddItemState.Custom.LinkedField( + FieldType.LINKED -> VaultAddEditState.Custom.LinkedField( itemId = UUID.randomUUID().toString(), name = this.name.orEmpty(), vaultLinkedFieldType = fromId(requireNotNull(this.linkedId)), @@ -93,8 +93,8 @@ private fun FieldView.toCustomField() = } @Suppress("MaxLineLength") -private fun String?.toTitleOrDefault(): VaultAddItemState.ViewState.Content.ItemType.Identity.Title = - VaultAddItemState.ViewState.Content.ItemType.Identity.Title +private fun String?.toTitleOrDefault(): VaultAddEditState.ViewState.Content.ItemType.Identity.Title = + VaultAddEditState.ViewState.Content.ItemType.Identity.Title .entries .find { it.name == this } - ?: VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MR + ?: VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MR diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/VaultAddItemStateExtensions.kt b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/VaultAddItemStateExtensions.kt index f80e2f876..a0b9973da 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/VaultAddItemStateExtensions.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/VaultAddItemStateExtensions.kt @@ -13,13 +13,13 @@ import com.bitwarden.core.SecureNoteType import com.bitwarden.core.SecureNoteView import com.bitwarden.core.UriMatchType import com.x8bit.bitwarden.ui.platform.base.util.orNullIfBlank -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState import java.time.Instant /** - * Transforms a [VaultAddItemState.ViewState.ItemType] into [CipherView]. + * Transforms a [VaultAddEditState.ViewState.ItemType] into [CipherView]. */ -fun VaultAddItemState.ViewState.Content.toCipherView(): CipherView = +fun VaultAddEditState.ViewState.Content.toCipherView(): CipherView = CipherView( // Pulled from original cipher when editing, otherwise uses defaults id = common.originalCipher?.id, @@ -54,16 +54,16 @@ fun VaultAddItemState.ViewState.Content.toCipherView(): CipherView = fields = common.customFieldData.map { it.toFieldView() }, ) -private fun VaultAddItemState.ViewState.Content.ItemType.toCipherType(): CipherType = +private fun VaultAddEditState.ViewState.Content.ItemType.toCipherType(): CipherType = when (this) { - is VaultAddItemState.ViewState.Content.ItemType.Card -> CipherType.CARD - is VaultAddItemState.ViewState.Content.ItemType.Identity -> CipherType.IDENTITY - is VaultAddItemState.ViewState.Content.ItemType.Login -> CipherType.LOGIN - is VaultAddItemState.ViewState.Content.ItemType.SecureNotes -> CipherType.SECURE_NOTE + is VaultAddEditState.ViewState.Content.ItemType.Card -> CipherType.CARD + is VaultAddEditState.ViewState.Content.ItemType.Identity -> CipherType.IDENTITY + is VaultAddEditState.ViewState.Content.ItemType.Login -> CipherType.LOGIN + is VaultAddEditState.ViewState.Content.ItemType.SecureNotes -> CipherType.SECURE_NOTE } -private fun VaultAddItemState.ViewState.Content.ItemType.toCardView(): CardView? = - (this as? VaultAddItemState.ViewState.Content.ItemType.Card)?.let { +private fun VaultAddEditState.ViewState.Content.ItemType.toCardView(): CardView? = + (this as? VaultAddEditState.ViewState.Content.ItemType.Card)?.let { // TODO Create real CardView from Content (BIT-668) CardView( cardholderName = null, @@ -75,8 +75,8 @@ private fun VaultAddItemState.ViewState.Content.ItemType.toCardView(): CardView? ) } -private fun VaultAddItemState.ViewState.Content.ItemType.toIdentityView(): IdentityView? = - (this as? VaultAddItemState.ViewState.Content.ItemType.Identity)?.let { +private fun VaultAddEditState.ViewState.Content.ItemType.toIdentityView(): IdentityView? = + (this as? VaultAddEditState.ViewState.Content.ItemType.Identity)?.let { IdentityView( title = it.selectedTitle.name, firstName = it.firstName.orNullIfBlank(), @@ -99,10 +99,10 @@ private fun VaultAddItemState.ViewState.Content.ItemType.toIdentityView(): Ident ) } -private fun VaultAddItemState.ViewState.Content.ItemType.toLoginView( - common: VaultAddItemState.ViewState.Content.Common, +private fun VaultAddEditState.ViewState.Content.ItemType.toLoginView( + common: VaultAddEditState.ViewState.Content.Common, ): LoginView? = - (this as? VaultAddItemState.ViewState.Content.ItemType.Login)?.let { + (this as? VaultAddEditState.ViewState.Content.ItemType.Login)?.let { LoginView( username = it.username, password = it.password, @@ -120,12 +120,12 @@ private fun VaultAddItemState.ViewState.Content.ItemType.toLoginView( ) } -private fun VaultAddItemState.ViewState.Content.ItemType.toSecureNotesView(): SecureNoteView? = - (this as? VaultAddItemState.ViewState.Content.ItemType.SecureNotes)?.let { +private fun VaultAddEditState.ViewState.Content.ItemType.toSecureNotesView(): SecureNoteView? = + (this as? VaultAddEditState.ViewState.Content.ItemType.SecureNotes)?.let { SecureNoteView(type = SecureNoteType.GENERIC) } -private fun VaultAddItemState.ViewState.Content.Common.toCipherRepromptType(): CipherRepromptType = +private fun VaultAddEditState.ViewState.Content.Common.toCipherRepromptType(): CipherRepromptType = if (masterPasswordReprompt) { CipherRepromptType.PASSWORD } else { @@ -135,9 +135,9 @@ private fun VaultAddItemState.ViewState.Content.Common.toCipherRepromptType(): C /** * Transforms [VaultAddItemState.Custom into [FieldView]. */ -private fun VaultAddItemState.Custom.toFieldView(): FieldView = +private fun VaultAddEditState.Custom.toFieldView(): FieldView = when (val item = this) { - is VaultAddItemState.Custom.BooleanField -> { + is VaultAddEditState.Custom.BooleanField -> { FieldView( name = item.name, value = item.value.toString(), @@ -146,7 +146,7 @@ private fun VaultAddItemState.Custom.toFieldView(): FieldView = ) } - is VaultAddItemState.Custom.HiddenField -> { + is VaultAddEditState.Custom.HiddenField -> { FieldView( name = item.name, value = item.value, @@ -155,7 +155,7 @@ private fun VaultAddItemState.Custom.toFieldView(): FieldView = ) } - is VaultAddItemState.Custom.LinkedField -> { + is VaultAddEditState.Custom.LinkedField -> { FieldView( name = item.name, value = null, @@ -164,7 +164,7 @@ private fun VaultAddItemState.Custom.toFieldView(): FieldView = ) } - is VaultAddItemState.Custom.TextField -> { + is VaultAddEditState.Custom.TextField -> { FieldView( name = item.name, value = item.value, diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreenTest.kt similarity index 87% rename from app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemScreenTest.kt rename to app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreenTest.kt index dd3c7b465..28cdf3515 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditScreenTest.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import androidx.compose.ui.geometry.Offset import androidx.compose.ui.platform.ClipboardManager @@ -34,7 +34,7 @@ import com.x8bit.bitwarden.ui.util.isProgressBar import com.x8bit.bitwarden.ui.util.onAllNodesWithTextAfterScroll import com.x8bit.bitwarden.ui.util.onNodeWithContentDescriptionAfterScroll import com.x8bit.bitwarden.ui.util.onNodeWithTextAfterScroll -import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType +import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType import com.x8bit.bitwarden.ui.vault.model.VaultAddEditType import io.mockk.every import io.mockk.just @@ -48,19 +48,19 @@ import org.junit.Before import org.junit.Test @Suppress("LargeClass") -class VaultAddItemScreenTest : BaseComposeTest() { +class VaultAddEditScreenTest : BaseComposeTest() { private var onNavigateBackCalled = false private var onNavigateQrCodeScanScreenCalled = false private val clipboardManager = mockk() - private val mutableEventFlow = bufferedMutableSharedFlow() + private val mutableEventFlow = bufferedMutableSharedFlow() private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE_LOGIN) private val fakePermissionManager: FakePermissionManager = FakePermissionManager() - private val viewModel = mockk(relaxed = true) { + private val viewModel = mockk(relaxed = true) { every { eventFlow } returns mutableEventFlow every { stateFlow } returns mutableStateFlow } @@ -68,7 +68,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { @Before fun setup() { composeTestRule.setContent { - VaultAddItemScreen( + VaultAddEditScreen( viewModel = viewModel, onNavigateBack = { onNavigateBackCalled = true }, permissionsManager = fakePermissionManager, @@ -82,14 +82,14 @@ class VaultAddItemScreenTest : BaseComposeTest() { @Test fun `on NavigateBack event should invoke onNavigateBack`() { - mutableEventFlow.tryEmit(VaultAddItemEvent.NavigateBack) + mutableEventFlow.tryEmit(VaultAddEditEvent.NavigateBack) assertTrue(onNavigateBackCalled) } @Suppress("MaxLineLength") @Test fun `on NavigateToQrCodeScan event should invoke NavigateToQrCodeScan`() { - mutableEventFlow.tryEmit(VaultAddItemEvent.NavigateToQrCodeScan) + mutableEventFlow.tryEmit(VaultAddEditEvent.NavigateToQrCodeScan) assertTrue(onNavigateQrCodeScanScreenCalled) } @@ -99,7 +99,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { every { clipboardManager.setText(textString.toAnnotatedString()) } just runs - mutableEventFlow.tryEmit(VaultAddItemEvent.CopyToClipboard(textString)) + mutableEventFlow.tryEmit(VaultAddEditEvent.CopyToClipboard(textString)) verify(exactly = 1) { clipboardManager.setText(textString.toAnnotatedString()) @@ -114,7 +114,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.CloseClick, + VaultAddEditAction.Common.CloseClick, ) } } @@ -127,7 +127,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.SaveClick, + VaultAddEditAction.Common.SaveClick, ) } } @@ -143,7 +143,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.DismissDialog, + VaultAddEditAction.Common.DismissDialog, ) } } @@ -169,22 +169,22 @@ class VaultAddItemScreenTest : BaseComposeTest() { fun `error text and retry should be displayed according to state`() { val message = "error_message" mutableStateFlow.update { - it.copy(viewState = VaultAddItemState.ViewState.Loading) + it.copy(viewState = VaultAddEditState.ViewState.Loading) } composeTestRule.onNodeWithText(message).assertIsNotDisplayed() mutableStateFlow.update { it.copy( - viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common(), - type = VaultAddItemState.ViewState.Content.ItemType.Login(), + viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common(), + type = VaultAddEditState.ViewState.Content.ItemType.Login(), ), ) } composeTestRule.onNodeWithText(message).assertIsNotDisplayed() mutableStateFlow.update { - it.copy(viewState = VaultAddItemState.ViewState.Error(message.asText())) + it.copy(viewState = VaultAddEditState.ViewState.Error(message.asText())) } composeTestRule.onNodeWithText(message).assertIsDisplayed() } @@ -192,20 +192,20 @@ class VaultAddItemScreenTest : BaseComposeTest() { @Test fun `progressbar should be displayed according to state`() { mutableStateFlow.update { - it.copy(viewState = VaultAddItemState.ViewState.Loading) + it.copy(viewState = VaultAddEditState.ViewState.Loading) } composeTestRule.onNode(isProgressBar).assertIsDisplayed() mutableStateFlow.update { - it.copy(viewState = VaultAddItemState.ViewState.Error("Fail".asText())) + it.copy(viewState = VaultAddEditState.ViewState.Error("Fail".asText())) } composeTestRule.onNode(isProgressBar).assertDoesNotExist() mutableStateFlow.update { it.copy( - viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common(), - type = VaultAddItemState.ViewState.Content.ItemType.Login(), + viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common(), + type = VaultAddEditState.ViewState.Content.ItemType.Login(), ), ) } @@ -228,7 +228,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.TypeOptionSelect(VaultAddItemState.ItemTypeOption.LOGIN), + VaultAddEditAction.Common.TypeOptionSelect(VaultAddEditState.ItemTypeOption.LOGIN), ) } } @@ -241,9 +241,9 @@ class VaultAddItemScreenTest : BaseComposeTest() { mutableStateFlow.update { it.copy( - viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common(), - type = VaultAddItemState.ViewState.Content.ItemType.Card, + viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common(), + type = VaultAddEditState.ViewState.Content.ItemType.Card, ), ) } @@ -261,7 +261,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.UsernameTextChange(username = "TestUsername"), + VaultAddEditAction.ItemType.LoginType.UsernameTextChange(username = "TestUsername"), ) } } @@ -290,7 +290,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.OpenUsernameGeneratorClick, + VaultAddEditAction.ItemType.LoginType.OpenUsernameGeneratorClick, ) } } @@ -305,7 +305,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { .performClick() verify { - viewModel.trySendAction(VaultAddItemAction.ItemType.LoginType.PasswordCheckerClick) + viewModel.trySendAction(VaultAddEditAction.ItemType.LoginType.PasswordCheckerClick) } } @@ -320,7 +320,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.OpenPasswordGeneratorClick, + VaultAddEditAction.ItemType.LoginType.OpenPasswordGeneratorClick, ) } } @@ -333,7 +333,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.PasswordTextChange("TestPassword"), + VaultAddEditAction.ItemType.LoginType.PasswordTextChange("TestPassword"), ) } } @@ -396,7 +396,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.CopyTotpKeyClick(testCode), + VaultAddEditAction.ItemType.LoginType.CopyTotpKeyClick(testCode), ) } } @@ -418,7 +418,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.SetupTotpClick( + VaultAddEditAction.ItemType.LoginType.SetupTotpClick( isGranted = fakePermissionManager.getPermissionsResult, ), ) @@ -455,7 +455,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.SetupTotpClick(true), + VaultAddEditAction.ItemType.LoginType.SetupTotpClick(true), ) } } @@ -472,7 +472,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.SetupTotpClick( + VaultAddEditAction.ItemType.LoginType.SetupTotpClick( isGranted = true, ), ) @@ -491,7 +491,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.SetupTotpClick( + VaultAddEditAction.ItemType.LoginType.SetupTotpClick( isGranted = false, ), ) @@ -506,7 +506,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.UriTextChange("TestURI"), + VaultAddEditAction.ItemType.LoginType.UriTextChange("TestURI"), ) } } @@ -537,7 +537,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.UriSettingsClick, + VaultAddEditAction.ItemType.LoginType.UriSettingsClick, ) } } @@ -550,7 +550,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.LoginType.AddNewUriClick, + VaultAddEditAction.ItemType.LoginType.AddNewUriClick, ) } } @@ -572,8 +572,8 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.TitleSelected( - title = VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MX, + VaultAddEditAction.ItemType.IdentityType.TitleSelected( + title = VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MX, ), ) } @@ -589,7 +589,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { mutableStateFlow.update { currentState -> updateIdentityType(currentState) { copy( - selectedTitle = VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MX, + selectedTitle = VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MX, ) } } @@ -609,7 +609,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.FirstNameTextChange( + VaultAddEditAction.ItemType.IdentityType.FirstNameTextChange( firstName = "TestFirstName", ), ) @@ -643,7 +643,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.MiddleNameTextChange( + VaultAddEditAction.ItemType.IdentityType.MiddleNameTextChange( middleName = "TestMiddleName", ), ) @@ -677,7 +677,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.LastNameTextChange( + VaultAddEditAction.ItemType.IdentityType.LastNameTextChange( lastName = "TestLastName", ), ) @@ -710,7 +710,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.UsernameTextChange( + VaultAddEditAction.ItemType.IdentityType.UsernameTextChange( username = "TestUsername", ), ) @@ -743,7 +743,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.CompanyTextChange( + VaultAddEditAction.ItemType.IdentityType.CompanyTextChange( company = "TestCompany", ), ) @@ -776,7 +776,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.SsnTextChange( + VaultAddEditAction.ItemType.IdentityType.SsnTextChange( ssn = "TestSsn", ), ) @@ -809,7 +809,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.PassportNumberTextChange( + VaultAddEditAction.ItemType.IdentityType.PassportNumberTextChange( passportNumber = "TestPassportNumber", ), ) @@ -843,7 +843,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.LicenseNumberTextChange( + VaultAddEditAction.ItemType.IdentityType.LicenseNumberTextChange( licenseNumber = "TestLicenseNumber", ), ) @@ -876,7 +876,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.EmailTextChange( + VaultAddEditAction.ItemType.IdentityType.EmailTextChange( email = "TestEmail", ), ) @@ -909,7 +909,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.Address1TextChange( + VaultAddEditAction.ItemType.IdentityType.Address1TextChange( address1 = "TestAddress1", ), ) @@ -942,7 +942,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.Address2TextChange( + VaultAddEditAction.ItemType.IdentityType.Address2TextChange( address2 = "TestAddress2", ), ) @@ -975,7 +975,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.Address3TextChange( + VaultAddEditAction.ItemType.IdentityType.Address3TextChange( address3 = "TestAddress3", ), ) @@ -1008,7 +1008,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.CityTextChange( + VaultAddEditAction.ItemType.IdentityType.CityTextChange( city = "TestCity", ), ) @@ -1041,7 +1041,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.ZipTextChange( + VaultAddEditAction.ItemType.IdentityType.ZipTextChange( zip = "TestZip", ), ) @@ -1074,7 +1074,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.CountryTextChange( + VaultAddEditAction.ItemType.IdentityType.CountryTextChange( country = "TestCountry", ), ) @@ -1090,7 +1090,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.ItemType.IdentityType.StateTextChange( + VaultAddEditAction.ItemType.IdentityType.StateTextChange( state = "TestState", ), ) @@ -1158,7 +1158,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.AddNewCustomFieldClick( + VaultAddEditAction.Common.AddNewCustomFieldClick( customFieldType = CustomFieldType.LINKED, name = "TestLinked", ), @@ -1184,7 +1184,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.OwnershipChange("a@b.com"), + VaultAddEditAction.Common.OwnershipChange("a@b.com"), ) } } @@ -1216,7 +1216,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.NameTextChange(name = "TestName"), + VaultAddEditAction.Common.NameTextChange(name = "TestName"), ) } } @@ -1256,7 +1256,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.FolderChange("Folder 1".asText()), + VaultAddEditAction.Common.FolderChange("Folder 1".asText()), ) } } @@ -1290,7 +1290,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.ToggleFavorite( + VaultAddEditAction.Common.ToggleFavorite( isFavorite = true, ), ) @@ -1327,7 +1327,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.ToggleMasterPasswordReprompt( + VaultAddEditAction.Common.ToggleMasterPasswordReprompt( isMasterPasswordReprompt = true, ), ) @@ -1362,7 +1362,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.TooltipClick, + VaultAddEditAction.Common.TooltipClick, ) } } @@ -1378,7 +1378,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.NotesTextChange("TestNotes"), + VaultAddEditAction.Common.NotesTextChange("TestNotes"), ) } } @@ -1421,7 +1421,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.OwnershipChange("a@b.com"), + VaultAddEditAction.Common.OwnershipChange("a@b.com"), ) } } @@ -1472,7 +1472,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.AddNewCustomFieldClick( + VaultAddEditAction.Common.AddNewCustomFieldClick( customFieldType = CustomFieldType.TEXT, name = "TestText", ), @@ -1527,7 +1527,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.AddNewCustomFieldClick( + VaultAddEditAction.Common.AddNewCustomFieldClick( customFieldType = CustomFieldType.BOOLEAN, name = "TestBoolean", ), @@ -1563,7 +1563,7 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.AddNewCustomFieldClick( + VaultAddEditAction.Common.AddNewCustomFieldClick( customFieldType = CustomFieldType.HIDDEN, name = "TestHidden", ), @@ -1582,8 +1582,8 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.CustomFieldValueChange( - VaultAddItemState.Custom.TextField("Test ID", "TestText", ""), + VaultAddEditAction.Common.CustomFieldValueChange( + VaultAddEditState.Custom.TextField("Test ID", "TestText", ""), ), ) } @@ -1600,8 +1600,8 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.CustomFieldValueChange( - VaultAddItemState.Custom.HiddenField("Test ID", "TestHidden", ""), + VaultAddEditAction.Common.CustomFieldValueChange( + VaultAddEditState.Custom.HiddenField("Test ID", "TestHidden", ""), ), ) } @@ -1618,8 +1618,8 @@ class VaultAddItemScreenTest : BaseComposeTest() { verify { viewModel.trySendAction( - VaultAddItemAction.Common.CustomFieldValueChange( - VaultAddItemState.Custom.BooleanField("Test ID", "TestBoolean", true), + VaultAddEditAction.Common.CustomFieldValueChange( + VaultAddEditState.Custom.BooleanField("Test ID", "TestBoolean", true), ), ) } @@ -1628,14 +1628,14 @@ class VaultAddItemScreenTest : BaseComposeTest() { //region Helper functions private fun updateLoginType( - currentState: VaultAddItemState, - transform: VaultAddItemState.ViewState.Content.ItemType.Login.() -> - VaultAddItemState.ViewState.Content.ItemType.Login, - ): VaultAddItemState { + currentState: VaultAddEditState, + transform: VaultAddEditState.ViewState.Content.ItemType.Login.() -> + VaultAddEditState.ViewState.Content.ItemType.Login, + ): VaultAddEditState { val updatedType = when (val viewState = currentState.viewState) { - is VaultAddItemState.ViewState.Content -> { + is VaultAddEditState.ViewState.Content -> { when (val type = viewState.type) { - is VaultAddItemState.ViewState.Content.ItemType.Login -> { + is VaultAddEditState.ViewState.Content.ItemType.Login -> { viewState.copy( type = type.transform(), ) @@ -1651,14 +1651,14 @@ class VaultAddItemScreenTest : BaseComposeTest() { } private fun updateIdentityType( - currentState: VaultAddItemState, - transform: VaultAddItemState.ViewState.Content.ItemType.Identity.() -> - VaultAddItemState.ViewState.Content.ItemType.Identity, - ): VaultAddItemState { + currentState: VaultAddEditState, + transform: VaultAddEditState.ViewState.Content.ItemType.Identity.() -> + VaultAddEditState.ViewState.Content.ItemType.Identity, + ): VaultAddEditState { val updatedType = when (val viewState = currentState.viewState) { - is VaultAddItemState.ViewState.Content -> { + is VaultAddEditState.ViewState.Content -> { when (val type = viewState.type) { - is VaultAddItemState.ViewState.Content.ItemType.Identity -> { + is VaultAddEditState.ViewState.Content.ItemType.Identity -> { viewState.copy( type = type.transform(), ) @@ -1675,12 +1675,12 @@ class VaultAddItemScreenTest : BaseComposeTest() { @Suppress("MaxLineLength") private fun updateCommonContent( - currentState: VaultAddItemState, - transform: VaultAddItemState.ViewState.Content.Common.() - -> VaultAddItemState.ViewState.Content.Common, - ): VaultAddItemState { + currentState: VaultAddEditState, + transform: VaultAddEditState.ViewState.Content.Common.() + -> VaultAddEditState.ViewState.Content.Common, + ): VaultAddEditState { val updatedType = when (val viewState = currentState.viewState) { - is VaultAddItemState.ViewState.Content -> + is VaultAddEditState.ViewState.Content -> viewState.copy(common = viewState.common.transform()) else -> viewState @@ -1691,58 +1691,58 @@ class VaultAddItemScreenTest : BaseComposeTest() { //endregion Helper functions companion object { - private val DEFAULT_STATE_LOGIN_DIALOG = VaultAddItemState( - viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common(), - type = VaultAddItemState.ViewState.Content.ItemType.Login(), + private val DEFAULT_STATE_LOGIN_DIALOG = VaultAddEditState( + viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common(), + type = VaultAddEditState.ViewState.Content.ItemType.Login(), ), - dialog = VaultAddItemState.DialogState.Error("test".asText()), + dialog = VaultAddEditState.DialogState.Error("test".asText()), vaultAddEditType = VaultAddEditType.AddItem, ) - private val DEFAULT_STATE_LOGIN = VaultAddItemState( + private val DEFAULT_STATE_LOGIN = VaultAddEditState( vaultAddEditType = VaultAddEditType.AddItem, - viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common(), - type = VaultAddItemState.ViewState.Content.ItemType.Login(), + viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common(), + type = VaultAddEditState.ViewState.Content.ItemType.Login(), ), dialog = null, ) - private val DEFAULT_STATE_IDENTITY = VaultAddItemState( + private val DEFAULT_STATE_IDENTITY = VaultAddEditState( vaultAddEditType = VaultAddEditType.AddItem, - viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common(), - type = VaultAddItemState.ViewState.Content.ItemType.Identity(), + viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common(), + type = VaultAddEditState.ViewState.Content.ItemType.Identity(), ), dialog = null, ) @Suppress("MaxLineLength") - private val DEFAULT_STATE_SECURE_NOTES_CUSTOM_FIELDS = VaultAddItemState( - viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common( + private val DEFAULT_STATE_SECURE_NOTES_CUSTOM_FIELDS = VaultAddEditState( + viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common( customFieldData = listOf( - VaultAddItemState.Custom.BooleanField("Test ID", "TestBoolean", false), - VaultAddItemState.Custom.TextField("Test ID", "TestText", "TestTextVal"), - VaultAddItemState.Custom.HiddenField( + VaultAddEditState.Custom.BooleanField("Test ID", "TestBoolean", false), + VaultAddEditState.Custom.TextField("Test ID", "TestText", "TestTextVal"), + VaultAddEditState.Custom.HiddenField( "Test ID", "TestHidden", "TestHiddenVal", ), ), ), - type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes, + type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes, ), dialog = null, vaultAddEditType = VaultAddEditType.AddItem, ) - private val DEFAULT_STATE_SECURE_NOTES = VaultAddItemState( + private val DEFAULT_STATE_SECURE_NOTES = VaultAddEditState( vaultAddEditType = VaultAddEditType.AddItem, - viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common(), - type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes, + viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common(), + type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes, ), dialog = null, ) diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModelTest.kt similarity index 75% rename from app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemViewModelTest.kt rename to app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModelTest.kt index ebe4c026f..f8ab948e7 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/VaultAddItemViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModelTest.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem +package com.x8bit.bitwarden.ui.vault.feature.addedit import androidx.lifecycle.SavedStateHandle import app.cash.turbine.test @@ -12,9 +12,9 @@ import com.x8bit.bitwarden.data.vault.repository.model.UpdateCipherResult import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest import com.x8bit.bitwarden.ui.platform.base.util.Text import com.x8bit.bitwarden.ui.platform.base.util.asText -import com.x8bit.bitwarden.ui.vault.feature.additem.model.CustomFieldType -import com.x8bit.bitwarden.ui.vault.feature.additem.model.toCustomField -import com.x8bit.bitwarden.ui.vault.feature.additem.util.toViewState +import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType +import com.x8bit.bitwarden.ui.vault.feature.addedit.model.toCustomField +import com.x8bit.bitwarden.ui.vault.feature.addedit.util.toViewState import com.x8bit.bitwarden.ui.vault.model.VaultAddEditType import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType import io.mockk.coEvery @@ -34,7 +34,7 @@ import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import java.util.UUID -class VaultAddItemViewModelTest : BaseViewModelTest() { +class VaultAddEditViewModelTest : BaseViewModelTest() { private val loginInitialState = createVaultAddItemState( typeContentViewState = createLoginTypeContentViewState(), @@ -108,7 +108,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { ), ) assertEquals( - initState.copy(viewState = VaultAddItemState.ViewState.Loading), + initState.copy(viewState = VaultAddEditState.ViewState.Loading), viewModel.stateFlow.value, ) verify(exactly = 1) { @@ -120,8 +120,8 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { fun `CloseClick should emit NavigateBack`() = runTest { val viewModel = createAddVaultItemViewModel() viewModel.eventFlow.test { - viewModel.actionChannel.trySend(VaultAddItemAction.Common.CloseClick) - assertEquals(VaultAddItemEvent.NavigateBack, awaitItem()) + viewModel.actionChannel.trySend(VaultAddEditAction.Common.CloseClick) + assertEquals(VaultAddEditEvent.NavigateBack, awaitItem()) } } @@ -130,7 +130,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { runTest { val stateWithDialog = createVaultAddItemState( vaultAddEditType = VaultAddEditType.AddItem, - dialogState = VaultAddItemState.DialogState.Loading( + dialogState = VaultAddEditState.DialogState.Loading( R.string.saving.asText(), ), commonContentViewState = createCommonContentViewState( @@ -157,7 +157,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { } returns CreateCipherResult.Success viewModel.stateFlow.test { - viewModel.actionChannel.trySend(VaultAddItemAction.Common.SaveClick) + viewModel.actionChannel.trySend(VaultAddEditAction.Common.SaveClick) assertEquals(stateWithName, awaitItem()) assertEquals(stateWithDialog, awaitItem()) assertEquals(stateWithName, awaitItem()) @@ -188,8 +188,8 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { vaultRepository.createCipher(any()) } returns CreateCipherResult.Success viewModel.eventFlow.test { - viewModel.actionChannel.trySend(VaultAddItemAction.Common.SaveClick) - assertEquals(VaultAddItemEvent.NavigateBack, awaitItem()) + viewModel.actionChannel.trySend(VaultAddEditAction.Common.SaveClick) + assertEquals(VaultAddEditEvent.NavigateBack, awaitItem()) } } @@ -213,8 +213,8 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { vaultRepository.createCipher(any()) } returns CreateCipherResult.Error viewModel.eventFlow.test { - viewModel.actionChannel.trySend(VaultAddItemAction.Common.SaveClick) - assertEquals(VaultAddItemEvent.ShowToast("Save Item Failure".asText()), awaitItem()) + viewModel.actionChannel.trySend(VaultAddEditAction.Common.SaveClick) + assertEquals(VaultAddEditEvent.ShowToast("Save Item Failure".asText()), awaitItem()) } } @@ -225,7 +225,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { val vaultAddEditType = VaultAddEditType.EditItem(DEFAULT_EDIT_ITEM_ID) val stateWithDialog = createVaultAddItemState( vaultAddEditType = vaultAddEditType, - dialogState = VaultAddItemState.DialogState.Loading( + dialogState = VaultAddEditState.DialogState.Loading( R.string.saving.asText(), ), commonContentViewState = createCommonContentViewState( @@ -255,7 +255,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { viewModel.stateFlow.test { assertEquals(stateWithName, awaitItem()) - viewModel.actionChannel.trySend(VaultAddItemAction.Common.SaveClick) + viewModel.actionChannel.trySend(VaultAddEditAction.Common.SaveClick) assertEquals(stateWithDialog, awaitItem()) assertEquals(stateWithName, awaitItem()) } @@ -291,8 +291,8 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { ) viewModel.eventFlow.test { - viewModel.actionChannel.trySend(VaultAddItemAction.Common.SaveClick) - assertEquals(VaultAddItemEvent.ShowToast("Save Item Failure".asText()), awaitItem()) + viewModel.actionChannel.trySend(VaultAddEditAction.Common.SaveClick) + assertEquals(VaultAddEditEvent.ShowToast("Save Item Failure".asText()), awaitItem()) } coVerify(exactly = 1) { @@ -308,7 +308,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { val stateWithNoNameAndDialog = createVaultAddItemState( commonContentViewState = createCommonContentViewState(name = ""), - dialogState = VaultAddItemState.DialogState.Error( + dialogState = VaultAddEditState.DialogState.Error( R.string.validation_field_required .asText(R.string.name.asText()), ), @@ -322,7 +322,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { ) coEvery { vaultRepository.createCipher(any()) } returns CreateCipherResult.Success viewModel.stateFlow.test { - viewModel.actionChannel.trySend(VaultAddItemAction.Common.SaveClick) + viewModel.actionChannel.trySend(VaultAddEditAction.Common.SaveClick) assertEquals(stateWithNoName, awaitItem()) assertEquals(stateWithNoNameAndDialog, awaitItem()) } @@ -332,7 +332,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { fun `HandleDialogDismiss will remove the current dialog`() = runTest { val errorState = createVaultAddItemState( vaultAddEditType = VaultAddEditType.AddItem, - dialogState = VaultAddItemState.DialogState.Error( + dialogState = VaultAddEditState.DialogState.Error( R.string.validation_field_required .asText(R.string.name.asText()), ), @@ -347,7 +347,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { coEvery { vaultRepository.createCipher(any()) } returns CreateCipherResult.Success viewModel.stateFlow.test { - viewModel.actionChannel.trySend(VaultAddItemAction.Common.DismissDialog) + viewModel.actionChannel.trySend(VaultAddEditAction.Common.DismissDialog) assertEquals(errorState, awaitItem()) assertEquals(null, awaitItem().dialog) } @@ -356,14 +356,14 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `TypeOptionSelect LOGIN should switch to LoginItem`() = runTest { val viewModel = createAddVaultItemViewModel() - val action = VaultAddItemAction.Common.TypeOptionSelect( - VaultAddItemState.ItemTypeOption.LOGIN, + val action = VaultAddEditAction.Common.TypeOptionSelect( + VaultAddEditState.ItemTypeOption.LOGIN, ) viewModel.actionChannel.trySend(action) val expectedState = loginInitialState.copy( - viewState = VaultAddItemState.ViewState.Content( + viewState = VaultAddEditState.ViewState.Content( common = createCommonContentViewState(), type = createLoginTypeContentViewState(), ), @@ -377,17 +377,16 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Nested inner class VaultAddLoginTypeItemActions { - private lateinit var viewModel: VaultAddItemViewModel + private lateinit var viewModel: VaultAddEditViewModel @BeforeEach fun setup() { viewModel = createAddVaultItemViewModel() } - @Suppress("MaxLineLength") @Test fun `UsernameTextChange should update username in LoginItem`() = runTest { - val action = VaultAddItemAction.ItemType.LoginType.UsernameTextChange("newUsername") + val action = VaultAddEditAction.ItemType.LoginType.UsernameTextChange("newUsername") val expectedState = createVaultAddItemState( typeContentViewState = createLoginTypeContentViewState( username = "newUsername", @@ -398,10 +397,9 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { assertEquals(expectedState, viewModel.stateFlow.value) } - @Suppress("MaxLineLength") @Test fun `PasswordTextChange should update password in LoginItem`() = runTest { - val action = VaultAddItemAction.ItemType.LoginType.PasswordTextChange("newPassword") + val action = VaultAddEditAction.ItemType.LoginType.PasswordTextChange("newPassword") viewModel.actionChannel.trySend(action) @@ -416,7 +414,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `UriTextChange should update uri in LoginItem`() = runTest { - val action = VaultAddItemAction.ItemType.LoginType.UriTextChange("newUri") + val action = VaultAddEditAction.ItemType.LoginType.UriTextChange("newUri") viewModel.actionChannel.trySend(action) @@ -437,10 +435,10 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { viewModel.eventFlow.test { viewModel.actionChannel.trySend( - VaultAddItemAction.ItemType.LoginType.OpenUsernameGeneratorClick, + VaultAddEditAction.ItemType.LoginType.OpenUsernameGeneratorClick, ) assertEquals( - VaultAddItemEvent.ShowToast("Open Username Generator".asText()), + VaultAddEditEvent.ShowToast("Open Username Generator".asText()), awaitItem(), ) } @@ -454,10 +452,10 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { viewModel.eventFlow.test { viewModel .actionChannel - .trySend(VaultAddItemAction.ItemType.LoginType.PasswordCheckerClick) + .trySend(VaultAddEditAction.ItemType.LoginType.PasswordCheckerClick) assertEquals( - VaultAddItemEvent.ShowToast( + VaultAddEditEvent.ShowToast( "Password Checker".asText(), ), awaitItem(), @@ -474,10 +472,10 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { viewModel.eventFlow.test { viewModel .actionChannel - .trySend(VaultAddItemAction.ItemType.LoginType.OpenPasswordGeneratorClick) + .trySend(VaultAddEditAction.ItemType.LoginType.OpenPasswordGeneratorClick) assertEquals( - VaultAddItemEvent.ShowToast("Open Password Generator".asText()), + VaultAddEditEvent.ShowToast("Open Password Generator".asText()), awaitItem(), ) } @@ -485,22 +483,21 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Suppress("MaxLineLength") @Test - fun `SetupTotpClick should emit NavigateToQrCodeScan when isGranted is true`() = - runTest { - val viewModel = createAddVaultItemViewModel() + fun `SetupTotpClick should emit NavigateToQrCodeScan when isGranted is true`() = runTest { + val viewModel = createAddVaultItemViewModel() - viewModel.eventFlow.test { - viewModel.actionChannel.trySend( - VaultAddItemAction.ItemType.LoginType.SetupTotpClick( - isGranted = true, - ), - ) - assertEquals( - VaultAddItemEvent.NavigateToQrCodeScan, - awaitItem(), - ) - } + viewModel.eventFlow.test { + viewModel.actionChannel.trySend( + VaultAddEditAction.ItemType.LoginType.SetupTotpClick( + isGranted = true, + ), + ) + assertEquals( + VaultAddEditEvent.NavigateToQrCodeScan, + awaitItem(), + ) } + } @Suppress("MaxLineLength") @Test @@ -510,12 +507,12 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { viewModel.eventFlow.test { viewModel.actionChannel.trySend( - VaultAddItemAction.ItemType.LoginType.SetupTotpClick( + VaultAddEditAction.ItemType.LoginType.SetupTotpClick( isGranted = false, ), ) assertEquals( - VaultAddItemEvent.ShowToast("Permission Not Granted, Manual QR Code Entry Not Implemented".asText()), + VaultAddEditEvent.ShowToast("Permission Not Granted, Manual QR Code Entry Not Implemented".asText()), awaitItem(), ) } @@ -529,26 +526,25 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { viewModel.eventFlow.test { viewModel.actionChannel.trySend( - VaultAddItemAction.ItemType.LoginType.CopyTotpKeyClick( + VaultAddEditAction.ItemType.LoginType.CopyTotpKeyClick( testKey, ), ) assertEquals( - VaultAddItemEvent.CopyToClipboard(testKey), + VaultAddEditEvent.CopyToClipboard(testKey), awaitItem(), ) } } - @Suppress("MaxLineLength") @Test fun `TotpCodeReceive should update totp code in state`() = runTest { val viewModel = createAddVaultItemViewModel() val testKey = "TestKey" val expectedState = loginInitialState.copy( - viewState = VaultAddItemState.ViewState.Content( + viewState = VaultAddEditState.ViewState.Content( common = createCommonContentViewState(), type = createLoginTypeContentViewState( totpCode = testKey, @@ -558,13 +554,13 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { viewModel.eventFlow.test { viewModel.actionChannel.trySend( - VaultAddItemAction.Internal.TotpCodeReceive( + VaultAddEditAction.Internal.TotpCodeReceive( testKey, ), ) assertEquals( - VaultAddItemEvent.ShowToast(R.string.authenticator_key_added.asText()), + VaultAddEditEvent.ShowToast(R.string.authenticator_key_added.asText()), awaitItem(), ) @@ -581,8 +577,8 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { val viewModel = createAddVaultItemViewModel() viewModel.eventFlow.test { - viewModel.actionChannel.trySend(VaultAddItemAction.ItemType.LoginType.UriSettingsClick) - assertEquals(VaultAddItemEvent.ShowToast("URI Settings".asText()), awaitItem()) + viewModel.actionChannel.trySend(VaultAddEditAction.ItemType.LoginType.UriSettingsClick) + assertEquals(VaultAddEditEvent.ShowToast("URI Settings".asText()), awaitItem()) } } @@ -594,24 +590,24 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { viewModel .actionChannel .trySend( - VaultAddItemAction.ItemType.LoginType.AddNewUriClick, + VaultAddEditAction.ItemType.LoginType.AddNewUriClick, ) - assertEquals(VaultAddItemEvent.ShowToast("Add New URI".asText()), awaitItem()) + assertEquals(VaultAddEditEvent.ShowToast("Add New URI".asText()), awaitItem()) } } } @Nested inner class VaultAddIdentityTypeItemActions { - private lateinit var viewModel: VaultAddItemViewModel - private lateinit var vaultAddItemInitialState: VaultAddItemState + private lateinit var viewModel: VaultAddEditViewModel + private lateinit var vaultAddItemInitialState: VaultAddEditState private lateinit var identityInitialSavedStateHandle: SavedStateHandle @BeforeEach fun setup() { vaultAddItemInitialState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity(), + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity(), ) identityInitialSavedStateHandle = createSavedStateHandleWithState( state = vaultAddItemInitialState, @@ -624,11 +620,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `FirstNameTextChange should update first name`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.FirstNameTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.FirstNameTextChange( firstName = "newFirstName", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( firstName = "newFirstName", ), ) @@ -639,11 +635,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `MiddleNameTextChange should update middle name`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.MiddleNameTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.MiddleNameTextChange( middleName = "newMiddleName", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( middleName = "newMiddleName", ), ) @@ -654,11 +650,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `LastNameTextChange should update last name`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.LastNameTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.LastNameTextChange( lastName = "newLastName", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( lastName = "newLastName", ), ) @@ -669,11 +665,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `UsernameTextChange should update username`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.UsernameTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.UsernameTextChange( username = "newUsername", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( username = "newUsername", ), ) @@ -684,11 +680,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `CompanyTextChange should update company`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.CompanyTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.CompanyTextChange( company = "newCompany", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( company = "newCompany", ), ) @@ -699,11 +695,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `SsnTextChange should update SSN`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.SsnTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.SsnTextChange( ssn = "newSsn", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( ssn = "newSsn", ), ) @@ -714,11 +710,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `PassportNumberTextChange should update passport number`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.PassportNumberTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.PassportNumberTextChange( passportNumber = "newPassportNumber", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( passportNumber = "newPassportNumber", ), ) @@ -729,11 +725,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `LicenseNumberTextChange should update license number`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.LicenseNumberTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.LicenseNumberTextChange( licenseNumber = "newLicenseNumber", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( licenseNumber = "newLicenseNumber", ), ) @@ -744,11 +740,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `EmailTextChange should update email`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.EmailTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.EmailTextChange( email = "newEmail", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( email = "newEmail", ), ) @@ -759,11 +755,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `PhoneTextChange should update phone`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.PhoneTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.PhoneTextChange( phone = "newPhone", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( phone = "newPhone", ), ) @@ -774,11 +770,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `Address1TextChange should update address1`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.Address1TextChange( + val action = VaultAddEditAction.ItemType.IdentityType.Address1TextChange( address1 = "newAddress1", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( address1 = "newAddress1", ), ) @@ -789,11 +785,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `Address2TextChange should update address2`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.Address2TextChange( + val action = VaultAddEditAction.ItemType.IdentityType.Address2TextChange( address2 = "newAddress2", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( address2 = "newAddress2", ), ) @@ -804,11 +800,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `Address3TextChange should update address3`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.Address3TextChange( + val action = VaultAddEditAction.ItemType.IdentityType.Address3TextChange( address3 = "newAddress3", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( address3 = "newAddress3", ), ) @@ -819,11 +815,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `CityTextChange should update city`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.CityTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.CityTextChange( city = "newCity", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( city = "newCity", ), ) @@ -834,11 +830,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `StateTextChange should update state text`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.StateTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.StateTextChange( state = "newState", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( state = "newState", ), ) @@ -849,11 +845,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `ZipTextChange should update zip`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.ZipTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.ZipTextChange( zip = "newZip", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( zip = "newZip", ), ) @@ -864,11 +860,11 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `CountryTextChange should update country`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.CountryTextChange( + val action = VaultAddEditAction.ItemType.IdentityType.CountryTextChange( country = "newCountry", ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( country = "newCountry", ), ) @@ -879,12 +875,12 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `TitleSelected should update title`() = runTest { - val action = VaultAddItemAction.ItemType.IdentityType.TitleSelected( - title = VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MX, + val action = VaultAddEditAction.ItemType.IdentityType.TitleSelected( + title = VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MX, ) val expectedState = createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.Identity( - selectedTitle = VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MX, + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity( + selectedTitle = VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MX, ), ) viewModel.actionChannel.trySend(action) @@ -895,8 +891,8 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Nested inner class VaultAddItemCommonActions { - private lateinit var viewModel: VaultAddItemViewModel - private lateinit var vaultAddItemInitialState: VaultAddItemState + private lateinit var viewModel: VaultAddEditViewModel + private lateinit var vaultAddItemInitialState: VaultAddEditState private lateinit var secureNotesInitialSavedStateHandle: SavedStateHandle @BeforeEach @@ -906,7 +902,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { state = vaultAddItemInitialState, vaultAddEditType = VaultAddEditType.AddItem, ) - viewModel = VaultAddItemViewModel( + viewModel = VaultAddEditViewModel( savedStateHandle = secureNotesInitialSavedStateHandle, vaultRepository = vaultRepository, ) @@ -914,12 +910,12 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `NameTextChange should update name`() = runTest { - val action = VaultAddItemAction.Common.NameTextChange("newName") + val action = VaultAddEditAction.Common.NameTextChange("newName") viewModel.actionChannel.trySend(action) val expectedState = vaultAddItemInitialState.copy( - viewState = VaultAddItemState.ViewState.Content( + viewState = VaultAddEditState.ViewState.Content( common = createCommonContentViewState( name = "newName", ), @@ -932,14 +928,14 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `FolderChange should update folder`() = runTest { - val action = VaultAddItemAction.Common.FolderChange( + val action = VaultAddEditAction.Common.FolderChange( "newFolder".asText(), ) viewModel.actionChannel.trySend(action) val expectedState = vaultAddItemInitialState.copy( - viewState = VaultAddItemState.ViewState.Content( + viewState = VaultAddEditState.ViewState.Content( common = createCommonContentViewState( folder = "newFolder".asText(), ), @@ -952,12 +948,12 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `ToggleFavorite should update favorite`() = runTest { - val action = VaultAddItemAction.Common.ToggleFavorite(true) + val action = VaultAddEditAction.Common.ToggleFavorite(true) viewModel.actionChannel.trySend(action) val expectedState = vaultAddItemInitialState.copy( - viewState = VaultAddItemState.ViewState.Content( + viewState = VaultAddEditState.ViewState.Content( common = createCommonContentViewState( favorite = true, ), @@ -968,39 +964,36 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { assertEquals(expectedState, viewModel.stateFlow.value) } - @Suppress("MaxLineLength") @Test - fun `ToggleMasterPasswordReprompt should update masterPasswordReprompt`() = - runTest { - val action = - VaultAddItemAction.Common.ToggleMasterPasswordReprompt( - isMasterPasswordReprompt = true, - ) - - viewModel.actionChannel.trySend(action) - - val expectedState = vaultAddItemInitialState.copy( - viewState = VaultAddItemState.ViewState.Content( - common = createCommonContentViewState( - masterPasswordReprompt = true, - ), - type = createLoginTypeContentViewState(), - ), - ) - - assertEquals(expectedState, viewModel.stateFlow.value) - } - - @Suppress("MaxLineLength") - @Test - fun `NotesTextChange should update notes`() = runTest { + fun `ToggleMasterPasswordReprompt should update masterPasswordReprompt`() = runTest { val action = - VaultAddItemAction.Common.NotesTextChange(notes = "newNotes") + VaultAddEditAction.Common.ToggleMasterPasswordReprompt( + isMasterPasswordReprompt = true, + ) viewModel.actionChannel.trySend(action) val expectedState = vaultAddItemInitialState.copy( - viewState = VaultAddItemState.ViewState.Content( + viewState = VaultAddEditState.ViewState.Content( + common = createCommonContentViewState( + masterPasswordReprompt = true, + ), + type = createLoginTypeContentViewState(), + ), + ) + + assertEquals(expectedState, viewModel.stateFlow.value) + } + + @Test + fun `NotesTextChange should update notes`() = runTest { + val action = + VaultAddEditAction.Common.NotesTextChange(notes = "newNotes") + + viewModel.actionChannel.trySend(action) + + val expectedState = vaultAddItemInitialState.copy( + viewState = VaultAddEditState.ViewState.Content( common = createCommonContentViewState( notes = "newNotes", ), @@ -1013,12 +1006,12 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Test fun `OwnershipChange should update ownership`() = runTest { - val action = VaultAddItemAction.Common.OwnershipChange(ownership = "newOwner") + val action = VaultAddEditAction.Common.OwnershipChange(ownership = "newOwner") viewModel.actionChannel.trySend(action) val expectedState = vaultAddItemInitialState.copy( - viewState = VaultAddItemState.ViewState.Content( + viewState = VaultAddEditState.ViewState.Content( common = createCommonContentViewState( ownership = "newOwner", ), @@ -1060,79 +1053,70 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { ) } - @Suppress("MaxLineLength") @Test - fun `CustomFieldValueChange should allow a user to update a text custom field`() = - runTest { - - val initState = - createVaultAddItemState( - vaultAddEditType = VaultAddEditType.AddItem, - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.SecureNotes, - commonContentViewState = VaultAddItemState.ViewState.Content.Common( - customFieldData = listOf( - VaultAddItemState.Custom.TextField( - "TestId 1", - "Test Text", - "Test Text", - ), - ), + fun `CustomFieldValueChange should allow a user to update a text custom field`() = runTest { + val initState = createVaultAddItemState( + vaultAddEditType = VaultAddEditType.AddItem, + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.SecureNotes, + commonContentViewState = VaultAddEditState.ViewState.Content.Common( + customFieldData = listOf( + VaultAddEditState.Custom.TextField( + "TestId 1", + "Test Text", + "Test Text", ), - ) + ), + ), + ) - assertCustomFieldValueChange( - initState, - CustomFieldType.TEXT, - ) - } + assertCustomFieldValueChange( + initState, + CustomFieldType.TEXT, + ) + } @Test - @Suppress("MaxLineLength") - fun `CustomFieldValueChange should update hidden custom fields`() = - runTest { - val initState = - createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.SecureNotes, - commonContentViewState = VaultAddItemState.ViewState.Content.Common( - customFieldData = listOf( - VaultAddItemState.Custom.HiddenField( - "TestId 2", - "Test Text", - "Test Text", - ), + fun `CustomFieldValueChange should update hidden custom fields`() = runTest { + val initState = + createVaultAddItemState( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.SecureNotes, + commonContentViewState = VaultAddEditState.ViewState.Content.Common( + customFieldData = listOf( + VaultAddEditState.Custom.HiddenField( + "TestId 2", + "Test Text", + "Test Text", ), ), - ) - - assertCustomFieldValueChange( - initState, - CustomFieldType.HIDDEN, + ), ) - } - @Suppress("MaxLineLength") + assertCustomFieldValueChange( + initState, + CustomFieldType.HIDDEN, + ) + } + @Test - fun `CustomFieldValueChange should update boolean custom fields`() = - runTest { - val initState = - createVaultAddItemState( - typeContentViewState = VaultAddItemState.ViewState.Content.ItemType.SecureNotes, - commonContentViewState = VaultAddItemState.ViewState.Content.Common( - customFieldData = listOf( - VaultAddItemState.Custom.BooleanField( - "TestId 3", - "Boolean Field", - true, - ), - ), + fun `CustomFieldValueChange should update boolean custom fields`() = runTest { + val initState = createVaultAddItemState( + typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.SecureNotes, + commonContentViewState = VaultAddEditState.ViewState.Content.Common( + customFieldData = listOf( + VaultAddEditState.Custom.BooleanField( + "TestId 3", + "Boolean Field", + true, ), - ) + ), + ), + ) - assertCustomFieldValueChange( - initState, - CustomFieldType.BOOLEAN, - ) - } + assertCustomFieldValueChange( + initState, + CustomFieldType.BOOLEAN, + ) + } @Test fun `TooltipClick should emit ShowToast with 'Tooltip' message`() = runTest { @@ -1140,10 +1124,10 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { viewModel .actionChannel .trySend( - VaultAddItemAction.Common.TooltipClick, + VaultAddEditAction.Common.TooltipClick, ) assertEquals( - VaultAddItemEvent.ShowToast( + VaultAddEditEvent.ShowToast( "Not yet implemented".asText(), ), awaitItem(), @@ -1157,13 +1141,13 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { @Suppress("MaxLineLength") private fun createVaultAddItemState( vaultAddEditType: VaultAddEditType = VaultAddEditType.AddItem, - commonContentViewState: VaultAddItemState.ViewState.Content.Common = createCommonContentViewState(), - typeContentViewState: VaultAddItemState.ViewState.Content.ItemType = createLoginTypeContentViewState(), - dialogState: VaultAddItemState.DialogState? = null, - ): VaultAddItemState = - VaultAddItemState( + commonContentViewState: VaultAddEditState.ViewState.Content.Common = createCommonContentViewState(), + typeContentViewState: VaultAddEditState.ViewState.Content.ItemType = createLoginTypeContentViewState(), + dialogState: VaultAddEditState.DialogState? = null, + ): VaultAddEditState = + VaultAddEditState( vaultAddEditType = vaultAddEditType, - viewState = VaultAddItemState.ViewState.Content( + viewState = VaultAddEditState.ViewState.Content( common = commonContentViewState, type = typeContentViewState, ), @@ -1177,10 +1161,10 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { favorite: Boolean = false, masterPasswordReprompt: Boolean = false, notes: String = "", - customFieldData: List = listOf(), + customFieldData: List = listOf(), ownership: String = "placeholder@email.com", - ): VaultAddItemState.ViewState.Content.Common = - VaultAddItemState.ViewState.Content.Common( + ): VaultAddEditState.ViewState.Content.Common = + VaultAddEditState.ViewState.Content.Common( name = name, folderName = folder, favorite = favorite, @@ -1195,8 +1179,8 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { password: String = "", uri: String = "", totpCode: String? = null, - ): VaultAddItemState.ViewState.Content.ItemType.Login = - VaultAddItemState.ViewState.Content.ItemType.Login( + ): VaultAddEditState.ViewState.Content.ItemType.Login = + VaultAddEditState.ViewState.Content.ItemType.Login( username = username, password = password, uri = uri, @@ -1204,7 +1188,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { ) private fun createSavedStateHandleWithState( - state: VaultAddItemState?, + state: VaultAddEditState?, vaultAddEditType: VaultAddEditType, ) = SavedStateHandle().apply { set("state", state) @@ -1221,8 +1205,8 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { private fun createAddVaultItemViewModel( savedStateHandle: SavedStateHandle = loginInitialSavedStateHandle, vaultRepo: VaultRepository = vaultRepository, - ): VaultAddItemViewModel = - VaultAddItemViewModel( + ): VaultAddEditViewModel = + VaultAddEditViewModel( savedStateHandle = savedStateHandle, vaultRepository = vaultRepo, ) @@ -1231,16 +1215,16 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { * A function to test the changes in custom fields for each type. */ private fun assertCustomFieldValueChange( - initialState: VaultAddItemState, + initialState: VaultAddEditState, type: CustomFieldType, ) { - lateinit var expectedCustomField: VaultAddItemState.Custom - lateinit var action: VaultAddItemAction.Common - lateinit var expectedState: VaultAddItemState.ViewState.Content + lateinit var expectedCustomField: VaultAddEditState.Custom + lateinit var action: VaultAddEditAction.Common + lateinit var expectedState: VaultAddEditState.ViewState.Content when (type) { CustomFieldType.LINKED -> { - expectedCustomField = VaultAddItemState.Custom.LinkedField( + expectedCustomField = VaultAddEditState.Custom.LinkedField( "TestId 4", "Linked Field", VaultLinkedFieldType.PASSWORD, @@ -1248,7 +1232,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { } CustomFieldType.HIDDEN -> { - expectedCustomField = VaultAddItemState.Custom.HiddenField( + expectedCustomField = VaultAddEditState.Custom.HiddenField( "TestId 2", "Test Hidden", "Updated Test Text", @@ -1256,7 +1240,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { } CustomFieldType.BOOLEAN -> { - expectedCustomField = VaultAddItemState.Custom.BooleanField( + expectedCustomField = VaultAddEditState.Custom.BooleanField( "TestId 3", "Boolean Field", false, @@ -1264,7 +1248,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { } CustomFieldType.TEXT -> { - expectedCustomField = VaultAddItemState.Custom.TextField( + expectedCustomField = VaultAddEditState.Custom.TextField( "TestId 1", "Test Text", "Updated Test Text", @@ -1280,8 +1264,8 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { ) val currentContentState = - (viewModel.stateFlow.value.viewState as VaultAddItemState.ViewState.Content) - action = VaultAddItemAction.Common.CustomFieldValueChange(expectedCustomField) + (viewModel.stateFlow.value.viewState as VaultAddEditState.ViewState.Content) + action = VaultAddEditAction.Common.CustomFieldValueChange(expectedCustomField) expectedState = currentContentState .copy( common = currentContentState.common.copy( @@ -1298,7 +1282,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { * A function to test the addition of new custom fields for each type. */ private fun assertAddNewCustomFieldClick( - initialState: VaultAddItemState, + initialState: VaultAddEditState, type: CustomFieldType, ) { val viewModel = createAddVaultItemViewModel( @@ -1309,14 +1293,14 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { ) var name = "" - lateinit var expectedCustomField: VaultAddItemState.Custom - lateinit var action: VaultAddItemAction.Common - lateinit var expectedState: VaultAddItemState.ViewState.Content + lateinit var expectedCustomField: VaultAddEditState.Custom + lateinit var action: VaultAddEditAction.Common + lateinit var expectedState: VaultAddEditState.ViewState.Content when (type) { CustomFieldType.LINKED -> { name = "Linked" - expectedCustomField = VaultAddItemState.Custom.LinkedField( + expectedCustomField = VaultAddEditState.Custom.LinkedField( itemId = TEST_ID, name = name, vaultLinkedFieldType = VaultLinkedFieldType.USERNAME, @@ -1325,7 +1309,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { CustomFieldType.HIDDEN -> { name = "Hidden" - expectedCustomField = VaultAddItemState.Custom.HiddenField( + expectedCustomField = VaultAddEditState.Custom.HiddenField( itemId = TEST_ID, name = name, value = "", @@ -1334,7 +1318,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { CustomFieldType.BOOLEAN -> { name = "Boolean" - expectedCustomField = VaultAddItemState.Custom.BooleanField( + expectedCustomField = VaultAddEditState.Custom.BooleanField( itemId = TEST_ID, name = name, value = false, @@ -1343,7 +1327,7 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { CustomFieldType.TEXT -> { name = "Text" - expectedCustomField = VaultAddItemState.Custom.TextField( + expectedCustomField = VaultAddEditState.Custom.TextField( itemId = TEST_ID, name = name, value = "", @@ -1352,8 +1336,8 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { } val currentContentState = - (viewModel.stateFlow.value.viewState as VaultAddItemState.ViewState.Content) - action = VaultAddItemAction.Common.AddNewCustomFieldClick(type, name) + (viewModel.stateFlow.value.viewState as VaultAddEditState.ViewState.Content) + action = VaultAddEditAction.Common.AddNewCustomFieldClick(type, name) expectedState = currentContentState .copy( common = currentContentState.common.copy( @@ -1371,6 +1355,6 @@ class VaultAddItemViewModelTest : BaseViewModelTest() { private const val TEST_ID = "testId" private const val CIPHER_VIEW_EXTENSIONS_PATH: String = - "com.x8bit.bitwarden.ui.vault.feature.additem.util.CipherViewExtensionsKt" + "com.x8bit.bitwarden.ui.vault.feature.addedit.util.CipherViewExtensionsKt" private const val DEFAULT_EDIT_ITEM_ID: String = "edit_item_id" diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/model/CustomFieldTypeTests.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/model/CustomFieldTypeTests.kt similarity index 83% rename from app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/model/CustomFieldTypeTests.kt rename to app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/model/CustomFieldTypeTests.kt index 9ae851f94..abfb89930 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/model/CustomFieldTypeTests.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/model/CustomFieldTypeTests.kt @@ -1,6 +1,6 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem.model +package com.x8bit.bitwarden.ui.vault.feature.addedit.model -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType import io.mockk.every import io.mockk.mockkStatic @@ -30,7 +30,7 @@ class CustomFieldTypeTests { val name = "test" val type = CustomFieldType.BOOLEAN - val expected = VaultAddItemState.Custom.BooleanField(TEST_ID, "test", false) + val expected = VaultAddEditState.Custom.BooleanField(TEST_ID, "test", false) val actual = type.toCustomField(name) assertEquals(expected, actual) @@ -42,7 +42,7 @@ class CustomFieldTypeTests { val type = CustomFieldType.LINKED val expected = - VaultAddItemState.Custom.LinkedField(TEST_ID, "test", VaultLinkedFieldType.USERNAME) + VaultAddEditState.Custom.LinkedField(TEST_ID, "test", VaultLinkedFieldType.USERNAME) val actual = type.toCustomField(name) assertEquals(expected, actual) @@ -53,7 +53,7 @@ class CustomFieldTypeTests { val name = "test" val type = CustomFieldType.TEXT - val expected = VaultAddItemState.Custom.TextField(TEST_ID, "test", "") + val expected = VaultAddEditState.Custom.TextField(TEST_ID, "test", "") val actual = type.toCustomField(name) assertEquals(expected, actual) @@ -64,7 +64,7 @@ class CustomFieldTypeTests { val name = "test" val type = CustomFieldType.HIDDEN - val expected = VaultAddItemState.Custom.HiddenField(TEST_ID, "test", "") + val expected = VaultAddEditState.Custom.HiddenField(TEST_ID, "test", "") val actual = type.toCustomField(name) assertEquals(expected, actual) diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/util/CipherViewExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/util/CipherViewExtensionsTest.kt similarity index 84% rename from app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/util/CipherViewExtensionsTest.kt rename to app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/util/CipherViewExtensionsTest.kt index 04fb7631f..2a8aaa4e3 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/additem/util/CipherViewExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/util/CipherViewExtensionsTest.kt @@ -1,4 +1,4 @@ -package com.x8bit.bitwarden.ui.vault.feature.additem.util +package com.x8bit.bitwarden.ui.vault.feature.addedit.util import com.bitwarden.core.CardView import com.bitwarden.core.CipherRepromptType @@ -14,7 +14,7 @@ import com.bitwarden.core.SecureNoteType import com.bitwarden.core.SecureNoteView import com.x8bit.bitwarden.R import com.x8bit.bitwarden.ui.platform.base.util.asText -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType import io.mockk.every import io.mockk.mockkStatic @@ -46,8 +46,8 @@ class CipherViewExtensionsTest { val result = cipherView.toViewState() assertEquals( - VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common( + VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common( originalCipher = cipherView, name = "cipher", folderName = R.string.folder_none.asText(), @@ -56,10 +56,10 @@ class CipherViewExtensionsTest { notes = "Lots of notes", ownership = "", customFieldData = listOf( - VaultAddItemState.Custom.BooleanField(TEST_ID, "TestBoolean", false), - VaultAddItemState.Custom.TextField(TEST_ID, "TestText", "TestText"), - VaultAddItemState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"), - VaultAddItemState.Custom.LinkedField( + VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false), + VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"), + VaultAddEditState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"), + VaultAddEditState.Custom.LinkedField( TEST_ID, "TestLinked", VaultLinkedFieldType.USERNAME, @@ -68,7 +68,7 @@ class CipherViewExtensionsTest { availableFolders = emptyList(), availableOwners = emptyList(), ), - type = VaultAddItemState.ViewState.Content.ItemType.Card, + type = VaultAddEditState.ViewState.Content.ItemType.Card, ), result, ) @@ -81,8 +81,8 @@ class CipherViewExtensionsTest { val result = cipherView.toViewState() assertEquals( - VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common( + VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common( originalCipher = cipherView, name = "cipher", folderName = R.string.folder_none.asText(), @@ -91,10 +91,10 @@ class CipherViewExtensionsTest { notes = "Lots of notes", ownership = "", customFieldData = listOf( - VaultAddItemState.Custom.BooleanField(TEST_ID, "TestBoolean", false), - VaultAddItemState.Custom.TextField(TEST_ID, "TestText", "TestText"), - VaultAddItemState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"), - VaultAddItemState.Custom.LinkedField( + VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false), + VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"), + VaultAddEditState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"), + VaultAddEditState.Custom.LinkedField( TEST_ID, "TestLinked", VaultLinkedFieldType.USERNAME, @@ -103,7 +103,7 @@ class CipherViewExtensionsTest { availableFolders = emptyList(), availableOwners = emptyList(), ), - type = VaultAddItemState.ViewState.Content.ItemType.Identity( + type = VaultAddEditState.ViewState.Content.ItemType.Identity( firstName = "John", middleName = "Richard", lastName = "Smith", @@ -127,8 +127,8 @@ class CipherViewExtensionsTest { val result = cipherView.toViewState() assertEquals( - VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common( + VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common( originalCipher = cipherView, name = "cipher", folderName = R.string.folder_none.asText(), @@ -139,17 +139,17 @@ class CipherViewExtensionsTest { availableFolders = emptyList(), availableOwners = emptyList(), customFieldData = listOf( - VaultAddItemState.Custom.BooleanField(TEST_ID, "TestBoolean", false), - VaultAddItemState.Custom.TextField(TEST_ID, "TestText", "TestText"), - VaultAddItemState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"), - VaultAddItemState.Custom.LinkedField( + VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false), + VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"), + VaultAddEditState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"), + VaultAddEditState.Custom.LinkedField( TEST_ID, "TestLinked", VaultLinkedFieldType.USERNAME, ), ), ), - type = VaultAddItemState.ViewState.Content.ItemType.Login( + type = VaultAddEditState.ViewState.Content.ItemType.Login( username = "username", password = "password", uri = "www.example.com", @@ -167,8 +167,8 @@ class CipherViewExtensionsTest { val result = cipherView.toViewState() assertEquals( - VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common( + VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common( originalCipher = cipherView, name = "cipher", folderName = R.string.folder_none.asText(), @@ -177,14 +177,14 @@ class CipherViewExtensionsTest { notes = "Lots of notes", ownership = "", customFieldData = listOf( - VaultAddItemState.Custom.BooleanField(TEST_ID, "TestBoolean", false), - VaultAddItemState.Custom.TextField(TEST_ID, "TestText", "TestText"), - VaultAddItemState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"), + VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false), + VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"), + VaultAddEditState.Custom.HiddenField(TEST_ID, "TestHidden", "TestHidden"), ), availableFolders = emptyList(), availableOwners = emptyList(), ), - type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes, + type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes, ), result, ) diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/VaultAddItemStateExtensionsTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/VaultAddItemStateExtensionsTest.kt index b74861c06..817a8042a 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/VaultAddItemStateExtensionsTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/util/VaultAddItemStateExtensionsTest.kt @@ -13,7 +13,7 @@ import com.bitwarden.core.SecureNoteType import com.bitwarden.core.SecureNoteView import com.bitwarden.core.UriMatchType import com.x8bit.bitwarden.ui.platform.base.util.asText -import com.x8bit.bitwarden.ui.vault.feature.additem.VaultAddItemState +import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState import com.x8bit.bitwarden.ui.vault.model.VaultLinkedFieldType import io.mockk.every import io.mockk.mockkStatic @@ -37,8 +37,8 @@ class VaultAddItemStateExtensionsTest { mockkStatic(Instant::class) every { Instant.now() } returns Instant.MIN - val loginItemType = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common( + val loginItemType = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common( name = "mockName-1", folderName = "mockFolder-1".asText(), favorite = false, @@ -46,7 +46,7 @@ class VaultAddItemStateExtensionsTest { notes = "mockNotes-1", ownership = "mockOwnership-1", ), - type = VaultAddItemState.ViewState.Content.ItemType.Login( + type = VaultAddEditState.ViewState.Content.ItemType.Login( username = "mockUsername-1", password = "mockPassword-1", uri = "mockUri-1", @@ -103,18 +103,18 @@ class VaultAddItemStateExtensionsTest { @Test fun `toCipherView should transform Login ItemType to CipherView with original cipher`() { val cipherView = DEFAULT_LOGIN_CIPHER_VIEW - val viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common( + val viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common( originalCipher = cipherView, name = "mockName-1", folderName = "mockFolder-1".asText(), favorite = true, masterPasswordReprompt = false, customFieldData = listOf( - VaultAddItemState.Custom.BooleanField("testId", "TestBoolean", false), - VaultAddItemState.Custom.TextField("testId", "TestText", "TestText"), - VaultAddItemState.Custom.HiddenField("testId", "TestHidden", "TestHidden"), - VaultAddItemState.Custom.LinkedField( + VaultAddEditState.Custom.BooleanField("testId", "TestBoolean", false), + VaultAddEditState.Custom.TextField("testId", "TestText", "TestText"), + VaultAddEditState.Custom.HiddenField("testId", "TestHidden", "TestHidden"), + VaultAddEditState.Custom.LinkedField( "testId", "TestLinked", VaultLinkedFieldType.USERNAME, @@ -123,7 +123,7 @@ class VaultAddItemStateExtensionsTest { notes = "mockNotes-1", ownership = "mockOwnership-1", ), - type = VaultAddItemState.ViewState.Content.ItemType.Login( + type = VaultAddEditState.ViewState.Content.ItemType.Login( username = "mockUsername-1", password = "mockPassword-1", uri = "mockUri-1", @@ -195,8 +195,8 @@ class VaultAddItemStateExtensionsTest { fun `toCipherView should transform SecureNotes ItemType to CipherView`() { mockkStatic(Instant::class) every { Instant.now() } returns Instant.MIN - val viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common( + val viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common( name = "mockName-1", folderName = "mockFolder-1".asText(), favorite = false, @@ -204,12 +204,12 @@ class VaultAddItemStateExtensionsTest { notes = "mockNotes-1", ownership = "mockOwnership-1", customFieldData = listOf( - VaultAddItemState.Custom.BooleanField("testId", "TestBoolean", false), - VaultAddItemState.Custom.TextField("testId", "TestText", "TestText"), - VaultAddItemState.Custom.HiddenField("testId", "TestHidden", "TestHidden"), + VaultAddEditState.Custom.BooleanField("testId", "TestBoolean", false), + VaultAddEditState.Custom.TextField("testId", "TestText", "TestText"), + VaultAddEditState.Custom.HiddenField("testId", "TestHidden", "TestHidden"), ), ), - type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes, + type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes, ) val result = viewState.toCipherView() @@ -267,8 +267,8 @@ class VaultAddItemStateExtensionsTest { @Test fun `toCipherView should transform SecureNotes ItemType to CipherView with original cipher`() { val cipherView = DEFAULT_SECURE_NOTES_CIPHER_VIEW - val viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common( + val viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common( originalCipher = cipherView, name = "mockName-1", folderName = "mockFolder-1".asText(), @@ -278,7 +278,7 @@ class VaultAddItemStateExtensionsTest { ownership = "mockOwnership-1", customFieldData = emptyList(), ), - type = VaultAddItemState.ViewState.Content.ItemType.SecureNotes, + type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes, ) val result = viewState.toCipherView() @@ -300,8 +300,8 @@ class VaultAddItemStateExtensionsTest { fun `toCipherView should transform Identity ItemType to CipherView`() { mockkStatic(Instant::class) every { Instant.now() } returns Instant.MIN - val viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common( + val viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common( name = "mockName-1", folderName = "mockFolder-1".asText(), favorite = false, @@ -309,8 +309,8 @@ class VaultAddItemStateExtensionsTest { notes = "mockNotes-1", ownership = "mockOwnership-1", ), - type = VaultAddItemState.ViewState.Content.ItemType.Identity( - selectedTitle = VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MR, + type = VaultAddEditState.ViewState.Content.ItemType.Identity( + selectedTitle = VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MR, firstName = "mockFirstName", lastName = "mockLastName", middleName = "mockMiddleName", @@ -386,18 +386,18 @@ class VaultAddItemStateExtensionsTest { @Test fun `toCipherView should transform Identity ItemType to CipherView with original cipher`() { val cipherView = DEFAULT_IDENTITY_CIPHER_VIEW - val viewState = VaultAddItemState.ViewState.Content( - common = VaultAddItemState.ViewState.Content.Common( + val viewState = VaultAddEditState.ViewState.Content( + common = VaultAddEditState.ViewState.Content.Common( originalCipher = cipherView, name = "mockName-1", folderName = "mockFolder-1".asText(), favorite = true, masterPasswordReprompt = false, customFieldData = listOf( - VaultAddItemState.Custom.BooleanField("testId", "TestBoolean", false), - VaultAddItemState.Custom.TextField("testId", "TestText", "TestText"), - VaultAddItemState.Custom.HiddenField("testId", "TestHidden", "TestHidden"), - VaultAddItemState.Custom.LinkedField( + VaultAddEditState.Custom.BooleanField("testId", "TestBoolean", false), + VaultAddEditState.Custom.TextField("testId", "TestText", "TestText"), + VaultAddEditState.Custom.HiddenField("testId", "TestHidden", "TestHidden"), + VaultAddEditState.Custom.LinkedField( "testId", "TestLinked", VaultLinkedFieldType.USERNAME, @@ -406,8 +406,8 @@ class VaultAddItemStateExtensionsTest { notes = "mockNotes-1", ownership = "mockOwnership-1", ), - type = VaultAddItemState.ViewState.Content.ItemType.Identity( - selectedTitle = VaultAddItemState.ViewState.Content.ItemType.Identity.Title.MR, + type = VaultAddEditState.ViewState.Content.ItemType.Identity( + selectedTitle = VaultAddEditState.ViewState.Content.ItemType.Identity.Title.MR, firstName = "mockFirstName", lastName = "mockLastName", middleName = "mockMiddleName",