mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 10:48:47 +03:00
Add send delete confirmation dialog (#595)
This commit is contained in:
parent
0d171e91b9
commit
5288a697e5
2 changed files with 48 additions and 4 deletions
|
@ -9,7 +9,10 @@ import androidx.compose.material3.TopAppBarDefaults
|
|||
import androidx.compose.material3.rememberTopAppBarState
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
@ -29,6 +32,7 @@ import com.x8bit.bitwarden.ui.platform.components.BitwardenOverflowActionItem
|
|||
import com.x8bit.bitwarden.ui.platform.components.BitwardenScaffold
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenTextButton
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenTopAppBar
|
||||
import com.x8bit.bitwarden.ui.platform.components.BitwardenTwoButtonDialog
|
||||
import com.x8bit.bitwarden.ui.platform.components.LoadingDialogState
|
||||
import com.x8bit.bitwarden.ui.platform.components.OverflowMenuItemData
|
||||
import com.x8bit.bitwarden.ui.platform.util.persistentListOfNotNull
|
||||
|
@ -69,6 +73,23 @@ fun AddSendScreen(
|
|||
{ viewModel.trySendAction(AddSendAction.DismissDialogClick) }
|
||||
},
|
||||
)
|
||||
var shouldShowDeleteConfirmationDialog by rememberSaveable { mutableStateOf(false) }
|
||||
if (shouldShowDeleteConfirmationDialog) {
|
||||
BitwardenTwoButtonDialog(
|
||||
title = stringResource(id = R.string.delete),
|
||||
message = stringResource(id = R.string.are_you_sure_delete_send),
|
||||
confirmButtonText = stringResource(id = R.string.yes),
|
||||
dismissButtonText = stringResource(id = R.string.cancel),
|
||||
onConfirmClick = remember(viewModel) {
|
||||
{
|
||||
viewModel.trySendAction(AddSendAction.DeleteClick)
|
||||
shouldShowDeleteConfirmationDialog = false
|
||||
}
|
||||
},
|
||||
onDismissClick = { shouldShowDeleteConfirmationDialog = false },
|
||||
onDismissRequest = { shouldShowDeleteConfirmationDialog = false },
|
||||
)
|
||||
}
|
||||
|
||||
BitwardenScaffold(
|
||||
modifier = Modifier
|
||||
|
@ -118,9 +139,7 @@ fun AddSendScreen(
|
|||
),
|
||||
OverflowMenuItemData(
|
||||
text = stringResource(id = R.string.delete),
|
||||
onClick = remember(viewModel) {
|
||||
{ viewModel.trySendAction(AddSendAction.DeleteClick) }
|
||||
},
|
||||
onClick = { shouldShowDeleteConfirmationDialog = true },
|
||||
),
|
||||
),
|
||||
)
|
||||
|
|
|
@ -181,7 +181,7 @@ class AddSendScreenTest : BaseComposeTest() {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `on overflow remove Delete button click should send DeleteClick`() {
|
||||
fun `on overflow Delete button click should Display delete confirmation dialog`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE.copy(
|
||||
addSendType = AddSendType.EditItem(sendItemId = "sendId"),
|
||||
)
|
||||
|
@ -194,6 +194,31 @@ class AddSendScreenTest : BaseComposeTest() {
|
|||
.onNodeWithText("Delete")
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Are you sure you want to delete this Send?")
|
||||
.assert(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on delete confirmation dialog yes click should send DeleteClick`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE.copy(
|
||||
addSendType = AddSendType.EditItem(sendItemId = "sendId"),
|
||||
)
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("More")
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Delete")
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Yes")
|
||||
.assert(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
|
||||
verify(exactly = 1) {
|
||||
viewModel.trySendAction(AddSendAction.DeleteClick)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue