Skip to content

Commit

Permalink
[PM-9439] Use passkey icon for items with FIDO2 credentials in search…
Browse files Browse the repository at this point in the history
… results (#4541)
  • Loading branch information
SaintPatrck authored Jan 9, 2025
1 parent f2c87d1 commit 0a8d1fa
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.bitwarden.vault.CipherView
import com.bitwarden.vault.CollectionView
import com.bitwarden.vault.FolderView
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.autofill.util.isActiveWithFido2Credentials
import com.x8bit.bitwarden.data.platform.util.SpecialCharWithPrecedenceComparator
import com.x8bit.bitwarden.data.platform.util.subtitle
import com.x8bit.bitwarden.ui.platform.base.util.asText
Expand Down Expand Up @@ -247,7 +248,7 @@ private fun CipherView.toIconData(
login?.uris.toLoginIconData(
baseIconUrl = baseIconUrl,
isIconLoadingDisabled = isIconLoadingDisabled,
usePasskeyDefaultIcon = false,
usePasskeyDefaultIcon = this.isActiveWithFido2Credentials,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.bitwarden.vault.CollectionView
import com.bitwarden.vault.FolderView
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockCipherView
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSdkFido2CredentialList
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
import com.x8bit.bitwarden.ui.platform.base.util.asText
import com.x8bit.bitwarden.ui.platform.feature.search.SearchState
Expand Down Expand Up @@ -458,6 +459,43 @@ class SearchTypeDataExtensionsTest {
)
}

@Test
fun `CipherViews toViewState should usePasskeyDefaultIcon based on cipher fido2 credentials`() {
mockkStatic(Uri::parse)
every { Uri.parse(any()) } returns mockk {
every { host } returns "www.mockuri.com"
}
val result = listOf(
createMockCipherView(
number = 1,
fido2Credentials = createMockSdkFido2CredentialList(number = 1),
),
createMockCipherView(number = 2),
).toViewState(
searchTerm = "mock",
baseIconUrl = "https://vault.bitwarden.com/icons",
isIconLoadingDisabled = false,
hasMasterPassword = true,
isAutofill = false,
isPremiumUser = true,
isTotp = false,
organizationPremiumStatusMap = emptyMap(),
)

assertEquals(
SearchState.ViewState.Content(
displayItems = listOf(
createMockDisplayItemForCipher(
number = 1,
fallbackIconRes = R.drawable.ic_bw_passkey,
),
createMockDisplayItemForCipher(number = 2),
),
),
result,
)
}

@Test
fun `SendViews filterAndOrganize should return empty list when search term is blank`() {
val sends = listOf(createMockSendView(number = 1))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.x8bit.bitwarden.ui.platform.feature.search.util

import androidx.annotation.DrawableRes
import com.bitwarden.send.SendType
import com.bitwarden.vault.CipherType
import com.x8bit.bitwarden.R
Expand All @@ -16,6 +17,7 @@ fun createMockDisplayItemForCipher(
number: Int,
cipherType: CipherType = CipherType.LOGIN,
isTotp: Boolean = false,
@DrawableRes fallbackIconRes: Int = R.drawable.ic_globe,
): SearchState.DisplayItem =
when (cipherType) {
CipherType.LOGIN -> {
Expand All @@ -27,7 +29,7 @@ fun createMockDisplayItemForCipher(
subtitleTestTag = "CipherSubTitleLabel",
iconData = IconData.Network(
uri = "https://vault.bitwarden.com/icons/www.mockuri.com/icon.png",
fallbackIconRes = R.drawable.ic_globe,
fallbackIconRes = fallbackIconRes,
),
extraIconList = listOf(
IconRes(
Expand Down

0 comments on commit 0a8d1fa

Please sign in to comment.