mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-2101 BIT-2103: Update export flow for JSON (password protected) (#1188)
This commit is contained in:
committed by
Álison Fernandes
parent
3565054a4c
commit
90ff2897f5
+35
@@ -2,6 +2,7 @@ package com.x8bit.bitwarden.ui.platform.feature.settings.exportvault
|
||||
|
||||
import androidx.compose.ui.test.assert
|
||||
import androidx.compose.ui.test.assertIsDisplayed
|
||||
import androidx.compose.ui.test.assertIsNotDisplayed
|
||||
import androidx.compose.ui.test.filterToOne
|
||||
import androidx.compose.ui.test.hasAnyAncestor
|
||||
import androidx.compose.ui.test.isDialog
|
||||
@@ -14,6 +15,7 @@ import androidx.compose.ui.test.performClick
|
||||
import androidx.compose.ui.test.performScrollTo
|
||||
import androidx.compose.ui.test.performTextInput
|
||||
import com.x8bit.bitwarden.data.platform.repository.util.bufferedMutableSharedFlow
|
||||
import com.x8bit.bitwarden.ui.auth.feature.createaccount.PasswordStrengthState
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseComposeTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.feature.settings.exportvault.model.ExportVaultFormat
|
||||
@@ -215,6 +217,36 @@ class ExportVaultScreenTest : BaseComposeTest() {
|
||||
assertTrue(onNavigateBackCalled)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `confirm file password input change should send ConfirmFilePasswordInputChange action`() {
|
||||
composeTestRule.onNodeWithText("Confirm file password").assertIsNotDisplayed()
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
exportFormat = ExportVaultFormat.JSON_ENCRYPTED,
|
||||
)
|
||||
}
|
||||
val input = "Test123"
|
||||
composeTestRule.onNodeWithText("Confirm file password").performTextInput(input)
|
||||
verify {
|
||||
viewModel.trySendAction(ExportVaultAction.ConfirmFilePasswordInputChange("Test123"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `file password input change should send FilePasswordInputChange action`() {
|
||||
composeTestRule.onNodeWithText("File password").assertIsNotDisplayed()
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
exportFormat = ExportVaultFormat.JSON_ENCRYPTED,
|
||||
)
|
||||
}
|
||||
val input = "Test123"
|
||||
composeTestRule.onNodeWithText("File password").performTextInput(input)
|
||||
verify {
|
||||
viewModel.trySendAction(ExportVaultAction.FilePasswordInputChange("Test123"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `password input change should send PasswordInputChange action`() {
|
||||
val input = "Test123"
|
||||
@@ -226,9 +258,12 @@ class ExportVaultScreenTest : BaseComposeTest() {
|
||||
}
|
||||
|
||||
private val DEFAULT_STATE = ExportVaultState(
|
||||
confirmFilePasswordInput = "",
|
||||
dialogState = null,
|
||||
exportFormat = ExportVaultFormat.JSON,
|
||||
filePasswordInput = "",
|
||||
passwordInput = "",
|
||||
exportData = "",
|
||||
passwordStrengthState = PasswordStrengthState.NONE,
|
||||
policyPreventsExport = false,
|
||||
)
|
||||
|
||||
+48
-21
@@ -12,6 +12,7 @@ import com.x8bit.bitwarden.data.vault.datasource.network.model.createMockPolicy
|
||||
import com.x8bit.bitwarden.data.vault.manager.FileManager
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.ExportVaultDataResult
|
||||
import com.x8bit.bitwarden.ui.auth.feature.createaccount.PasswordStrengthState
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.feature.settings.exportvault.model.ExportVaultFormat
|
||||
@@ -194,18 +195,42 @@ class ExportVaultViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `PasswordInputChanged should update the password input in the state`() = runTest {
|
||||
fun `ConfirmFilePasswordInputChanged should update the confirm password input in the state`() {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(ExportVaultAction.PasswordInputChanged("Test123"))
|
||||
viewModel.trySendAction(ExportVaultAction.ConfirmFilePasswordInputChange("Test123"))
|
||||
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
passwordInput = "Test123",
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
confirmFilePasswordInput = "Test123",
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `FilePasswordInputChanged should update the file password input in the state`() {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(ExportVaultAction.FilePasswordInputChange("Test123"))
|
||||
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
filePasswordInput = "Test123",
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `PasswordInputChanged should update the password input in the state`() {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(ExportVaultAction.PasswordInputChanged("Test123"))
|
||||
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(
|
||||
passwordInput = "Test123",
|
||||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -327,23 +352,25 @@ class ExportVaultViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private fun createViewModel(
|
||||
initialState: ExportVaultState? = null,
|
||||
): ExportVaultViewModel =
|
||||
ExportVaultViewModel(
|
||||
authRepository = authRepository,
|
||||
policyManager = policyManager,
|
||||
savedStateHandle = SavedStateHandle(
|
||||
initialState = mapOf("state" to initialState),
|
||||
),
|
||||
fileManager = fileManager,
|
||||
vaultRepository = vaultRepository,
|
||||
clock = clock,
|
||||
)
|
||||
): ExportVaultViewModel = ExportVaultViewModel(
|
||||
authRepository = authRepository,
|
||||
policyManager = policyManager,
|
||||
savedStateHandle = SavedStateHandle(
|
||||
initialState = mapOf("state" to initialState),
|
||||
),
|
||||
fileManager = fileManager,
|
||||
vaultRepository = vaultRepository,
|
||||
clock = clock,
|
||||
)
|
||||
}
|
||||
|
||||
private val DEFAULT_STATE = ExportVaultState(
|
||||
confirmFilePasswordInput = "",
|
||||
dialogState = null,
|
||||
exportFormat = ExportVaultFormat.JSON,
|
||||
filePasswordInput = "",
|
||||
passwordInput = "",
|
||||
exportData = null,
|
||||
passwordStrengthState = PasswordStrengthState.NONE,
|
||||
policyPreventsExport = false,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user