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

Commit 08bd4282 authored by Justin Weir's avatar Justin Weir Committed by Android (Google) Code Review
Browse files

Merge "Fix ShadeBackActionInteractorImplTest" into main

parents cf6414d5 603daaa6
Loading
Loading
Loading
Loading
+34 −13
Original line number Diff line number Diff line
@@ -22,7 +22,12 @@ import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.SceneKey
import com.android.systemui.SysuiTestCase
import com.android.systemui.authentication.data.repository.fakeAuthenticationRepository
import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.keyguard.data.repository.deviceEntryFingerprintAuthRepository
import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Scenes
@@ -31,77 +36,93 @@ import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Assume
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
@Ignore("b/328827631")
@EnableSceneContainer
class ShadeBackActionInteractorImplTest : SysuiTestCase() {
    val kosmos = testKosmos()
    val testScope = kosmos.testScope
    val sceneInteractor = kosmos.sceneInteractor
    val underTest = kosmos.shadeBackActionInteractor
    val sceneInteractor by lazy { kosmos.sceneInteractor }
    val shadeInteractor by lazy { kosmos.shadeInteractor }
    val fakeAuthenticationRepository by lazy { kosmos.fakeAuthenticationRepository }
    val deviceEntryFingerprintAuthRepository by lazy { kosmos.deviceEntryFingerprintAuthRepository }

    lateinit var underTest: ShadeBackActionInteractor

    @Before
    fun ignoreSplitShade() {
    fun ignoreSplitShadeAndSetup() {
        Assume.assumeFalse(Utilities.isLargeScreen(kosmos.applicationContext))
        underTest = kosmos.shadeBackActionInteractor
    }

    @Test
    fun animateCollapseQs_notOnQs() =
        testScope.runTest {
            val actual by collectLastValue(sceneInteractor.currentScene)
            setScene(Scenes.Shade)
            underTest.animateCollapseQs(true)
            runCurrent()
            assertThat(sceneInteractor.currentScene.value).isEqualTo(Scenes.Shade)
            assertThat(actual).isEqualTo(Scenes.Shade)
        }

    @Test
    fun animateCollapseQs_fullyCollapse_entered() =
        testScope.runTest {
            val actual by collectLastValue(sceneInteractor.currentScene)
            enterDevice()
            setScene(Scenes.QuickSettings)
            underTest.animateCollapseQs(true)
            runCurrent()
            assertThat(sceneInteractor.currentScene.value).isEqualTo(Scenes.Gone)
            assertThat(actual).isEqualTo(Scenes.Gone)
        }

    @Test
    fun animateCollapseQs_fullyCollapse_locked() =
        testScope.runTest {
            val actual by collectLastValue(sceneInteractor.currentScene)
            setScene(Scenes.QuickSettings)
            underTest.animateCollapseQs(true)
            runCurrent()
            assertThat(sceneInteractor.currentScene.value).isEqualTo(Scenes.Lockscreen)
            assertThat(actual).isEqualTo(Scenes.Lockscreen)
        }

    @Test
    fun animateCollapseQs_notFullyCollapse() =
        testScope.runTest {
            val actual by collectLastValue(sceneInteractor.currentScene)
            setScene(Scenes.QuickSettings)
            underTest.animateCollapseQs(false)
            runCurrent()
            assertThat(sceneInteractor.currentScene.value).isEqualTo(Scenes.Shade)
            assertThat(actual).isEqualTo(Scenes.Shade)
        }

    private fun enterDevice() {
        testScope.runCurrent()
    private fun TestScope.enterDevice() {
        // configure device unlocked state
        fakeAuthenticationRepository.setAuthenticationMethod(AuthenticationMethodModel.Pin)
        runCurrent()
        deviceEntryFingerprintAuthRepository.setAuthenticationStatus(
            SuccessFingerprintAuthenticationStatus(0, true)
        )
        runCurrent()
        setScene(Scenes.Gone)
    }

    private fun setScene(key: SceneKey) {
    private fun TestScope.setScene(key: SceneKey) {
        val actual by collectLastValue(sceneInteractor.currentScene)
        sceneInteractor.changeScene(key, "test")
        sceneInteractor.setTransitionState(
            MutableStateFlow<ObservableTransitionState>(ObservableTransitionState.Idle(key))
        )
        testScope.runCurrent()
        runCurrent()
        assertThat(actual).isEqualTo(key)
    }
}