diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/snackbar/BitwardenSnackbar.kt b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/snackbar/BitwardenSnackbar.kt index 827e8d2f9..a25592d6e 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/snackbar/BitwardenSnackbar.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/platform/components/snackbar/BitwardenSnackbar.kt @@ -1,6 +1,7 @@ package com.x8bit.bitwarden.ui.platform.components.snackbar import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -28,6 +29,7 @@ import com.x8bit.bitwarden.ui.platform.theme.BitwardenTheme * Custom snackbar for Bitwarden. * Shows a message with an optional actions and title. */ +@Suppress("LongMethod") @Composable fun BitwardenSnackbar( bitwardenSnackbarData: BitwardenSnackbarData, @@ -45,6 +47,12 @@ fun BitwardenSnackbar( color = BitwardenTheme.colorScheme.background.alert, 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), ) { Column { diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsScreenTest.kt index 0d48a3516..090260451 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/platform/feature/settings/vault/VaultSettingsScreenTest.kt @@ -2,6 +2,7 @@ package com.x8bit.bitwarden.ui.platform.feature.settings.vault import androidx.compose.ui.test.assert import androidx.compose.ui.test.assertIsDisplayed +import androidx.compose.ui.test.assertIsNotDisplayed import androidx.compose.ui.test.hasAnyAncestor import androidx.compose.ui.test.isDialog import androidx.compose.ui.test.onNodeWithContentDescription @@ -227,4 +228,17 @@ class VaultSettingsScreenTest : BaseComposeTest() { mutableEventFlow.tryEmit(VaultSettingsEvent.ShowSnackbar(data)) 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() + } } diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreenTest.kt index ef752981f..33c4bcddb 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/vault/VaultScreenTest.kt @@ -1206,6 +1206,19 @@ class VaultScreenTest : BaseComposeTest() { 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 fun `SSH key group header should display correctly based on state`() { val count = 1