BIT-1301 Adding icons to collection items (#840)

This commit is contained in:
Oleg Semenenko
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent 82ef39e15d
commit 2d652c8a2e
12 changed files with 247 additions and 10 deletions
@@ -26,7 +26,16 @@ fun createMockDisplayItemForCipher(
uri = "https://vault.bitwarden.com/icons/www.mockuri.com/icon.png",
fallbackIconRes = R.drawable.ic_login_item,
),
extraIconList = emptyList(),
extraIconList = listOf(
IconRes(
iconRes = R.drawable.ic_collection,
contentDescription = R.string.collections.asText(),
),
IconRes(
iconRes = R.drawable.ic_attachment,
contentDescription = R.string.attachments.asText(),
),
),
overflowOptions = listOf(
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
@@ -50,7 +59,16 @@ fun createMockDisplayItemForCipher(
title = "mockName-$number",
subtitle = null,
iconData = IconData.Local(R.drawable.ic_secure_note_item),
extraIconList = emptyList(),
extraIconList = listOf(
IconRes(
iconRes = R.drawable.ic_collection,
contentDescription = R.string.collections.asText(),
),
IconRes(
iconRes = R.drawable.ic_attachment,
contentDescription = R.string.attachments.asText(),
),
),
overflowOptions = listOf(
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
@@ -68,7 +86,16 @@ fun createMockDisplayItemForCipher(
title = "mockName-$number",
subtitle = "er-$number",
iconData = IconData.Local(R.drawable.ic_card_item),
extraIconList = emptyList(),
extraIconList = listOf(
IconRes(
iconRes = R.drawable.ic_collection,
contentDescription = R.string.collections.asText(),
),
IconRes(
iconRes = R.drawable.ic_attachment,
contentDescription = R.string.attachments.asText(),
),
),
overflowOptions = listOf(
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
@@ -89,7 +116,16 @@ fun createMockDisplayItemForCipher(
title = "mockName-$number",
subtitle = "mockFirstName-${number}mockLastName-$number",
iconData = IconData.Local(R.drawable.ic_identity_item),
extraIconList = emptyList(),
extraIconList = listOf(
IconRes(
iconRes = R.drawable.ic_collection,
contentDescription = R.string.collections.asText(),
),
IconRes(
iconRes = R.drawable.ic_attachment,
contentDescription = R.string.attachments.asText(),
),
),
overflowOptions = listOf(
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
@@ -27,7 +27,16 @@ fun createMockDisplayItemForCipher(
"https://vault.bitwarden.com/icons/www.mockuri.com/icon.png",
fallbackIconRes = R.drawable.ic_login_item,
),
extraIconList = emptyList(),
extraIconList = listOf(
IconRes(
iconRes = R.drawable.ic_collection,
contentDescription = R.string.collections.asText(),
),
IconRes(
iconRes = R.drawable.ic_attachment,
contentDescription = R.string.attachments.asText(),
),
),
overflowOptions = listOf(
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
@@ -50,7 +59,16 @@ fun createMockDisplayItemForCipher(
title = "mockName-$number",
subtitle = subtitle,
iconData = IconData.Local(R.drawable.ic_secure_note_item),
extraIconList = emptyList(),
extraIconList = listOf(
IconRes(
iconRes = R.drawable.ic_collection,
contentDescription = R.string.collections.asText(),
),
IconRes(
iconRes = R.drawable.ic_attachment,
contentDescription = R.string.attachments.asText(),
),
),
overflowOptions = listOf(
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
@@ -67,7 +85,16 @@ fun createMockDisplayItemForCipher(
title = "mockName-$number",
subtitle = subtitle,
iconData = IconData.Local(R.drawable.ic_card_item),
extraIconList = emptyList(),
extraIconList = listOf(
IconRes(
iconRes = R.drawable.ic_collection,
contentDescription = R.string.collections.asText(),
),
IconRes(
iconRes = R.drawable.ic_attachment,
contentDescription = R.string.attachments.asText(),
),
),
overflowOptions = listOf(
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
@@ -87,7 +114,16 @@ fun createMockDisplayItemForCipher(
title = "mockName-$number",
subtitle = subtitle,
iconData = IconData.Local(R.drawable.ic_identity_item),
extraIconList = emptyList(),
extraIconList = listOf(
IconRes(
iconRes = R.drawable.ic_collection,
contentDescription = R.string.collections.asText(),
),
IconRes(
iconRes = R.drawable.ic_attachment,
contentDescription = R.string.attachments.asText(),
),
),
overflowOptions = listOf(
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
@@ -7,7 +7,9 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockIdentityVie
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockLoginView
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSecureNoteView
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockUriView
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction
import com.x8bit.bitwarden.ui.vault.model.VaultTrailingIcon
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
@@ -202,4 +204,83 @@ class CipherViewExtensionsTest {
result,
)
}
@Test
fun `toTrailingIcons should return collection icon if collectionId is not empty`() {
val cipher = createMockCipherView(1).copy(
organizationId = null,
attachments = null,
)
val expected = listOf(VaultTrailingIcon.COLLECTION).map {
IconRes(iconRes = it.iconRes, contentDescription = it.contentDescription)
}
val result = cipher.toLabelIcons()
assertEquals(expected, result)
}
@Test
fun `toTrailingIcons should return collection icon if organizationId is not null`() {
val cipher = createMockCipherView(1).copy(
collectionIds = listOf(),
attachments = null,
)
val expected = listOf(VaultTrailingIcon.COLLECTION).map {
IconRes(iconRes = it.iconRes, contentDescription = it.contentDescription)
}
val result = cipher.toLabelIcons()
assertEquals(expected, result)
}
@Test
fun `toTrailingIcons should return attachment icon if attachments is not null`() {
val cipher = createMockCipherView(1).copy(
collectionIds = listOf(),
organizationId = null,
)
val expected = listOf(VaultTrailingIcon.ATTACHMENT).map {
IconRes(iconRes = it.iconRes, contentDescription = it.contentDescription)
}
val result = cipher.toLabelIcons()
assertEquals(expected, result)
}
@Test
fun `toTrailingIcons should return trailing icons if cipher has correct data`() {
val cipher = createMockCipherView(1)
val expected = listOf(
VaultTrailingIcon.COLLECTION,
VaultTrailingIcon.ATTACHMENT,
).map {
IconRes(iconRes = it.iconRes, contentDescription = it.contentDescription)
}
val result = cipher.toLabelIcons()
assertEquals(expected, result)
}
@Test
fun `toTrailingIcons should return empty list if no data requires an extra icon`() {
val cipher = createMockCipherView(1).copy(
collectionIds = listOf(),
organizationId = null,
attachments = null,
)
val expected = listOf<IconRes>()
val result = cipher.toLabelIcons()
assertEquals(expected, result)
}
}