mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-1648: Add the copy totp code overflow option (#850)
This commit is contained in:
committed by
Álison Fernandes
parent
0c6ea8d18d
commit
20dd839923
+46
@@ -18,6 +18,7 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockFolderView
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.DeleteSendResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.GenerateTotpResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.RemovePasswordSendResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
|
||||
@@ -331,6 +332,51 @@ class SearchViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyTotpClick with GenerateTotpCode success should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val totpCode = "totpCode"
|
||||
val code = "Code"
|
||||
|
||||
coEvery {
|
||||
vaultRepository.generateTotp(totpCode, clock.instant())
|
||||
} returns GenerateTotpResult.Success(code, 30)
|
||||
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(
|
||||
SearchAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyTotpClick(totpCode),
|
||||
),
|
||||
)
|
||||
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(code)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyTotpClick with GenerateTotpCode failure should not call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val totpCode = "totpCode"
|
||||
|
||||
coEvery {
|
||||
vaultRepository.generateTotp(totpCode, clock.instant())
|
||||
} returns GenerateTotpResult.Error
|
||||
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(
|
||||
SearchAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyTotpClick(totpCode),
|
||||
),
|
||||
)
|
||||
|
||||
verify(exactly = 0) {
|
||||
clipboardManager.setText(text = any<String>())
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyPasswordClick should call setText on the ClipboardManager`() =
|
||||
|
||||
@@ -45,6 +45,9 @@ fun createMockDisplayItemForCipher(
|
||||
ListingItemOverflowAction.VaultAction.CopyPasswordClick(
|
||||
password = "mockPassword-$number",
|
||||
),
|
||||
ListingItemOverflowAction.VaultAction.CopyTotpClick(
|
||||
totpCode = "mockTotp-$number",
|
||||
),
|
||||
ListingItemOverflowAction.VaultAction.LaunchClick(
|
||||
url = "www.mockuri$number.com",
|
||||
),
|
||||
|
||||
+46
@@ -25,6 +25,7 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockFolderView
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.DeleteSendResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.GenerateTotpResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.RemovePasswordSendResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
|
||||
@@ -511,6 +512,51 @@ class VaultItemListingViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyTotpClick with GenerateTotpCode success should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val totpCode = "totpCode"
|
||||
val code = "Code"
|
||||
|
||||
coEvery {
|
||||
vaultRepository.generateTotp(totpCode, clock.instant())
|
||||
} returns GenerateTotpResult.Success(code, 30)
|
||||
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
viewModel.trySendAction(
|
||||
VaultItemListingsAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyTotpClick(totpCode),
|
||||
),
|
||||
)
|
||||
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(code)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyTotpClick with GenerateTotpCode failure should not call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val totpCode = "totpCode"
|
||||
|
||||
coEvery {
|
||||
vaultRepository.generateTotp(totpCode, clock.instant())
|
||||
} returns GenerateTotpResult.Error
|
||||
|
||||
val viewModel = createVaultItemListingViewModel()
|
||||
viewModel.trySendAction(
|
||||
VaultItemListingsAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyTotpClick(totpCode),
|
||||
),
|
||||
)
|
||||
|
||||
verify(exactly = 0) {
|
||||
clipboardManager.setText(text = any<String>())
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyUsernameClick should call setText on the ClipboardManager`() =
|
||||
|
||||
+3
@@ -46,6 +46,9 @@ fun createMockDisplayItemForCipher(
|
||||
ListingItemOverflowAction.VaultAction.CopyPasswordClick(
|
||||
password = "mockPassword-$number",
|
||||
),
|
||||
ListingItemOverflowAction.VaultAction.CopyTotpClick(
|
||||
totpCode = "mockTotp-$number",
|
||||
),
|
||||
ListingItemOverflowAction.VaultAction.LaunchClick(
|
||||
url = "www.mockuri$number.com",
|
||||
),
|
||||
|
||||
+3
@@ -20,6 +20,7 @@ class CipherViewExtensionsTest {
|
||||
val id = "mockId-1"
|
||||
val username = "Bitwarden"
|
||||
val password = "password"
|
||||
val totpCode = "mockTotp-1"
|
||||
val uri = "www.test.com"
|
||||
val cipher = createMockCipherView(number = 1, cipherType = CipherType.LOGIN).copy(
|
||||
id = id,
|
||||
@@ -38,6 +39,7 @@ class CipherViewExtensionsTest {
|
||||
ListingItemOverflowAction.VaultAction.EditClick(cipherId = id),
|
||||
ListingItemOverflowAction.VaultAction.CopyUsernameClick(username = username),
|
||||
ListingItemOverflowAction.VaultAction.CopyPasswordClick(password = password),
|
||||
ListingItemOverflowAction.VaultAction.CopyTotpClick(totpCode = totpCode),
|
||||
ListingItemOverflowAction.VaultAction.LaunchClick(url = uri),
|
||||
),
|
||||
result,
|
||||
@@ -58,6 +60,7 @@ class CipherViewExtensionsTest {
|
||||
username = null,
|
||||
password = null,
|
||||
uris = null,
|
||||
totp = null,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockCollectionV
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockFolderView
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockSendView
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.GenerateTotpResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.VaultData
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
@@ -25,6 +26,7 @@ import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterData
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.model.VaultFilterType
|
||||
import com.x8bit.bitwarden.ui.vault.feature.vault.util.toViewState
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultItemListingType
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
@@ -36,9 +38,16 @@ import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.Clock
|
||||
import java.time.Instant
|
||||
import java.time.ZoneOffset
|
||||
|
||||
@Suppress("LargeClass")
|
||||
class VaultViewModelTest : BaseViewModelTest() {
|
||||
private val clock: Clock = Clock.fixed(
|
||||
Instant.parse("2023-10-27T12:00:00Z"),
|
||||
ZoneOffset.UTC,
|
||||
)
|
||||
|
||||
private val clipboardManager: BitwardenClipboardManager = mockk {
|
||||
every { setText(any<String>()) } just runs
|
||||
@@ -1108,6 +1117,51 @@ class VaultViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyTotpClick with GenerateTotpCode success should call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val totpCode = "totpCode"
|
||||
val code = "Code"
|
||||
|
||||
coEvery {
|
||||
vaultRepository.generateTotp(totpCode, clock.instant())
|
||||
} returns GenerateTotpResult.Success(code, 30)
|
||||
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(
|
||||
VaultAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyTotpClick(totpCode),
|
||||
),
|
||||
)
|
||||
|
||||
verify(exactly = 1) {
|
||||
clipboardManager.setText(code)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopyTotpClick with GenerateTotpCode failure should not call setText on the ClipboardManager`() =
|
||||
runTest {
|
||||
val totpCode = "totpCode"
|
||||
|
||||
coEvery {
|
||||
vaultRepository.generateTotp(totpCode, clock.instant())
|
||||
} returns GenerateTotpResult.Error
|
||||
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(
|
||||
VaultAction.OverflowOptionClick(
|
||||
ListingItemOverflowAction.VaultAction.CopyTotpClick(totpCode),
|
||||
),
|
||||
)
|
||||
|
||||
verify(exactly = 0) {
|
||||
clipboardManager.setText(text = any<String>())
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OverflowOptionClick Vault CopySecurityCodeClick should call setText on the ClipboardManager`() =
|
||||
@@ -1188,8 +1242,9 @@ class VaultViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private fun createViewModel(): VaultViewModel =
|
||||
VaultViewModel(
|
||||
clipboardManager = clipboardManager,
|
||||
authRepository = authRepository,
|
||||
clipboardManager = clipboardManager,
|
||||
clock = clock,
|
||||
settingsRepository = settingsRepository,
|
||||
vaultRepository = vaultRepository,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user