Loading packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/interactor/SceneBackInteractorTest.kt +24 −22 Original line number Diff line number Diff line Loading @@ -23,19 +23,19 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.authentication.data.repository.FakeAuthenticationRepository import com.android.systemui.authentication.domain.interactor.AuthenticationResult import com.android.systemui.authentication.domain.interactor.authenticationInteractor import com.android.systemui.coroutines.collectLastValue import com.android.systemui.flags.EnableSceneContainer import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.scene.data.model.asIterable import com.android.systemui.scene.data.model.sceneStackOf import com.android.systemui.scene.domain.startable.sceneContainerStartable import com.android.systemui.scene.shared.model.Scenes import com.android.systemui.shade.domain.interactor.enableSingleShade import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Test import org.junit.runner.RunWith Loading @@ -43,18 +43,15 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class SceneBackInteractorTest : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope private val sceneInteractor by lazy { kosmos.sceneInteractor } private val sceneContainerStartable by lazy { kosmos.sceneContainerStartable } private val authenticationInteractor by lazy { kosmos.authenticationInteractor } private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val underTest by lazy { kosmos.sceneBackInteractor } @Test @EnableSceneContainer fun navigateToQs_thenBack_whileLocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() assertRoute( Loading @@ -69,7 +66,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_thenUnlock() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() assertRoute( Loading @@ -83,7 +81,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_skippingShade_thenBack_whileLocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() assertRoute( Loading @@ -96,7 +95,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_skippingShade_thenBack_thenShade_whileLocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() assertRoute( Loading @@ -110,7 +110,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_thenBack_whileUnlocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() unlockDevice() Loading @@ -126,7 +127,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_skippingShade_thenBack_whileUnlocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() unlockDevice() Loading @@ -140,7 +142,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_skippingShade_thenBack_thenShade_whileUnlocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() unlockDevice() Loading @@ -155,7 +158,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun updateBackStack() = testScope.runTest { kosmos.runTest { enableSingleShade() underTest.onSceneChange(from = Scenes.Lockscreen, to = Scenes.Shade) underTest.onSceneChange(from = Scenes.Shade, to = Scenes.QuickSettings) assertThat(underTest.backStack.value.asIterable().toList()) Loading @@ -170,13 +174,12 @@ class SceneBackInteractorTest : SysuiTestCase() { .isEqualTo(listOf(Scenes.Lockscreen, Scenes.Shade)) } private suspend fun TestScope.assertRoute(vararg route: RouteNode) { private suspend fun Kosmos.assertRoute(vararg route: RouteNode) { val currentScene by collectLastValue(sceneInteractor.currentScene) val backScene by collectLastValue(underTest.backScene) route.forEachIndexed { index, node -> sceneInteractor.changeScene(node.changeSceneTo, "") runCurrent() assertWithMessage("node at index $index currentScene mismatch") .that(currentScene) .isEqualTo(node.changeSceneTo) Loading @@ -189,9 +192,8 @@ class SceneBackInteractorTest : SysuiTestCase() { } } private suspend fun TestScope.unlockDevice() { private suspend fun Kosmos.unlockDevice() { val currentScene by collectLastValue(sceneInteractor.currentScene) runCurrent() assertThat(authenticationInteractor.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)) .isEqualTo(AuthenticationResult.SUCCEEDED) assertThat(currentScene).isEqualTo(Scenes.Gone) Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/scene/domain/interactor/SceneBackInteractorTest.kt +24 −22 Original line number Diff line number Diff line Loading @@ -23,19 +23,19 @@ import com.android.systemui.SysuiTestCase import com.android.systemui.authentication.data.repository.FakeAuthenticationRepository import com.android.systemui.authentication.domain.interactor.AuthenticationResult import com.android.systemui.authentication.domain.interactor.authenticationInteractor import com.android.systemui.coroutines.collectLastValue import com.android.systemui.flags.EnableSceneContainer import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.scene.data.model.asIterable import com.android.systemui.scene.data.model.sceneStackOf import com.android.systemui.scene.domain.startable.sceneContainerStartable import com.android.systemui.scene.shared.model.Scenes import com.android.systemui.shade.domain.interactor.enableSingleShade import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Test import org.junit.runner.RunWith Loading @@ -43,18 +43,15 @@ import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class SceneBackInteractorTest : SysuiTestCase() { private val kosmos = testKosmos() private val testScope = kosmos.testScope private val sceneInteractor by lazy { kosmos.sceneInteractor } private val sceneContainerStartable by lazy { kosmos.sceneContainerStartable } private val authenticationInteractor by lazy { kosmos.authenticationInteractor } private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val underTest by lazy { kosmos.sceneBackInteractor } @Test @EnableSceneContainer fun navigateToQs_thenBack_whileLocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() assertRoute( Loading @@ -69,7 +66,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_thenUnlock() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() assertRoute( Loading @@ -83,7 +81,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_skippingShade_thenBack_whileLocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() assertRoute( Loading @@ -96,7 +95,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_skippingShade_thenBack_thenShade_whileLocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() assertRoute( Loading @@ -110,7 +110,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_thenBack_whileUnlocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() unlockDevice() Loading @@ -126,7 +127,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_skippingShade_thenBack_whileUnlocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() unlockDevice() Loading @@ -140,7 +142,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun navigateToQs_skippingShade_thenBack_thenShade_whileUnlocked() = testScope.runTest { kosmos.runTest { enableSingleShade() sceneContainerStartable.start() unlockDevice() Loading @@ -155,7 +158,8 @@ class SceneBackInteractorTest : SysuiTestCase() { @Test @EnableSceneContainer fun updateBackStack() = testScope.runTest { kosmos.runTest { enableSingleShade() underTest.onSceneChange(from = Scenes.Lockscreen, to = Scenes.Shade) underTest.onSceneChange(from = Scenes.Shade, to = Scenes.QuickSettings) assertThat(underTest.backStack.value.asIterable().toList()) Loading @@ -170,13 +174,12 @@ class SceneBackInteractorTest : SysuiTestCase() { .isEqualTo(listOf(Scenes.Lockscreen, Scenes.Shade)) } private suspend fun TestScope.assertRoute(vararg route: RouteNode) { private suspend fun Kosmos.assertRoute(vararg route: RouteNode) { val currentScene by collectLastValue(sceneInteractor.currentScene) val backScene by collectLastValue(underTest.backScene) route.forEachIndexed { index, node -> sceneInteractor.changeScene(node.changeSceneTo, "") runCurrent() assertWithMessage("node at index $index currentScene mismatch") .that(currentScene) .isEqualTo(node.changeSceneTo) Loading @@ -189,9 +192,8 @@ class SceneBackInteractorTest : SysuiTestCase() { } } private suspend fun TestScope.unlockDevice() { private suspend fun Kosmos.unlockDevice() { val currentScene by collectLastValue(sceneInteractor.currentScene) runCurrent() assertThat(authenticationInteractor.authenticate(FakeAuthenticationRepository.DEFAULT_PIN)) .isEqualTo(AuthenticationResult.SUCCEEDED) assertThat(currentScene).isEqualTo(Scenes.Gone) Loading