mirror of
https://github.com/bitwarden/android.git
synced 2024-11-21 17:05:44 +03:00
Simplify usages of turbineScope (#4167)
This commit is contained in:
parent
f8bf864fc9
commit
0960f61c37
8 changed files with 40 additions and 90 deletions
|
@ -4309,18 +4309,11 @@ class VaultRepositoryTest {
|
|||
)
|
||||
} returns Throwable().asFailure()
|
||||
|
||||
turbineScope {
|
||||
val expected = DecryptFido2CredentialAutofillViewResult.Error
|
||||
val result = vaultRepository
|
||||
.getDecryptedFido2CredentialAutofillViews(
|
||||
val result = vaultRepository.getDecryptedFido2CredentialAutofillViews(
|
||||
cipherViewList = cipherViewList,
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected,
|
||||
result,
|
||||
)
|
||||
}
|
||||
assertEquals(DecryptFido2CredentialAutofillViewResult.Error, result)
|
||||
coVerify {
|
||||
vaultSdkSource.decryptFido2CredentialAutofillViews(
|
||||
userId = MOCK_USER_STATE.activeUserId,
|
||||
|
@ -4346,17 +4339,11 @@ class VaultRepositoryTest {
|
|||
)
|
||||
} returns autofillViewList.asSuccess()
|
||||
|
||||
turbineScope {
|
||||
val result = vaultRepository
|
||||
.getDecryptedFido2CredentialAutofillViews(
|
||||
val result = vaultRepository.getDecryptedFido2CredentialAutofillViews(
|
||||
cipherViewList = cipherViewList,
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expected,
|
||||
result,
|
||||
)
|
||||
}
|
||||
assertEquals(expected, result)
|
||||
coVerify {
|
||||
vaultSdkSource.decryptFido2CredentialAutofillViews(
|
||||
userId = MOCK_USER_STATE.activeUserId,
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.x8bit.bitwarden.ui.auth.feature.completeregistration
|
|||
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import app.cash.turbine.turbineScope
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength.LEVEL_0
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength.LEVEL_1
|
||||
|
@ -154,9 +153,7 @@ class CompleteRegistrationViewModelTest : BaseViewModelTest() {
|
|||
)
|
||||
} returns RegisterResult.Success(captchaToken = CAPTCHA_BYPASS_TOKEN)
|
||||
val viewModel = createCompleteRegistrationViewModel(VALID_INPUT_STATE)
|
||||
turbineScope {
|
||||
val stateFlow = viewModel.stateFlow.testIn(backgroundScope)
|
||||
val eventFlow = viewModel.eventFlow.testIn(backgroundScope)
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
assertEquals(VALID_INPUT_STATE, stateFlow.awaitItem())
|
||||
viewModel.trySendAction(CompleteRegistrationAction.CallToActionClick)
|
||||
assertEquals(
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.x8bit.bitwarden.ui.auth.feature.createaccount
|
|||
import android.net.Uri
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import app.cash.turbine.turbineScope
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength.LEVEL_0
|
||||
import com.x8bit.bitwarden.data.auth.datasource.sdk.model.PasswordStrength.LEVEL_1
|
||||
|
@ -243,9 +242,7 @@ class CreateAccountViewModelTest : BaseViewModelTest() {
|
|||
savedStateHandle = validInputHandle,
|
||||
authRepository = repo,
|
||||
)
|
||||
turbineScope {
|
||||
val stateFlow = viewModel.stateFlow.testIn(backgroundScope)
|
||||
val eventFlow = viewModel.eventFlow.testIn(backgroundScope)
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
assertEquals(VALID_INPUT_STATE, stateFlow.awaitItem())
|
||||
viewModel.trySendAction(CreateAccountAction.SubmitClick)
|
||||
assertEquals(
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.x8bit.bitwarden.ui.auth.feature.enterprisesignon
|
|||
import android.net.Uri
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import app.cash.turbine.turbineScope
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.LoginResult
|
||||
|
@ -511,10 +510,7 @@ class EnterpriseSignOnViewModelTest : BaseViewModelTest() {
|
|||
)
|
||||
val ssoCallbackResult = SsoCallbackResult.Success(state = "abc", code = "lmn")
|
||||
|
||||
turbineScope {
|
||||
val stateFlow = viewModel.stateFlow.testIn(backgroundScope)
|
||||
val eventFlow = viewModel.eventFlow.testIn(backgroundScope)
|
||||
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
assertEquals(initialState, stateFlow.awaitItem())
|
||||
|
||||
mutableSsoCallbackResultFlow.tryEmit(ssoCallbackResult)
|
||||
|
@ -566,10 +562,7 @@ class EnterpriseSignOnViewModelTest : BaseViewModelTest() {
|
|||
)
|
||||
val ssoCallbackResult = SsoCallbackResult.Success(state = "abc", code = "lmn")
|
||||
|
||||
turbineScope {
|
||||
val stateFlow = viewModel.stateFlow.testIn(backgroundScope)
|
||||
val eventFlow = viewModel.eventFlow.testIn(backgroundScope)
|
||||
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
assertEquals(initialState, stateFlow.awaitItem())
|
||||
|
||||
mutableSsoCallbackResultFlow.tryEmit(ssoCallbackResult)
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.x8bit.bitwarden.ui.auth.feature.startregistration
|
|||
import android.net.Uri
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import app.cash.turbine.turbineScope
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.repository.AuthRepository
|
||||
import com.x8bit.bitwarden.data.auth.repository.model.SendVerificationEmailResult
|
||||
|
@ -177,9 +176,7 @@ class StartRegistrationViewModelTest : BaseViewModelTest() {
|
|||
environmentRepository = fakeEnvironmentRepository,
|
||||
featureFlagManager = featureFlagManager,
|
||||
)
|
||||
turbineScope {
|
||||
val stateFlow = viewModel.stateFlow.testIn(backgroundScope)
|
||||
val eventFlow = viewModel.eventFlow.testIn(backgroundScope)
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
assertEquals(VALID_INPUT_STATE, stateFlow.awaitItem())
|
||||
viewModel.trySendAction(ContinueClick)
|
||||
assertEquals(
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.x8bit.bitwarden.ui.vault.feature.addedit
|
|||
import android.content.pm.SigningInfo
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import app.cash.turbine.turbineScope
|
||||
import com.bitwarden.send.SendView
|
||||
import com.bitwarden.vault.CipherView
|
||||
import com.bitwarden.vault.CollectionView
|
||||
|
@ -611,25 +610,22 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
|||
vaultRepository.createCipherInOrganization(any(), any())
|
||||
} returns CreateCipherResult.Success
|
||||
|
||||
turbineScope {
|
||||
val stateTurbine = viewModel.stateFlow.testIn(backgroundScope)
|
||||
val eventTurbine = viewModel.eventFlow.testIn(backgroundScope)
|
||||
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
viewModel.trySendAction(VaultAddEditAction.Common.SaveClick)
|
||||
|
||||
assertEquals(stateWithName, stateTurbine.awaitItem())
|
||||
assertEquals(stateWithDialog, stateTurbine.awaitItem())
|
||||
assertEquals(stateWithName, stateTurbine.awaitItem())
|
||||
assertEquals(stateWithName, stateFlow.awaitItem())
|
||||
assertEquals(stateWithDialog, stateFlow.awaitItem())
|
||||
assertEquals(stateWithName, stateFlow.awaitItem())
|
||||
|
||||
assertEquals(
|
||||
VaultAddEditEvent.ShowToast(
|
||||
R.string.new_item_created.asText(),
|
||||
),
|
||||
eventTurbine.awaitItem(),
|
||||
eventFlow.awaitItem(),
|
||||
)
|
||||
assertEquals(
|
||||
VaultAddEditEvent.NavigateBack,
|
||||
eventTurbine.awaitItem(),
|
||||
eventFlow.awaitItem(),
|
||||
)
|
||||
}
|
||||
coVerify(exactly = 1) {
|
||||
|
@ -680,19 +676,16 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
|||
vaultRepository.createCipherInOrganization(any(), any())
|
||||
} returns CreateCipherResult.Success
|
||||
|
||||
turbineScope {
|
||||
val stateTurbine = viewModel.stateFlow.testIn(backgroundScope)
|
||||
val eventTurbine = viewModel.eventFlow.testIn(backgroundScope)
|
||||
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
viewModel.trySendAction(VaultAddEditAction.Common.SaveClick)
|
||||
|
||||
assertEquals(stateWithName, stateTurbine.awaitItem())
|
||||
assertEquals(stateWithDialog, stateTurbine.awaitItem())
|
||||
assertEquals(stateWithName, stateTurbine.awaitItem())
|
||||
assertEquals(stateWithName, stateFlow.awaitItem())
|
||||
assertEquals(stateWithDialog, stateFlow.awaitItem())
|
||||
assertEquals(stateWithName, stateFlow.awaitItem())
|
||||
|
||||
assertEquals(
|
||||
VaultAddEditEvent.ExitApp,
|
||||
eventTurbine.awaitItem(),
|
||||
eventFlow.awaitItem(),
|
||||
)
|
||||
}
|
||||
assertNull(specialCircumstanceManager.specialCircumstance)
|
||||
|
@ -821,17 +814,14 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
|||
} returns mockAttestationOptions
|
||||
every { authRepository.activeUserId } returns "mockUserId"
|
||||
|
||||
turbineScope {
|
||||
val stateTurbine = viewModel.stateFlow.testIn(backgroundScope)
|
||||
val eventTurbine = viewModel.eventFlow.testIn(backgroundScope)
|
||||
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
viewModel.trySendAction(VaultAddEditAction.Common.SaveClick)
|
||||
|
||||
assertEquals(stateWithNewLogin, stateTurbine.awaitItem())
|
||||
assertEquals(stateWithSavingDialog, stateTurbine.awaitItem())
|
||||
assertEquals(stateWithNewLogin, stateFlow.awaitItem())
|
||||
assertEquals(stateWithSavingDialog, stateFlow.awaitItem())
|
||||
assertEquals(
|
||||
VaultAddEditEvent.Fido2UserVerification(isRequired = true),
|
||||
eventTurbine.awaitItem(),
|
||||
eventFlow.awaitItem(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -899,22 +889,19 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
|||
} returns mockAttestationOptions
|
||||
every { authRepository.activeUserId } returns mockUserId
|
||||
|
||||
turbineScope {
|
||||
val stateTurbine = viewModel.stateFlow.testIn(backgroundScope)
|
||||
val eventTurbine = viewModel.eventFlow.testIn(backgroundScope)
|
||||
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
viewModel.trySendAction(VaultAddEditAction.Common.SaveClick)
|
||||
|
||||
assertEquals(stateWithName, stateTurbine.awaitItem())
|
||||
assertEquals(stateWithSavingDialog, stateTurbine.awaitItem())
|
||||
assertEquals(stateWithName, stateFlow.awaitItem())
|
||||
assertEquals(stateWithSavingDialog, stateFlow.awaitItem())
|
||||
assertEquals(
|
||||
VaultAddEditEvent.ShowToast(R.string.item_updated.asText()),
|
||||
eventTurbine.awaitItem(),
|
||||
eventFlow.awaitItem(),
|
||||
)
|
||||
assertEquals(stateWithName, stateTurbine.awaitItem())
|
||||
assertEquals(stateWithName, stateFlow.awaitItem())
|
||||
assertEquals(
|
||||
VaultAddEditEvent.CompleteFido2Registration(mockCreateResult),
|
||||
eventTurbine.awaitItem(),
|
||||
eventFlow.awaitItem(),
|
||||
)
|
||||
coVerify(exactly = 1) {
|
||||
fido2CredentialManager.registerFido2Credential(
|
||||
|
@ -1059,11 +1046,10 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
|||
|
||||
viewModel.trySendAction(VaultAddEditAction.Common.SaveClick)
|
||||
|
||||
turbineScope {
|
||||
val eventTurbine = viewModel.eventFlow.testIn(backgroundScope)
|
||||
viewModel.eventFlow.test {
|
||||
assertEquals(
|
||||
VaultAddEditEvent.Fido2UserVerification(isRequired = false),
|
||||
eventTurbine.awaitItem(),
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1105,11 +1091,10 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
|||
|
||||
viewModel.trySendAction(VaultAddEditAction.Common.SaveClick)
|
||||
|
||||
turbineScope {
|
||||
val eventTurbine = viewModel.eventFlow.testIn(backgroundScope)
|
||||
viewModel.eventFlow.test {
|
||||
assertEquals(
|
||||
VaultAddEditEvent.Fido2UserVerification(isRequired = true),
|
||||
eventTurbine.awaitItem(),
|
||||
awaitItem(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.x8bit.bitwarden.ui.vault.feature.importlogins
|
||||
|
||||
import app.cash.turbine.test
|
||||
import app.cash.turbine.turbineScope
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.vault.repository.VaultRepository
|
||||
import com.x8bit.bitwarden.data.vault.repository.model.SyncVaultDataResult
|
||||
|
@ -95,9 +94,7 @@ class ImportLoginsViewModelTest : BaseViewModelTest() {
|
|||
@Test
|
||||
fun `ConfirmImportLater sets dialog state to null and sends NavigateBack event`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
turbineScope {
|
||||
val stateFlow = viewModel.stateFlow.testIn(backgroundScope)
|
||||
val eventFlow = viewModel.eventFlow.testIn(backgroundScope)
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
// Initial state
|
||||
assertEquals(DEFAULT_STATE, stateFlow.awaitItem())
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.x8bit.bitwarden.ui.vault.feature.item
|
|||
import android.net.Uri
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import app.cash.turbine.test
|
||||
import app.cash.turbine.turbineScope
|
||||
import com.bitwarden.vault.CipherView
|
||||
import com.x8bit.bitwarden.R
|
||||
import com.x8bit.bitwarden.data.auth.datasource.disk.model.OnboardingStatus
|
||||
|
@ -653,9 +652,7 @@ class VaultItemViewModelTest : BaseViewModelTest() {
|
|||
val loginState = DEFAULT_STATE.copy(viewState = loginViewState)
|
||||
val viewModel = createViewModel(state = loginState)
|
||||
|
||||
turbineScope {
|
||||
val stateFlow = viewModel.stateFlow.testIn(backgroundScope)
|
||||
val eventFlow = viewModel.eventFlow.testIn(backgroundScope)
|
||||
viewModel.stateEventFlow(backgroundScope) { stateFlow, eventFlow ->
|
||||
assertEquals(loginState, stateFlow.awaitItem())
|
||||
viewModel.trySendAction(
|
||||
VaultItemAction.Common.MasterPasswordSubmit(
|
||||
|
|
Loading…
Reference in a new issue