mirror of
https://github.com/bitwarden/android.git
synced 2025-02-16 20:09:59 +03:00
Rename AppearanceAction properties & add dialog tests (#498)
This commit is contained in:
parent
b24c2ba7e7
commit
6486a6dc6a
2 changed files with 40 additions and 11 deletions
|
@ -40,17 +40,17 @@ class AppearanceViewModel @Inject constructor(
|
|||
|
||||
private fun handleLanguageChanged(action: AppearanceAction.LanguageChange) {
|
||||
// TODO: BIT-1328 implement language selection support
|
||||
mutableStateFlow.update { it.copy(language = action.newLanguage) }
|
||||
mutableStateFlow.update { it.copy(language = action.language) }
|
||||
}
|
||||
|
||||
private fun handleShowWebsiteIconsToggled(action: AppearanceAction.ShowWebsiteIconsToggle) {
|
||||
// TODO: BIT-541 add website icon support
|
||||
mutableStateFlow.update { it.copy(showWebsiteIcons = action.newValue) }
|
||||
mutableStateFlow.update { it.copy(showWebsiteIcons = action.showWebsiteIcons) }
|
||||
}
|
||||
|
||||
private fun handleThemeChanged(action: AppearanceAction.ThemeChange) {
|
||||
// TODO: BIT-1327 add theme support
|
||||
mutableStateFlow.update { it.copy(theme = action.newTheme) }
|
||||
mutableStateFlow.update { it.copy(theme = action.theme) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,20 +106,20 @@ sealed class AppearanceAction {
|
|||
* Indicates that the user changed the Language.
|
||||
*/
|
||||
data class LanguageChange(
|
||||
val newLanguage: AppearanceState.Language,
|
||||
val language: AppearanceState.Language,
|
||||
) : AppearanceAction()
|
||||
|
||||
/**
|
||||
* Indicates that the user toggled the Show Website Icons switch to [newValue].
|
||||
* Indicates that the user toggled the Show Website Icons switch to [showWebsiteIcons].
|
||||
*/
|
||||
data class ShowWebsiteIconsToggle(
|
||||
val newValue: Boolean,
|
||||
val showWebsiteIcons: Boolean,
|
||||
) : AppearanceAction()
|
||||
|
||||
/**
|
||||
* Indicates that the user selected a new theme.
|
||||
*/
|
||||
data class ThemeChange(
|
||||
val newTheme: AppearanceState.Theme,
|
||||
val theme: AppearanceState.Theme,
|
||||
) : AppearanceAction()
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import androidx.compose.ui.test.onNodeWithText
|
|||
import androidx.compose.ui.test.performClick
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
|
||||
import com.x8bit.bitwarden.ui.util.assertNoDialogExists
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
|
@ -56,17 +57,31 @@ class AppearanceScreenTest : BaseComposeTest() {
|
|||
@Test
|
||||
fun `on language selection dialog item click should send LanguageChange`() {
|
||||
composeTestRule.onNodeWithText("Language").performClick()
|
||||
composeTestRule.onNodeWithText("English").performClick()
|
||||
composeTestRule
|
||||
.onAllNodesWithText("English")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
composeTestRule.assertNoDialogExists()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
AppearanceAction.LanguageChange(
|
||||
newLanguage = AppearanceState.Language.ENGLISH,
|
||||
language = AppearanceState.Language.ENGLISH,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on language selection dialog cancel click should dismiss dialog`() {
|
||||
composeTestRule.onNodeWithText("Language").performClick()
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Cancel")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
composeTestRule.assertNoDialogExists()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on theme row click should display theme selection dialog`() {
|
||||
composeTestRule.onNodeWithText("Theme").performClick()
|
||||
|
@ -79,17 +94,31 @@ class AppearanceScreenTest : BaseComposeTest() {
|
|||
@Test
|
||||
fun `on theme selection dialog item click should send ThemeChange`() {
|
||||
composeTestRule.onNodeWithText("Theme").performClick()
|
||||
composeTestRule.onNodeWithText("Dark").performClick()
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Dark")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
composeTestRule.assertNoDialogExists()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
AppearanceAction.ThemeChange(
|
||||
newTheme = AppearanceState.Theme.DARK,
|
||||
theme = AppearanceState.Theme.DARK,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on theme selection dialog cancel click should dismiss dialog`() {
|
||||
composeTestRule.onNodeWithText("Theme").performClick()
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Cancel")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
composeTestRule.assertNoDialogExists()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on show website icons row click should send ShowWebsiteIconsToggled`() {
|
||||
composeTestRule.onNodeWithText("Show website icons").performClick()
|
||||
|
|
Loading…
Add table
Reference in a new issue