diff --git a/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt b/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt index d7678350f1b..159ed4dd22c 100644 --- a/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/data/vault/repository/VaultRepositoryTest.kt @@ -4309,18 +4309,11 @@ class VaultRepositoryTest { ) } returns Throwable().asFailure() - turbineScope { - val expected = DecryptFido2CredentialAutofillViewResult.Error - val result = vaultRepository - .getDecryptedFido2CredentialAutofillViews( - cipherViewList = cipherViewList, - ) + 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( - cipherViewList = cipherViewList, - ) + val result = vaultRepository.getDecryptedFido2CredentialAutofillViews( + cipherViewList = cipherViewList, + ) - assertEquals( - expected, - result, - ) - } + assertEquals(expected, result) coVerify { vaultSdkSource.decryptFido2CredentialAutofillViews( userId = MOCK_USER_STATE.activeUserId, diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/completeregistration/CompleteRegistrationViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/completeregistration/CompleteRegistrationViewModelTest.kt index 82748359cf9..4d2d75b9c14 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/completeregistration/CompleteRegistrationViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/completeregistration/CompleteRegistrationViewModelTest.kt @@ -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( diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountViewModelTest.kt index 0801b442ec7..39a69be6180 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/createaccount/CreateAccountViewModelTest.kt @@ -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( diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/enterprisesignon/EnterpriseSignOnViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/enterprisesignon/EnterpriseSignOnViewModelTest.kt index 0ffffe07be9..0b8497bdf1b 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/enterprisesignon/EnterpriseSignOnViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/enterprisesignon/EnterpriseSignOnViewModelTest.kt @@ -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) diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/startregistration/StartRegistrationViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/startregistration/StartRegistrationViewModelTest.kt index c558c940303..76d6d88b1f4 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/startregistration/StartRegistrationViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/auth/feature/startregistration/StartRegistrationViewModelTest.kt @@ -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( diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModelTest.kt index e4091d26130..5169d97d99b 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModelTest.kt @@ -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(), ) } } diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/importlogins/ImportLoginsViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/importlogins/ImportLoginsViewModelTest.kt index 6885b654448..a53be8adc4d 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/importlogins/ImportLoginsViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/importlogins/ImportLoginsViewModelTest.kt @@ -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()) diff --git a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt index 607a19227e8..160e78575ff 100644 --- a/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt +++ b/app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/item/VaultItemViewModelTest.kt @@ -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(