From 8c98f9889fb57776a1f85b93dc53642ea0891cea Mon Sep 17 00:00:00 2001 From: sebaslogen Date: Sun, 19 Nov 2023 11:56:56 +0100 Subject: [PATCH] Update public API contracts and fix test --- .../sebaslogen/resaca/koin/ScopedMemoizers.kt | 1 - .../sample/ComposeActivityRecreationTests.kt | 22 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/resacakoin/src/main/java/com/sebaslogen/resaca/koin/ScopedMemoizers.kt b/resacakoin/src/main/java/com/sebaslogen/resaca/koin/ScopedMemoizers.kt index 089bd2d1..c7dac39d 100644 --- a/resacakoin/src/main/java/com/sebaslogen/resaca/koin/ScopedMemoizers.kt +++ b/resacakoin/src/main/java/com/sebaslogen/resaca/koin/ScopedMemoizers.kt @@ -13,7 +13,6 @@ import com.sebaslogen.resaca.ScopedViewModelContainer.ExternalKey import com.sebaslogen.resaca.ScopedViewModelContainer.InternalKey import com.sebaslogen.resaca.ScopedViewModelOwner import com.sebaslogen.resaca.generateKeysAndObserveLifecycle -import com.sebaslogen.resaca.viewModelScoped import org.koin.androidx.viewmodel.factory.KoinViewModelFactory import org.koin.core.annotation.KoinInternalApi import org.koin.core.context.GlobalContext diff --git a/sample/src/test/java/com/sebaslogen/resacaapp/sample/ComposeActivityRecreationTests.kt b/sample/src/test/java/com/sebaslogen/resacaapp/sample/ComposeActivityRecreationTests.kt index 44869e21..94740d36 100644 --- a/sample/src/test/java/com/sebaslogen/resacaapp/sample/ComposeActivityRecreationTests.kt +++ b/sample/src/test/java/com/sebaslogen/resacaapp/sample/ComposeActivityRecreationTests.kt @@ -15,6 +15,8 @@ import com.sebaslogen.resacaapp.sample.ui.main.rememberScopedDestination import com.sebaslogen.resacaapp.sample.ui.main.showSingleScopedViewModel import com.sebaslogen.resacaapp.sample.ui.main.viewModelScopedDestination import com.sebaslogen.resacaapp.sample.utils.ComposeTestUtils +import kotlinx.coroutines.delay +import kotlinx.coroutines.runBlocking import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith @@ -92,15 +94,17 @@ class ComposeActivityRecreationTests : ComposeTestUtils { showSingleScopedViewModel = false // This is a fake night-mode change but it will remove Composable after Activity re-creation activity.recreate() printComposeUiTreeToLog() - Thread.sleep(COMPOSITION_RESUMED_TIMEOUT_IN_SECONDS * 1000) // Wait for the ViewModel to be cleared - printComposeUiTreeToLog() // Second print is needed to push the main thread forward - val finalAmountOfViewModelsCleared = viewModelsClearedGloballySharedCounter.get() - - // Then the scoped ViewModel disappears - onNodeWithTestTag("FakeInjectedViewModel Scoped", assertDisplayed = false).assertDoesNotExist() - assert(finalAmountOfViewModelsCleared == initialAmountOfViewModelsCleared + 1) { - "The amount of FakeInjectedViewModel that were cleared after key change ($finalAmountOfViewModelsCleared) " + - "was not higher that the amount before the key change ($initialAmountOfViewModelsCleared)" + runBlocking { + delay(COMPOSITION_RESUMED_TIMEOUT_IN_SECONDS * 1000) // Wait for the ViewModel to be cleared + printComposeUiTreeToLog() // Second print is needed to push the main thread forward + val finalAmountOfViewModelsCleared = viewModelsClearedGloballySharedCounter.get() + + // Then the scoped ViewModel disappears + onNodeWithTestTag("FakeInjectedViewModel Scoped", assertDisplayed = false).assertDoesNotExist() + assert(finalAmountOfViewModelsCleared == initialAmountOfViewModelsCleared + 1) { + "The amount of FakeInjectedViewModel that were cleared after key change ($finalAmountOfViewModelsCleared) " + + "was not higher that the amount before the key change ($initialAmountOfViewModelsCleared)" + } } } }