mirror of
https://github.com/bitwarden/android.git
synced 2026-06-02 11:12:00 -05:00
BIT-470: Add support for fingerprint phrase dialog (#196)
This commit is contained in:
@@ -14,6 +14,7 @@ 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 androidx.core.net.toUri
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.IntentHandler
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
@@ -257,9 +258,60 @@ class AccountSecurityScreenTest : BaseComposeTest() {
|
||||
verify { viewModel.trySendAction(AccountSecurityAction.DismissDialog) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `fingerprint phrase dialog should be shown or hidden according to the state`() {
|
||||
composeTestRule.onNode(isDialog()).assertDoesNotExist()
|
||||
mutableStateFlow.update { it.copy(dialog = AccountSecurityDialog.FingerprintPhrase) }
|
||||
composeTestRule
|
||||
.onNodeWithText("Fingerprint phrase")
|
||||
.assert(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
composeTestRule
|
||||
.onNodeWithText("Learn more")
|
||||
.assert(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
composeTestRule
|
||||
.onNodeWithText("Close")
|
||||
.assert(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
composeTestRule
|
||||
.onNodeWithText("fingerprint-placeholder")
|
||||
.assert(hasAnyAncestor(isDialog()))
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on close click should send DismissDialog`() {
|
||||
mutableStateFlow.update { it.copy(dialog = AccountSecurityDialog.FingerprintPhrase) }
|
||||
composeTestRule
|
||||
.onNodeWithText("Close")
|
||||
.assert(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
verify { viewModel.trySendAction(AccountSecurityAction.DismissDialog) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on learn more click should send FingerPrintLearnMoreClick`() {
|
||||
mutableStateFlow.update { it.copy(dialog = AccountSecurityDialog.FingerprintPhrase) }
|
||||
composeTestRule
|
||||
.onNodeWithText("Learn more")
|
||||
.assert(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
verify { viewModel.trySendAction(AccountSecurityAction.FingerPrintLearnMoreClick) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on NavigateToFingerprintPhrase should call launchUri on intentHandler`() {
|
||||
mutableEventFlow.tryEmit(AccountSecurityEvent.NavigateToFingerprintPhrase)
|
||||
verify {
|
||||
intentHandler.launchUri("http://bitwarden.com/help/fingerprint-phrase".toUri())
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val DEFAULT_STATE = AccountSecurityState(
|
||||
dialog = null,
|
||||
fingerprintPhrase = "fingerprint-placeholder".asText(),
|
||||
isApproveLoginRequestsEnabled = false,
|
||||
isUnlockWithBiometricsEnabled = false,
|
||||
isUnlockWithPinEnabled = false,
|
||||
|
||||
@@ -22,14 +22,21 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on AccountFingerprintPhraseClick should emit ShowToast`() = runTest {
|
||||
fun `on AccountFingerprintPhraseClick should show the fingerprint phrase dialog`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(AccountSecurityAction.AccountFingerprintPhraseClick)
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(dialog = AccountSecurityDialog.FingerprintPhrase),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on FingerPrintLearnMoreClick should emit NavigateToFingerprintPhrase`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(AccountSecurityAction.AccountFingerprintPhraseClick)
|
||||
assertEquals(
|
||||
AccountSecurityEvent.ShowToast("Display fingerprint phrase.".asText()),
|
||||
awaitItem(),
|
||||
)
|
||||
viewModel.trySendAction(AccountSecurityAction.FingerPrintLearnMoreClick)
|
||||
assertEquals(AccountSecurityEvent.NavigateToFingerprintPhrase, awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +233,9 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private fun createViewModel(
|
||||
authRepository: AuthRepository = mockk(relaxed = true),
|
||||
savedStateHandle: SavedStateHandle = SavedStateHandle(),
|
||||
savedStateHandle: SavedStateHandle = SavedStateHandle().apply {
|
||||
set("state", DEFAULT_STATE)
|
||||
},
|
||||
): AccountSecurityViewModel = AccountSecurityViewModel(
|
||||
authRepository = authRepository,
|
||||
savedStateHandle = savedStateHandle,
|
||||
@@ -235,6 +244,7 @@ class AccountSecurityViewModelTest : BaseViewModelTest() {
|
||||
companion object {
|
||||
private val DEFAULT_STATE = AccountSecurityState(
|
||||
dialog = null,
|
||||
fingerprintPhrase = "fingerprint-placeholder".asText(),
|
||||
isApproveLoginRequestsEnabled = false,
|
||||
isUnlockWithBiometricsEnabled = false,
|
||||
isUnlockWithPinEnabled = false,
|
||||
|
||||
Reference in New Issue
Block a user