mirror of
https://github.com/bitwarden/android.git
synced 2025-02-13 18:39:56 +03:00
PM-13698 only dismiss the card if the user dismisses or completes the… (#4165)
This commit is contained in:
parent
c47f8606cd
commit
064db9fb6a
6 changed files with 53 additions and 23 deletions
app/src
main/java/com/x8bit/bitwarden/ui
auth/feature/accountsetup
vault/feature/importlogins
test/java/com/x8bit/bitwarden/ui
auth/feature/accountsetup
vault/feature/importlogins
|
@ -104,6 +104,7 @@ class SetupAutoFillViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun handleContinueClick() {
|
||||
firstTimeActionManager.storeShowAutoFillSettingBadge(showBadge = false)
|
||||
if (state.isInitialSetup) {
|
||||
updateOnboardingStatusToNextStep()
|
||||
} else {
|
||||
|
|
|
@ -80,6 +80,7 @@ class SetupUnlockViewModel @Inject constructor(
|
|||
}
|
||||
|
||||
private fun handleContinueClick() {
|
||||
firstTimeActionManager.storeShowUnlockSettingBadge(showBadge = false)
|
||||
if (state.isInitialSetup) {
|
||||
updateOnboardingStatusToNextStep()
|
||||
} else {
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.x8bit.bitwarden.ui.vault.feature.importlogins
|
|||
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.platform.manager.FirstTimeActionManager
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.SyncVaultDataResult
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModel
|
||||
|
@ -19,6 +20,7 @@ import javax.inject.Inject
|
|||
@HiltViewModel
|
||||
class ImportLoginsViewModel @Inject constructor(
|
||||
private val vaultRepository: VaultRepository,
|
||||
private val firstTimeActionManager: FirstTimeActionManager,
|
||||
) :
|
||||
BaseViewModel<ImportLoginsState, ImportLoginsEvent, ImportLoginsAction>(
|
||||
initialState = ImportLoginsState(
|
||||
|
@ -94,6 +96,7 @@ class ImportLoginsViewModel @Inject constructor(
|
|||
|
||||
is SyncVaultDataResult.Success -> {
|
||||
if (result.itemsAvailable) {
|
||||
firstTimeActionManager.storeShowImportLogins(showImportLogins = false)
|
||||
mutableStateFlow.update {
|
||||
it.copy(
|
||||
showBottomSheet = true,
|
||||
|
|
|
@ -125,35 +125,43 @@ class SetupAutoFillViewModelTest : BaseViewModelTest() {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `handleContinueClick sets onboarding status to FINAL_STEP`() {
|
||||
fun `handleContinueClick sets onboarding status to FINAL_STEP and sets first time flag to false`() {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(SetupAutoFillAction.ContinueClick)
|
||||
verify {
|
||||
verify(exactly = 1) {
|
||||
authRepository.setOnboardingStatus(
|
||||
DEFAULT_USER_ID,
|
||||
OnboardingStatus.FINAL_STEP,
|
||||
)
|
||||
firstTimeActionManager.storeShowAutoFillSettingBadge(showBadge = false)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `handleContinueClick send NavigateBack event when not initial setup`() = runTest {
|
||||
val viewModel = createViewModel(initialState = DEFAULT_STATE.copy(isInitialSetup = false))
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(SetupAutoFillAction.ContinueClick)
|
||||
assertEquals(
|
||||
SetupAutoFillEvent.NavigateBack,
|
||||
awaitItem(),
|
||||
)
|
||||
fun `handleContinueClick send NavigateBack event when not initial setup and sets first time flag to false`() =
|
||||
runTest {
|
||||
val viewModel =
|
||||
createViewModel(initialState = DEFAULT_STATE.copy(isInitialSetup = false))
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(SetupAutoFillAction.ContinueClick)
|
||||
assertEquals(
|
||||
SetupAutoFillEvent.NavigateBack,
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
verify(exactly = 1) {
|
||||
firstTimeActionManager.storeShowAutoFillSettingBadge(showBadge = false)
|
||||
}
|
||||
verify(exactly = 0) {
|
||||
authRepository.setOnboardingStatus(
|
||||
DEFAULT_USER_ID,
|
||||
OnboardingStatus.FINAL_STEP,
|
||||
)
|
||||
}
|
||||
}
|
||||
verify(exactly = 0) {
|
||||
authRepository.setOnboardingStatus(
|
||||
DEFAULT_USER_ID,
|
||||
OnboardingStatus.FINAL_STEP,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `handleTurnOnLaterConfirmClick sets showAutoFillSettingBadge to true`() {
|
||||
|
|
|
@ -86,14 +86,16 @@ class SetupUnlockViewModelTest : BaseViewModelTest() {
|
|||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `ContinueClick should send NavigateBack event if this is not the initial setup`() =
|
||||
fun `ContinueClick should send NavigateBack event if this is not the initial setup and set first time value to false`() =
|
||||
runTest {
|
||||
val viewModel = createViewModel(DEFAULT_STATE.copy(isInitialSetup = false))
|
||||
viewModel.eventFlow.test {
|
||||
viewModel.trySendAction(SetupUnlockAction.ContinueClick)
|
||||
assertEquals(SetupUnlockEvent.NavigateBack, awaitItem())
|
||||
}
|
||||
|
||||
verify(exactly = 1) {
|
||||
firstTimeActionManager.storeShowUnlockSettingBadge(showBadge = false)
|
||||
}
|
||||
verify(exactly = 0) {
|
||||
authRepository.setOnboardingStatus(
|
||||
userId = DEFAULT_USER_ID,
|
||||
|
@ -118,15 +120,16 @@ class SetupUnlockViewModelTest : BaseViewModelTest() {
|
|||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `ContinueClick should call setOnboardingStatus and set to FINAL_STEP if AutoFill is already enabled`() {
|
||||
fun `ContinueClick should call setOnboardingStatus and set to FINAL_STEP if AutoFill is already enabled and set first time value to false`() {
|
||||
mutableAutofillEnabledStateFlow.update { true }
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(SetupUnlockAction.ContinueClick)
|
||||
verify {
|
||||
verify(exactly = 1) {
|
||||
authRepository.setOnboardingStatus(
|
||||
userId = DEFAULT_USER_ID,
|
||||
status = OnboardingStatus.FINAL_STEP,
|
||||
)
|
||||
firstTimeActionManager.storeShowUnlockSettingBadge(showBadge = false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,13 +2,18 @@ package com.x8bit.bitwarden.ui.vault.feature.importlogins
|
|||
|
||||
import app.cash.turbine.test
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.platform.manager.FirstTimeActionManager
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.SyncVaultDataResult
|
||||
import com.x8bit.bitwarden.ui.platform.base.BaseViewModelTest
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import io.mockk.coEvery
|
||||
import io.mockk.coVerify
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.mockk
|
||||
import io.mockk.runs
|
||||
import io.mockk.verify
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||
|
@ -17,10 +22,14 @@ import org.junit.jupiter.api.Test
|
|||
|
||||
class ImportLoginsViewModelTest : BaseViewModelTest() {
|
||||
|
||||
private val vaultRepository: VaultRepository = mockk() {
|
||||
private val vaultRepository: VaultRepository = mockk {
|
||||
coEvery { syncForResult() } returns SyncVaultDataResult.Success(itemsAvailable = true)
|
||||
}
|
||||
|
||||
private val firstTimeActionManager: FirstTimeActionManager = mockk {
|
||||
every { storeShowImportLogins(any()) } just runs
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `initial state is correct`() {
|
||||
val viewModel = createViewModel()
|
||||
|
@ -295,8 +304,9 @@ class ImportLoginsViewModelTest : BaseViewModelTest() {
|
|||
coVerify { vaultRepository.syncForResult() }
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `SyncVaultDataResult success should update state to show bottom sheet`() {
|
||||
fun `SyncVaultDataResult success should update state to show bottom sheet and set first time values to false`() {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.trySendAction(ImportLoginsAction.MoveToSyncInProgress)
|
||||
assertEquals(
|
||||
|
@ -308,6 +318,9 @@ class ImportLoginsViewModelTest : BaseViewModelTest() {
|
|||
),
|
||||
viewModel.stateFlow.value,
|
||||
)
|
||||
verify {
|
||||
firstTimeActionManager.storeShowImportLogins(showImportLogins = false)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
|
@ -429,6 +442,7 @@ class ImportLoginsViewModelTest : BaseViewModelTest() {
|
|||
|
||||
private fun createViewModel(): ImportLoginsViewModel = ImportLoginsViewModel(
|
||||
vaultRepository = vaultRepository,
|
||||
firstTimeActionManager = firstTimeActionManager,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue