Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit edcbb43a authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Move runMonotonicClockTest into MotionTestingComposeLib 1/2" into main

parents 40683b8d 15a37420
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -47,8 +47,6 @@ import com.android.compose.animation.scene.content.state.TransitionState.Transit
import com.android.compose.animation.scene.subjects.assertThat
import com.android.compose.gesture.NestedDraggable
import com.android.compose.gesture.effect.OffsetOverscrollEffectFactory
import com.android.compose.test.MonotonicClockTestScope
import com.android.compose.test.runMonotonicClockTest
import com.android.mechanics.spec.InputDirection
import com.google.common.truth.Truth.assertThat
import kotlin.math.nextUp
@@ -59,6 +57,8 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import org.junit.Test
import org.junit.runner.RunWith
import platform.test.motion.compose.MonotonicClockTestScope
import platform.test.motion.compose.runMonotonicClockTest

private const val SCREEN_SIZE = 100f
private val LAYOUT_SIZE = IntSize(SCREEN_SIZE.toInt(), SCREEN_SIZE.toInt())
+1 −1
Original line number Diff line number Diff line
@@ -24,13 +24,13 @@ import com.android.compose.animation.scene.TestScenes.SceneB
import com.android.compose.animation.scene.TestScenes.SceneC
import com.android.compose.animation.scene.content.state.TransitionState
import com.android.compose.animation.scene.subjects.assertThat
import com.android.compose.test.runMonotonicClockTest
import com.android.compose.test.transition
import com.google.common.truth.Correspondence
import com.google.common.truth.Truth.assertThat
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import platform.test.motion.compose.runMonotonicClockTest

@RunWith(AndroidJUnit4::class)
class InterruptionHandlerTest {
+1 −1
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.compose.animation.scene.TestScenes.SceneC
import com.android.compose.animation.scene.content.state.TransitionState
import com.android.compose.animation.scene.subjects.assertThat
import com.android.compose.test.TestSceneTransition
import com.android.compose.test.runMonotonicClockTest
import com.android.compose.test.transition
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.CompletableDeferred
@@ -40,6 +39,7 @@ import org.junit.Assert.assertThrows
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import platform.test.motion.compose.runMonotonicClockTest

@RunWith(AndroidJUnit4::class)
class SceneTransitionLayoutStateTest {
+1 −1
Original line number Diff line number Diff line
@@ -24,13 +24,13 @@ import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.NestedScrollSource.Companion.UserInput
import androidx.compose.ui.unit.Velocity
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.compose.test.runMonotonicClockTest
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith
import platform.test.motion.compose.runMonotonicClockTest

@RunWith(AndroidJUnit4::class)
class PriorityNestedScrollConnectionTest {
+0 −50
Original line number Diff line number Diff line
package com.android.compose.test

import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.TestMonotonicFrameClock
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.test.TestCoroutineScheduler
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runTest
import kotlinx.coroutines.withContext

/**
 * This method creates a [CoroutineScope] that can be used in animations created in a composable
 * function.
 *
 * The [TestCoroutineScheduler] is passed to provide the functionality to wait for idle.
 *
 * Note: Please refer to the documentation for [runTest], as this feature utilizes it. This will
 * provide a comprehensive understanding of all its behaviors.
 */
@OptIn(ExperimentalTestApi::class)
fun runMonotonicClockTest(block: suspend MonotonicClockTestScope.() -> Unit) = runTest {
    val testScope: TestScope = this

    withContext(TestMonotonicFrameClock(coroutineScope = testScope)) {
        val testScopeWithMonotonicFrameClock: CoroutineScope = this

        val scope =
            MonotonicClockTestScope(
                testScope = testScopeWithMonotonicFrameClock,
                testScheduler = testScope.testScheduler,
                backgroundScope = backgroundScope,
            )

        // Run the test
        scope.block()
    }
}

/**
 * A coroutine scope that for launching test coroutines for Compose.
 *
 * @param testScheduler The delay-skipping scheduler used by the test dispatchers running the code
 *   in this scope (see [TestScope.testScheduler]).
 * @param backgroundScope A scope for background work (see [TestScope.backgroundScope]).
 */
class MonotonicClockTestScope(
    testScope: CoroutineScope,
    val testScheduler: TestCoroutineScheduler,
    val backgroundScope: CoroutineScope,
) : CoroutineScope by testScope