mirror of
https://github.com/bitwarden/android.git
synced 2026-11-20 11:37:52 -06:00
Add overflow options to the listing screen and the search screen (#734)
This commit is contained in:
committed by
Álison Fernandes
parent
e1a078e511
commit
ed38cd6090
+6
-4
@@ -37,7 +37,7 @@ fun createMockCipherView(
|
||||
name = "mockName-$number",
|
||||
notes = "mockNotes-$number",
|
||||
type = cipherType,
|
||||
login = createMockLoginView(number = number),
|
||||
login = createMockLoginView(number = number).takeIf { cipherType == CipherType.LOGIN },
|
||||
creationDate = ZonedDateTime
|
||||
.parse("2023-10-27T12:00:00Z")
|
||||
.toInstant(),
|
||||
@@ -52,13 +52,15 @@ fun createMockCipherView(
|
||||
.parse("2023-10-27T12:00:00Z")
|
||||
.toInstant(),
|
||||
attachments = listOf(createMockAttachmentView(number = number)),
|
||||
card = createMockCardView(number = number),
|
||||
card = createMockCardView(number = number).takeIf { cipherType == CipherType.CARD },
|
||||
fields = listOf(createMockFieldView(number = number)),
|
||||
identity = createMockIdentityView(number = number),
|
||||
identity = createMockIdentityView(number = number).takeIf {
|
||||
cipherType == CipherType.IDENTITY
|
||||
},
|
||||
favorite = false,
|
||||
passwordHistory = listOf(createMockPasswordHistoryView(number = number)),
|
||||
reprompt = CipherRepromptType.NONE,
|
||||
secureNote = createMockSecureNoteView(),
|
||||
secureNote = createMockSecureNoteView().takeIf { cipherType == CipherType.SECURE_NOTE },
|
||||
edit = false,
|
||||
organizationUseTotp = false,
|
||||
viewPassword = false,
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.core.net.toUri
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
@@ -43,6 +44,7 @@ class SearchScreenTest : BaseComposeTest() {
|
||||
}
|
||||
private val intentManager: IntentManager = mockk {
|
||||
every { shareText(any()) } just runs
|
||||
every { launchUri(any()) } just runs
|
||||
}
|
||||
|
||||
private var onNavigateBackCalled = false
|
||||
@@ -91,6 +93,15 @@ class SearchScreenTest : BaseComposeTest() {
|
||||
assertEquals(cipherId, onNavigateToViewCipherId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `NavigateToUrl should call launchUri on the IntentManager`() {
|
||||
val url = "www.test.com"
|
||||
mutableEventFlow.tryEmit(SearchEvent.NavigateToUrl(url))
|
||||
verify(exactly = 1) {
|
||||
intentManager.launchUri(url.toUri())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ShowShareSheet should call onNavigateBack`() {
|
||||
val sendUrl = "www.test.com"
|
||||
|
||||
+124
@@ -301,6 +301,130 @@ class SearchViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyNoteClick should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val notes = "notes"
|
||||
val viewModel = createViewModel()
|
||||
viewModel.actionChannel.trySend(
|
||||
SearchAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyNoteClick(notes = notes),
|
||||
),
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(notes)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyNumberClick should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val number = "12345-4321-9876-6789"
|
||||
val viewModel = createViewModel()
|
||||
viewModel.actionChannel.trySend(
|
||||
SearchAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyNumberClick(number = number),
|
||||
),
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(number)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyPasswordClick should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val password = "passTheWord"
|
||||
val viewModel = createViewModel()
|
||||
viewModel.actionChannel.trySend(
|
||||
SearchAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyPasswordClick(password = password),
|
||||
),
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(password)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopySecurityCodeClick should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val securityCode = "234"
|
||||
val viewModel = createViewModel()
|
||||
viewModel.actionChannel.trySend(
|
||||
SearchAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopySecurityCodeClick(
|
||||
securityCode = securityCode,
|
||||
),
|
||||
),
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(securityCode)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyUsernameClick should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val username = "bitwarden"
|
||||
val viewModel = createViewModel()
|
||||
viewModel.actionChannel.trySend(
|
||||
SearchAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyUsernameClick(
|
||||
username = username,
|
||||
),
|
||||
),
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(username)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault EditClick should emit NavigateToEditCipher`() = runTest {
|
||||
val cipherId = "cipherId-1234"
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(
|
||||
SearchAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = cipherId),
|
||||
),
|
||||
)
|
||||
assertEquals(SearchEvent.NavigateToEditCipher(cipherId), awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault LaunchClick should emit NavigateToUrl`() = runTest {
|
||||
val url = "www.test.com"
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(
|
||||
SearchAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.LaunchClick(url = url),
|
||||
),
|
||||
)
|
||||
assertEquals(SearchEvent.NavigateToUrl(url), awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault ViewClick should emit NavigateToUrl`() = runTest {
|
||||
val cipherId = "cipherId-9876"
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(
|
||||
SearchAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = cipherId),
|
||||
),
|
||||
)
|
||||
assertEquals(SearchEvent.NavigateToViewCipher(cipherId), awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `vaultDataStateFlow Loaded with items should update ViewState to Content`() = runTest {
|
||||
setupMockUri()
|
||||
|
||||
+34
-4
@@ -27,7 +27,19 @@ fun createMockDisplayItemForCipher(
|
||||
fallbackIconRes = R.drawable.ic_login_item,
|
||||
),
|
||||
extraIconList = emptyList(),
|
||||
overflowOptions = emptyList(),
|
||||
overflowOptions = listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.CopyUsernameClick(
|
||||
username = "mockUsername-$number",
|
||||
),
|
||||
ListingItemOverflowAction.VaultAction.CopyPasswordClick(
|
||||
password = "mockPassword-$number",
|
||||
),
|
||||
ListingItemOverflowAction.VaultAction.LaunchClick(
|
||||
url = "www.mockuri$number.com",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -38,7 +50,13 @@ fun createMockDisplayItemForCipher(
|
||||
subtitle = null,
|
||||
iconData = IconData.Local(R.drawable.ic_secure_note_item),
|
||||
extraIconList = emptyList(),
|
||||
overflowOptions = emptyList(),
|
||||
overflowOptions = listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.CopyNoteClick(
|
||||
notes = "mockNotes-$number",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -49,7 +67,16 @@ fun createMockDisplayItemForCipher(
|
||||
subtitle = "er-$number",
|
||||
iconData = IconData.Local(R.drawable.ic_card_item),
|
||||
extraIconList = emptyList(),
|
||||
overflowOptions = emptyList(),
|
||||
overflowOptions = listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.CopyNumberClick(
|
||||
number = "mockNumber-$number",
|
||||
),
|
||||
ListingItemOverflowAction.VaultAction.CopySecurityCodeClick(
|
||||
securityCode = "mockCode-$number",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -60,7 +87,10 @@ fun createMockDisplayItemForCipher(
|
||||
subtitle = "mockFirstName-${number}mockLastName-$number",
|
||||
iconData = IconData.Local(R.drawable.ic_identity_item),
|
||||
extraIconList = emptyList(),
|
||||
overflowOptions = emptyList(),
|
||||
overflowOptions = listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -17,6 +17,7 @@ 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.core.net.toUri
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.Environment
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.baseIconUrl
|
||||
@@ -51,10 +52,12 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
private var onNavigateToAddSendScreenCalled = false
|
||||
private var onNavigateToEditSendItemId: String? = null
|
||||
private var onNavigateToVaultItemId: String? = null
|
||||
private var onNavigateToVaultEditItemScreenId: String? = null
|
||||
private var onNavigateToSearchType: SearchType? = null
|
||||
|
||||
private val intentManager: IntentManager = mockk {
|
||||
every { shareText(any()) } just runs
|
||||
every { launchUri(any()) } just runs
|
||||
}
|
||||
private val mutableEventFlow = bufferedMutableSharedFlow<VaultItemListingEvent>()
|
||||
private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE)
|
||||
@@ -75,6 +78,7 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
onNavigateToAddSendItem = { onNavigateToAddSendScreenCalled = true },
|
||||
onNavigateToEditSendItem = { onNavigateToEditSendItemId = it },
|
||||
onNavigateToSearch = { onNavigateToSearchType = it },
|
||||
onNavigateToVaultEditItemScreen = { onNavigateToVaultEditItemScreenId = it },
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -157,6 +161,13 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
assertEquals(searchType, onNavigateToSearchType)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `NavigateToEditCipher should call onNavigateToVaultEditItemScreen`() {
|
||||
val cipherId = "cipherId"
|
||||
mutableEventFlow.tryEmit(VaultItemListingEvent.NavigateToEditCipher(cipherId))
|
||||
assertEquals(cipherId, onNavigateToVaultEditItemScreenId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `NavigateToSendItem event should call onNavigateToEditSendItemId`() {
|
||||
val sendId = "sendId"
|
||||
@@ -171,6 +182,15 @@ class VaultItemListingScreenTest : BaseComposeTest() {
|
||||
assertEquals(id, onNavigateToVaultItemId)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `NavigateToUrl should call launchUri on the IntentManager`() {
|
||||
val url = "www.test.com"
|
||||
mutableEventFlow.tryEmit(VaultItemListingEvent.NavigateToUrl(url))
|
||||
verify(exactly = 1) {
|
||||
intentManager.launchUri(url.toUri())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `progressbar should be displayed according to state`() {
|
||||
mutableStateFlow.update { DEFAULT_STATE }
|
||||
|
||||
+129
-7
@@ -53,7 +53,9 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
ZoneOffset.UTC,
|
||||
)
|
||||
|
||||
private val clipboardManager: BitwardenClipboardManager = mockk()
|
||||
private val clipboardManager: BitwardenClipboardManager = mockk {
|
||||
every { setText(any<String>()) } just runs
|
||||
}
|
||||
|
||||
private val mutableVaultDataStateFlow =
|
||||
MutableStateFlow<DataState<VaultData>>(DataState.Loading)
|
||||
@@ -350,18 +352,138 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyNoteClick should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val notes = "notes"
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
viewModel.actionChannel.trySend(
|
||||
VaultItemListingsAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyNoteClick(notes = notes),
|
||||
),
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(notes)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyNumberClick should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val number = "12345-4321-9876-6789"
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
viewModel.actionChannel.trySend(
|
||||
VaultItemListingsAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyNumberClick(number = number),
|
||||
),
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(number)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyPasswordClick should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val password = "passTheWord"
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
viewModel.actionChannel.trySend(
|
||||
VaultItemListingsAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyPasswordClick(password = password),
|
||||
),
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(password)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopySecurityCodeClick should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val securityCode = "234"
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
viewModel.actionChannel.trySend(
|
||||
VaultItemListingsAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopySecurityCodeClick(
|
||||
securityCode = securityCode,
|
||||
),
|
||||
),
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(securityCode)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyUsernameClick should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val username = "bitwarden"
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
viewModel.actionChannel.trySend(
|
||||
VaultItemListingsAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyUsernameClick(
|
||||
username = username,
|
||||
),
|
||||
),
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(username)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault EditClick should emit NavigateToEditCipher`() = runTest {
|
||||
val cipherId = "cipherId-1234"
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(
|
||||
VaultItemListingsAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = cipherId),
|
||||
),
|
||||
)
|
||||
assertEquals(VaultItemListingEvent.NavigateToEditCipher(cipherId), awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault LaunchClick should emit NavigateToUrl`() = runTest {
|
||||
val url = "www.test.com"
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(
|
||||
VaultItemListingsAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.LaunchClick(url = url),
|
||||
),
|
||||
)
|
||||
assertEquals(VaultItemListingEvent.NavigateToUrl(url), awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault ViewClick should emit NavigateToUrl`() = runTest {
|
||||
val cipherId = "cipherId-9876"
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(
|
||||
VaultItemListingsAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = cipherId),
|
||||
),
|
||||
)
|
||||
assertEquals(VaultItemListingEvent.NavigateToVaultItem(cipherId), awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `vaultDataStateFlow Loaded with items should update ViewState to Content`() =
|
||||
runTest {
|
||||
setupMockUri()
|
||||
|
||||
val dataState = DataState.Loaded(
|
||||
data = VaultData(
|
||||
cipherViewList = listOf(
|
||||
createMockCipherView(
|
||||
number = 1,
|
||||
isDeleted = false,
|
||||
),
|
||||
),
|
||||
cipherViewList = listOf(createMockCipherView(number = 1, isDeleted = false)),
|
||||
folderViewList = listOf(createMockFolderView(number = 1)),
|
||||
collectionViewList = listOf(createMockCollectionView(number = 1)),
|
||||
sendViewList = listOf(createMockSendView(number = 1)),
|
||||
|
||||
+34
-4
@@ -28,7 +28,19 @@ fun createMockDisplayItemForCipher(
|
||||
fallbackIconRes = R.drawable.ic_login_item,
|
||||
),
|
||||
extraIconList = emptyList(),
|
||||
overflowOptions = emptyList(),
|
||||
overflowOptions = listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.CopyUsernameClick(
|
||||
username = "mockUsername-$number",
|
||||
),
|
||||
ListingItemOverflowAction.VaultAction.CopyPasswordClick(
|
||||
password = "mockPassword-$number",
|
||||
),
|
||||
ListingItemOverflowAction.VaultAction.LaunchClick(
|
||||
url = "www.mockuri$number.com",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -39,7 +51,13 @@ fun createMockDisplayItemForCipher(
|
||||
subtitle = subtitle,
|
||||
iconData = IconData.Local(R.drawable.ic_secure_note_item),
|
||||
extraIconList = emptyList(),
|
||||
overflowOptions = emptyList(),
|
||||
overflowOptions = listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.CopyNoteClick(
|
||||
notes = "mockNotes-$number",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -50,7 +68,16 @@ fun createMockDisplayItemForCipher(
|
||||
subtitle = subtitle,
|
||||
iconData = IconData.Local(R.drawable.ic_card_item),
|
||||
extraIconList = emptyList(),
|
||||
overflowOptions = emptyList(),
|
||||
overflowOptions = listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.CopyNumberClick(
|
||||
number = "mockNumber-$number",
|
||||
),
|
||||
ListingItemOverflowAction.VaultAction.CopySecurityCodeClick(
|
||||
securityCode = "mockCode-$number",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -61,7 +88,10 @@ fun createMockDisplayItemForCipher(
|
||||
subtitle = subtitle,
|
||||
iconData = IconData.Local(R.drawable.ic_identity_item),
|
||||
extraIconList = emptyList(),
|
||||
overflowOptions = emptyList(),
|
||||
overflowOptions = listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = "mockId-$number"),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = "mockId-$number"),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+205
@@ -0,0 +1,205 @@
|
||||
package com.x8bit.bitwarden.ui.vault.feature.util
|
||||
|
||||
import com.bitwarden.core.CipherType
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockCardView
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockCipherView
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockIdentityView
|
||||
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.vault.feature.itemlisting.model.ListingItemOverflowAction
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class CipherViewExtensionsTest {
|
||||
|
||||
@Test
|
||||
fun `toOverflowActions should return all actions for a login cipher`() {
|
||||
val id = "mockId-1"
|
||||
val username = "Bitwarden"
|
||||
val password = "password"
|
||||
val uri = "www.test.com"
|
||||
val cipher = createMockCipherView(number = 1, cipherType = CipherType.LOGIN).copy(
|
||||
id = id,
|
||||
login = createMockLoginView(number = 1).copy(
|
||||
username = username,
|
||||
password = password,
|
||||
uris = listOf(createMockUriView(number = 1).copy(uri = uri)),
|
||||
),
|
||||
)
|
||||
|
||||
val result = cipher.toOverflowActions()
|
||||
|
||||
assertEquals(
|
||||
listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = id),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = id),
|
||||
ListingItemOverflowAction.VaultAction.CopyUsernameClick(username = username),
|
||||
ListingItemOverflowAction.VaultAction.CopyPasswordClick(password = password),
|
||||
ListingItemOverflowAction.VaultAction.LaunchClick(url = uri),
|
||||
),
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toOverflowActions should return minimum actions for a login cipher`() {
|
||||
val id = "mockId-1"
|
||||
val cipher = createMockCipherView(
|
||||
number = 1,
|
||||
isDeleted = true,
|
||||
cipherType = CipherType.LOGIN,
|
||||
)
|
||||
.copy(
|
||||
id = id,
|
||||
login = createMockLoginView(number = 1).copy(
|
||||
username = null,
|
||||
password = null,
|
||||
uris = null,
|
||||
),
|
||||
)
|
||||
|
||||
val result = cipher.toOverflowActions()
|
||||
|
||||
assertEquals(
|
||||
listOf(ListingItemOverflowAction.VaultAction.ViewClick(cipherId = id)),
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toOverflowActions should return all actions for a card cipher`() {
|
||||
val id = "mockId-1"
|
||||
val number = "1322-2414-7634-2354"
|
||||
val securityCode = "123"
|
||||
val cipher = createMockCipherView(number = 1, cipherType = CipherType.CARD).copy(
|
||||
id = id,
|
||||
card = createMockCardView(number = 1).copy(
|
||||
number = number,
|
||||
code = securityCode,
|
||||
),
|
||||
)
|
||||
|
||||
val result = cipher.toOverflowActions()
|
||||
|
||||
assertEquals(
|
||||
listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = id),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = id),
|
||||
ListingItemOverflowAction.VaultAction.CopyNumberClick(number = number),
|
||||
ListingItemOverflowAction.VaultAction.CopySecurityCodeClick(
|
||||
securityCode = securityCode,
|
||||
),
|
||||
),
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toOverflowActions should return minimum actions for a card cipher`() {
|
||||
val id = "mockId-1"
|
||||
val cipher = createMockCipherView(
|
||||
number = 1,
|
||||
isDeleted = true,
|
||||
cipherType = CipherType.CARD,
|
||||
)
|
||||
.copy(
|
||||
id = id,
|
||||
card = createMockCardView(number = 1).copy(
|
||||
number = null,
|
||||
code = null,
|
||||
),
|
||||
)
|
||||
|
||||
val result = cipher.toOverflowActions()
|
||||
|
||||
assertEquals(
|
||||
listOf(ListingItemOverflowAction.VaultAction.ViewClick(cipherId = id)),
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toOverflowActions should return all actions for a identity cipher`() {
|
||||
val id = "mockId-1"
|
||||
val cipher = createMockCipherView(number = 1, cipherType = CipherType.IDENTITY).copy(
|
||||
id = id,
|
||||
identity = createMockIdentityView(number = 1),
|
||||
)
|
||||
|
||||
val result = cipher.toOverflowActions()
|
||||
|
||||
assertEquals(
|
||||
listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = id),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = id),
|
||||
),
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toOverflowActions should return minimum actions for a identity cipher`() {
|
||||
val id = "mockId-1"
|
||||
val cipher = createMockCipherView(
|
||||
number = 1,
|
||||
isDeleted = true,
|
||||
cipherType = CipherType.IDENTITY,
|
||||
)
|
||||
.copy(
|
||||
id = id,
|
||||
identity = createMockIdentityView(number = 1),
|
||||
)
|
||||
|
||||
val result = cipher.toOverflowActions()
|
||||
|
||||
assertEquals(
|
||||
listOf(ListingItemOverflowAction.VaultAction.ViewClick(cipherId = id)),
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toOverflowActions should return all actions for a secure note cipher`() {
|
||||
val id = "mockId-1"
|
||||
val notes = "so secure"
|
||||
val cipher = createMockCipherView(number = 1, cipherType = CipherType.SECURE_NOTE).copy(
|
||||
id = id,
|
||||
secureNote = createMockSecureNoteView(),
|
||||
notes = notes,
|
||||
)
|
||||
|
||||
val result = cipher.toOverflowActions()
|
||||
|
||||
assertEquals(
|
||||
listOf(
|
||||
ListingItemOverflowAction.VaultAction.ViewClick(cipherId = id),
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = id),
|
||||
ListingItemOverflowAction.VaultAction.CopyNoteClick(notes = notes),
|
||||
),
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `toOverflowActions should return minimum actions for a secure note cipher`() {
|
||||
val id = "mockId-1"
|
||||
val cipher = createMockCipherView(
|
||||
number = 1,
|
||||
isDeleted = true,
|
||||
cipherType = CipherType.SECURE_NOTE,
|
||||
)
|
||||
.copy(
|
||||
id = id,
|
||||
secureNote = createMockSecureNoteView(),
|
||||
notes = null,
|
||||
)
|
||||
|
||||
val result = cipher.toOverflowActions()
|
||||
|
||||
assertEquals(
|
||||
listOf(ListingItemOverflowAction.VaultAction.ViewClick(cipherId = id)),
|
||||
result,
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user