mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-503: Move item to trash from edit screen (#786)
This commit is contained in:
committed by
Álison Fernandes
parent
05bdf5a25e
commit
bc3a76260f
+100
@@ -2225,6 +2225,11 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
.onAllNodesWithText("Move to Organization")
|
||||
.filterToOne(hasAnyAncestor(isPopup()))
|
||||
.assertDoesNotExist()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Delete")
|
||||
.filterToOne(hasAnyAncestor(isPopup()))
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -2260,6 +2265,101 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
.onAllNodesWithText("Collections")
|
||||
.filterToOne(hasAnyAncestor(isPopup()))
|
||||
.assertDoesNotExist()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Delete")
|
||||
.filterToOne(hasAnyAncestor(isPopup()))
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Delete dialog ok click should send ConfirmDeleteClick`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
vaultAddEditType = VaultAddEditType.EditItem(vaultItemId = "mockId-1"),
|
||||
viewState = VaultAddEditState.ViewState.Content(
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
originalCipher = createMockCipherView(1),
|
||||
),
|
||||
type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule.assertNoDialogExists()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("More")
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Delete")
|
||||
.filterToOne(hasAnyAncestor(isPopup()))
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Do you really want to send to the trash?")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Cancel")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Ok")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
|
||||
composeTestRule.assertNoDialogExists()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(VaultAddEditAction.Common.ConfirmDeleteClick)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Delete dialog cancel click should dismiss the dialog`() {
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
vaultAddEditType = VaultAddEditType.EditItem(vaultItemId = "mockId-1"),
|
||||
viewState = VaultAddEditState.ViewState.Content(
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
originalCipher = createMockCipherView(1),
|
||||
),
|
||||
type = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
composeTestRule.assertNoDialogExists()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("More")
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Delete")
|
||||
.filterToOne(hasAnyAncestor(isPopup()))
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Do you really want to send to the trash?")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Cancel")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Ok")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
|
||||
composeTestRule.assertNoDialogExists()
|
||||
}
|
||||
|
||||
//region Helper functions
|
||||
|
||||
+104
@@ -14,6 +14,7 @@ import com.x8bit.bitwarden.data.tools.generator.repository.util.FakeGeneratorRep
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockCipherView
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
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.ui.platform.base.BaseViewModelTest
|
||||
@@ -223,6 +224,97 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Suppress("MaxLineLength")
|
||||
fun `ConfirmDeleteClick with DeleteCipherResult Success should emit ShowToast and NavigateBack`() =
|
||||
runTest {
|
||||
val vaultAddEditType = VaultAddEditType.EditItem(DEFAULT_EDIT_ITEM_ID)
|
||||
val initState = createVaultAddItemState(vaultAddEditType = vaultAddEditType)
|
||||
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),
|
||||
)
|
||||
} returns DeleteCipherResult.Success
|
||||
|
||||
viewModel.trySendAction(VaultAddEditAction.Common.ConfirmDeleteClick)
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
assertEquals(
|
||||
VaultAddEditEvent.ShowToast(R.string.item_soft_deleted.asText()),
|
||||
awaitItem(),
|
||||
)
|
||||
assertEquals(
|
||||
VaultAddEditEvent.NavigateBack,
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ConfirmDeleteClick with DeleteCipherResult Failure should show generic error`() =
|
||||
runTest {
|
||||
val vaultAddEditType = VaultAddEditType.EditItem(DEFAULT_EDIT_ITEM_ID)
|
||||
val initState = createVaultAddItemState(vaultAddEditType = vaultAddEditType)
|
||||
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),
|
||||
)
|
||||
} returns DeleteCipherResult.Error
|
||||
|
||||
viewModel.trySendAction(VaultAddEditAction.Common.ConfirmDeleteClick)
|
||||
|
||||
assertEquals(
|
||||
createVaultAddItemState(
|
||||
vaultAddEditType = vaultAddEditType,
|
||||
dialogState = VaultAddEditState.DialogState.Generic(
|
||||
message = R.string.generic_error_message.asText(),
|
||||
),
|
||||
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(
|
||||
itemId = "testId",
|
||||
name = "mockName-1",
|
||||
value = "mockValue-1",
|
||||
),
|
||||
),
|
||||
),
|
||||
typeContentViewState = createLoginTypeContentViewState(
|
||||
username = "mockUsername-1",
|
||||
password = "mockPassword-1",
|
||||
uri = "www.mockuri1.com",
|
||||
totpCode = "mockTotp-1",
|
||||
canViewPassword = false,
|
||||
),
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `in add mode, SaveClick should show dialog, and remove it once an item is saved`() =
|
||||
runTest {
|
||||
@@ -1785,6 +1877,13 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
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(),
|
||||
),
|
||||
availableOwners: List<String> = listOf("a@b.com", "c@d.com"),
|
||||
): VaultAddEditState.ViewState.Content.Common =
|
||||
VaultAddEditState.ViewState.Content.Common(
|
||||
name = name,
|
||||
@@ -1794,6 +1893,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
masterPasswordReprompt = masterPasswordReprompt,
|
||||
notes = notes,
|
||||
ownership = ownership,
|
||||
originalCipher = originalCipher,
|
||||
availableFolders = availableFolders,
|
||||
availableOwners = availableOwners,
|
||||
)
|
||||
|
||||
private fun createLoginTypeContentViewState(
|
||||
@@ -1801,12 +1903,14 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
password: String = "",
|
||||
uri: String = "",
|
||||
totpCode: String? = null,
|
||||
canViewPassword: Boolean = true,
|
||||
): VaultAddEditState.ViewState.Content.ItemType.Login =
|
||||
VaultAddEditState.ViewState.Content.ItemType.Login(
|
||||
username = username,
|
||||
password = password,
|
||||
uri = uri,
|
||||
totp = totpCode,
|
||||
canViewPassword = canViewPassword,
|
||||
)
|
||||
|
||||
private fun createSavedStateHandleWithState(
|
||||
|
||||
Reference in New Issue
Block a user