mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-1402 adding Password checker to Add Edit Screen (#769)
This commit is contained in:
committed by
Álison Fernandes
parent
27a9719532
commit
54802db0b3
+6
-2
@@ -432,10 +432,14 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in ItemType_Login state clicking Password checker action should trigger PasswordCheckerClick`() {
|
||||
mutableStateFlow.update { currentState ->
|
||||
updateLoginType(currentState) { copy(password = "password") }
|
||||
}
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithTextAfterScroll(text = "Password")
|
||||
.onSiblings()
|
||||
.onFirst()
|
||||
.filterToOne(hasContentDescription("Check if password has been exposed."))
|
||||
.performClick()
|
||||
|
||||
verify {
|
||||
@@ -2298,7 +2302,7 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
common = VaultAddEditState.ViewState.Content.Common(),
|
||||
type = VaultAddEditState.ViewState.Content.ItemType.Login(),
|
||||
),
|
||||
dialog = VaultAddEditState.DialogState.Error("test".asText()),
|
||||
dialog = VaultAddEditState.DialogState.Generic(message = "test".asText()),
|
||||
vaultAddEditType = VaultAddEditType.AddItem,
|
||||
)
|
||||
|
||||
|
||||
+64
-21
@@ -4,11 +4,14 @@ import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import com.bitwarden.core.CipherView
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.BreachCountResult
|
||||
import com.x8bit.bitwarden.data.platform.manager.clipboard.BitwardenClipboardManager
|
||||
import com.x8bit.bitwarden.data.platform.repository.model.DataState
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
|
||||
import com.x8bit.bitwarden.data.tools.generator.repository.GeneratorRepository
|
||||
import com.x8bit.bitwarden.data.tools.generator.repository.util.FakeGeneratorRepository
|
||||
import com.x8bit.bitwarden.data.vault.datasource.sdk.model.createMockCipherView
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.CreateCipherResult
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.TotpCodeResult
|
||||
@@ -49,6 +52,8 @@ import java.util.UUID
|
||||
@Suppress("LargeClass")
|
||||
class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private val authRepository: AuthRepository = mockk()
|
||||
|
||||
private val loginInitialState = createVaultAddItemState(
|
||||
typeContentViewState = createLoginTypeContentViewState(),
|
||||
)
|
||||
@@ -402,7 +407,8 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
assertEquals(
|
||||
stateWithName.copy(
|
||||
dialog = VaultAddEditState.DialogState.Error(
|
||||
dialog = VaultAddEditState.DialogState.Generic(
|
||||
title = R.string.an_error_has_occurred.asText(),
|
||||
message = R.string.generic_error_message.asText(),
|
||||
),
|
||||
),
|
||||
@@ -449,7 +455,8 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
assertEquals(
|
||||
stateWithName.copy(
|
||||
dialog = VaultAddEditState.DialogState.Error(
|
||||
dialog = VaultAddEditState.DialogState.Generic(
|
||||
title = R.string.an_error_has_occurred.asText(),
|
||||
message = errorMessage.asText(),
|
||||
),
|
||||
),
|
||||
@@ -468,9 +475,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
|
||||
val stateWithNoNameAndDialog = createVaultAddItemState(
|
||||
commonContentViewState = createCommonContentViewState(name = ""),
|
||||
dialogState = VaultAddEditState.DialogState.Error(
|
||||
R.string.validation_field_required
|
||||
.asText(R.string.name.asText()),
|
||||
dialogState = VaultAddEditState.DialogState.Generic(
|
||||
title = R.string.an_error_has_occurred.asText(),
|
||||
message = R.string.validation_field_required.asText(R.string.name.asText()),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -492,9 +499,9 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
fun `HandleDialogDismiss will remove the current dialog`() = runTest {
|
||||
val errorState = createVaultAddItemState(
|
||||
vaultAddEditType = VaultAddEditType.AddItem,
|
||||
dialogState = VaultAddEditState.DialogState.Error(
|
||||
R.string.validation_field_required
|
||||
.asText(R.string.name.asText()),
|
||||
dialogState = VaultAddEditState.DialogState.Generic(
|
||||
title = R.string.an_error_has_occurred.asText(),
|
||||
message = R.string.validation_field_required.asText(R.string.name.asText()),
|
||||
),
|
||||
)
|
||||
|
||||
@@ -687,24 +694,58 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `PasswordCheckerClick should emit ShowToast with 'Password Checker' message`() =
|
||||
runTest {
|
||||
val viewModel = createAddVaultItemViewModel()
|
||||
fun `on CheckForBreachClick should process a password`() = runTest {
|
||||
val cipherView = createMockCipherView(1)
|
||||
val password = "Password"
|
||||
|
||||
viewModel.eventFlow.test {
|
||||
viewModel
|
||||
.actionChannel
|
||||
.trySend(VaultAddEditAction.ItemType.LoginType.PasswordCheckerClick)
|
||||
val loginState = loginInitialState.copy(
|
||||
viewState = VaultAddEditState.ViewState.Content(
|
||||
common = createCommonContentViewState(),
|
||||
type = createLoginTypeContentViewState(
|
||||
password = password,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
VaultAddEditEvent.ShowToast(
|
||||
"Password Checker".asText(),
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
savedStateHandle = createSavedStateHandleWithState(
|
||||
state = loginState,
|
||||
vaultAddEditType = VaultAddEditType.AddItem,
|
||||
),
|
||||
)
|
||||
|
||||
mutableVaultItemFlow.value = DataState.Loaded(data = cipherView)
|
||||
|
||||
val breachCount = 5
|
||||
coEvery {
|
||||
authRepository.getPasswordBreachCount(password)
|
||||
} returns BreachCountResult.Success(breachCount = breachCount)
|
||||
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(loginState, awaitItem())
|
||||
viewModel.trySendAction(VaultAddEditAction.ItemType.LoginType.PasswordCheckerClick)
|
||||
assertEquals(
|
||||
loginState.copy(
|
||||
dialog = VaultAddEditState.DialogState.Loading(
|
||||
label = R.string.loading.asText(),
|
||||
),
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
),
|
||||
awaitItem(),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
loginState.copy(
|
||||
dialog = VaultAddEditState.DialogState.Generic(
|
||||
message = R.string.password_exposed.asText(breachCount),
|
||||
),
|
||||
),
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
|
||||
coVerify(exactly = 1) { authRepository.getPasswordBreachCount(password) }
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `OpenPasswordGeneratorClick should emit NavigateToGeneratorModal with with password GeneratorMode`() =
|
||||
@@ -1289,6 +1330,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
vaultRepository = vaultRepository,
|
||||
generatorRepository = generatorRepository,
|
||||
resourceManager = resourceManager,
|
||||
authRepository = authRepository,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1796,6 +1838,7 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
vaultRepository = vaultRepo,
|
||||
generatorRepository = generatorRepo,
|
||||
resourceManager = bitwardenResourceManager,
|
||||
authRepository = authRepository,
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user