Skip to content

Commit

Permalink
Update public API contracts and fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaslogen committed Nov 19, 2023
1 parent 3077642 commit 8c98f98
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"
}
}
}
}
Expand Down

0 comments on commit 8c98f98

Please sign in to comment.