Skip to content

Commit

Permalink
Remove orchestrator, clear enro result channels before running the Co…
Browse files Browse the repository at this point in the history
…mposableListResultTests.kt and RecyclerViewResultTests.kt
  • Loading branch information
isaac-udy committed Oct 18, 2022
1 parent 88f4637 commit 24f046b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
3 changes: 0 additions & 3 deletions enro/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ android {
}
testOptions {
animationsDisabled = true
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
packagingOptions {
resources.excludes.add("META-INF/*")
Expand Down Expand Up @@ -54,13 +53,11 @@ dependencies {
androidTestImplementation deps.testing.androidx.espressoRecyclerView
androidTestImplementation deps.testing.androidx.espressoIntents
androidTestImplementation deps.testing.androidx.runner
androidTestUtil deps.testing.androidx.orchestrator

androidTestImplementation deps.testing.androidx.compose

androidTestImplementation deps.androidx.navigation.fragment
androidTestImplementation deps.androidx.navigation.ui

}

afterEvaluate {
Expand Down
12 changes: 12 additions & 0 deletions enro/src/androidTest/java/dev/enro/TestExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,18 @@ fun getActiveEnroResultChannels(): List<EnroResultChannel<*, *>> {
return channels.values.toList()
}

fun clearAllEnroResultChannels() {
val enroResultClass = Class.forName("dev.enro.core.result.EnroResult")
val getEnroResult = enroResultClass.getDeclaredMethod("from", NavigationController::class.java)
getEnroResult.isAccessible = true
val enroResult = getEnroResult.invoke(null, application.navigationController)
getEnroResult.isAccessible = false

requireNotNull(enroResult)
val channels = enroResult.getPrivate<MutableMap<Any, EnroResultChannel<*, * >>>("channels")
channels.clear()
}

@Suppress("unused")
fun <T> Any.callPrivate(methodName: String, vararg args: Any): T {
val method = this::class.java.declaredMethods.first { it.name.startsWith(methodName) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.unit.dp
import dev.enro.DefaultActivity
import dev.enro.clearAllEnroResultChannels
import dev.enro.core.compose.registerForNavigationResult
import dev.enro.getActiveEnroResultChannels
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import java.util.*
Expand All @@ -34,6 +36,13 @@ class ComposableListResultTests {
@get:Rule
val composeContentRule = createAndroidComposeRule<DefaultActivity>()

@Before
fun before() {
// TODO: There's something not quite right on CI, these tests pass on local machines, but
// something on CI causes previous tests to leave hanging result channels. This needs to be cleaned up.
clearAllEnroResultChannels()
}

@Test
fun whenListItemWithResultIsRenderedOnItsOwn_thenResultIsRetrievedSuccessfully() {
val id = UUID.randomUUID().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.contrib.RecyclerViewActions
import androidx.test.espresso.matcher.ViewMatchers.*
import dev.enro.annotations.NavigationDestination
import dev.enro.clearAllEnroResultChannels
import dev.enro.core.NavigationHandle
import dev.enro.core.NavigationKey
import dev.enro.core.navigationHandle
Expand All @@ -27,12 +28,20 @@ import dev.enro.getActiveEnroResultChannels
import kotlinx.parcelize.Parcelize
import org.hamcrest.Matchers
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import java.util.*


class RecyclerViewResultTests {

@Before
fun before() {
// TODO: There's something not quite right on CI, these tests pass on local machines, but
// something on CI causes previous tests to leave hanging result channels. This needs to be cleaned up.
clearAllEnroResultChannels()
}

@Test
fun whenListItemWithResultIsRenderedOnItsOwn_thenResultIsRetrievedSuccessfully() {
val scenario = ActivityScenario.launch(RecyclerViewResultActivity::class.java)
Expand Down

0 comments on commit 24f046b

Please sign in to comment.