BIT-506: Hard delete (#910)

This commit is contained in:
Ramsey Smith
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent 087018bd26
commit 81d0e2f4db
5 changed files with 122 additions and 9 deletions
@@ -660,6 +660,44 @@ class VaultItemScreenTest : BaseComposeTest() {
}
}
@Test
fun `Delete dialog text should display according to state`() {
// Open the overflow menu
composeTestRule
.onNodeWithContentDescription("More")
.performClick()
// Click on the delete item in the dropdown
composeTestRule
.onAllNodesWithText("Delete")
.filterToOne(hasAnyAncestor(isPopup()))
.performClick()
composeTestRule
.onAllNodesWithText("Do you really want to send to the trash?")
.filterToOne(hasAnyAncestor(isDialog()))
.assertIsDisplayed()
mutableStateFlow.update {
it.copy(
viewState = DEFAULT_LOGIN_VIEW_STATE.copy(
common = DEFAULT_COMMON.copy(
currentCipher = createMockCipherView(
number = 1,
isDeleted = true,
),
),
),
)
}
composeTestRule
.onAllNodesWithText(
text = "Do you really want to permanently delete? This cannot be undone.",
)
.filterToOne(hasAnyAncestor(isDialog()))
.assertIsDisplayed()
}
@Test
fun `Restore click should send show restore confirmation dialog`() {
mutableStateFlow.update {
@@ -42,6 +42,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import java.time.Instant
@Suppress("LargeClass")
class VaultItemViewModelTest : BaseViewModelTest() {
@@ -240,6 +241,52 @@ class VaultItemViewModelTest : BaseViewModelTest() {
)
}
@Test
fun `ConfirmDeleteClick with deleted cipher should should invoke hardDeleteCipher`() =
runTest {
val loginViewState = DEFAULT_VIEW_STATE.copy(
common = DEFAULT_COMMON
.copy(
requiresReprompt = false,
currentCipher = DEFAULT_COMMON
.currentCipher
?.copy(deletedDate = Instant.MIN),
),
)
val mockCipherView = mockk<CipherView> {
every {
toViewState(
isPremiumUser = true,
totpCodeItemData = createTotpCodeData(),
)
} returns loginViewState
}
mutableVaultItemFlow.value = DataState.Loaded(data = mockCipherView)
mutableAuthCodeItemFlow.value =
DataState.Loaded(data = createVerificationCodeItem())
val viewModel = createViewModel(state = DEFAULT_STATE)
coEvery {
vaultRepo.hardDeleteCipher(
cipherId = VAULT_ITEM_ID,
)
} returns DeleteCipherResult.Success
viewModel.trySendAction(VaultItemAction.Common.ConfirmDeleteClick)
viewModel.eventFlow.test {
assertEquals(
VaultItemEvent.ShowToast(R.string.item_deleted.asText()),
awaitItem(),
)
assertEquals(
VaultItemEvent.NavigateBack,
awaitItem(),
)
}
coVerify { vaultRepo.hardDeleteCipher(cipherId = VAULT_ITEM_ID) }
}
@Test
@Suppress("MaxLineLength")
fun `ConfirmRestoreClick with RestoreCipherResult Success should should ShowToast and NavigateBack`() =