Hide inline autofill option when not supported (#3455)

This commit is contained in:
David Perez 2024-07-12 16:09:14 -05:00 committed by GitHub
parent 101b807b5c
commit 20d37e2f90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 68 additions and 13 deletions

View file

@ -133,19 +133,23 @@ fun AutoFillScreen(
.testTag("AutofillServicesSwitch")
.padding(horizontal = 16.dp),
)
BitwardenWideSwitch(
label = stringResource(id = R.string.inline_autofill),
description = stringResource(id = R.string.use_inline_autofill_explanation_long),
isChecked = state.isUseInlineAutoFillEnabled,
onCheckedChange = remember(viewModel) {
{ viewModel.trySendAction(AutoFillAction.UseInlineAutofillClick(it)) }
},
enabled = state.canInteractWithInlineAutofillToggle,
modifier = Modifier
.fillMaxWidth()
.testTag("InlineAutofillSwitch")
.padding(horizontal = 16.dp),
)
if (state.showInlineAutofillOption) {
BitwardenWideSwitch(
label = stringResource(id = R.string.inline_autofill),
description = stringResource(
id = R.string.use_inline_autofill_explanation_long,
),
isChecked = state.isUseInlineAutoFillEnabled,
onCheckedChange = remember(viewModel) {
{ viewModel.trySendAction(AutoFillAction.UseInlineAutofillClick(it)) }
},
enabled = state.canInteractWithInlineAutofillToggle,
modifier = Modifier
.fillMaxWidth()
.testTag("InlineAutofillSwitch")
.padding(horizontal = 16.dp),
)
}
Spacer(modifier = Modifier.height(16.dp))
BitwardenListHeaderText(
label = stringResource(id = R.string.additional_options),

View file

@ -1,10 +1,12 @@
package com.x8bit.bitwarden.ui.platform.feature.settings.autofill
import android.os.Build
import android.os.Parcelable
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
import com.x8bit.bitwarden.data.platform.repository.model.UriMatchType
import com.x8bit.bitwarden.data.platform.util.isBuildVersionBelow
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
import com.x8bit.bitwarden.ui.platform.base.util.Text
import dagger.hilt.android.lifecycle.HiltViewModel
@ -32,6 +34,7 @@ class AutoFillViewModel @Inject constructor(
isAutoFillServicesEnabled = settingsRepository.isAutofillEnabledStateFlow.value,
isCopyTotpAutomaticallyEnabled = !settingsRepository.isAutoCopyTotpDisabled,
isUseInlineAutoFillEnabled = settingsRepository.isInlineAutofillEnabled,
showInlineAutofillOption = !isBuildVersionBelow(Build.VERSION_CODES.R),
defaultUriMatchType = settingsRepository.defaultUriMatchType,
),
) {
@ -121,6 +124,7 @@ data class AutoFillState(
val isAutoFillServicesEnabled: Boolean,
val isCopyTotpAutomaticallyEnabled: Boolean,
val isUseInlineAutoFillEnabled: Boolean,
val showInlineAutofillOption: Boolean,
val defaultUriMatchType: UriMatchType,
) : Parcelable {

View file

@ -187,6 +187,24 @@ class AutoFillScreenTest : BaseComposeTest() {
.assertIsNotEnabled()
}
@Test
fun `use inline autofill should be displayed according to state`() {
mutableStateFlow.update {
it.copy(showInlineAutofillOption = true)
}
composeTestRule
.onNodeWithText(text = "Use inline autofill")
.performScrollTo()
.assertIsDisplayed()
mutableStateFlow.update {
it.copy(showInlineAutofillOption = false)
}
composeTestRule.onNodeWithText(text = "Use inline autofill").assertDoesNotExist()
}
@Test
fun `on copy TOTP automatically toggle should send CopyTotpAutomaticallyClick`() {
composeTestRule
@ -337,5 +355,6 @@ private val DEFAULT_STATE: AutoFillState = AutoFillState(
isAutoFillServicesEnabled = false,
isCopyTotpAutomaticallyEnabled = false,
isUseInlineAutoFillEnabled = false,
showInlineAutofillOption = true,
defaultUriMatchType = UriMatchType.DOMAIN,
)

View file

@ -1,18 +1,24 @@
package com.x8bit.bitwarden.ui.platform.feature.settings.autofill
import android.os.Build
import androidx.lifecycle.SavedStateHandle
import app.cash.turbine.test
import com.x8bit.bitwarden.data.platform.repository.SettingsRepository
import com.x8bit.bitwarden.data.platform.repository.model.UriMatchType
import com.x8bit.bitwarden.data.platform.util.isBuildVersionBelow
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.runs
import io.mockk.unmockkStatic
import io.mockk.verify
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
class AutoFillViewModelTest : BaseViewModelTest() {
@ -31,6 +37,17 @@ class AutoFillViewModelTest : BaseViewModelTest() {
every { disableAutofill() } just runs
}
@BeforeEach
fun setup() {
mockkStatic(::isBuildVersionBelow)
every { isBuildVersionBelow(Build.VERSION_CODES.R) } returns true
}
@AfterEach
fun tearDown() {
unmockkStatic(::isBuildVersionBelow)
}
@Test
fun `initial state should be correct when not set`() {
val viewModel = createViewModel(state = null)
@ -48,6 +65,16 @@ class AutoFillViewModelTest : BaseViewModelTest() {
assertEquals(state, viewModel.stateFlow.value)
}
@Test
fun `showInlineAutofillOption should be true when the build version is not below R`() {
every { isBuildVersionBelow(Build.VERSION_CODES.R) } returns false
val viewModel = createViewModel(state = null)
assertEquals(
DEFAULT_STATE.copy(showInlineAutofillOption = true),
viewModel.stateFlow.value,
)
}
@Test
fun `changes in autofill enabled status should update the state`() {
val viewModel = createViewModel()
@ -183,5 +210,6 @@ private val DEFAULT_STATE: AutoFillState = AutoFillState(
isAutoFillServicesEnabled = false,
isCopyTotpAutomaticallyEnabled = false,
isUseInlineAutoFillEnabled = true,
showInlineAutofillOption = false,
defaultUriMatchType = UriMatchType.DOMAIN,
)