Skip to content

Commit

Permalink
PM-14352 Dismiss Snackbar when user clicks it as a default unless the…
Browse files Browse the repository at this point in the history
… specific dismiss action is present. (#4291)
  • Loading branch information
dseverns-livefront authored Nov 12, 2024
1 parent c6beaec commit 9a5aa21
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9a5aa21

Please sign in to comment.