PM-14352 Dismiss Snackbar when user clicks it as a default unless the specific dismiss action is present. (#4291)

This commit is contained in:
Dave Severns 2024-11-12 13:39:30 -05:00 committed by GitHub
parent c6beaec102
commit 9a5aa217e6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 35 additions and 0 deletions

View file

@ -1,6 +1,7 @@
package com.x8bit.bitwarden.ui.platform.components.snackbar package com.x8bit.bitwarden.ui.platform.components.snackbar
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -28,6 +29,7 @@ import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme
* Custom snackbar for Bitwarden. * Custom snackbar for Bitwarden.
* Shows a message with an optional actions and title. * Shows a message with an optional actions and title.
*/ */
@Suppress("LongMethod")
@Composable @Composable
fun BitwardenSnackbar( fun BitwardenSnackbar(
bitwardenSnackbarData: BitwardenSnackbarData, bitwardenSnackbarData: BitwardenSnackbarData,
@ -45,6 +47,12 @@ fun BitwardenSnackbar(
color = BitwardenTheme.colorScheme.background.alert, color = BitwardenTheme.colorScheme.background.alert,
shape = BitwardenTheme.shapes.snackbar, shape = BitwardenTheme.shapes.snackbar,
) )
// I there is no explicit dismiss action, the Snackbar can be dismissed by clicking
// anywhere on the Snackbar.
.clickable(
enabled = !bitwardenSnackbarData.withDismissAction,
onClick = onDismiss,
)
.padding(16.dp), .padding(16.dp),
) { ) {
Column { Column {

View file

@ -2,6 +2,7 @@ package com.x8bit.bitwarden.ui.platform.feature.settings.vault
import androidx.compose.ui.test.assert import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.hasAnyAncestor import androidx.compose.ui.test.hasAnyAncestor
import androidx.compose.ui.test.isDialog import androidx.compose.ui.test.isDialog
import androidx.compose.ui.test.onNodeWithContentDescription import androidx.compose.ui.test.onNodeWithContentDescription
@ -227,4 +228,17 @@ class VaultSettingsScreenTest : BaseComposeTest() {
mutableEventFlow.tryEmit(VaultSettingsEvent.ShowSnackbar(data)) mutableEventFlow.tryEmit(VaultSettingsEvent.ShowSnackbar(data))
composeTestRule.onNodeWithText("message").assertIsDisplayed() composeTestRule.onNodeWithText("message").assertIsDisplayed()
} }
@Test
fun `when snackbar is displayed clicking on it should dismiss`() {
val data = BitwardenSnackbarData("message".asText())
mutableEventFlow.tryEmit(VaultSettingsEvent.ShowSnackbar(data))
composeTestRule
.onNodeWithText("message")
.assertIsDisplayed()
.performClick()
composeTestRule
.onNodeWithText("message")
.assertIsNotDisplayed()
}
} }

View file

@ -1206,6 +1206,19 @@ class VaultScreenTest : BaseComposeTest() {
composeTestRule.onNodeWithText("message").assertIsDisplayed() composeTestRule.onNodeWithText("message").assertIsDisplayed()
} }
@Test
fun `when snackbar is displayed clicking on it should dismiss`() {
val data = BitwardenSnackbarData("message".asText())
mutableEventFlow.tryEmit(VaultEvent.ShowSnackbar(data))
composeTestRule
.onNodeWithText("message")
.assertIsDisplayed()
.performClick()
composeTestRule
.onNodeWithText("message")
.assertIsNotDisplayed()
}
@Test @Test
fun `SSH key group header should display correctly based on state`() { fun `SSH key group header should display correctly based on state`() {
val count = 1 val count = 1