mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-1309: Ownership in the add item screen (#831)
This commit is contained in:
committed by
Álison Fernandes
parent
f1a799955c
commit
b3f23ab172
+16
@@ -4,6 +4,7 @@ import android.net.Uri
|
||||
import com.x8bit.bitwarden.data.platform.base.BaseServiceTest
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.api.AzureApi
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.api.CiphersApi
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.CreateCipherInOrganizationJsonRequest
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.FileUploadType
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.ShareCipherJsonRequest
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.UpdateCipherResponseJson
|
||||
@@ -63,6 +64,21 @@ class CiphersServiceTest : BaseServiceTest() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `createCipherInOrganization should return the correct response`() = runTest {
|
||||
server.enqueue(MockResponse().setBody(CREATE_UPDATE_CIPHER_SUCCESS_JSON))
|
||||
val result = ciphersService.createCipherInOrganization(
|
||||
body = CreateCipherInOrganizationJsonRequest(
|
||||
cipher = createMockCipherJsonRequest(number = 1),
|
||||
collectionIds = listOf("12345"),
|
||||
),
|
||||
)
|
||||
assertEquals(
|
||||
createMockCipher(number = 1),
|
||||
result.getOrThrow(),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `createAttachment should return the correct response`() = runTest {
|
||||
server.enqueue(MockResponse().setBody(CREATE_ATTACHMENT_SUCCESS_JSON))
|
||||
|
||||
@@ -37,6 +37,7 @@ import com.x8bit.bitwarden.data.platform.util.asFailure
|
||||
import com.x8bit.bitwarden.data.platform.util.asSuccess
|
||||
import com.x8bit.bitwarden.data.vault.datasource.disk.VaultDiskSource
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.AttachmentJsonRequest
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.CreateCipherInOrganizationJsonRequest
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.FileUploadType
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.FolderJsonRequest
|
||||
import com.x8bit.bitwarden.data.vault.datasource.network.model.SendFileResponseJson
|
||||
@@ -1704,6 +1705,115 @@ class VaultRepositoryTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `createCipherInOrganization with no active user should return CreateCipherResult Error`() =
|
||||
runTest {
|
||||
fakeAuthDiskSource.userState = null
|
||||
|
||||
val result = vaultRepository.createCipherInOrganization(
|
||||
cipherView = mockk(),
|
||||
collectionIds = mockk(),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
CreateCipherResult.Error,
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MaxLineLength")
|
||||
fun `createCipherInOrganization with encryptCipher failure should return CreateCipherResult Error`() =
|
||||
runTest {
|
||||
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
||||
val userId = "mockId-1"
|
||||
val mockCipherView = createMockCipherView(number = 1)
|
||||
coEvery {
|
||||
vaultSdkSource.encryptCipher(
|
||||
userId = userId,
|
||||
cipherView = mockCipherView,
|
||||
)
|
||||
} returns IllegalStateException().asFailure()
|
||||
|
||||
val result = vaultRepository.createCipherInOrganization(
|
||||
cipherView = mockCipherView,
|
||||
collectionIds = mockk(),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
CreateCipherResult.Error,
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MaxLineLength")
|
||||
fun `createCipherInOrganization with ciphersService createCipher failure should return CreateCipherResult Error`() =
|
||||
runTest {
|
||||
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
||||
val userId = "mockId-1"
|
||||
val mockCipherView = createMockCipherView(number = 1)
|
||||
coEvery {
|
||||
vaultSdkSource.encryptCipher(
|
||||
userId = userId,
|
||||
cipherView = mockCipherView,
|
||||
)
|
||||
} returns createMockSdkCipher(number = 1).asSuccess()
|
||||
coEvery {
|
||||
ciphersService.createCipherInOrganization(
|
||||
body = CreateCipherInOrganizationJsonRequest(
|
||||
cipher = createMockCipherJsonRequest(number = 1, hasNullUri = true),
|
||||
collectionIds = listOf("mockId-1"),
|
||||
),
|
||||
)
|
||||
} returns IllegalStateException().asFailure()
|
||||
|
||||
val result = vaultRepository.createCipherInOrganization(
|
||||
cipherView = mockCipherView,
|
||||
collectionIds = listOf("mockId-1"),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
CreateCipherResult.Error,
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MaxLineLength")
|
||||
fun `createCipherInOrganization with ciphersService createCipher success should return CreateCipherResult success`() =
|
||||
runTest {
|
||||
fakeAuthDiskSource.userState = MOCK_USER_STATE
|
||||
val userId = "mockId-1"
|
||||
val mockCipherView = createMockCipherView(number = 1)
|
||||
coEvery {
|
||||
vaultSdkSource.encryptCipher(
|
||||
userId = userId,
|
||||
cipherView = mockCipherView,
|
||||
)
|
||||
} returns createMockSdkCipher(number = 1).asSuccess()
|
||||
val mockCipher = createMockCipher(number = 1)
|
||||
coEvery {
|
||||
ciphersService.createCipherInOrganization(
|
||||
body = CreateCipherInOrganizationJsonRequest(
|
||||
cipher = createMockCipherJsonRequest(number = 1, hasNullUri = true),
|
||||
collectionIds = listOf("mockId-1"),
|
||||
),
|
||||
)
|
||||
} returns mockCipher.asSuccess()
|
||||
coEvery { vaultDiskSource.saveCipher(userId, mockCipher) } just runs
|
||||
|
||||
val result = vaultRepository.createCipherInOrganization(
|
||||
cipherView = mockCipherView,
|
||||
collectionIds = listOf("mockId-1"),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
CreateCipherResult.Success,
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `updateCipher with no active user should return UpdateCipherResult Error`() =
|
||||
runTest {
|
||||
|
||||
+93
-16
@@ -1633,6 +1633,8 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
|
||||
@Test
|
||||
fun `clicking a Ownership option should send OwnershipChange action`() {
|
||||
updateStateWithOwners()
|
||||
|
||||
// Opens the menu
|
||||
composeTestRule
|
||||
.onNodeWithContentDescriptionAfterScroll(
|
||||
@@ -1642,20 +1644,27 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
|
||||
// Choose the option from the menu
|
||||
composeTestRule
|
||||
.onAllNodesWithText(text = "a@b.com")
|
||||
.onAllNodesWithText(text = "mockOwnerName-2")
|
||||
.onLast()
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
VaultAddEditAction.Common.OwnershipChange("a@b.com"),
|
||||
VaultAddEditAction.Common.OwnershipChange(
|
||||
VaultAddEditState.Owner(
|
||||
id = "mockOwnerId-2",
|
||||
name = "mockOwnerName-2",
|
||||
collections = emptyList(),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the Ownership control should display the text provided by the state`() {
|
||||
updateStateWithOwners()
|
||||
composeTestRule
|
||||
.onNodeWithContentDescriptionAfterScroll(
|
||||
label = "Who owns this item?, placeholder@email.com",
|
||||
@@ -1663,11 +1672,11 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
.assertIsDisplayed()
|
||||
|
||||
mutableStateFlow.update { currentState ->
|
||||
updateCommonContent(currentState) { copy(ownership = "Owner 2") }
|
||||
updateCommonContent(currentState) { copy(selectedOwnerId = "mockOwnerId-2") }
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescriptionAfterScroll(label = "Who owns this item?, Owner 2")
|
||||
.onNodeWithContentDescriptionAfterScroll(label = "Who owns this item?, mockOwnerName-2")
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@@ -1705,7 +1714,7 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
|
||||
@Test
|
||||
fun `clicking a Folder Option should send FolderChange action`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE_SECURE_NOTES
|
||||
updateStateWithFolders()
|
||||
|
||||
// Opens the menu
|
||||
composeTestRule
|
||||
@@ -1714,14 +1723,19 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
|
||||
// Choose the option from the menu
|
||||
composeTestRule
|
||||
.onAllNodesWithText(text = "Folder 1")
|
||||
.onAllNodesWithText(text = "mockFolderName-1")
|
||||
.onLast()
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
VaultAddEditAction.Common.FolderChange("Folder 1".asText()),
|
||||
VaultAddEditAction.Common.FolderChange(
|
||||
VaultAddEditState.Folder(
|
||||
id = "mockFolderId-1",
|
||||
name = "mockFolderName-1",
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1729,18 +1743,18 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `the folder control should display the text provided by the state`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE_SECURE_NOTES
|
||||
updateStateWithFolders()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescriptionAfterScroll(label = "Folder, No Folder")
|
||||
.assertIsDisplayed()
|
||||
|
||||
mutableStateFlow.update { currentState ->
|
||||
updateCommonContent(currentState) { copy(folderName = "Folder 2".asText()) }
|
||||
updateCommonContent(currentState) { copy(selectedFolderId = "mockFolderId-1") }
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescriptionAfterScroll(label = "Folder, Folder 2")
|
||||
.onNodeWithContentDescriptionAfterScroll(label = "Folder, mockFolderName-1")
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@@ -1870,7 +1884,9 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `Ownership option should send OwnershipChange action`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE_SECURE_NOTES
|
||||
mutableStateFlow.value = DEFAULT_STATE_SECURE_NOTES
|
||||
|
||||
updateStateWithOwners()
|
||||
|
||||
// Opens the menu
|
||||
composeTestRule
|
||||
@@ -1879,14 +1895,20 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
|
||||
// Choose the option from the menu
|
||||
composeTestRule
|
||||
.onAllNodesWithText(text = "a@b.com")
|
||||
.onAllNodesWithText(text = "mockOwnerName-2")
|
||||
.onLast()
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
VaultAddEditAction.Common.OwnershipChange("a@b.com"),
|
||||
VaultAddEditAction.Common.OwnershipChange(
|
||||
VaultAddEditState.Owner(
|
||||
id = "mockOwnerId-2",
|
||||
name = "mockOwnerName-2",
|
||||
collections = emptyList(),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1894,18 +1916,18 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in ItemType_SecureNotes the Ownership control should display the text provided by the state`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE_SECURE_NOTES
|
||||
updateStateWithOwners()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescriptionAfterScroll(label = "Who owns this item?, placeholder@email.com")
|
||||
.assertIsDisplayed()
|
||||
|
||||
mutableStateFlow.update { currentState ->
|
||||
updateCommonContent(currentState) { copy(ownership = "Owner 2") }
|
||||
updateCommonContent(currentState) { copy(selectedOwnerId = "mockOwnerId-2") }
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescriptionAfterScroll(label = "Who owns this item?, Owner 2")
|
||||
.onNodeWithContentDescriptionAfterScroll(label = "Who owns this item?, mockOwnerName-2")
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@@ -2459,6 +2481,28 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
return currentState.copy(viewState = updatedType)
|
||||
}
|
||||
|
||||
private fun updateStateWithOwners() {
|
||||
mutableStateFlow.update { currentState ->
|
||||
updateCommonContent(currentState) {
|
||||
copy(
|
||||
selectedOwnerId = null,
|
||||
availableOwners = DEFAULT_OWNERS,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateStateWithFolders() {
|
||||
mutableStateFlow.update {
|
||||
updateCommonContent(it) {
|
||||
copy(
|
||||
selectedFolderId = null,
|
||||
availableFolders = DEFAULT_FOLDERS,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//endregion Helper functions
|
||||
|
||||
companion object {
|
||||
@@ -2526,5 +2570,38 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
),
|
||||
dialog = null,
|
||||
)
|
||||
|
||||
private val DEFAULT_OWNERS = listOf(
|
||||
VaultAddEditState.Owner(
|
||||
id = null,
|
||||
name = "placeholder@email.com",
|
||||
collections = emptyList(),
|
||||
),
|
||||
VaultAddEditState.Owner(
|
||||
id = "mockOwnerId-1",
|
||||
name = "mockOwnerName-1",
|
||||
collections = emptyList(),
|
||||
),
|
||||
VaultAddEditState.Owner(
|
||||
id = "mockOwnerId-2",
|
||||
name = "mockOwnerName-2",
|
||||
collections = emptyList(),
|
||||
),
|
||||
)
|
||||
|
||||
private val DEFAULT_FOLDERS = listOf(
|
||||
VaultAddEditState.Folder(
|
||||
id = null,
|
||||
name = "No Folder",
|
||||
),
|
||||
VaultAddEditState.Folder(
|
||||
id = "mockFolderId-1",
|
||||
name = "mockFolderName-1",
|
||||
),
|
||||
VaultAddEditState.Folder(
|
||||
id = "mockFolderId-2",
|
||||
name = "mockFolderName-2",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+224
-64
@@ -3,16 +3,23 @@ package com.x8bit.bitwarden.ui.vault.feature.addedit
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import com.bitwarden.core.CipherView
|
||||
import com.bitwarden.core.CollectionView
|
||||
import com.bitwarden.core.FolderView
|
||||
import com.bitwarden.core.SendView
|
||||
import com.bitwarden.core.UriMatchType
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.BreachCountResult
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.Organization
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.UserState
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.VaultUnlockType
|
||||
import com.x8bit.bitwarden.data.autofill.model.AutofillSelectionData
|
||||
import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.SpecialCircumstanceManagerImpl
|
||||
import com.x8bit.bitwarden.data.platform.manager.clipboard.BitwardenClipboardManager
|
||||
import com.x8bit.bitwarden.data.platform.manager.model.SpecialCircumstance
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.DataState
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.Environment
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
|
||||
import com.x8bit.bitwarden.data.tools.generator.repository.GeneratorRepository
|
||||
import com.x8bit.bitwarden.data.tools.generator.repository.util.FakeGeneratorRepository
|
||||
@@ -22,8 +29,8 @@ import com.x8bit.bitwarden.data.vault.repository.model.CreateCipherResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.DeleteCipherResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.TotpCodeResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.UpdateCipherResult
|
||||
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.Text
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.manager.resource.ResourceManager
|
||||
import com.x8bit.bitwarden.ui.tools.feature.generator.model.GeneratorMode
|
||||
@@ -60,7 +67,10 @@ import java.util.UUID
|
||||
@Suppress("LargeClass")
|
||||
class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private val authRepository: AuthRepository = mockk()
|
||||
private val mutableUserStateFlow = MutableStateFlow<UserState?>(createUserState())
|
||||
private val authRepository: AuthRepository = mockk {
|
||||
every { userStateFlow } returns mutableUserStateFlow
|
||||
}
|
||||
|
||||
private val loginInitialState = createVaultAddItemState(
|
||||
typeContentViewState = createLoginTypeContentViewState(),
|
||||
@@ -72,11 +82,13 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private val totpTestCodeFlow: MutableSharedFlow<TotpCodeResult> = bufferedMutableSharedFlow()
|
||||
|
||||
private val mutableVaultItemFlow = MutableStateFlow<DataState<CipherView?>>(DataState.Loading)
|
||||
private val resourceManager: ResourceManager = mockk()
|
||||
private val mutableVaultDataFlow = MutableStateFlow<DataState<VaultData>>(DataState.Loading)
|
||||
private val resourceManager: ResourceManager = mockk {
|
||||
every { getString(R.string.folder_none) } returns "No Folder"
|
||||
}
|
||||
private val clipboardManager: BitwardenClipboardManager = mockk()
|
||||
private val vaultRepository: VaultRepository = mockk {
|
||||
every { getVaultItemStateFlow(DEFAULT_EDIT_ITEM_ID) } returns mutableVaultItemFlow
|
||||
every { vaultDataStateFlow } returns mutableVaultDataFlow
|
||||
every { totpCodeFlow } returns totpTestCodeFlow
|
||||
}
|
||||
private val specialCircumstanceManager: SpecialCircumstanceManager =
|
||||
@@ -107,7 +119,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(
|
||||
loginInitialState,
|
||||
loginInitialState.copy(viewState = VaultAddEditState.ViewState.Loading),
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
@@ -123,9 +135,12 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
vaultAddEditType = vaultAddEditType,
|
||||
),
|
||||
)
|
||||
assertEquals(initState, viewModel.stateFlow.value)
|
||||
verify(exactly = 0) {
|
||||
vaultRepository.getVaultItemStateFlow(DEFAULT_EDIT_ITEM_ID)
|
||||
assertEquals(
|
||||
initState.copy(viewState = VaultAddEditState.ViewState.Loading),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
vaultRepository.vaultDataStateFlow
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,9 +167,12 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
vaultAddEditType = vaultAddEditType,
|
||||
),
|
||||
)
|
||||
assertEquals(initState, viewModel.stateFlow.value)
|
||||
verify(exactly = 0) {
|
||||
vaultRepository.getVaultItemStateFlow(DEFAULT_EDIT_ITEM_ID)
|
||||
assertEquals(
|
||||
initState.copy(viewState = VaultAddEditState.ViewState.Loading),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
vaultRepository.vaultDataStateFlow
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +191,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
vaultRepository.getVaultItemStateFlow(DEFAULT_EDIT_ITEM_ID)
|
||||
vaultRepository.vaultDataStateFlow
|
||||
}
|
||||
}
|
||||
|
||||
@@ -192,7 +210,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
verify(exactly = 1) {
|
||||
vaultRepository.getVaultItemStateFlow(DEFAULT_EDIT_ITEM_ID)
|
||||
vaultRepository.vaultDataStateFlow
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,20 +284,23 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
@Suppress("MaxLineLength")
|
||||
fun `ConfirmDeleteClick with DeleteCipherResult Success should emit ShowToast and NavigateBack`() =
|
||||
runTest {
|
||||
val cipherView = createMockCipherView(1)
|
||||
val vaultAddEditType = VaultAddEditType.EditItem(DEFAULT_EDIT_ITEM_ID)
|
||||
val initState = createVaultAddItemState(vaultAddEditType = vaultAddEditType)
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
data = createVaultData(cipherView = cipherView),
|
||||
)
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
savedStateHandle = createSavedStateHandleWithState(
|
||||
state = initState,
|
||||
vaultAddEditType = vaultAddEditType,
|
||||
),
|
||||
)
|
||||
mutableVaultItemFlow.value = DataState.Loaded(data = createMockCipherView(number = 1))
|
||||
|
||||
coEvery {
|
||||
vaultRepository.softDeleteCipher(
|
||||
cipherId = "mockId-1",
|
||||
cipherView = createMockCipherView(number = 1),
|
||||
cipherView = cipherView,
|
||||
)
|
||||
} returns DeleteCipherResult.Success
|
||||
|
||||
@@ -300,20 +321,24 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
@Test
|
||||
fun `ConfirmDeleteClick with DeleteCipherResult Failure should show generic error`() =
|
||||
runTest {
|
||||
val cipherView = createMockCipherView(1)
|
||||
val vaultAddEditType = VaultAddEditType.EditItem(DEFAULT_EDIT_ITEM_ID)
|
||||
val initState = createVaultAddItemState(vaultAddEditType = vaultAddEditType)
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
data = createVaultData(cipherView = cipherView),
|
||||
)
|
||||
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
savedStateHandle = createSavedStateHandleWithState(
|
||||
state = initState,
|
||||
vaultAddEditType = vaultAddEditType,
|
||||
),
|
||||
)
|
||||
mutableVaultItemFlow.value = DataState.Loaded(data = createMockCipherView(number = 1))
|
||||
|
||||
coEvery {
|
||||
vaultRepository.softDeleteCipher(
|
||||
cipherId = "mockId-1",
|
||||
cipherView = createMockCipherView(number = 1),
|
||||
cipherView = cipherView,
|
||||
)
|
||||
} returns DeleteCipherResult.Error
|
||||
|
||||
@@ -327,11 +352,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
),
|
||||
commonContentViewState = createCommonContentViewState(
|
||||
name = "mockName-1",
|
||||
folder = "mockId-1".asText(),
|
||||
ownership = "",
|
||||
originalCipher = createMockCipherView(number = 1),
|
||||
availableFolders = emptyList(),
|
||||
availableOwners = emptyList(),
|
||||
notes = "mockNotes-1",
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.HiddenField(
|
||||
@@ -347,7 +368,8 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
uri = listOf(UriItem("testId", "www.mockuri1.com", UriMatchType.HOST)),
|
||||
totpCode = "mockTotp-1",
|
||||
canViewPassword = false,
|
||||
),
|
||||
)
|
||||
.copy(totp = "mockTotp-1"),
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
@@ -362,17 +384,21 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
R.string.saving.asText(),
|
||||
),
|
||||
commonContentViewState = createCommonContentViewState(
|
||||
name = "mockName",
|
||||
name = "mockName-1",
|
||||
),
|
||||
)
|
||||
|
||||
val stateWithName = createVaultAddItemState(
|
||||
vaultAddEditType = VaultAddEditType.AddItem,
|
||||
commonContentViewState = createCommonContentViewState(
|
||||
name = "mockName",
|
||||
name = "mockName-1",
|
||||
),
|
||||
)
|
||||
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(),
|
||||
)
|
||||
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
createSavedStateHandleWithState(
|
||||
state = stateWithName,
|
||||
@@ -381,7 +407,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
|
||||
coEvery {
|
||||
vaultRepository.createCipher(any())
|
||||
vaultRepository.createCipherInOrganization(any(), any())
|
||||
} returns CreateCipherResult.Success
|
||||
|
||||
viewModel.stateFlow.test {
|
||||
@@ -392,7 +418,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
|
||||
coVerify(exactly = 1) {
|
||||
vaultRepository.createCipher(any())
|
||||
vaultRepository.createCipherInOrganization(any(), any())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -401,10 +427,12 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
val stateWithName = createVaultAddItemState(
|
||||
vaultAddEditType = VaultAddEditType.AddItem,
|
||||
commonContentViewState = createCommonContentViewState(
|
||||
name = "mockName",
|
||||
name = "mockName-1",
|
||||
),
|
||||
)
|
||||
|
||||
mutableVaultDataFlow.value = DataState.Loaded(createVaultData())
|
||||
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
createSavedStateHandleWithState(
|
||||
state = stateWithName,
|
||||
@@ -413,7 +441,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
|
||||
coEvery {
|
||||
vaultRepository.createCipher(any())
|
||||
vaultRepository.createCipherInOrganization(any(), any())
|
||||
} returns CreateCipherResult.Success
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(VaultAddEditAction.Common.SaveClick)
|
||||
@@ -423,12 +451,14 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `in add mode, SaveClick createCipher error should emit ShowToast`() = runTest {
|
||||
|
||||
val stateWithName = createVaultAddItemState(
|
||||
vaultAddEditType = VaultAddEditType.AddItem,
|
||||
commonContentViewState = createCommonContentViewState(
|
||||
name = "mockName",
|
||||
name = "mockName-1",
|
||||
),
|
||||
)
|
||||
mutableVaultDataFlow.value = DataState.Loaded(createVaultData())
|
||||
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
createSavedStateHandleWithState(
|
||||
@@ -438,7 +468,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
|
||||
coEvery {
|
||||
vaultRepository.createCipher(any())
|
||||
vaultRepository.createCipherInOrganization(any(), any())
|
||||
} returns CreateCipherResult.Error
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.actionChannel.trySend(VaultAddEditAction.Common.SaveClick)
|
||||
@@ -449,7 +479,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
@Test
|
||||
fun `in edit mode, SaveClick should show dialog, and remove it once an item is saved`() =
|
||||
runTest {
|
||||
val cipherView = mockk<CipherView>()
|
||||
val cipherView = createMockCipherView(1)
|
||||
val vaultAddEditType = VaultAddEditType.EditItem(DEFAULT_EDIT_ITEM_ID)
|
||||
val stateWithDialog = createVaultAddItemState(
|
||||
vaultAddEditType = vaultAddEditType,
|
||||
@@ -457,14 +487,32 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
R.string.saving.asText(),
|
||||
),
|
||||
commonContentViewState = createCommonContentViewState(
|
||||
name = "mockName",
|
||||
name = "mockName-1",
|
||||
originalCipher = cipherView,
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.HiddenField(
|
||||
itemId = "testId",
|
||||
name = "mockName-1",
|
||||
value = "mockValue-1",
|
||||
),
|
||||
),
|
||||
notes = "mockNotes-1",
|
||||
),
|
||||
)
|
||||
|
||||
val stateWithName = createVaultAddItemState(
|
||||
vaultAddEditType = vaultAddEditType,
|
||||
commonContentViewState = createCommonContentViewState(
|
||||
name = "mockName",
|
||||
name = "mockName-1",
|
||||
originalCipher = cipherView,
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.HiddenField(
|
||||
itemId = "testId",
|
||||
name = "mockName-1",
|
||||
value = "mockValue-1",
|
||||
),
|
||||
),
|
||||
notes = "mockNotes-1",
|
||||
),
|
||||
)
|
||||
every {
|
||||
@@ -473,7 +521,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
resourceManager = resourceManager,
|
||||
)
|
||||
} returns stateWithName.viewState
|
||||
mutableVaultItemFlow.value = DataState.Loaded(cipherView)
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
data = createVaultData(cipherView = cipherView),
|
||||
)
|
||||
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
createSavedStateHandleWithState(
|
||||
@@ -506,12 +556,21 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
@Test
|
||||
fun `in edit mode, SaveClick updateCipher error with a null message should show an error dialog with a generic message`() =
|
||||
runTest {
|
||||
val cipherView = mockk<CipherView>()
|
||||
val cipherView = createMockCipherView(1)
|
||||
val vaultAddEditType = VaultAddEditType.EditItem(DEFAULT_EDIT_ITEM_ID)
|
||||
val stateWithName = createVaultAddItemState(
|
||||
vaultAddEditType = vaultAddEditType,
|
||||
commonContentViewState = createCommonContentViewState(
|
||||
name = "mockName",
|
||||
name = "mockName-1",
|
||||
originalCipher = cipherView,
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.HiddenField(
|
||||
itemId = "testId",
|
||||
name = "mockName-1",
|
||||
value = "mockValue-1",
|
||||
),
|
||||
),
|
||||
notes = "mockNotes-1",
|
||||
),
|
||||
)
|
||||
|
||||
@@ -524,7 +583,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
coEvery {
|
||||
vaultRepository.updateCipher(DEFAULT_EDIT_ITEM_ID, any())
|
||||
} returns UpdateCipherResult.Error(errorMessage = null)
|
||||
mutableVaultItemFlow.value = DataState.Loaded(cipherView)
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
data = createVaultData(cipherView = cipherView),
|
||||
)
|
||||
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
createSavedStateHandleWithState(
|
||||
@@ -553,26 +614,34 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
@Test
|
||||
fun `in edit mode, SaveClick updateCipher error with a non-null message should show an error dialog with that message`() =
|
||||
runTest {
|
||||
val cipherView = mockk<CipherView>()
|
||||
val cipherView = createMockCipherView(1)
|
||||
val vaultAddEditType = VaultAddEditType.EditItem(DEFAULT_EDIT_ITEM_ID)
|
||||
val stateWithName = createVaultAddItemState(
|
||||
vaultAddEditType = vaultAddEditType,
|
||||
commonContentViewState = createCommonContentViewState(
|
||||
name = "mockName",
|
||||
name = "mockName-1",
|
||||
originalCipher = cipherView,
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.HiddenField(
|
||||
itemId = "testId",
|
||||
name = "mockName-1",
|
||||
value = "mockValue-1",
|
||||
),
|
||||
),
|
||||
notes = "mockNotes-1",
|
||||
),
|
||||
)
|
||||
val errorMessage = "You do not have permission to edit this."
|
||||
|
||||
every {
|
||||
cipherView.toViewState(
|
||||
isClone = false,
|
||||
resourceManager = resourceManager,
|
||||
)
|
||||
cipherView.toViewState(isClone = false, resourceManager = resourceManager)
|
||||
} returns stateWithName.viewState
|
||||
coEvery {
|
||||
vaultRepository.updateCipher(DEFAULT_EDIT_ITEM_ID, any())
|
||||
} returns UpdateCipherResult.Error(errorMessage = errorMessage)
|
||||
mutableVaultItemFlow.value = DataState.Loaded(cipherView)
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(cipherView = cipherView),
|
||||
)
|
||||
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
createSavedStateHandleWithState(
|
||||
@@ -599,6 +668,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `Saving item with an empty name field will cause a dialog to show up`() = runTest {
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(cipherView = createMockCipherView(1)),
|
||||
)
|
||||
val stateWithNoName = createVaultAddItemState(
|
||||
commonContentViewState = createCommonContentViewState(name = ""),
|
||||
)
|
||||
@@ -627,6 +699,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `HandleDialogDismiss will remove the current dialog`() = runTest {
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(cipherView = createMockCipherView(1)),
|
||||
)
|
||||
val errorState = createVaultAddItemState(
|
||||
vaultAddEditType = VaultAddEditType.AddItem,
|
||||
dialogState = VaultAddEditState.DialogState.Generic(
|
||||
@@ -652,6 +727,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `TypeOptionSelect LOGIN should switch to LoginItem`() = runTest {
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(cipherView = createMockCipherView(1)),
|
||||
)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddEditAction.Common.TypeOptionSelect(
|
||||
VaultAddEditState.ItemTypeOption.LOGIN,
|
||||
@@ -678,6 +756,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `TypeOptionSelect CARD should switch to CardItem`() = runTest {
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(cipherView = createMockCipherView(1)),
|
||||
)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddEditAction.Common.TypeOptionSelect(
|
||||
VaultAddEditState.ItemTypeOption.CARD,
|
||||
@@ -704,6 +785,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `TypeOptionSelect IDENTITY should switch to IdentityItem`() = runTest {
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(cipherView = createMockCipherView(1)),
|
||||
)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddEditAction.Common.TypeOptionSelect(
|
||||
VaultAddEditState.ItemTypeOption.IDENTITY,
|
||||
@@ -730,6 +814,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `TypeOptionSelect SECURE_NOTES should switch to SecureNotesItem`() = runTest {
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(cipherView = createMockCipherView(1)),
|
||||
)
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
val action = VaultAddEditAction.Common.TypeOptionSelect(
|
||||
VaultAddEditState.ItemTypeOption.SECURE_NOTES,
|
||||
@@ -760,6 +847,10 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(cipherView = createMockCipherView(1)),
|
||||
)
|
||||
|
||||
viewModel = createAddVaultItemViewModel()
|
||||
}
|
||||
|
||||
@@ -846,7 +937,11 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
),
|
||||
)
|
||||
|
||||
mutableVaultItemFlow.value = DataState.Loaded(data = cipherView)
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
data = createVaultData(
|
||||
cipherView = cipherView,
|
||||
),
|
||||
)
|
||||
|
||||
val breachCount = 5
|
||||
coEvery {
|
||||
@@ -1053,6 +1148,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(cipherView = createMockCipherView(1)),
|
||||
)
|
||||
vaultAddItemInitialState = createVaultAddItemState(
|
||||
typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Identity(),
|
||||
)
|
||||
@@ -1344,6 +1442,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(cipherView = createMockCipherView(1)),
|
||||
)
|
||||
vaultAddItemInitialState = createVaultAddItemState(
|
||||
typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.Card(),
|
||||
)
|
||||
@@ -1456,6 +1557,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
mutableVaultDataFlow.value = DataState.Loaded(
|
||||
createVaultData(cipherView = createMockCipherView(1)),
|
||||
)
|
||||
vaultAddItemInitialState = createVaultAddItemState()
|
||||
secureNotesInitialSavedStateHandle = createSavedStateHandleWithState(
|
||||
state = vaultAddItemInitialState,
|
||||
@@ -1493,16 +1597,18 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
@Test
|
||||
fun `FolderChange should update folder`() = runTest {
|
||||
val action = VaultAddEditAction.Common.FolderChange(
|
||||
"newFolder".asText(),
|
||||
VaultAddEditState.Folder(
|
||||
id = "mockId-1",
|
||||
name = "Folder 1",
|
||||
),
|
||||
)
|
||||
|
||||
viewModel.actionChannel.trySend(action)
|
||||
|
||||
val expectedState = vaultAddItemInitialState.copy(
|
||||
viewState = VaultAddEditState.ViewState.Content(
|
||||
common = createCommonContentViewState(
|
||||
folder = "newFolder".asText(),
|
||||
),
|
||||
common = createCommonContentViewState()
|
||||
.copy(selectedFolderId = "mockId-1"),
|
||||
type = createLoginTypeContentViewState(),
|
||||
),
|
||||
)
|
||||
@@ -1570,15 +1676,20 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
@Test
|
||||
fun `OwnershipChange should update ownership`() = runTest {
|
||||
val action = VaultAddEditAction.Common.OwnershipChange(ownership = "newOwner")
|
||||
val action = VaultAddEditAction.Common.OwnershipChange(
|
||||
ownership = VaultAddEditState.Owner(
|
||||
id = "mockId-1",
|
||||
name = "a@b.com",
|
||||
collections = emptyList(),
|
||||
),
|
||||
)
|
||||
|
||||
viewModel.actionChannel.trySend(action)
|
||||
|
||||
val expectedState = vaultAddItemInitialState.copy(
|
||||
viewState = VaultAddEditState.ViewState.Content(
|
||||
common = createCommonContentViewState(
|
||||
ownership = "newOwner",
|
||||
),
|
||||
common = createCommonContentViewState()
|
||||
.copy(selectedOwnerId = "mockId-1"),
|
||||
type = createLoginTypeContentViewState(),
|
||||
),
|
||||
)
|
||||
@@ -1917,28 +2028,38 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
@Suppress("LongParameterList")
|
||||
private fun createCommonContentViewState(
|
||||
name: String = "",
|
||||
folder: Text = R.string.folder_none.asText(),
|
||||
favorite: Boolean = false,
|
||||
masterPasswordReprompt: Boolean = false,
|
||||
notes: String = "",
|
||||
customFieldData: List<VaultAddEditState.Custom> = listOf(),
|
||||
ownership: String = "placeholder@email.com",
|
||||
originalCipher: CipherView? = null,
|
||||
availableFolders: List<Text> = listOf(
|
||||
"Folder 1".asText(),
|
||||
"Folder 2".asText(),
|
||||
"Folder 3".asText(),
|
||||
availableFolders: List<VaultAddEditState.Folder> = listOf(
|
||||
VaultAddEditState.Folder(
|
||||
id = null,
|
||||
name = "No Folder",
|
||||
),
|
||||
),
|
||||
availableOwners: List<VaultAddEditState.Owner> = listOf(
|
||||
VaultAddEditState.Owner(
|
||||
id = null,
|
||||
name = "activeEmail",
|
||||
collections = emptyList(),
|
||||
),
|
||||
VaultAddEditState.Owner(
|
||||
id = "organizationId",
|
||||
name = "organizationName",
|
||||
collections = emptyList(),
|
||||
),
|
||||
),
|
||||
availableOwners: List<String> = listOf("a@b.com", "c@d.com"),
|
||||
): VaultAddEditState.ViewState.Content.Common =
|
||||
VaultAddEditState.ViewState.Content.Common(
|
||||
name = name,
|
||||
folderName = folder,
|
||||
selectedFolderId = null,
|
||||
favorite = favorite,
|
||||
customFieldData = customFieldData,
|
||||
masterPasswordReprompt = masterPasswordReprompt,
|
||||
notes = notes,
|
||||
ownership = ownership,
|
||||
selectedOwnerId = null,
|
||||
originalCipher = originalCipher,
|
||||
availableFolders = availableFolders,
|
||||
availableOwners = availableOwners,
|
||||
@@ -1992,6 +2113,45 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
authRepository = authRepository,
|
||||
)
|
||||
|
||||
private fun createVaultData(
|
||||
cipherView: CipherView? = null,
|
||||
collectionViewList: List<CollectionView> = emptyList(),
|
||||
folderViewList: List<FolderView> = emptyList(),
|
||||
sendViewList: List<SendView> = emptyList(),
|
||||
): VaultData =
|
||||
VaultData(
|
||||
cipherViewList = cipherView?.let { listOf(it) } ?: emptyList(),
|
||||
collectionViewList = collectionViewList,
|
||||
folderViewList = folderViewList,
|
||||
sendViewList = sendViewList,
|
||||
)
|
||||
|
||||
fun createUserState(): UserState =
|
||||
UserState(
|
||||
activeUserId = "activeUserId",
|
||||
accounts = listOf(
|
||||
UserState.Account(
|
||||
userId = "activeUserId",
|
||||
name = "activeName",
|
||||
email = "activeEmail",
|
||||
avatarColorHex = "#ffecbc49",
|
||||
environment = Environment.Eu,
|
||||
isPremium = true,
|
||||
isLoggedIn = false,
|
||||
isVaultUnlocked = false,
|
||||
organizations = listOf(
|
||||
Organization(
|
||||
id = "organizationId",
|
||||
name = "organizationName",
|
||||
),
|
||||
),
|
||||
isBiometricsEnabled = true,
|
||||
vaultUnlockType = VaultUnlockType.MASTER_PASSWORD,
|
||||
),
|
||||
),
|
||||
hasPendingAccountAddition = false,
|
||||
)
|
||||
|
||||
/**
|
||||
* A function to test the changes in custom fields for each type.
|
||||
*/
|
||||
@@ -2135,4 +2295,4 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private const val TEST_ID = "testId"
|
||||
|
||||
private const val DEFAULT_EDIT_ITEM_ID: String = "edit_item_id"
|
||||
private const val DEFAULT_EDIT_ITEM_ID: String = "mockId-1"
|
||||
|
||||
-11
@@ -13,7 +13,6 @@ import com.bitwarden.core.PasswordHistoryView
|
||||
import com.bitwarden.core.SecureNoteType
|
||||
import com.bitwarden.core.SecureNoteView
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.manager.resource.ResourceManager
|
||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState
|
||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.UriItem
|
||||
@@ -61,11 +60,9 @@ class CipherViewExtensionsTest {
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
originalCipher = cipherView,
|
||||
name = "cipher",
|
||||
folderName = R.string.folder_none.asText(),
|
||||
favorite = false,
|
||||
masterPasswordReprompt = true,
|
||||
notes = "Lots of notes",
|
||||
ownership = "",
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
|
||||
VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"),
|
||||
@@ -105,11 +102,9 @@ class CipherViewExtensionsTest {
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
originalCipher = cipherView,
|
||||
name = "cipher",
|
||||
folderName = R.string.folder_none.asText(),
|
||||
favorite = false,
|
||||
masterPasswordReprompt = true,
|
||||
notes = "Lots of notes",
|
||||
ownership = "",
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
|
||||
VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"),
|
||||
@@ -154,11 +149,9 @@ class CipherViewExtensionsTest {
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
originalCipher = cipherView,
|
||||
name = "cipher",
|
||||
folderName = R.string.folder_none.asText(),
|
||||
favorite = false,
|
||||
masterPasswordReprompt = true,
|
||||
notes = "Lots of notes",
|
||||
ownership = "",
|
||||
availableFolders = emptyList(),
|
||||
availableOwners = emptyList(),
|
||||
customFieldData = listOf(
|
||||
@@ -198,11 +191,9 @@ class CipherViewExtensionsTest {
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
originalCipher = cipherView,
|
||||
name = "cipher",
|
||||
folderName = R.string.folder_none.asText(),
|
||||
favorite = false,
|
||||
masterPasswordReprompt = true,
|
||||
notes = "Lots of notes",
|
||||
ownership = "",
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
|
||||
VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"),
|
||||
@@ -231,11 +222,9 @@ class CipherViewExtensionsTest {
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
originalCipher = cipherView,
|
||||
name = "cipher - Clone",
|
||||
folderName = R.string.folder_none.asText(),
|
||||
favorite = false,
|
||||
masterPasswordReprompt = true,
|
||||
notes = "Lots of notes",
|
||||
ownership = "",
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.BooleanField(TEST_ID, "TestBoolean", false),
|
||||
VaultAddEditState.Custom.TextField(TEST_ID, "TestText", "TestText"),
|
||||
|
||||
+3
-2
@@ -18,6 +18,7 @@ import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.util.onNodeWithContentDescriptionAfterScroll
|
||||
import com.x8bit.bitwarden.ui.vault.feature.movetoorganization.util.createMockOrganizationList
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultCollection
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
@@ -100,7 +101,7 @@ class VaultMoveToOrganizationScreenTest : BaseComposeTest() {
|
||||
id = "mockOrganizationId-2",
|
||||
name = "mockOrganizationName-2",
|
||||
collections = listOf(
|
||||
VaultMoveToOrganizationState.ViewState.Content.Collection(
|
||||
VaultCollection(
|
||||
id = "mockId-2",
|
||||
name = "mockName-2",
|
||||
isSelected = false,
|
||||
@@ -141,7 +142,7 @@ class VaultMoveToOrganizationScreenTest : BaseComposeTest() {
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
VaultMoveToOrganizationAction.CollectionSelect(
|
||||
VaultMoveToOrganizationState.ViewState.Content.Collection(
|
||||
VaultCollection(
|
||||
id = "mockId-1",
|
||||
name = "mockName-1",
|
||||
isSelected = true,
|
||||
|
||||
+2
-1
@@ -18,6 +18,7 @@ import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.concat
|
||||
import com.x8bit.bitwarden.ui.vault.feature.movetoorganization.util.createMockOrganizationList
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultCollection
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.every
|
||||
@@ -119,7 +120,7 @@ class VaultMoveToOrganizationViewModelTest : BaseViewModelTest() {
|
||||
mutableCollectionFlow.tryEmit(value = DataState.Loaded(DEFAULT_COLLECTIONS))
|
||||
mutableVaultItemFlow.tryEmit(value = DataState.Loaded(createMockCipherView(number = 1)))
|
||||
val unselectCollection1Action = VaultMoveToOrganizationAction.CollectionSelect(
|
||||
VaultMoveToOrganizationState.ViewState.Content.Collection(
|
||||
VaultCollection(
|
||||
id = "mockId-1",
|
||||
name = "mockName-1",
|
||||
isSelected = true,
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package com.x8bit.bitwarden.ui.vault.feature.movetoorganization.util
|
||||
|
||||
import com.x8bit.bitwarden.ui.vault.feature.movetoorganization.VaultMoveToOrganizationState
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultCollection
|
||||
|
||||
/**
|
||||
* Creates a list of mock [VaultMoveToOrganizationState.ViewState.Content.Organization].
|
||||
@@ -24,7 +25,7 @@ fun createMockOrganization(
|
||||
id = "mockOrganizationId-$number",
|
||||
name = "mockOrganizationName-$number",
|
||||
collections = listOf(
|
||||
VaultMoveToOrganizationState.ViewState.Content.Collection(
|
||||
VaultCollection(
|
||||
id = "mockId-$number",
|
||||
name = "mockName-$number",
|
||||
isSelected = isCollectionSelected,
|
||||
|
||||
+24
-19
@@ -12,7 +12,6 @@ import com.bitwarden.core.PasswordHistoryView
|
||||
import com.bitwarden.core.SecureNoteType
|
||||
import com.bitwarden.core.SecureNoteView
|
||||
import com.bitwarden.core.UriMatchType
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.VaultAddEditState
|
||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.UriItem
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultIdentityTitle
|
||||
@@ -42,11 +41,11 @@ class VaultAddItemStateExtensionsTest {
|
||||
val loginItemType = VaultAddEditState.ViewState.Content(
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
name = "mockName-1",
|
||||
folderName = "mockFolder-1".asText(),
|
||||
selectedFolderId = "mockFolderId-1",
|
||||
favorite = false,
|
||||
masterPasswordReprompt = false,
|
||||
notes = "mockNotes-1",
|
||||
ownership = "mockOwnership-1",
|
||||
selectedOwnerId = "mockOwnerId-1",
|
||||
),
|
||||
type = VaultAddEditState.ViewState.Content.ItemType.Login(
|
||||
username = "mockUsername-1",
|
||||
@@ -61,8 +60,8 @@ class VaultAddItemStateExtensionsTest {
|
||||
assertEquals(
|
||||
CipherView(
|
||||
id = null,
|
||||
organizationId = null,
|
||||
folderId = null,
|
||||
organizationId = "mockOwnerId-1",
|
||||
folderId = "mockFolderId-1",
|
||||
collectionIds = emptyList(),
|
||||
key = null,
|
||||
name = "mockName-1",
|
||||
@@ -109,7 +108,7 @@ class VaultAddItemStateExtensionsTest {
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
originalCipher = cipherView,
|
||||
name = "mockName-1",
|
||||
folderName = "mockFolder-1".asText(),
|
||||
selectedFolderId = "mockFolderId-1",
|
||||
favorite = true,
|
||||
masterPasswordReprompt = false,
|
||||
customFieldData = listOf(
|
||||
@@ -123,7 +122,7 @@ class VaultAddItemStateExtensionsTest {
|
||||
),
|
||||
),
|
||||
notes = "mockNotes-1",
|
||||
ownership = "mockOwnership-1",
|
||||
selectedOwnerId = "mockOwnerId-1",
|
||||
),
|
||||
type = VaultAddEditState.ViewState.Content.ItemType.Login(
|
||||
username = "mockUsername-1",
|
||||
@@ -141,6 +140,8 @@ class VaultAddItemStateExtensionsTest {
|
||||
name = "mockName-1",
|
||||
notes = "mockNotes-1",
|
||||
type = CipherType.LOGIN,
|
||||
folderId = "mockFolderId-1",
|
||||
organizationId = "mockOwnerId-1",
|
||||
login = LoginView(
|
||||
username = "mockUsername-1",
|
||||
password = "mockPassword-1",
|
||||
@@ -200,11 +201,11 @@ class VaultAddItemStateExtensionsTest {
|
||||
val viewState = VaultAddEditState.ViewState.Content(
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
name = "mockName-1",
|
||||
folderName = "mockFolder-1".asText(),
|
||||
selectedFolderId = "mockId-1",
|
||||
favorite = false,
|
||||
masterPasswordReprompt = false,
|
||||
notes = "mockNotes-1",
|
||||
ownership = "mockOwnership-1",
|
||||
selectedOwnerId = "mockOwnership-1",
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.BooleanField("testId", "TestBoolean", false),
|
||||
VaultAddEditState.Custom.TextField("testId", "TestText", "TestText"),
|
||||
@@ -219,8 +220,8 @@ class VaultAddItemStateExtensionsTest {
|
||||
assertEquals(
|
||||
CipherView(
|
||||
id = null,
|
||||
organizationId = null,
|
||||
folderId = null,
|
||||
organizationId = "mockOwnership-1",
|
||||
folderId = "mockId-1",
|
||||
collectionIds = emptyList(),
|
||||
key = null,
|
||||
name = "mockName-1",
|
||||
@@ -273,11 +274,11 @@ class VaultAddItemStateExtensionsTest {
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
originalCipher = cipherView,
|
||||
name = "mockName-1",
|
||||
folderName = "mockFolder-1".asText(),
|
||||
selectedFolderId = "mockId-1",
|
||||
favorite = false,
|
||||
masterPasswordReprompt = true,
|
||||
notes = "mockNotes-1",
|
||||
ownership = "mockOwnership-1",
|
||||
selectedOwnerId = "mockOwnerId-1",
|
||||
customFieldData = emptyList(),
|
||||
),
|
||||
type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
|
||||
@@ -289,6 +290,8 @@ class VaultAddItemStateExtensionsTest {
|
||||
cipherView.copy(
|
||||
name = "mockName-1",
|
||||
notes = "mockNotes-1",
|
||||
organizationId = "mockOwnerId-1",
|
||||
folderId = "mockId-1",
|
||||
type = CipherType.SECURE_NOTE,
|
||||
secureNote = SecureNoteView(SecureNoteType.GENERIC),
|
||||
reprompt = CipherRepromptType.PASSWORD,
|
||||
@@ -305,11 +308,11 @@ class VaultAddItemStateExtensionsTest {
|
||||
val viewState = VaultAddEditState.ViewState.Content(
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
name = "mockName-1",
|
||||
folderName = "mockFolder-1".asText(),
|
||||
selectedFolderId = "mockId-1",
|
||||
favorite = false,
|
||||
masterPasswordReprompt = false,
|
||||
notes = "mockNotes-1",
|
||||
ownership = "mockOwnership-1",
|
||||
selectedOwnerId = "mockOwnerId-1",
|
||||
),
|
||||
type = VaultAddEditState.ViewState.Content.ItemType.Identity(
|
||||
selectedTitle = VaultIdentityTitle.MR,
|
||||
@@ -338,8 +341,8 @@ class VaultAddItemStateExtensionsTest {
|
||||
assertEquals(
|
||||
CipherView(
|
||||
id = null,
|
||||
organizationId = null,
|
||||
folderId = null,
|
||||
organizationId = "mockOwnerId-1",
|
||||
folderId = "mockId-1",
|
||||
collectionIds = emptyList(),
|
||||
key = null,
|
||||
name = "mockName-1",
|
||||
@@ -392,7 +395,7 @@ class VaultAddItemStateExtensionsTest {
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
originalCipher = cipherView,
|
||||
name = "mockName-1",
|
||||
folderName = "mockFolder-1".asText(),
|
||||
selectedFolderId = "mockId-1",
|
||||
favorite = true,
|
||||
masterPasswordReprompt = false,
|
||||
customFieldData = listOf(
|
||||
@@ -406,7 +409,7 @@ class VaultAddItemStateExtensionsTest {
|
||||
),
|
||||
),
|
||||
notes = "mockNotes-1",
|
||||
ownership = "mockOwnership-1",
|
||||
selectedOwnerId = "mockOwnerId-1",
|
||||
),
|
||||
type = VaultAddEditState.ViewState.Content.ItemType.Identity(
|
||||
selectedTitle = VaultIdentityTitle.MR,
|
||||
@@ -437,6 +440,8 @@ class VaultAddItemStateExtensionsTest {
|
||||
cipherView.copy(
|
||||
name = "mockName-1",
|
||||
notes = "mockNotes-1",
|
||||
organizationId = "mockOwnerId-1",
|
||||
folderId = "mockId-1",
|
||||
type = CipherType.IDENTITY,
|
||||
identity = IdentityView(
|
||||
title = "MR",
|
||||
|
||||
Reference in New Issue
Block a user