[PM-6702] Add email verification feature flag to landing create account click

This commit is contained in:
André Bispo 2024-08-16 14:46:31 +01:00
parent bd55b9ce72
commit 1d05f5f758
No known key found for this signature in database
GPG key ID: E5610EF043C76548
2 changed files with 32 additions and 2 deletions

View file

@ -6,6 +6,8 @@ import androidx.lifecycle.viewModelScope
import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
import com.x8bit.bitwarden.data.auth.repository.model.UserState
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
import com.x8bit.bitwarden.data.platform.manager.model.FlagKey
import com.x8bit.bitwarden.data.platform.repository.EnvironmentRepository
import com.x8bit.bitwarden.data.platform.repository.model.Environment
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
@ -34,6 +36,7 @@ class LandingViewModel @Inject constructor(
private val authRepository: AuthRepository,
private val vaultRepository: VaultRepository,
private val environmentRepository: EnvironmentRepository,
private val featureFlagManager: FeatureFlagManager,
savedStateHandle: SavedStateHandle,
) : BaseViewModel<LandingState, LandingEvent, LandingAction>(
initialState = savedStateHandle[KEY_STATE]
@ -191,8 +194,11 @@ class LandingViewModel @Inject constructor(
}
private fun handleCreateAccountClicked() {
// TODO PM-9401: ADD FEATURE FLAG email-verification and navigation to StartRegistration
sendEvent(LandingEvent.NavigateToCreateAccount)
if (featureFlagManager.getFeatureFlag(FlagKey.EmailVerification)) {
sendEvent(LandingEvent.NavigateToStartRegistration)
} else {
sendEvent(LandingEvent.NavigateToCreateAccount)
}
}
private fun handleDialogDismiss() {

View file

@ -6,6 +6,8 @@ import com.x8bit.bitwarden.R
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
import com.x8bit.bitwarden.data.auth.repository.model.UserState
import com.x8bit.bitwarden.data.auth.repository.model.VaultUnlockType
import com.x8bit.bitwarden.data.platform.manager.FeatureFlagManager
import com.x8bit.bitwarden.data.platform.manager.model.FlagKey
import com.x8bit.bitwarden.data.platform.repository.model.Environment
import com.x8bit.bitwarden.data.platform.repository.util.FakeEnvironmentRepository
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
@ -34,6 +36,7 @@ class LandingViewModelTest : BaseViewModelTest() {
every { lockVault(any()) } just runs
}
private val fakeEnvironmentRepository = FakeEnvironmentRepository()
private val featureFlagManager: FeatureFlagManager = mockk()
@Test
fun `initial state should be correct when there is no remembered email`() = runTest {
@ -358,6 +361,9 @@ class LandingViewModelTest : BaseViewModelTest() {
@Test
fun `CreateAccountClick should emit NavigateToCreateAccount`() = runTest {
every {
featureFlagManager.getFeatureFlag(FlagKey.EmailVerification)
} returns false
val viewModel = createViewModel()
viewModel.eventFlow.test {
viewModel.trySendAction(LandingAction.CreateAccountClick)
@ -368,6 +374,23 @@ class LandingViewModelTest : BaseViewModelTest() {
}
}
@Suppress("MaxLineLength")
@Test
fun `CreateAccountClick should emit NavigateToStartRegistration if EmailVerification feature flag is true`() =
runTest {
every {
featureFlagManager.getFeatureFlag(FlagKey.EmailVerification)
} returns true
val viewModel = createViewModel()
viewModel.eventFlow.test {
viewModel.trySendAction(LandingAction.CreateAccountClick)
assertEquals(
LandingEvent.NavigateToStartRegistration,
awaitItem(),
)
}
}
@Test
fun `DialogDismiss should clear the active dialog`() {
val initialState = DEFAULT_STATE.copy(
@ -543,6 +566,7 @@ class LandingViewModelTest : BaseViewModelTest() {
},
vaultRepository = vaultRepository,
environmentRepository = fakeEnvironmentRepository,
featureFlagManager = featureFlagManager,
savedStateHandle = savedStateHandle,
)