Skip to content

Commit

Permalink
Delay ViewModel init actions slightly, as these were occurring too qu…
Browse files Browse the repository at this point in the history
…ickly and causing the test to be flaky in some cases
  • Loading branch information
isaac-udy committed Apr 28, 2024
1 parent 19a5538 commit d02d2a3
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions enro/src/androidTest/java/dev/enro/result/ViewModelResultTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@ package dev.enro.result
import android.os.Bundle
import android.view.View
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import androidx.test.core.app.ActivityScenario
import dev.enro.*
import dev.enro.DefaultActivity
import dev.enro.TestFragment
import dev.enro.annotations.NavigationDestination
import dev.enro.core.NavigationKey
import dev.enro.core.closeWithResult
import dev.enro.core.forward
import dev.enro.core.result.registerForNavigationResult
import dev.enro.expectFragment
import dev.enro.getNavigationHandle
import dev.enro.viewmodel.enroViewModels
import dev.enro.viewmodel.navigationHandle
import dev.enro.waitFor
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.parcelize.Parcelize
import leakcanary.DetectLeaksAfterTestSuccess
import org.junit.Rule
Expand Down Expand Up @@ -52,7 +59,10 @@ class OrchestratorViewModel : ViewModel() {
}

init {
resultOne.open(FirstStepKey())
viewModelScope.launch {
delay(100)
resultOne.open(FirstStepKey())
}
}
}

Expand All @@ -70,7 +80,10 @@ class FirstStepKey : NavigationKey.WithResult<String>
class FirstStepViewModel : ViewModel() {
private val navigation by navigationHandle<FirstStepKey>()
init {
navigation.closeWithResult("FirstStep")
viewModelScope.launch {
delay(100)
navigation.closeWithResult("FirstStep")
}
}
}

Expand All @@ -91,7 +104,10 @@ class SecondStepViewModel : ViewModel() {
navigation.closeWithResult("SecondStep($it)")
}
init {
nested.open(SecondStepNestedKey())
viewModelScope.launch {
delay(100)
nested.open(SecondStepNestedKey())
}
}
}

Expand All @@ -110,7 +126,10 @@ class SecondStepNestedKey : NavigationKey.WithResult<String>
class SecondStepNestedViewModel : ViewModel() {
private val navigation by navigationHandle<SecondStepNestedKey>()
init {
navigation.closeWithResult("SecondStepNested")
viewModelScope.launch {
delay(100)
navigation.closeWithResult("SecondStepNested")
}
}
}

Expand Down

0 comments on commit d02d2a3

Please sign in to comment.