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

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

Merge "[Dual Shade] Fix SceneBackInteractorTest for Dual Shade on." into main

parents 03f77887 1b2fef26
Loading
Loading
Loading
Loading
+24 −22
Original line number Diff line number Diff line
@@ -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

@@ -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(
@@ -69,7 +66,8 @@ class SceneBackInteractorTest : SysuiTestCase() {
    @Test
    @EnableSceneContainer
    fun navigateToQs_thenUnlock() =
        testScope.runTest {
        kosmos.runTest {
            enableSingleShade()
            sceneContainerStartable.start()

            assertRoute(
@@ -83,7 +81,8 @@ class SceneBackInteractorTest : SysuiTestCase() {
    @Test
    @EnableSceneContainer
    fun navigateToQs_skippingShade_thenBack_whileLocked() =
        testScope.runTest {
        kosmos.runTest {
            enableSingleShade()
            sceneContainerStartable.start()

            assertRoute(
@@ -96,7 +95,8 @@ class SceneBackInteractorTest : SysuiTestCase() {
    @Test
    @EnableSceneContainer
    fun navigateToQs_skippingShade_thenBack_thenShade_whileLocked() =
        testScope.runTest {
        kosmos.runTest {
            enableSingleShade()
            sceneContainerStartable.start()

            assertRoute(
@@ -110,7 +110,8 @@ class SceneBackInteractorTest : SysuiTestCase() {
    @Test
    @EnableSceneContainer
    fun navigateToQs_thenBack_whileUnlocked() =
        testScope.runTest {
        kosmos.runTest {
            enableSingleShade()
            sceneContainerStartable.start()
            unlockDevice()

@@ -126,7 +127,8 @@ class SceneBackInteractorTest : SysuiTestCase() {
    @Test
    @EnableSceneContainer
    fun navigateToQs_skippingShade_thenBack_whileUnlocked() =
        testScope.runTest {
        kosmos.runTest {
            enableSingleShade()
            sceneContainerStartable.start()
            unlockDevice()

@@ -140,7 +142,8 @@ class SceneBackInteractorTest : SysuiTestCase() {
    @Test
    @EnableSceneContainer
    fun navigateToQs_skippingShade_thenBack_thenShade_whileUnlocked() =
        testScope.runTest {
        kosmos.runTest {
            enableSingleShade()
            sceneContainerStartable.start()
            unlockDevice()

@@ -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())
@@ -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)
@@ -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)