Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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