PM-19807: Remove IconResource class (#4963)

This commit is contained in:
David Perez
2025-04-02 15:21:58 +00:00
committed by GitHub
parent b82b1ad570
commit 8e7de92609
28 changed files with 161 additions and 224 deletions
@@ -6,9 +6,9 @@ import com.bitwarden.vault.CipherType
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.platform.components.model.IconData
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
import com.x8bit.bitwarden.ui.platform.feature.search.SearchState
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction
import kotlinx.collections.immutable.persistentListOf
/**
* Create a mock [SearchState.DisplayItem] with a given [number].
@@ -31,13 +31,13 @@ fun createMockDisplayItemForCipher(
uri = "https://vault.bitwarden.com/icons/www.mockuri.com/icon.png",
fallbackIconRes = fallbackIconRes,
),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_collections,
contentDescription = R.string.collections.asText(),
testTag = "CipherInCollectionIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_paperclip,
contentDescription = R.string.attachments.asText(),
testTag = "CipherWithAttachmentsIcon",
@@ -85,13 +85,13 @@ fun createMockDisplayItemForCipher(
subtitle = null,
subtitleTestTag = "CipherSubTitleLabel",
iconData = IconData.Local(R.drawable.ic_note),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_collections,
contentDescription = R.string.collections.asText(),
testTag = "CipherInCollectionIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_paperclip,
contentDescription = R.string.attachments.asText(),
testTag = "CipherWithAttachmentsIcon",
@@ -128,13 +128,13 @@ fun createMockDisplayItemForCipher(
subtitle = "mockBrand-$number, *er-$number",
subtitleTestTag = "CipherSubTitleLabel",
iconData = IconData.Local(R.drawable.ic_payment_card),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_collections,
contentDescription = R.string.collections.asText(),
testTag = "CipherInCollectionIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_paperclip,
contentDescription = R.string.attachments.asText(),
testTag = "CipherWithAttachmentsIcon",
@@ -177,13 +177,13 @@ fun createMockDisplayItemForCipher(
subtitle = "mockFirstName-${number}mockLastName-$number",
subtitleTestTag = "CipherSubTitleLabel",
iconData = IconData.Local(R.drawable.ic_id_card),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_collections,
contentDescription = R.string.collections.asText(),
testTag = "CipherInCollectionIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_paperclip,
contentDescription = R.string.attachments.asText(),
testTag = "CipherWithAttachmentsIcon",
@@ -217,8 +217,8 @@ fun createMockDisplayItemForCipher(
subtitle = "mockPublicKey-$number",
subtitleTestTag = "CipherSubTitleLabel",
iconData = IconData.Local(R.drawable.ic_ssh_key),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_collections,
contentDescription = R.string.collections.asText(),
testTag = "CipherInCollectionIcon",
@@ -262,13 +262,13 @@ fun createMockDisplayItemForSend(
subtitle = "Oct 27, 2023, 12:00 PM",
subtitleTestTag = "SendDateLabel",
iconData = IconData.Local(R.drawable.ic_file),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_key,
contentDescription = R.string.password.asText(),
testTag = "PasswordProtectedSendIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_send_max_access_count_reached,
contentDescription = R.string.maximum_access_count_reached.asText(),
testTag = "MaxAccessSendIcon",
@@ -302,13 +302,13 @@ fun createMockDisplayItemForSend(
subtitle = "Oct 27, 2023, 12:00 PM",
subtitleTestTag = "SendDateLabel",
iconData = IconData.Local(R.drawable.ic_file_text),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_key,
contentDescription = R.string.password.asText(),
testTag = "PasswordProtectedSendIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_send_max_access_count_reached,
contentDescription = R.string.maximum_access_count_reached.asText(),
testTag = "MaxAccessSendIcon",
@@ -35,6 +35,7 @@ import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import org.junit.Assert.assertEquals
@@ -782,7 +783,7 @@ private val DEFAULT_SEND_ITEM: SendState.ViewState.Content.SendItem =
name = "mockName-1",
deletionDate = "1",
type = SendState.ViewState.Content.SendItem.Type.FILE,
iconList = emptyList(),
iconList = persistentListOf(),
shareUrl = "www.test.com/#/send/mockAccessId-1/mockKey-1",
hasPassword = true,
)
@@ -797,7 +798,7 @@ private val DEFAULT_CONTENT_VIEW_STATE: SendState.ViewState.Content = SendState.
name = "mockName-2",
deletionDate = "1",
type = SendState.ViewState.Content.SendItem.Type.TEXT,
iconList = emptyList(),
iconList = persistentListOf(),
shareUrl = "www.test.com/#/send/mockAccessId-1/mockKey-1",
hasPassword = true,
),
@@ -4,12 +4,14 @@ import com.bitwarden.send.SendType
import com.bitwarden.send.SendView
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
import com.x8bit.bitwarden.data.vault.repository.model.SendData
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
import com.x8bit.bitwarden.ui.platform.components.model.IconData
import com.x8bit.bitwarden.ui.tools.feature.send.SendState
import com.x8bit.bitwarden.ui.tools.feature.send.model.SendStatusIcon
import io.mockk.every
import io.mockk.mockkStatic
import io.mockk.unmockkStatic
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
@@ -100,24 +102,24 @@ class SendDataExtensionsTest {
private const val DEFAULT_BASE_URL: String = "www.test.com/"
private val DEFAULT_SEND_STATUS_ICONS: List<IconRes> = listOf(
IconRes(
private val DEFAULT_SEND_STATUS_ICONS: ImmutableList<IconData> = persistentListOf(
IconData.Local(
iconRes = SendStatusIcon.DISABLED.iconRes,
contentDescription = SendStatusIcon.DISABLED.contentDescription,
),
IconRes(
IconData.Local(
iconRes = SendStatusIcon.PASSWORD.iconRes,
contentDescription = SendStatusIcon.PASSWORD.contentDescription,
),
IconRes(
IconData.Local(
iconRes = SendStatusIcon.MAX_ACCESS_COUNT_REACHED.iconRes,
contentDescription = SendStatusIcon.MAX_ACCESS_COUNT_REACHED.contentDescription,
),
IconRes(
IconData.Local(
iconRes = SendStatusIcon.EXPIRED.iconRes,
contentDescription = SendStatusIcon.EXPIRED.contentDescription,
),
IconRes(
IconData.Local(
iconRes = SendStatusIcon.PENDING_DELETE.iconRes,
contentDescription = SendStatusIcon.PENDING_DELETE.contentDescription,
),
@@ -1,9 +1,11 @@
package com.x8bit.bitwarden.ui.tools.feature.send.util
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
import com.x8bit.bitwarden.ui.platform.components.model.IconData
import com.x8bit.bitwarden.ui.tools.feature.send.model.SendStatusIcon
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.time.Clock
@@ -58,7 +60,7 @@ class SendViewExtensionsTest {
val result = sendView.toLabelIcons(clock)
assertEquals(emptyList<IconRes>(), result)
assertEquals(emptyList<IconData.Local>(), result)
}
@Suppress("MaxLineLength")
@@ -114,28 +116,28 @@ class SendViewExtensionsTest {
}
}
private val ALL_SEND_STATUS_ICONS: List<IconRes> = listOf(
IconRes(
private val ALL_SEND_STATUS_ICONS: ImmutableList<IconData> = persistentListOf(
IconData.Local(
iconRes = SendStatusIcon.DISABLED.iconRes,
contentDescription = SendStatusIcon.DISABLED.contentDescription,
testTag = SendStatusIcon.DISABLED.testTag,
),
IconRes(
IconData.Local(
iconRes = SendStatusIcon.PASSWORD.iconRes,
contentDescription = SendStatusIcon.PASSWORD.contentDescription,
testTag = SendStatusIcon.PASSWORD.testTag,
),
IconRes(
IconData.Local(
iconRes = SendStatusIcon.MAX_ACCESS_COUNT_REACHED.iconRes,
contentDescription = SendStatusIcon.MAX_ACCESS_COUNT_REACHED.contentDescription,
testTag = SendStatusIcon.MAX_ACCESS_COUNT_REACHED.testTag,
),
IconRes(
IconData.Local(
iconRes = SendStatusIcon.EXPIRED.iconRes,
contentDescription = SendStatusIcon.EXPIRED.contentDescription,
testTag = SendStatusIcon.EXPIRED.testTag,
),
IconRes(
IconData.Local(
iconRes = SendStatusIcon.PENDING_DELETE.iconRes,
contentDescription = SendStatusIcon.PENDING_DELETE.contentDescription,
testTag = SendStatusIcon.PENDING_DELETE.testTag,
@@ -32,7 +32,6 @@ import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.platform.base.util.toHostOrPathOrNull
import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary
import com.x8bit.bitwarden.ui.platform.components.model.IconData
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
import com.x8bit.bitwarden.ui.platform.feature.search.model.SearchType
import com.x8bit.bitwarden.ui.platform.manager.biometrics.BiometricsManager
import com.x8bit.bitwarden.ui.platform.manager.exit.ExitManager
@@ -2275,24 +2274,24 @@ private fun createDisplayItem(number: Int): VaultItemListingState.DisplayItem =
subtitle = "mockSubtitle-$number",
subtitleTestTag = "SendDateLabel",
iconData = IconData.Local(R.drawable.ic_payment_card),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_send_disabled,
contentDescription = R.string.disabled.asText(),
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_key,
contentDescription = R.string.password.asText(),
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_send_max_access_count_reached,
contentDescription = R.string.maximum_access_count_reached.asText(),
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_send_expired,
contentDescription = R.string.expired.asText(),
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_send_pending_delete,
contentDescription = R.string.pending_delete.asText(),
),
@@ -2323,7 +2322,7 @@ private fun createCipherDisplayItem(number: Int): VaultItemListingState.DisplayI
subtitle = "mockSubtitle-$number",
subtitleTestTag = "CipherSubTitleLabel",
iconData = IconData.Local(R.drawable.ic_vault),
extraIconList = emptyList(),
extraIconList = persistentListOf(),
overflowOptions = listOf(
ListingItemOverflowAction.VaultAction.EditClick(
cipherId = "mockId-$number",
@@ -5,9 +5,9 @@ import com.bitwarden.vault.CipherType
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.platform.components.model.IconData
import com.x8bit.bitwarden.ui.platform.components.model.IconRes
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.VaultItemListingState
import com.x8bit.bitwarden.ui.vault.feature.itemlisting.model.ListingItemOverflowAction
import kotlinx.collections.immutable.persistentListOf
/**
* Create a mock [VaultItemListingState.DisplayItem] with a given [number].
@@ -35,13 +35,13 @@ fun createMockDisplayItemForCipher(
uri = "https://vault.bitwarden.com/icons/www.mockuri.com/icon.png",
fallbackIconRes = R.drawable.ic_globe,
),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_collections,
contentDescription = R.string.collections.asText(),
testTag = "CipherInCollectionIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_paperclip,
contentDescription = R.string.attachments.asText(),
testTag = "CipherWithAttachmentsIcon",
@@ -92,13 +92,13 @@ fun createMockDisplayItemForCipher(
subtitle = subtitle,
subtitleTestTag = "CipherSubTitleLabel",
iconData = IconData.Local(R.drawable.ic_note),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_collections,
contentDescription = R.string.collections.asText(),
testTag = "CipherInCollectionIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_paperclip,
contentDescription = R.string.attachments.asText(),
testTag = "CipherWithAttachmentsIcon",
@@ -138,13 +138,13 @@ fun createMockDisplayItemForCipher(
subtitle = subtitle,
subtitleTestTag = "CipherSubTitleLabel",
iconData = IconData.Local(R.drawable.ic_payment_card),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_collections,
contentDescription = R.string.collections.asText(),
testTag = "CipherInCollectionIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_paperclip,
contentDescription = R.string.attachments.asText(),
testTag = "CipherWithAttachmentsIcon",
@@ -190,13 +190,13 @@ fun createMockDisplayItemForCipher(
subtitle = subtitle,
subtitleTestTag = "CipherSubTitleLabel",
iconData = IconData.Local(R.drawable.ic_id_card),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_collections,
contentDescription = R.string.collections.asText(),
testTag = "CipherInCollectionIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_paperclip,
contentDescription = R.string.attachments.asText(),
testTag = "CipherWithAttachmentsIcon",
@@ -233,13 +233,13 @@ fun createMockDisplayItemForCipher(
subtitle = subtitle,
subtitleTestTag = "CipherSubTitleLabel",
iconData = IconData.Local(R.drawable.ic_ssh_key),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_collections,
contentDescription = R.string.collections.asText(),
testTag = "CipherInCollectionIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_paperclip,
contentDescription = R.string.attachments.asText(),
testTag = "CipherWithAttachmentsIcon",
@@ -286,13 +286,13 @@ fun createMockDisplayItemForSend(
subtitle = "Oct 27, 2023, 12:00 PM",
subtitleTestTag = "SendDateLabel",
iconData = IconData.Local(R.drawable.ic_file),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_key,
contentDescription = R.string.password.asText(),
testTag = "PasswordProtectedSendIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_send_max_access_count_reached,
contentDescription = R.string.maximum_access_count_reached.asText(),
testTag = "MaxAccessSendIcon",
@@ -329,13 +329,13 @@ fun createMockDisplayItemForSend(
subtitle = "Oct 27, 2023, 12:00 PM",
subtitleTestTag = "SendDateLabel",
iconData = IconData.Local(R.drawable.ic_file_text),
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_key,
contentDescription = R.string.password.asText(),
testTag = "PasswordProtectedSendIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_send_max_access_count_reached,
contentDescription = R.string.maximum_access_count_reached.asText(),
testTag = "MaxAccessSendIcon",
@@ -7,7 +7,7 @@ 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.platform.components.model.IconData
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
@@ -396,7 +396,7 @@ class CipherViewExtensionsTest {
)
val expected = listOf(VaultTrailingIcon.COLLECTION).map {
IconRes(
IconData.Local(
iconRes = it.iconRes,
contentDescription = it.contentDescription,
testTag = it.testTag,
@@ -416,7 +416,7 @@ class CipherViewExtensionsTest {
)
val expected = listOf(VaultTrailingIcon.COLLECTION).map {
IconRes(
IconData.Local(
iconRes = it.iconRes,
contentDescription = it.contentDescription,
testTag = it.testTag,
@@ -436,7 +436,7 @@ class CipherViewExtensionsTest {
)
val expected = listOf(VaultTrailingIcon.ATTACHMENT).map {
IconRes(
IconData.Local(
iconRes = it.iconRes,
contentDescription = it.contentDescription,
testTag = it.testTag,
@@ -456,7 +456,7 @@ class CipherViewExtensionsTest {
VaultTrailingIcon.COLLECTION,
VaultTrailingIcon.ATTACHMENT,
).map {
IconRes(
IconData.Local(
iconRes = it.iconRes,
contentDescription = it.contentDescription,
testTag = it.testTag,
@@ -476,7 +476,7 @@ class CipherViewExtensionsTest {
attachments = null,
)
val expected = listOf<IconRes>()
val expected = listOf<IconData>()
val result = cipher.toLabelIcons()
@@ -17,7 +17,6 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSshKeyView
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.platform.components.model.IconData
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.feature.util.toLabelIcons
import com.x8bit.bitwarden.ui.vault.feature.util.toOverflowActions
@@ -27,6 +26,7 @@ import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.unmockkStatic
import kotlinx.collections.immutable.persistentListOf
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.time.Clock
@@ -1003,13 +1003,13 @@ private fun createMockSshKeyVaultItem(number: Int): VaultState.ViewState.VaultIt
),
startIcon = IconData.Local(iconRes = R.drawable.ic_ssh_key),
startIconTestTag = "SshKeyCipherIcon",
extraIconList = listOf(
IconRes(
extraIconList = persistentListOf(
IconData.Local(
iconRes = R.drawable.ic_collections,
contentDescription = R.string.collections.asText(),
testTag = "CipherInCollectionIcon",
),
IconRes(
IconData.Local(
iconRes = R.drawable.ic_paperclip,
contentDescription = R.string.attachments.asText(),
testTag = "CipherWithAttachmentsIcon",