[PM-11303] Add button missing for folders (#4250)

This commit is contained in:
André Bispo 2024-11-11 16:26:04 +00:00 committed by GitHub
parent 16cc70f344
commit a3ed2bc068
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 96 additions and 32 deletions

View file

@ -75,8 +75,11 @@ fun NavGraphBuilder.vaultUnlockedGraph(
vaultItemListingDestinationAsRoot( vaultItemListingDestinationAsRoot(
onNavigateBack = { navController.popBackStack() }, onNavigateBack = { navController.popBackStack() },
onNavigateToVaultItemScreen = { navController.navigateToVaultItem(vaultItemId = it) }, onNavigateToVaultItemScreen = { navController.navigateToVaultItem(vaultItemId = it) },
onNavigateToVaultAddItemScreen = { onNavigateToVaultAddItemScreen = { cipherType, selectedFolderId ->
navController.navigateToVaultAddEdit(VaultAddEditType.AddItem(it)) navController.navigateToVaultAddEdit(
VaultAddEditType.AddItem(cipherType),
selectedFolderId,
)
}, },
onNavigateToSearchVault = { navController.navigateToSearch(searchType = it) }, onNavigateToSearchVault = { navController.navigateToSearch(searchType = it) },
onNavigateToVaultEditItemScreen = { onNavigateToVaultEditItemScreen = {
@ -86,8 +89,11 @@ fun NavGraphBuilder.vaultUnlockedGraph(
vaultUnlockedNavBarDestination( vaultUnlockedNavBarDestination(
onNavigateToExportVault = { navController.navigateToExportVault() }, onNavigateToExportVault = { navController.navigateToExportVault() },
onNavigateToFolders = { navController.navigateToFolders() }, onNavigateToFolders = { navController.navigateToFolders() },
onNavigateToVaultAddItem = { onNavigateToVaultAddItem = { cipherType, selectedFolderId ->
navController.navigateToVaultAddEdit(VaultAddEditType.AddItem(it)) navController.navigateToVaultAddEdit(
VaultAddEditType.AddItem(cipherType),
selectedFolderId,
)
}, },
onNavigateToVaultItem = { navController.navigateToVaultItem(it) }, onNavigateToVaultItem = { navController.navigateToVaultItem(it) },
onNavigateToVaultEditItem = { onNavigateToVaultEditItem = {

View file

@ -25,7 +25,7 @@ fun NavController.navigateToVaultUnlockedNavBar(navOptions: NavOptions? = null)
*/ */
@Suppress("LongParameterList") @Suppress("LongParameterList")
fun NavGraphBuilder.vaultUnlockedNavBarDestination( fun NavGraphBuilder.vaultUnlockedNavBarDestination(
onNavigateToVaultAddItem: (VaultItemCipherType) -> Unit, onNavigateToVaultAddItem: (VaultItemCipherType, String?) -> Unit,
onNavigateToVaultItem: (vaultItemId: String) -> Unit, onNavigateToVaultItem: (vaultItemId: String) -> Unit,
onNavigateToVaultEditItem: (vaultItemId: String) -> Unit, onNavigateToVaultEditItem: (vaultItemId: String) -> Unit,
onNavigateToSearchSend: (searchType: SearchType.Sends) -> Unit, onNavigateToSearchSend: (searchType: SearchType.Sends) -> Unit,

View file

@ -64,7 +64,7 @@ import com.x8bit.bitwarden.ui.vault.model.VaultItemCipherType
fun VaultUnlockedNavBarScreen( fun VaultUnlockedNavBarScreen(
viewModel: VaultUnlockedNavBarViewModel = hiltViewModel(), viewModel: VaultUnlockedNavBarViewModel = hiltViewModel(),
navController: NavHostController = rememberNavController(), navController: NavHostController = rememberNavController(),
onNavigateToVaultAddItem: (VaultItemCipherType) -> Unit, onNavigateToVaultAddItem: (VaultItemCipherType, String?) -> Unit,
onNavigateToVaultItem: (vaultItemId: String) -> Unit, onNavigateToVaultItem: (vaultItemId: String) -> Unit,
onNavigateToVaultEditItem: (vaultItemId: String) -> Unit, onNavigateToVaultEditItem: (vaultItemId: String) -> Unit,
onNavigateToSearchSend: (searchType: SearchType.Sends) -> Unit, onNavigateToSearchSend: (searchType: SearchType.Sends) -> Unit,
@ -158,7 +158,7 @@ private fun VaultUnlockedNavBarScaffold(
sendTabClickedAction: () -> Unit, sendTabClickedAction: () -> Unit,
generatorTabClickedAction: () -> Unit, generatorTabClickedAction: () -> Unit,
settingsTabClickedAction: () -> Unit, settingsTabClickedAction: () -> Unit,
navigateToVaultAddItem: (VaultItemCipherType) -> Unit, navigateToVaultAddItem: (VaultItemCipherType, String?) -> Unit,
onNavigateToVaultItem: (vaultItemId: String) -> Unit, onNavigateToVaultItem: (vaultItemId: String) -> Unit,
onNavigateToVaultEditItem: (vaultItemId: String) -> Unit, onNavigateToVaultEditItem: (vaultItemId: String) -> Unit,
onNavigateToSearchSend: (searchType: SearchType.Sends) -> Unit, onNavigateToSearchSend: (searchType: SearchType.Sends) -> Unit,

View file

@ -26,12 +26,14 @@ private const val ADD_ITEM_TYPE: String = "vault_add_item_type"
private const val ADD_EDIT_ITEM_PREFIX: String = "vault_add_edit_item" private const val ADD_EDIT_ITEM_PREFIX: String = "vault_add_edit_item"
private const val ADD_EDIT_ITEM_TYPE: String = "vault_add_edit_type" private const val ADD_EDIT_ITEM_TYPE: String = "vault_add_edit_type"
private const val ADD_SELECTED_FOLDER_ID: String = "vault_add_selected_folder_id"
private const val ADD_EDIT_ITEM_ROUTE: String = private const val ADD_EDIT_ITEM_ROUTE: String =
ADD_EDIT_ITEM_PREFIX + ADD_EDIT_ITEM_PREFIX +
"/{$ADD_EDIT_ITEM_TYPE}" + "/{$ADD_EDIT_ITEM_TYPE}" +
"?$EDIT_ITEM_ID={$EDIT_ITEM_ID}" + "?$EDIT_ITEM_ID={$EDIT_ITEM_ID}" +
"?$ADD_ITEM_TYPE={$ADD_ITEM_TYPE}" "?$ADD_ITEM_TYPE={$ADD_ITEM_TYPE}" +
"?$ADD_SELECTED_FOLDER_ID={$ADD_SELECTED_FOLDER_ID}"
/** /**
* Class to retrieve vault add & edit arguments from the [SavedStateHandle]. * Class to retrieve vault add & edit arguments from the [SavedStateHandle].
@ -39,6 +41,7 @@ private const val ADD_EDIT_ITEM_ROUTE: String =
@OmitFromCoverage @OmitFromCoverage
data class VaultAddEditArgs( data class VaultAddEditArgs(
val vaultAddEditType: VaultAddEditType, val vaultAddEditType: VaultAddEditType,
val selectedFolderId: String? = null,
) { ) {
constructor(savedStateHandle: SavedStateHandle) : this( constructor(savedStateHandle: SavedStateHandle) : this(
vaultAddEditType = when (requireNotNull(savedStateHandle[ADD_EDIT_ITEM_TYPE])) { vaultAddEditType = when (requireNotNull(savedStateHandle[ADD_EDIT_ITEM_TYPE])) {
@ -53,6 +56,7 @@ data class VaultAddEditArgs(
CLONE_TYPE -> VaultAddEditType.CloneItem(requireNotNull(savedStateHandle[EDIT_ITEM_ID])) CLONE_TYPE -> VaultAddEditType.CloneItem(requireNotNull(savedStateHandle[EDIT_ITEM_ID]))
else -> throw IllegalStateException("Unknown VaultAddEditType.") else -> throw IllegalStateException("Unknown VaultAddEditType.")
}, },
selectedFolderId = savedStateHandle[ADD_SELECTED_FOLDER_ID],
) )
} }
@ -72,6 +76,10 @@ fun NavGraphBuilder.vaultAddEditDestination(
route = ADD_EDIT_ITEM_ROUTE, route = ADD_EDIT_ITEM_ROUTE,
arguments = listOf( arguments = listOf(
navArgument(ADD_EDIT_ITEM_TYPE) { type = NavType.StringType }, navArgument(ADD_EDIT_ITEM_TYPE) { type = NavType.StringType },
navArgument(ADD_SELECTED_FOLDER_ID) {
type = NavType.StringType
nullable = true
},
), ),
) { ) {
VaultAddEditScreen( VaultAddEditScreen(
@ -90,12 +98,14 @@ fun NavGraphBuilder.vaultAddEditDestination(
*/ */
fun NavController.navigateToVaultAddEdit( fun NavController.navigateToVaultAddEdit(
vaultAddEditType: VaultAddEditType, vaultAddEditType: VaultAddEditType,
selectedFolderId: String? = null,
navOptions: NavOptions? = null, navOptions: NavOptions? = null,
) { ) {
navigate( navigate(
route = "$ADD_EDIT_ITEM_PREFIX/${vaultAddEditType.toTypeString()}" + route = "$ADD_EDIT_ITEM_PREFIX/${vaultAddEditType.toTypeString()}" +
"?$EDIT_ITEM_ID=${vaultAddEditType.toIdOrNull()}" + "?$EDIT_ITEM_ID=${vaultAddEditType.toIdOrNull()}" +
"?$ADD_ITEM_TYPE=${vaultAddEditType.toVaultItemCipherTypeOrNull()}", "?$ADD_ITEM_TYPE=${vaultAddEditType.toVaultItemCipherTypeOrNull()}" +
"?$ADD_SELECTED_FOLDER_ID=$selectedFolderId",
navOptions = navOptions, navOptions = navOptions,
) )
} }

View file

@ -109,6 +109,7 @@ class VaultAddEditViewModel @Inject constructor(
initialState = savedStateHandle[KEY_STATE] initialState = savedStateHandle[KEY_STATE]
?: run { ?: run {
val vaultAddEditType = VaultAddEditArgs(savedStateHandle).vaultAddEditType val vaultAddEditType = VaultAddEditArgs(savedStateHandle).vaultAddEditType
val selectedFolderId = VaultAddEditArgs(savedStateHandle).selectedFolderId
val isIndividualVaultDisabled = policyManager val isIndividualVaultDisabled = policyManager
.getActivePolicies(type = PolicyTypeJson.PERSONAL_OWNERSHIP) .getActivePolicies(type = PolicyTypeJson.PERSONAL_OWNERSHIP)
.any() .any()
@ -153,7 +154,9 @@ class VaultAddEditViewModel @Inject constructor(
isIndividualVaultDisabled = isIndividualVaultDisabled, isIndividualVaultDisabled = isIndividualVaultDisabled,
) )
?: VaultAddEditState.ViewState.Content( ?: VaultAddEditState.ViewState.Content(
common = VaultAddEditState.ViewState.Content.Common(), common = VaultAddEditState.ViewState.Content.Common(
selectedFolderId = selectedFolderId,
),
isIndividualVaultDisabled = isIndividualVaultDisabled, isIndividualVaultDisabled = isIndividualVaultDisabled,
type = vaultAddEditType.vaultItemCipherType.toItemType(), type = vaultAddEditType.vaultItemCipherType.toItemType(),
) )

View file

@ -131,7 +131,8 @@ fun VaultAddEditState.ViewState.appendFolderAndOwnerData(
common = currentContentState.common.copy( common = currentContentState.common.copy(
selectedFolderId = folderViewList.toSelectedFolderId( selectedFolderId = folderViewList.toSelectedFolderId(
cipherView = currentContentState.common.originalCipher, cipherView = currentContentState.common.originalCipher,
), )
?: currentContentState.common.selectedFolderId,
availableFolders = folderViewList.toAvailableFolders( availableFolders = folderViewList.toAvailableFolders(
resourceManager = resourceManager, resourceManager = resourceManager,
), ),

View file

@ -64,7 +64,10 @@ fun NavGraphBuilder.vaultItemListingDestination(
onNavigateToVaultItemScreen: (id: String) -> Unit, onNavigateToVaultItemScreen: (id: String) -> Unit,
onNavigateToVaultEditItemScreen: (cipherId: String) -> Unit, onNavigateToVaultEditItemScreen: (cipherId: String) -> Unit,
onNavigateToVaultItemListing: (vaultItemListingType: VaultItemListingType) -> Unit, onNavigateToVaultItemListing: (vaultItemListingType: VaultItemListingType) -> Unit,
onNavigateToVaultAddItemScreen: (vaultItemCipherType: VaultItemCipherType) -> Unit, onNavigateToVaultAddItemScreen: (
cipherType: VaultItemCipherType,
selectedFolderId: String?,
) -> Unit,
onNavigateToSearchVault: (searchType: SearchType.Vault) -> Unit, onNavigateToSearchVault: (searchType: SearchType.Vault) -> Unit,
) { ) {
internalVaultItemListingDestination( internalVaultItemListingDestination(
@ -87,7 +90,10 @@ fun NavGraphBuilder.vaultItemListingDestinationAsRoot(
onNavigateBack: () -> Unit, onNavigateBack: () -> Unit,
onNavigateToVaultItemScreen: (id: String) -> Unit, onNavigateToVaultItemScreen: (id: String) -> Unit,
onNavigateToVaultEditItemScreen: (cipherId: String) -> Unit, onNavigateToVaultEditItemScreen: (cipherId: String) -> Unit,
onNavigateToVaultAddItemScreen: (VaultItemCipherType) -> Unit, onNavigateToVaultAddItemScreen: (
cipherType: VaultItemCipherType,
selectedFolderId: String?,
) -> Unit,
onNavigateToSearchVault: (searchType: SearchType.Vault) -> Unit, onNavigateToSearchVault: (searchType: SearchType.Vault) -> Unit,
) { ) {
composableWithStayTransitions( composableWithStayTransitions(
@ -128,7 +134,7 @@ fun NavGraphBuilder.sendItemListingDestination(
onNavigateBack = onNavigateBack, onNavigateBack = onNavigateBack,
onNavigateToAddSendItem = onNavigateToAddSendItem, onNavigateToAddSendItem = onNavigateToAddSendItem,
onNavigateToEditSendItem = onNavigateToEditSendItem, onNavigateToEditSendItem = onNavigateToEditSendItem,
onNavigateToVaultAddItemScreen = { }, onNavigateToVaultAddItemScreen = { _, _ -> },
onNavigateToVaultItemScreen = { }, onNavigateToVaultItemScreen = { },
onNavigateToVaultEditItemScreen = { }, onNavigateToVaultEditItemScreen = { },
onNavigateToVaultItemListing = { }, onNavigateToVaultItemListing = { },
@ -146,7 +152,10 @@ private fun NavGraphBuilder.internalVaultItemListingDestination(
onNavigateToVaultItemScreen: (id: String) -> Unit, onNavigateToVaultItemScreen: (id: String) -> Unit,
onNavigateToVaultEditItemScreen: (cipherId: String) -> Unit, onNavigateToVaultEditItemScreen: (cipherId: String) -> Unit,
onNavigateToVaultItemListing: (vaultItemListingType: VaultItemListingType) -> Unit, onNavigateToVaultItemListing: (vaultItemListingType: VaultItemListingType) -> Unit,
onNavigateToVaultAddItemScreen: (vaultItemCipherType: VaultItemCipherType) -> Unit, onNavigateToVaultAddItemScreen: (
cipherType: VaultItemCipherType,
selectedFolderId: String?,
) -> Unit,
onNavigateToAddSendItem: () -> Unit, onNavigateToAddSendItem: () -> Unit,
onNavigateToEditSendItem: (sendId: String) -> Unit, onNavigateToEditSendItem: (sendId: String) -> Unit,
onNavigateToSearch: (searchType: SearchType) -> Unit, onNavigateToSearch: (searchType: SearchType) -> Unit,

View file

@ -72,7 +72,10 @@ fun VaultItemListingScreen(
onNavigateToVaultItem: (id: String) -> Unit, onNavigateToVaultItem: (id: String) -> Unit,
onNavigateToVaultEditItemScreen: (cipherVaultId: String) -> Unit, onNavigateToVaultEditItemScreen: (cipherVaultId: String) -> Unit,
onNavigateToVaultItemListing: (vaultItemListingType: VaultItemListingType) -> Unit, onNavigateToVaultItemListing: (vaultItemListingType: VaultItemListingType) -> Unit,
onNavigateToVaultAddItemScreen: (vaultItemCipherType: VaultItemCipherType) -> Unit, onNavigateToVaultAddItemScreen: (
vaultItemCipherType: VaultItemCipherType,
selectedFolderId: String?,
) -> Unit,
onNavigateToAddSendItem: () -> Unit, onNavigateToAddSendItem: () -> Unit,
onNavigateToEditSendItem: (sendId: String) -> Unit, onNavigateToEditSendItem: (sendId: String) -> Unit,
onNavigateToSearch: (searchType: SearchType) -> Unit, onNavigateToSearch: (searchType: SearchType) -> Unit,
@ -113,7 +116,10 @@ fun VaultItemListingScreen(
} }
is VaultItemListingEvent.NavigateToAddVaultItem -> { is VaultItemListingEvent.NavigateToAddVaultItem -> {
onNavigateToVaultAddItemScreen(event.vaultItemCipherType) onNavigateToVaultAddItemScreen(
event.vaultItemCipherType,
event.selectedFolderId,
)
} }
is VaultItemListingEvent.NavigateToEditCipher -> { is VaultItemListingEvent.NavigateToEditCipher -> {

View file

@ -534,6 +534,13 @@ class VaultItemListingViewModel @Inject constructor(
private fun handleAddVaultItemClick() { private fun handleAddVaultItemClick() {
val event = when (val itemListingType = state.itemListingType) { val event = when (val itemListingType = state.itemListingType) {
is VaultItemListingState.ItemListingType.Vault.Folder -> {
VaultItemListingEvent.NavigateToAddVaultItem(
vaultItemCipherType = itemListingType.toVaultItemCipherType(),
selectedFolderId = itemListingType.folderId,
)
}
is VaultItemListingState.ItemListingType.Vault -> { is VaultItemListingState.ItemListingType.Vault -> {
VaultItemListingEvent.NavigateToAddVaultItem( VaultItemListingEvent.NavigateToAddVaultItem(
vaultItemCipherType = itemListingType.toVaultItemCipherType(), vaultItemCipherType = itemListingType.toVaultItemCipherType(),
@ -2089,7 +2096,7 @@ data class VaultItemListingState(
get() = folderId get() = folderId
?.let { folderName.asText() } ?.let { folderName.asText() }
?: R.string.folder_none.asText() ?: R.string.folder_none.asText()
override val hasFab: Boolean get() = false override val hasFab: Boolean get() = true
} }
/** /**
@ -2150,6 +2157,7 @@ sealed class VaultItemListingEvent {
*/ */
data class NavigateToAddVaultItem( data class NavigateToAddVaultItem(
val vaultItemCipherType: VaultItemCipherType, val vaultItemCipherType: VaultItemCipherType,
val selectedFolderId: String? = null,
) : VaultItemListingEvent() ) : VaultItemListingEvent()
/** /**

View file

@ -40,8 +40,8 @@ fun VaultItemListingState.ItemListingType.Vault.toVaultItemCipherType(): VaultIt
is VaultItemListingState.ItemListingType.Vault.SshKey -> VaultItemCipherType.SSH_KEY is VaultItemListingState.ItemListingType.Vault.SshKey -> VaultItemCipherType.SSH_KEY
is VaultItemListingState.ItemListingType.Vault.Login -> VaultItemCipherType.LOGIN is VaultItemListingState.ItemListingType.Vault.Login -> VaultItemCipherType.LOGIN
is VaultItemListingState.ItemListingType.Vault.Collection -> VaultItemCipherType.LOGIN is VaultItemListingState.ItemListingType.Vault.Collection -> VaultItemCipherType.LOGIN
is VaultItemListingState.ItemListingType.Vault.Folder -> VaultItemCipherType.LOGIN
is VaultItemListingState.ItemListingType.Vault.Trash, is VaultItemListingState.ItemListingType.Vault.Trash,
is VaultItemListingState.ItemListingType.Vault.Folder,
-> { -> {
throw IllegalStateException( throw IllegalStateException(
"Cannot create vault item from this VaultItemListingState!", "Cannot create vault item from this VaultItemListingState!",

View file

@ -20,7 +20,10 @@ const val VAULT_GRAPH_ROUTE: String = "vault_graph"
@Suppress("LongParameterList") @Suppress("LongParameterList")
fun NavGraphBuilder.vaultGraph( fun NavGraphBuilder.vaultGraph(
navController: NavController, navController: NavController,
onNavigateToVaultAddItemScreen: (vaultItemCipherType: VaultItemCipherType) -> Unit, onNavigateToVaultAddItemScreen: (
vaultItemCipherType: VaultItemCipherType,
selectedFolderId: String?,
) -> Unit,
onNavigateToVaultItemScreen: (vaultItemId: String) -> Unit, onNavigateToVaultItemScreen: (vaultItemId: String) -> Unit,
onNavigateToVaultEditItemScreen: (vaultItemId: String) -> Unit, onNavigateToVaultEditItemScreen: (vaultItemId: String) -> Unit,
onNavigateToSearchVault: (searchType: SearchType.Vault) -> Unit, onNavigateToSearchVault: (searchType: SearchType.Vault) -> Unit,
@ -33,7 +36,7 @@ fun NavGraphBuilder.vaultGraph(
) { ) {
vaultDestination( vaultDestination(
onNavigateToVaultAddItemScreen = { onNavigateToVaultAddItemScreen = {
onNavigateToVaultAddItemScreen(VaultItemCipherType.LOGIN) onNavigateToVaultAddItemScreen(VaultItemCipherType.LOGIN, null)
}, },
onNavigateToVaultItemScreen = onNavigateToVaultItemScreen, onNavigateToVaultItemScreen = onNavigateToVaultItemScreen,
onNavigateToVaultEditItemScreen = onNavigateToVaultEditItemScreen, onNavigateToVaultEditItemScreen = onNavigateToVaultEditItemScreen,

View file

@ -41,7 +41,7 @@ class VaultUnlockedNavBarScreenTest : BaseComposeTest() {
VaultUnlockedNavBarScreen( VaultUnlockedNavBarScreen(
viewModel = viewModel, viewModel = viewModel,
navController = fakeNavHostController, navController = fakeNavHostController,
onNavigateToVaultAddItem = {}, onNavigateToVaultAddItem = { _, _ -> },
onNavigateToVaultItem = {}, onNavigateToVaultItem = {},
onNavigateToVaultEditItem = {}, onNavigateToVaultEditItem = {},
onNavigateToAddSend = {}, onNavigateToAddSend = {},

View file

@ -117,7 +117,9 @@ class VaultItemListingScreenTest : BaseComposeTest() {
biometricsManager = biometricsManager, biometricsManager = biometricsManager,
onNavigateBack = { onNavigateBackCalled = true }, onNavigateBack = { onNavigateBackCalled = true },
onNavigateToVaultItem = { onNavigateToVaultItemId = it }, onNavigateToVaultItem = { onNavigateToVaultItemId = it },
onNavigateToVaultAddItemScreen = { onNavigateToVaultAddItemScreenCalled = true }, onNavigateToVaultAddItemScreen = { _, _ ->
onNavigateToVaultAddItemScreenCalled = true
},
onNavigateToAddSendItem = { onNavigateToAddSendScreenCalled = true }, onNavigateToAddSendItem = { onNavigateToAddSendScreenCalled = true },
onNavigateToEditSendItem = { onNavigateToEditSendItemId = it }, onNavigateToEditSendItem = { onNavigateToEditSendItemId = it },
onNavigateToSearch = { onNavigateToSearchType = it }, onNavigateToSearch = { onNavigateToSearchType = it },

View file

@ -942,6 +942,27 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
} }
} }
@Suppress("MaxLineLength")
@Test
fun `AddVaultItemClick inside a folder should emit NavigateToAddVaultItem with a selected folder id`() =
runTest {
val viewModel = createVaultItemListingViewModel(
savedStateHandle = createSavedStateHandleWithVaultItemListingType(
vaultItemListingType = VaultItemListingType.Folder(folderId = "id"),
),
)
viewModel.eventFlow.test {
viewModel.trySendAction(VaultItemListingsAction.AddVaultItemClick)
assertEquals(
VaultItemListingEvent.NavigateToAddVaultItem(
VaultItemCipherType.LOGIN,
selectedFolderId = "id",
),
awaitItem(),
)
}
}
@Test @Test
fun `AddVaultItemClick for vault item should emit NavigateToAddVaultItem`() = runTest { fun `AddVaultItemClick for vault item should emit NavigateToAddVaultItem`() = runTest {
val viewModel = createVaultItemListingViewModel() val viewModel = createVaultItemListingViewModel()

View file

@ -130,6 +130,7 @@ class VaultItemListingStateExtensionsTest {
VaultItemListingState.ItemListingType.Vault.Login, VaultItemListingState.ItemListingType.Vault.Login,
VaultItemListingState.ItemListingType.Vault.Collection(collectionId = "mockId"), VaultItemListingState.ItemListingType.Vault.Collection(collectionId = "mockId"),
VaultItemListingState.ItemListingType.Vault.SshKey, VaultItemListingState.ItemListingType.Vault.SshKey,
VaultItemListingState.ItemListingType.Vault.Folder(folderId = "mockId"),
) )
val result = itemListingTypes.map { it.toVaultItemCipherType() } val result = itemListingTypes.map { it.toVaultItemCipherType() }
@ -142,6 +143,7 @@ class VaultItemListingStateExtensionsTest {
VaultItemCipherType.LOGIN, VaultItemCipherType.LOGIN,
VaultItemCipherType.LOGIN, VaultItemCipherType.LOGIN,
VaultItemCipherType.SSH_KEY, VaultItemCipherType.SSH_KEY,
VaultItemCipherType.LOGIN,
), ),
result, result,
) )
@ -149,15 +151,8 @@ class VaultItemListingStateExtensionsTest {
@Test @Test
fun `toVaultItemCipherType should throw an exception for unsupported ItemListingTypes`() { fun `toVaultItemCipherType should throw an exception for unsupported ItemListingTypes`() {
val itemListingTypes = listOf( assertThrows<IllegalStateException> {
VaultItemListingState.ItemListingType.Vault.Trash, VaultItemListingState.ItemListingType.Vault.Trash.toVaultItemCipherType()
VaultItemListingState.ItemListingType.Vault.Folder(
folderId = "mockId",
),
)
itemListingTypes.forEach {
assertThrows<IllegalStateException> { it.toVaultItemCipherType() }
} }
} }
} }