[PM-12319] Skip Auto-fill setup if already enabled. (#3934)

This commit is contained in:
Dave Severns 2024-09-19 13:36:11 -04:00 committed by GitHub
parent c8b1b71960
commit 71d3ae9ee8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 3 deletions

View file

@ -176,7 +176,12 @@ class SetupUnlockViewModel @Inject constructor(
}
private fun updateOnboardingStatusToNextStep() {
authRepository.setOnboardingStatus(state.userId, OnboardingStatus.AUTOFILL_SETUP)
val nextStep = if (settingsRepository.isAutofillEnabledStateFlow.value) {
OnboardingStatus.FINAL_STEP
} else {
OnboardingStatus.AUTOFILL_SETUP
}
authRepository.setOnboardingStatus(state.userId, nextStep)
}
}

View file

@ -21,6 +21,7 @@ import io.mockk.mockk
import io.mockk.runs
import io.mockk.verify
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
@ -33,9 +34,12 @@ class SetupUnlockViewModelTest : BaseViewModelTest() {
every { userStateFlow } returns mutableUserStateFlow
every { setOnboardingStatus(userId = any(), status = any()) } just runs
}
private val mutableAutofillEnabledStateFlow = MutableStateFlow(false)
private val settingsRepository = mockk<SettingsRepository> {
every { isUnlockWithPinEnabled } returns false
every { isUnlockWithBiometricsEnabled } returns false
every { isAutofillEnabledStateFlow } returns mutableAutofillEnabledStateFlow
}
private val biometricsEncryptionManager: BiometricsEncryptionManager = mockk {
every { getOrCreateCipher(userId = DEFAULT_USER_ID) } returns CIPHER
@ -51,8 +55,10 @@ class SetupUnlockViewModelTest : BaseViewModelTest() {
assertEquals(DEFAULT_STATE, viewModel.stateFlow.value)
}
@Suppress("MaxLineLength")
@Test
fun `ContinueClick should call setOnboardingStatus`() = runTest {
fun `ContinueClick should call setOnboardingStatus and set to AUTOFILL_SETUP if AutoFill is not enabled`() =
runTest {
val viewModel = createViewModel()
viewModel.trySendAction(SetupUnlockAction.ContinueClick)
verify {
@ -63,8 +69,10 @@ class SetupUnlockViewModelTest : BaseViewModelTest() {
}
}
@Suppress("MaxLineLength")
@Test
fun `SetUpLaterClick should call setOnboardingStatus`() = runTest {
fun `SetUpLaterClick should call setOnboardingStatus and set to AUTOFILL_SETUP if AutoFill is not enabled`() =
runTest {
val viewModel = createViewModel()
viewModel.trySendAction(SetupUnlockAction.SetUpLaterClick)
verify {
@ -75,6 +83,36 @@ class SetupUnlockViewModelTest : BaseViewModelTest() {
}
}
@Suppress("MaxLineLength")
@Test
fun `ContinueClick should call setOnboardingStatus and set to FINAL_STEP if AutoFill is already enabled`() =
runTest {
mutableAutofillEnabledStateFlow.update { true }
val viewModel = createViewModel()
viewModel.trySendAction(SetupUnlockAction.ContinueClick)
verify {
authRepository.setOnboardingStatus(
userId = DEFAULT_USER_ID,
status = OnboardingStatus.FINAL_STEP,
)
}
}
@Suppress("MaxLineLength")
@Test
fun `SetUpLaterClick should call setOnboardingStatus and set to FINAL_STEP if AutoFill is already enabled`() =
runTest {
mutableAutofillEnabledStateFlow.update { true }
val viewModel = createViewModel()
viewModel.trySendAction(SetupUnlockAction.SetUpLaterClick)
verify {
authRepository.setOnboardingStatus(
userId = DEFAULT_USER_ID,
status = OnboardingStatus.FINAL_STEP,
)
}
}
@Test
fun `on UnlockWithBiometricToggle false should call clearBiometricsKey and update the state`() =
runTest {