mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-2009 Add support for nested collections (#1111)
This commit is contained in:
committed by
Álison Fernandes
parent
5e1328eecb
commit
3b33360e58
+2
-2
@@ -5,12 +5,12 @@ import com.bitwarden.core.CollectionView
|
||||
/**
|
||||
* Create a mock [CollectionView] with a given [number].
|
||||
*/
|
||||
fun createMockCollectionView(number: Int): CollectionView =
|
||||
fun createMockCollectionView(number: Int, name: String? = null): CollectionView =
|
||||
CollectionView(
|
||||
id = "mockId-$number",
|
||||
organizationId = "mockOrganizationId-$number",
|
||||
hidePasswords = false,
|
||||
name = "mockName-$number",
|
||||
name = name ?: "mockName-$number",
|
||||
externalId = "mockExternalId-$number",
|
||||
readOnly = false,
|
||||
)
|
||||
|
||||
+142
-27
@@ -6,8 +6,6 @@ import androidx.compose.ui.test.assertIsNotDisplayed
|
||||
import androidx.compose.ui.test.assertTextEquals
|
||||
import androidx.compose.ui.test.filterToOne
|
||||
import androidx.compose.ui.test.hasAnyAncestor
|
||||
import androidx.compose.ui.test.hasScrollToNodeAction
|
||||
import androidx.compose.ui.test.hasText
|
||||
import androidx.compose.ui.test.isDialog
|
||||
import androidx.compose.ui.test.isDisplayed
|
||||
import androidx.compose.ui.test.isPopup
|
||||
@@ -15,7 +13,6 @@ import androidx.compose.ui.test.onAllNodesWithText
|
||||
import androidx.compose.ui.test.onNodeWithContentDescription
|
||||
import androidx.compose.ui.test.onNodeWithText
|
||||
import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performScrollToNode
|
||||
import androidx.compose.ui.test.performTextInput
|
||||
import androidx.core.net.toUri
|
||||
import com.x8bit.bitwarden.R
|
||||
@@ -39,6 +36,7 @@ import com.x8bit.bitwarden.ui.util.assertNoDialogExists
|
||||
import com.x8bit.bitwarden.ui.util.assertSwitcherIsDisplayed
|
||||
import com.x8bit.bitwarden.ui.util.assertSwitcherIsNotDisplayed
|
||||
import com.x8bit.bitwarden.ui.util.isProgressBar
|
||||
import com.x8bit.bitwarden.ui.util.onNodeWithTextAfterScroll
|
||||
import com.x8bit.bitwarden.ui.util.performAccountClick
|
||||
import com.x8bit.bitwarden.ui.util.performAccountIconClick
|
||||
import com.x8bit.bitwarden.ui.util.performAccountLongClick
|
||||
@@ -566,14 +564,12 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
name = "test", id = "1", count = 0,
|
||||
),
|
||||
),
|
||||
displayCollectionList = emptyList(),
|
||||
),
|
||||
)
|
||||
}
|
||||
composeTestRule
|
||||
.onNode(hasScrollToNodeAction())
|
||||
.performScrollToNode(hasText(folders))
|
||||
composeTestRule
|
||||
.onNodeWithText(text = folders)
|
||||
.onNodeWithTextAfterScroll(text = folders)
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@@ -592,14 +588,12 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
displayFolderList = listOf(
|
||||
VaultItemListingState.FolderDisplayItem(name = "test", id = "1", count = 0),
|
||||
),
|
||||
displayCollectionList = emptyList(),
|
||||
),
|
||||
)
|
||||
}
|
||||
composeTestRule
|
||||
.onNode(hasScrollToNodeAction())
|
||||
.performScrollToNode(hasText(folders))
|
||||
composeTestRule
|
||||
.onNodeWithText(text = folders)
|
||||
.onNodeWithTextAfterScroll(text = folders)
|
||||
.assertIsDisplayed()
|
||||
.assertTextEquals(folders, 1.toString())
|
||||
|
||||
@@ -624,15 +618,13 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
count = 0,
|
||||
),
|
||||
),
|
||||
displayCollectionList = emptyList(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNode(hasScrollToNodeAction())
|
||||
.performScrollToNode(hasText(folders))
|
||||
composeTestRule
|
||||
.onNodeWithText(text = folders)
|
||||
.onNodeWithTextAfterScroll(text = folders)
|
||||
.assertIsDisplayed()
|
||||
.assertTextEquals(folders, 3.toString())
|
||||
}
|
||||
@@ -648,6 +640,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = emptyList(),
|
||||
displayFolderList = listOf(
|
||||
VaultItemListingState.FolderDisplayItem(
|
||||
@@ -665,6 +658,123 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Collections text should be displayed according to state`() {
|
||||
val collectionName = "Collections"
|
||||
mutableStateFlow.update { DEFAULT_STATE }
|
||||
composeTestRule
|
||||
.onNodeWithText(text = collectionName)
|
||||
.assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayItemList = emptyList(),
|
||||
displayFolderList = emptyList(),
|
||||
displayCollectionList = listOf(
|
||||
VaultItemListingState.CollectionDisplayItem(
|
||||
name = "Collection",
|
||||
id = "1",
|
||||
count = 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
composeTestRule
|
||||
.onNodeWithTextAfterScroll(collectionName)
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Collection text count should be displayed according to state`() {
|
||||
val collections = "Collections"
|
||||
mutableStateFlow.update { DEFAULT_STATE }
|
||||
composeTestRule
|
||||
.onNodeWithText(text = collections)
|
||||
.assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayItemList = emptyList(),
|
||||
displayFolderList = emptyList(),
|
||||
displayCollectionList = listOf(
|
||||
VaultItemListingState.CollectionDisplayItem(
|
||||
name = "Collection",
|
||||
id = "1",
|
||||
count = 0,
|
||||
),
|
||||
VaultItemListingState.CollectionDisplayItem(
|
||||
name = "Collection2",
|
||||
id = "2",
|
||||
count = 0,
|
||||
),
|
||||
VaultItemListingState.CollectionDisplayItem(
|
||||
name = "Collection3",
|
||||
id = "3",
|
||||
count = 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
composeTestRule
|
||||
.onNodeWithTextAfterScroll(text = collections)
|
||||
.assertIsDisplayed()
|
||||
.assertTextEquals(collections, 3.toString())
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayItemList = emptyList(),
|
||||
displayFolderList = emptyList(),
|
||||
displayCollectionList = listOf(
|
||||
VaultItemListingState.CollectionDisplayItem(
|
||||
name = "Collection",
|
||||
id = "1",
|
||||
count = 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithTextAfterScroll(text = collections)
|
||||
.assertIsDisplayed()
|
||||
.assertTextEquals(collections, 1.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `collectionDisplayItems should be displayed according to state`() {
|
||||
val collectionName = "TestCollection"
|
||||
mutableStateFlow.update { DEFAULT_STATE }
|
||||
composeTestRule
|
||||
.onNodeWithText(text = collectionName)
|
||||
.assertDoesNotExist()
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayItemList = emptyList(),
|
||||
displayFolderList = emptyList(),
|
||||
displayCollectionList = listOf(
|
||||
VaultItemListingState.CollectionDisplayItem(
|
||||
name = collectionName,
|
||||
id = "1",
|
||||
count = 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText(text = collectionName)
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Items text should be displayed according to state`() {
|
||||
val items = "Items"
|
||||
@@ -676,6 +786,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createDisplayItem(number = 1),
|
||||
),
|
||||
@@ -684,10 +795,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
)
|
||||
}
|
||||
composeTestRule
|
||||
.onNode(hasScrollToNodeAction())
|
||||
.performScrollToNode(hasText(items))
|
||||
composeTestRule
|
||||
.onNodeWithText(text = items)
|
||||
.onNodeWithTextAfterScroll(text = items)
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@@ -702,6 +810,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createDisplayItem(number = 1),
|
||||
),
|
||||
@@ -710,16 +819,14 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
)
|
||||
}
|
||||
composeTestRule
|
||||
.onNode(hasScrollToNodeAction())
|
||||
.performScrollToNode(hasText(items))
|
||||
composeTestRule
|
||||
.onNodeWithText(text = items)
|
||||
.onNodeWithTextAfterScroll(text = items)
|
||||
.assertIsDisplayed()
|
||||
.assertTextEquals(items, 1.toString())
|
||||
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createDisplayItem(number = 1),
|
||||
createDisplayItem(number = 2),
|
||||
@@ -732,10 +839,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNode(hasScrollToNodeAction())
|
||||
.performScrollToNode(hasText(items))
|
||||
composeTestRule
|
||||
.onNodeWithText(text = items)
|
||||
.onNodeWithTextAfterScroll(text = items)
|
||||
.assertIsDisplayed()
|
||||
.assertTextEquals(items, 4.toString())
|
||||
}
|
||||
@@ -745,6 +849,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createDisplayItem(number = 1),
|
||||
),
|
||||
@@ -767,6 +872,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createDisplayItem(number = 1)
|
||||
.copy(
|
||||
@@ -794,6 +900,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createDisplayItem(number = 1)
|
||||
.copy(
|
||||
@@ -845,6 +952,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createDisplayItem(number = 1)
|
||||
.copy(
|
||||
@@ -875,6 +983,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createDisplayItem(number = 1)
|
||||
.copy(
|
||||
@@ -1015,6 +1124,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
it.copy(
|
||||
itemListingType = VaultItemListingState.ItemListingType.Vault.Login,
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(createCipherDisplayItem(number = 1)),
|
||||
displayFolderList = emptyList(),
|
||||
),
|
||||
@@ -1052,6 +1162,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
it.copy(
|
||||
itemListingType = VaultItemListingState.ItemListingType.Vault.Login,
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createCipherDisplayItem(number = 1)
|
||||
.copy(shouldShowMasterPasswordReprompt = true),
|
||||
@@ -1083,6 +1194,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
it.copy(
|
||||
itemListingType = VaultItemListingState.ItemListingType.Send.SendFile,
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(createDisplayItem(number = 1)),
|
||||
displayFolderList = emptyList(),
|
||||
),
|
||||
@@ -1109,6 +1221,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(createDisplayItem(number = number)),
|
||||
displayFolderList = emptyList(),
|
||||
),
|
||||
@@ -1133,6 +1246,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(createDisplayItem(number = number)),
|
||||
displayFolderList = emptyList(),
|
||||
),
|
||||
@@ -1222,6 +1336,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(createDisplayItem(number = 1)),
|
||||
displayFolderList = emptyList(),
|
||||
),
|
||||
|
||||
+18
@@ -305,6 +305,7 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
} returns ValidatePasswordResult.Error
|
||||
val initialState = createVaultItemListingState(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createMockDisplayItemForCipher(number = 1),
|
||||
),
|
||||
@@ -354,6 +355,7 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
val initialState = createVaultItemListingState(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createMockDisplayItemForCipher(number = 1),
|
||||
),
|
||||
@@ -485,6 +487,17 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `CollectionClick for vault item should emit NavigateToCollectionItem`() = runTest {
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
val testId = "1"
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(VaultItemListingsAction.CollectionClick(testId))
|
||||
assertEquals(VaultItemListingEvent.NavigateToCollectionItem(testId), awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `RefreshClick should sync`() = runTest {
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
@@ -842,6 +855,7 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
assertEquals(
|
||||
createVaultItemListingState(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createMockDisplayItemForCipher(number = 1),
|
||||
),
|
||||
@@ -889,6 +903,7 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
assertEquals(
|
||||
createVaultItemListingState(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createMockDisplayItemForCipher(number = 1).copy(isAutofill = true),
|
||||
),
|
||||
@@ -990,6 +1005,7 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
assertEquals(
|
||||
createVaultItemListingState(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createMockDisplayItemForCipher(number = 1),
|
||||
),
|
||||
@@ -1097,6 +1113,7 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
assertEquals(
|
||||
createVaultItemListingState(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createMockDisplayItemForCipher(number = 1),
|
||||
),
|
||||
@@ -1211,6 +1228,7 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
assertEquals(
|
||||
createVaultItemListingState(
|
||||
viewState = VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createMockDisplayItemForCipher(number = 1),
|
||||
),
|
||||
|
||||
+49
-1
@@ -397,6 +397,7 @@ class VaultItemListingDataExtensionsTest {
|
||||
|
||||
assertEquals(
|
||||
VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createMockDisplayItemForCipher(
|
||||
number = 1,
|
||||
@@ -469,6 +470,7 @@ class VaultItemListingDataExtensionsTest {
|
||||
|
||||
assertEquals(
|
||||
VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createMockDisplayItemForCipher(
|
||||
number = 1,
|
||||
@@ -582,6 +584,7 @@ class VaultItemListingDataExtensionsTest {
|
||||
|
||||
assertEquals(
|
||||
VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(
|
||||
createMockDisplayItemForSend(number = 1, sendType = SendType.FILE),
|
||||
createMockDisplayItemForSend(number = 2, sendType = SendType.TEXT),
|
||||
@@ -683,7 +686,7 @@ class VaultItemListingDataExtensionsTest {
|
||||
@Test
|
||||
fun `toViewState should properly filter and return the correct folders`() {
|
||||
val vaultData = VaultData(
|
||||
listOf(createMockCipherView(number = 1)),
|
||||
cipherViewList = listOf(createMockCipherView(number = 1)),
|
||||
collectionViewList = emptyList(),
|
||||
folderViewList = listOf(
|
||||
FolderView("1", "test", clock.instant()),
|
||||
@@ -705,6 +708,7 @@ class VaultItemListingDataExtensionsTest {
|
||||
|
||||
assertEquals(
|
||||
VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = emptyList(),
|
||||
displayItemList = listOf(),
|
||||
displayFolderList = listOf(
|
||||
VaultItemListingState.FolderDisplayItem(
|
||||
@@ -717,4 +721,48 @@ class VaultItemListingDataExtensionsTest {
|
||||
actual,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toViewState should properly filter and return the correct collections`() {
|
||||
val vaultData = VaultData(
|
||||
cipherViewList = emptyList(),
|
||||
collectionViewList = listOf(
|
||||
createMockCollectionView(1, "test"),
|
||||
createMockCollectionView(2, "test/test"),
|
||||
createMockCollectionView(3, "Collection/test"),
|
||||
createMockCollectionView(4, "test/Collection"),
|
||||
createMockCollectionView(5, "Collection"),
|
||||
),
|
||||
folderViewList = emptyList(),
|
||||
sendViewList = emptyList(),
|
||||
)
|
||||
|
||||
val actual = vaultData.toViewState(
|
||||
isIconLoadingDisabled = false,
|
||||
baseIconUrl = Environment.Us.environmentUrlData.baseIconUrl,
|
||||
autofillSelectionData = null,
|
||||
itemListingType = VaultItemListingState.ItemListingType.Vault.Collection("mockId-1"),
|
||||
vaultFilterType = VaultFilterType.AllVaults,
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
VaultItemListingState.ViewState.Content(
|
||||
displayCollectionList = listOf(
|
||||
VaultItemListingState.CollectionDisplayItem(
|
||||
id = "mockId-2",
|
||||
name = "test",
|
||||
count = 0,
|
||||
),
|
||||
VaultItemListingState.CollectionDisplayItem(
|
||||
id = "mockId-4",
|
||||
name = "Collection",
|
||||
count = 0,
|
||||
),
|
||||
),
|
||||
displayItemList = emptyList(),
|
||||
displayFolderList = emptyList(),
|
||||
),
|
||||
actual,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
package com.x8bit.bitwarden.ui.vault.feature.util
|
||||
|
||||
import com.bitwarden.core.CollectionView
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockCollectionView
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class CollectionViewExtensionsTest {
|
||||
|
||||
@Test
|
||||
fun `getCollections should get the collections for a collectionId with the correct names`() {
|
||||
val collectionList: List<CollectionView> = listOf(
|
||||
createMockCollectionView(number = 1, name = "test"),
|
||||
createMockCollectionView(number = 2, name = "test/test"),
|
||||
createMockCollectionView(number = 3, name = "test/Collection"),
|
||||
createMockCollectionView(number = 4, name = "test/test/test"),
|
||||
createMockCollectionView(number = 5, name = "Collection"),
|
||||
)
|
||||
|
||||
val expected = listOf(
|
||||
createMockCollectionView(number = 2, name = "test"),
|
||||
createMockCollectionView(number = 3, name = "Collection"),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected,
|
||||
collectionList.getCollections("mockId-1"),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getFilteredCollections should properly filter out sub collections in a list`() {
|
||||
val collectionList: List<CollectionView> = listOf(
|
||||
createMockCollectionView(number = 1, name = "test"),
|
||||
createMockCollectionView(number = 2, name = "test/test"),
|
||||
createMockCollectionView(number = 3, name = "test/Collection"),
|
||||
createMockCollectionView(number = 4, name = "test/test/test"),
|
||||
createMockCollectionView(number = 5, name = "Collection"),
|
||||
)
|
||||
|
||||
val expected = listOf(
|
||||
createMockCollectionView(number = 1, name = "test"),
|
||||
createMockCollectionView(number = 5, name = "Collection"),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected,
|
||||
collectionList.getFilteredCollections(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toCollectionDisplayName should return the correct name`() {
|
||||
val collectionName = "Collection/test/2"
|
||||
|
||||
val collectionList: List<CollectionView> = listOf(
|
||||
createMockCollectionView(number = 1, name = "Collection/test"),
|
||||
createMockCollectionView(number = 2, name = "test/test"),
|
||||
createMockCollectionView(number = 3, name = "test/Collection"),
|
||||
createMockCollectionView(number = 4, name = collectionName),
|
||||
createMockCollectionView(number = 5, name = "Collection"),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
"2",
|
||||
collectionName.toCollectionDisplayName(collectionList),
|
||||
)
|
||||
}
|
||||
}
|
||||
+20
-3
@@ -494,10 +494,16 @@ class VaultDataExtensionsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toViewState should properly filter nested folders out`() {
|
||||
fun `toViewState should properly filter nested items out`() {
|
||||
val vaultData = VaultData(
|
||||
listOf(createMockCipherView(number = 1)),
|
||||
collectionViewList = emptyList(),
|
||||
collectionViewList = listOf(
|
||||
createMockCollectionView(1, "test"),
|
||||
createMockCollectionView(2, "test/test"),
|
||||
createMockCollectionView(3, "Collection/test"),
|
||||
createMockCollectionView(4, "test/Collection"),
|
||||
createMockCollectionView(5, "Collection"),
|
||||
),
|
||||
folderViewList = listOf(
|
||||
FolderView("1", "test", clock.instant()),
|
||||
FolderView("2", "test/test", clock.instant()),
|
||||
@@ -522,6 +528,18 @@ class VaultDataExtensionsTest {
|
||||
identityItemsCount = 0,
|
||||
secureNoteItemsCount = 0,
|
||||
favoriteItems = listOf(),
|
||||
collectionItems = listOf(
|
||||
VaultState.ViewState.CollectionItem(
|
||||
id = "mockId-1",
|
||||
name = "test",
|
||||
itemCount = 1,
|
||||
),
|
||||
VaultState.ViewState.CollectionItem(
|
||||
id = "mockId-5",
|
||||
name = "Collection",
|
||||
itemCount = 0,
|
||||
),
|
||||
),
|
||||
folderItems = listOf(
|
||||
VaultState.ViewState.FolderItem(
|
||||
id = "1",
|
||||
@@ -540,7 +558,6 @@ class VaultDataExtensionsTest {
|
||||
),
|
||||
|
||||
),
|
||||
collectionItems = listOf(),
|
||||
noFolderItems = listOf(),
|
||||
trashItemsCount = 0,
|
||||
totpItemsCount = 1,
|
||||
|
||||
Reference in New Issue
Block a user