diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/accountsetup/SetupUnlockViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/accountsetup/SetupUnlockViewModel.kt index 75eb185ac..3dc21468a 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/accountsetup/SetupUnlockViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/accountsetup/SetupUnlockViewModel.kt @@ -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) } } diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/accountsetup/SetupUnlockViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/accountsetup/SetupUnlockViewModelTest.kt index 655b5206b..87ec1ffc7 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/accountsetup/SetupUnlockViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/accountsetup/SetupUnlockViewModelTest.kt @@ -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 { 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 {