BIT-1081: Add log out ability to Vault Unlock screen (#285)

This commit is contained in:
Brian Yencho
2023-11-28 09:13:16 -06:00
committed by GitHub
parent 2a1310cf3e
commit 8a951fbae6
6 changed files with 138 additions and 20 deletions

View File

@@ -3,6 +3,12 @@ package com.x8bit.bitwarden.ui.auth.feature.vaultunlock
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertIsEnabled
import androidx.compose.ui.test.assertIsNotEnabled
import androidx.compose.ui.test.filterToOne
import androidx.compose.ui.test.hasAnyAncestor
import androidx.compose.ui.test.isDialog
import androidx.compose.ui.test.isPopup
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onNodeWithContentDescription
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
@@ -77,6 +83,58 @@ class VaultUnlockScreenTest : BaseComposeTest() {
composeTestRule.onNodeWithText("Add account").assertDoesNotExist()
}
@Test
fun `logout click in the overflow menu should show the logout confirmation dialog`() {
// Confirm neither the popup nor the dialog are showing
composeTestRule.onNode(isPopup()).assertDoesNotExist()
composeTestRule.onNode(isDialog()).assertDoesNotExist()
// Expand the overflow menu
composeTestRule.onNodeWithContentDescription("More").performClick()
composeTestRule.onNode(isPopup()).assertIsDisplayed()
composeTestRule.onNode(isDialog()).assertDoesNotExist()
// Click on the logout item
composeTestRule
.onAllNodesWithText("Log out")
.filterToOne(hasAnyAncestor(isPopup()))
.performClick()
// Check for the dialog
composeTestRule
.onNode(isDialog())
.assertIsDisplayed()
composeTestRule
.onAllNodesWithText("Log out")
.filterToOne(hasAnyAncestor(isDialog()))
.assertIsDisplayed()
composeTestRule
.onAllNodesWithText("Are you sure you want to log out?")
.filterToOne(hasAnyAncestor(isDialog()))
.assertIsDisplayed()
}
@Test
fun `Yes click in the logout confirmation dialog should send the ConfirmLogoutClick action`() {
// Expand the overflow menu
composeTestRule.onNodeWithContentDescription("More").performClick()
// Click on the logout item to display the dialog
composeTestRule
.onAllNodesWithText("Log out")
.filterToOne(hasAnyAncestor(isPopup()))
.performClick()
composeTestRule.onNode(isDialog()).assertIsDisplayed()
// Click on the Yes button in the dialog
composeTestRule
.onAllNodesWithText("Yes")
.filterToOne(hasAnyAncestor(isDialog()))
.performClick()
verify { viewModel.trySendAction(VaultUnlockAction.ConfirmLogoutClick) }
}
@Test
fun `email state change should update logged in as text`() {
val newEmail = "david@bitwarden.com"

View File

@@ -17,7 +17,10 @@ import com.x8bit.bitwarden.ui.platform.components.model.AccountSummary
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
@@ -28,6 +31,7 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
private val environmentRepository = FakeEnvironmentRepository()
private val authRepository = mockk<AuthRepository>() {
every { userStateFlow } returns MutableStateFlow(DEFAULT_USER_STATE)
every { logout() } just runs
}
private val vaultRepository = mockk<VaultRepository>()
@@ -80,6 +84,13 @@ class VaultUnlockViewModelTest : BaseViewModelTest() {
)
}
@Test
fun `on ConfirmLogoutClick should call logout on the AuthRepository`() {
val viewModel = createViewModel()
viewModel.trySendAction(VaultUnlockAction.ConfirmLogoutClick)
verify { authRepository.logout() }
}
@Test
fun `on PasswordInputChanged should update the password input state`() = runTest {
val viewModel = createViewModel()