mirror of
https://github.com/bitwarden/android.git
synced 2025-03-15 18:58:59 +03:00
Rename URI detection method related VM and Screen items add add tests (#750)
This commit is contained in:
parent
5279f1a4ba
commit
862d9b5c94
4 changed files with 69 additions and 27 deletions
|
@ -172,10 +172,10 @@ fun AutoFillScreen(
|
|||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
)
|
||||
UriMatchDetectionDialog(
|
||||
selectedUriDetection = state.uriDetectionMethod,
|
||||
onDetectionSelect = remember(viewModel) {
|
||||
{ viewModel.trySendAction(AutoFillAction.UriDetectionMethodSelect(it)) }
|
||||
DefaultUriMatchTypeRow(
|
||||
selectedUriMatchType = state.defaultUriMatchType,
|
||||
onUriMatchTypeSelect = remember(viewModel) {
|
||||
{ viewModel.trySendAction(AutoFillAction.DefaultUriMatchTypeSelect(it)) }
|
||||
},
|
||||
)
|
||||
BitwardenTextRow(
|
||||
|
@ -194,9 +194,9 @@ fun AutoFillScreen(
|
|||
}
|
||||
|
||||
@Composable
|
||||
private fun UriMatchDetectionDialog(
|
||||
selectedUriDetection: UriMatchType,
|
||||
onDetectionSelect: (UriMatchType) -> Unit,
|
||||
private fun DefaultUriMatchTypeRow(
|
||||
selectedUriMatchType: UriMatchType,
|
||||
onUriMatchTypeSelect: (UriMatchType) -> Unit,
|
||||
) {
|
||||
var shouldShowDialog by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
|
@ -207,7 +207,7 @@ private fun UriMatchDetectionDialog(
|
|||
modifier = Modifier.fillMaxWidth(),
|
||||
) {
|
||||
Text(
|
||||
text = selectedUriDetection.displayLabel(),
|
||||
text = selectedUriMatchType.displayLabel(),
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
|
@ -222,10 +222,10 @@ private fun UriMatchDetectionDialog(
|
|||
uriMatchTypes.forEach { option ->
|
||||
BitwardenSelectionRow(
|
||||
text = option.displayLabel,
|
||||
isSelected = option == selectedUriDetection,
|
||||
isSelected = option == selectedUriMatchType,
|
||||
onClick = {
|
||||
shouldShowDialog = false
|
||||
onDetectionSelect(
|
||||
onUriMatchTypeSelect(
|
||||
uriMatchTypes.first { it == option },
|
||||
)
|
||||
},
|
||||
|
|
|
@ -33,7 +33,7 @@ class AutoFillViewModel @Inject constructor(
|
|||
isAutoFillServicesEnabled = settingsRepository.isAutofillEnabledStateFlow.value,
|
||||
isCopyTotpAutomaticallyEnabled = false,
|
||||
isUseInlineAutoFillEnabled = settingsRepository.isInlineAutofillEnabled,
|
||||
uriDetectionMethod = settingsRepository.defaultUriMatchType,
|
||||
defaultUriMatchType = settingsRepository.defaultUriMatchType,
|
||||
),
|
||||
) {
|
||||
|
||||
|
@ -56,7 +56,7 @@ class AutoFillViewModel @Inject constructor(
|
|||
is AutoFillAction.AutoFillServicesClick -> handleAutoFillServicesClick(action)
|
||||
AutoFillAction.BackClick -> handleBackClick()
|
||||
is AutoFillAction.CopyTotpAutomaticallyClick -> handleCopyTotpAutomaticallyClick(action)
|
||||
is AutoFillAction.UriDetectionMethodSelect -> handleUriDetectionMethodSelect(action)
|
||||
is AutoFillAction.DefaultUriMatchTypeSelect -> handleDefaultUriMatchTypeSelect(action)
|
||||
AutoFillAction.BlockAutoFillClick -> handleBlockAutoFillClick()
|
||||
is AutoFillAction.UseInlineAutofillClick -> handleUseInlineAutofillClick(action)
|
||||
is AutoFillAction.Internal.AutofillEnabledUpdateReceive -> {
|
||||
|
@ -95,10 +95,10 @@ class AutoFillViewModel @Inject constructor(
|
|||
mutableStateFlow.update { it.copy(isUseInlineAutoFillEnabled = action.isEnabled) }
|
||||
}
|
||||
|
||||
private fun handleUriDetectionMethodSelect(action: AutoFillAction.UriDetectionMethodSelect) {
|
||||
settingsRepository.defaultUriMatchType = action.uriDetectionMethod
|
||||
private fun handleDefaultUriMatchTypeSelect(action: AutoFillAction.DefaultUriMatchTypeSelect) {
|
||||
settingsRepository.defaultUriMatchType = action.defaultUriMatchType
|
||||
mutableStateFlow.update {
|
||||
it.copy(uriDetectionMethod = action.uriDetectionMethod)
|
||||
it.copy(defaultUriMatchType = action.defaultUriMatchType)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ data class AutoFillState(
|
|||
val isAutoFillServicesEnabled: Boolean,
|
||||
val isCopyTotpAutomaticallyEnabled: Boolean,
|
||||
val isUseInlineAutoFillEnabled: Boolean,
|
||||
val uriDetectionMethod: UriMatchType,
|
||||
val defaultUriMatchType: UriMatchType,
|
||||
) : Parcelable {
|
||||
|
||||
/**
|
||||
|
@ -195,8 +195,8 @@ sealed class AutoFillAction {
|
|||
/**
|
||||
* User selected a [UriMatchType].
|
||||
*/
|
||||
data class UriDetectionMethodSelect(
|
||||
val uriDetectionMethod: UriMatchType,
|
||||
data class DefaultUriMatchTypeSelect(
|
||||
val defaultUriMatchType: UriMatchType,
|
||||
) : AutoFillAction()
|
||||
|
||||
/**
|
||||
|
|
|
@ -232,7 +232,8 @@ class AutoFillScreenTest : BaseComposeTest() {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun `on default URI match detection toggle should display dialog`() {
|
||||
fun `on default URI match type click should display dialog`() {
|
||||
composeTestRule.assertNoDialogExists()
|
||||
composeTestRule
|
||||
.onNodeWithText("Default URI match detection")
|
||||
.performScrollTo()
|
||||
|
@ -244,8 +245,48 @@ class AutoFillScreenTest : BaseComposeTest() {
|
|||
.assertExists()
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `default URI match detection add login should be updated on or off according to state`() {
|
||||
fun `on default URI match type dialog item click should send DefaultUriMatchTypeSelect and close the dialog`() {
|
||||
composeTestRule
|
||||
.onNodeWithText("Default URI match detection")
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Exact")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
AutoFillAction.DefaultUriMatchTypeSelect(
|
||||
defaultUriMatchType = UriMatchType.EXACT,
|
||||
),
|
||||
)
|
||||
}
|
||||
composeTestRule.assertNoDialogExists()
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `on default URI match type dialog cancel click should close the dialog`() {
|
||||
composeTestRule
|
||||
.onNodeWithText("Default URI match detection")
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithText("Cancel")
|
||||
.filterToOne(hasAnyAncestor(isDialog()))
|
||||
.performClick()
|
||||
|
||||
verify(exactly = 0) { viewModel.trySendAction(any()) }
|
||||
composeTestRule.assertNoDialogExists()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `default URI match type should update according to state`() {
|
||||
composeTestRule
|
||||
.onNodeWithText("Base domain")
|
||||
.assertExists()
|
||||
|
@ -253,7 +294,7 @@ class AutoFillScreenTest : BaseComposeTest() {
|
|||
.onNodeWithText("Starts with")
|
||||
.assertDoesNotExist()
|
||||
mutableStateFlow.update {
|
||||
it.copy(uriDetectionMethod = UriMatchType.STARTS_WITH)
|
||||
it.copy(defaultUriMatchType = UriMatchType.STARTS_WITH)
|
||||
}
|
||||
composeTestRule
|
||||
.onNodeWithText("Base domain")
|
||||
|
@ -296,5 +337,5 @@ private val DEFAULT_STATE: AutoFillState = AutoFillState(
|
|||
isAutoFillServicesEnabled = false,
|
||||
isCopyTotpAutomaticallyEnabled = false,
|
||||
isUseInlineAutoFillEnabled = false,
|
||||
uriDetectionMethod = UriMatchType.DOMAIN,
|
||||
defaultUriMatchType = UriMatchType.DOMAIN,
|
||||
)
|
||||
|
|
|
@ -39,7 +39,7 @@ class AutoFillViewModelTest : BaseViewModelTest() {
|
|||
mutableIsAutofillEnabledStateFlow.value = true
|
||||
val state = DEFAULT_STATE.copy(
|
||||
isAutoFillServicesEnabled = true,
|
||||
uriDetectionMethod = UriMatchType.REGULAR_EXPRESSION,
|
||||
defaultUriMatchType = UriMatchType.REGULAR_EXPRESSION,
|
||||
)
|
||||
val viewModel = createViewModel(state = state)
|
||||
assertEquals(state, viewModel.stateFlow.value)
|
||||
|
@ -142,13 +142,14 @@ class AutoFillViewModelTest : BaseViewModelTest() {
|
|||
verify { settingsRepository.isInlineAutofillEnabled = false }
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `on UriDetectionMethodSelect should update the state and save the new value to settings`() {
|
||||
fun `on DefaultUriMatchTypeSelect should update the state and save the new value to settings`() {
|
||||
val viewModel = createViewModel()
|
||||
val method = UriMatchType.EXACT
|
||||
viewModel.trySendAction(AutoFillAction.UriDetectionMethodSelect(method))
|
||||
viewModel.trySendAction(AutoFillAction.DefaultUriMatchTypeSelect(method))
|
||||
assertEquals(
|
||||
DEFAULT_STATE.copy(uriDetectionMethod = method),
|
||||
DEFAULT_STATE.copy(defaultUriMatchType = method),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
verify { settingsRepository.defaultUriMatchType = method }
|
||||
|
@ -176,5 +177,5 @@ private val DEFAULT_STATE: AutoFillState = AutoFillState(
|
|||
isAutoFillServicesEnabled = false,
|
||||
isCopyTotpAutomaticallyEnabled = false,
|
||||
isUseInlineAutoFillEnabled = true,
|
||||
uriDetectionMethod = UriMatchType.DOMAIN,
|
||||
defaultUriMatchType = UriMatchType.DOMAIN,
|
||||
)
|
||||
|
|
Loading…
Add table
Reference in a new issue