Add dialog support for TrustedDeviceScreen (#1239)

This commit is contained in:
David Perez
2024-06-20 17:08:07 +01:00
committed by Álison Fernandes
parent a6a4c40693
commit 79f8703d9b
5 changed files with 125 additions and 1 deletions
@@ -1,14 +1,18 @@
package com.x8bit.bitwarden.ui.auth.feature.trusteddevice
import androidx.compose.ui.test.assert
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsOff
import androidx.compose.ui.test.assertIsOn
import androidx.compose.ui.test.hasAnyAncestor
import androidx.compose.ui.test.isDialog
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
import com.x8bit.bitwarden.ui.platform.base.util.asText
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
@@ -229,9 +233,47 @@ class TrustedDeviceScreenTest : BaseComposeTest() {
.performScrollTo()
.assertIsDisplayed()
}
@Test
fun `dialog should update according to state`() {
composeTestRule.onNode(isDialog()).assertDoesNotExist()
mutableStateFlow.update {
it.copy(
dialogState = TrustedDeviceState.DialogState.Loading(message = "Loading".asText()),
)
}
composeTestRule.onNode(isDialog()).assertIsDisplayed()
composeTestRule
.onNodeWithText(text = "Loading")
.assert(hasAnyAncestor(isDialog()))
.assertIsDisplayed()
mutableStateFlow.update {
it.copy(
dialogState = TrustedDeviceState.DialogState.Error(
title = "Hello".asText(),
message = "World".asText(),
),
)
}
composeTestRule.onNode(isDialog()).assertIsDisplayed()
composeTestRule
.onNodeWithText(text = "Hello")
.assert(hasAnyAncestor(isDialog()))
.assertIsDisplayed()
composeTestRule
.onNodeWithText(text = "World")
.assert(hasAnyAncestor(isDialog()))
.assertIsDisplayed()
mutableStateFlow.update { it.copy(dialogState = null) }
composeTestRule.onNode(isDialog()).assertDoesNotExist()
}
}
private val DEFAULT_STATE: TrustedDeviceState = TrustedDeviceState(
dialogState = null,
emailAddress = "email@bitwarden.com",
environmentLabel = "vault.bitwarden.pw",
isRemembered = false,
@@ -51,6 +51,18 @@ class TrustedDeviceViewModelTest : BaseViewModelTest() {
}
}
@Test
fun `on DismissDialog should clear dialogState`() {
val initialState = DEFAULT_STATE.copy(
dialogState = TrustedDeviceState.DialogState.Loading("Loading".asText()),
)
val viewModel = createViewModel(initialState)
viewModel.trySendAction(TrustedDeviceAction.DismissDialog)
assertEquals(initialState.copy(dialogState = null), viewModel.stateFlow.value)
}
@Test
fun `on RememberToggle updates the isRemembered state`() = runTest {
val viewModel = createViewModel()
@@ -142,6 +154,7 @@ private const val USER_ID: String = "userId"
private const val EMAIL: String = "email@bitwarden.com"
private val DEFAULT_STATE: TrustedDeviceState = TrustedDeviceState(
dialogState = null,
emailAddress = EMAIL,
environmentLabel = "bitwarden.com",
isRemembered = true,