diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/auth/AuthNavigation.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/auth/AuthNavigation.kt index 88a8c3682..7df1ecfa3 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/auth/AuthNavigation.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/auth/AuthNavigation.kt @@ -133,6 +133,7 @@ fun NavGraphBuilder.authGraph( welcomeDestination( onNavigateToCreateAccount = { navController.navigateToCreateAccount() }, onNavigateToLogin = { navController.navigateToLanding() }, + onNavigateToStartRegistration = { navController.navigateToStartRegistration() }, ) loginDestination( onNavigateBack = { navController.popBackStack() }, diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeNavigation.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeNavigation.kt index ca0fcfb5b..9ecf956e1 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeNavigation.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeNavigation.kt @@ -20,6 +20,7 @@ fun NavController.navigateToWelcome(navOptions: NavOptions? = null) { fun NavGraphBuilder.welcomeDestination( onNavigateToCreateAccount: () -> Unit, onNavigateToLogin: () -> Unit, + onNavigateToStartRegistration: () -> Unit, ) { composableWithStayTransitions( route = WELCOME_ROUTE, @@ -27,6 +28,7 @@ fun NavGraphBuilder.welcomeDestination( WelcomeScreen( onNavigateToCreateAccount = onNavigateToCreateAccount, onNavigateToLogin = onNavigateToLogin, + onNavigateToStartRegistration = onNavigateToStartRegistration, ) } } diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeScreen.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeScreen.kt index 14c9b7794..003fb7cf7 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeScreen.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeScreen.kt @@ -59,6 +59,7 @@ private val LANDSCAPE_HORIZONTAL_MARGIN: Dp = 128.dp fun WelcomeScreen( onNavigateToCreateAccount: () -> Unit, onNavigateToLogin: () -> Unit, + onNavigateToStartRegistration: () -> Unit, viewModel: WelcomeViewModel = hiltViewModel(), ) { val state by viewModel.stateFlow.collectAsStateWithLifecycle() @@ -72,6 +73,7 @@ fun WelcomeScreen( WelcomeEvent.NavigateToCreateAccount -> onNavigateToCreateAccount() WelcomeEvent.NavigateToLogin -> onNavigateToLogin() + WelcomeEvent.NavigateToStartRegistration -> onNavigateToStartRegistration() } } diff --git a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeViewModel.kt b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeViewModel.kt index ff6d10341..53a16e3ee 100644 --- a/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeViewModel.kt +++ b/app/src/main/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeViewModel.kt @@ -2,6 +2,8 @@ package com.x8bit.bitwarden.ui.auth.feature.welcome import android.os.Parcelable import com.x8bit.bitwarden.R +import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager +import com.x8bit.bitwarden.data.platform.manager.model.FlagKey import com.x8bit.bitwarden.ui.platform.base.BaseViewModel import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.update @@ -12,7 +14,9 @@ import javax.inject.Inject * Manages application state for the welcome screen. */ @HiltViewModel -class WelcomeViewModel @Inject constructor() : +class WelcomeViewModel @Inject constructor( + private val featureFlagManager: FeatureFlagManager, +) : BaseViewModel( initialState = WelcomeState( index = 0, @@ -43,7 +47,12 @@ class WelcomeViewModel @Inject constructor() : } private fun handleCreateAccountClick() { - sendEvent(WelcomeEvent.NavigateToCreateAccount) + val event = if (featureFlagManager.getFeatureFlag(FlagKey.EmailVerification)) { + WelcomeEvent.NavigateToStartRegistration + } else { + WelcomeEvent.NavigateToCreateAccount + } + sendEvent(event) } private fun handleLoginClick() { @@ -129,6 +138,11 @@ sealed class WelcomeEvent { * Navigates to the login screen. */ data object NavigateToLogin : WelcomeEvent() + + /** + * Navigates to the start registration screen. + */ + data object NavigateToStartRegistration : WelcomeEvent() } /** diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeScreenTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeScreenTest.kt index 1ca2ec6fb..b99a23f4a 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeScreenTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeScreenTest.kt @@ -16,6 +16,7 @@ import org.junit.jupiter.api.Assertions.assertTrue import org.robolectric.annotation.Config class WelcomeScreenTest : BaseComposeTest() { + private var onNavigateToStartRegistrationCalled = false private var onNavigateToCreateAccountCalled = false private var onNavigateToLoginCalled = false private val mutableStateFlow = MutableStateFlow(DEFAULT_STATE) @@ -31,6 +32,7 @@ class WelcomeScreenTest : BaseComposeTest() { WelcomeScreen( onNavigateToCreateAccount = { onNavigateToCreateAccountCalled = true }, onNavigateToLogin = { onNavigateToLoginCalled = true }, + onNavigateToStartRegistration = { onNavigateToStartRegistrationCalled = true }, viewModel = viewModel, ) } @@ -113,6 +115,12 @@ class WelcomeScreenTest : BaseComposeTest() { .performClick() verify { viewModel.trySendAction(WelcomeAction.LoginClick) } } + + @Test + fun `on NavigateToStartRegistration event should call onNavigateToStartRegistration`() { + mutableEventFlow.tryEmit(WelcomeEvent.NavigateToStartRegistration) + assertTrue(onNavigateToStartRegistrationCalled) + } } private val DEFAULT_STATE = WelcomeState( diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeViewModelTest.kt index f48e0af89..9cac1b424 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/welcome/WelcomeViewModelTest.kt @@ -1,15 +1,22 @@ package com.x8bit.bitwarden.ui.auth.feature.welcome import app.cash.turbine.test +import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager +import com.x8bit.bitwarden.data.platform.manager.model.FlagKey import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest +import io.mockk.every +import io.mockk.mockk import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test class WelcomeViewModelTest : BaseViewModelTest() { + + private val featureFlagManager = mockk() + @Test fun `initial state should be correct`() = runTest { - val viewModel = WelcomeViewModel() + val viewModel = WelcomeViewModel(featureFlagManager = featureFlagManager) viewModel.stateFlow.test { assertEquals( @@ -21,7 +28,7 @@ class WelcomeViewModelTest : BaseViewModelTest() { @Test fun `PagerSwipe should update state`() = runTest { - val viewModel = WelcomeViewModel() + val viewModel = WelcomeViewModel(featureFlagManager = featureFlagManager) val newIndex = 2 viewModel.trySendAction(WelcomeAction.PagerSwipe(index = newIndex)) @@ -36,7 +43,7 @@ class WelcomeViewModelTest : BaseViewModelTest() { @Test fun `DotClick should update state and emit UpdatePager`() = runTest { - val viewModel = WelcomeViewModel() + val viewModel = WelcomeViewModel(featureFlagManager = featureFlagManager) val newIndex = 2 viewModel.trySendAction(WelcomeAction.DotClick(index = newIndex)) @@ -55,10 +62,12 @@ class WelcomeViewModelTest : BaseViewModelTest() { } } + @Suppress("MaxLineLength") @Test - fun `CreateAccountClick should emit NavigateToCreateAccount`() = runTest { - val viewModel = WelcomeViewModel() - + fun `CreateAccountClick should emit NavigateToCreateAccount when email verification is disabled`() = + runTest { + val viewModel = WelcomeViewModel(featureFlagManager = featureFlagManager) + every { featureFlagManager.getFeatureFlag(FlagKey.EmailVerification) } returns false viewModel.trySendAction(WelcomeAction.CreateAccountClick) viewModel.eventFlow.test { @@ -69,9 +78,25 @@ class WelcomeViewModelTest : BaseViewModelTest() { } } + @Suppress("MaxLineLength") + @Test + fun `CreateAccountClick should emit NavigateToStartRegistration when email verification is enabled`() = + runTest { + val viewModel = WelcomeViewModel(featureFlagManager = featureFlagManager) + every { featureFlagManager.getFeatureFlag(FlagKey.EmailVerification) } returns true + viewModel.trySendAction(WelcomeAction.CreateAccountClick) + + viewModel.eventFlow.test { + assertEquals( + WelcomeEvent.NavigateToStartRegistration, + awaitItem(), + ) + } + } + @Test fun `LoginClick should emit NavigateToLogin`() = runTest { - val viewModel = WelcomeViewModel() + val viewModel = WelcomeViewModel(featureFlagManager = featureFlagManager) viewModel.trySendAction(WelcomeAction.LoginClick)