Skip to content

Commit

Permalink
[PM-12319] Skip Auto-fill setup if already enabled. (#3934)
Browse files Browse the repository at this point in the history
  • Loading branch information
dseverns-livefront authored Sep 19, 2024
1 parent c8b1b71 commit 71d3ae9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 71d3ae9

Please sign in to comment.