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

Commit 08d21955 authored by Justin Weir's avatar Justin Weir
Browse files

Migrate tests to Kosmos and deviceless

Bug: 307719099
Flag: NONE
Test: yes, these are tests
Change-Id: I1f2165e71a3ea8e12b5885e8fedcb42c59792a79
parent 9f2f3960
Loading
Loading
Loading
Loading
+20 −54
Original line number Diff line number Diff line
@@ -16,71 +16,37 @@

package com.android.systemui.shade.domain.interactor

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysUITestComponent
import com.android.systemui.SysUITestModule
import com.android.systemui.SysuiTestCase
import com.android.systemui.TestMocksModule
import com.android.systemui.collectLastValue
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.flags.FakeFeatureFlagsClassicModule
import com.android.systemui.flags.Flags
import com.android.systemui.runCurrent
import com.android.systemui.runTest
import com.android.systemui.scene.domain.interactor.SceneInteractor
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.ObservableTransitionState
import com.android.systemui.scene.shared.model.SceneKey
import com.android.systemui.statusbar.phone.DozeParameters
import com.android.systemui.user.domain.UserDomainLayerModule
import com.android.systemui.util.mockito.mock
import com.android.systemui.testKosmos
import com.google.common.truth.Truth
import dagger.BindsInstance
import dagger.Component
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
class ShadeAnimationInteractorSceneContainerImplTest : SysuiTestCase() {
    val kosmos = testKosmos()
    val testScope = kosmos.testScope
    val sceneInteractor = kosmos.sceneInteractor

    @SysUISingleton
    @Component(
        modules =
            [
                SysUITestModule::class,
                UserDomainLayerModule::class,
            ]
    )
    interface TestComponent : SysUITestComponent<ShadeAnimationInteractorSceneContainerImpl> {
        val sceneInteractor: SceneInteractor

        @Component.Factory
        interface Factory {
            fun create(
                @BindsInstance test: SysuiTestCase,
                featureFlags: FakeFeatureFlagsClassicModule,
                mocks: TestMocksModule,
            ): TestComponent
        }
    }

    private val dozeParameters: DozeParameters = mock()

    private val testComponent: TestComponent =
        DaggerShadeAnimationInteractorSceneContainerImplTest_TestComponent.factory()
            .create(
                test = this,
                featureFlags =
                    FakeFeatureFlagsClassicModule { set(Flags.FULL_SCREEN_USER_SWITCHER, true) },
                mocks =
                    TestMocksModule(
                        dozeParameters = dozeParameters,
                    ),
            )
    val underTest = kosmos.shadeAnimationInteractorSceneContainerImpl

    @Test
    fun isAnyCloseAnimationRunning_qsToShade() =
        testComponent.runTest() {
        testScope.runTest {
            val actual by collectLastValue(underTest.isAnyCloseAnimationRunning)

            // WHEN transitioning from QS to Shade
@@ -103,10 +69,10 @@ class ShadeAnimationInteractorSceneContainerImplTest : SysuiTestCase() {

    @Test
    fun isAnyCloseAnimationRunning_qsToGone_userInputNotOngoing() =
        testComponent.runTest() {
        testScope.runTest() {
            val actual by collectLastValue(underTest.isAnyCloseAnimationRunning)

            // WHEN transitioning from QS to Gone with no ongoing user input
            // WHEN transitioning from QS to Gone lwith no ongoing user input
            val transitionState =
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Transition(
@@ -126,7 +92,7 @@ class ShadeAnimationInteractorSceneContainerImplTest : SysuiTestCase() {

    @Test
    fun isAnyCloseAnimationRunning_qsToGone_userInputOngoing() =
        testComponent.runTest() {
        testScope.runTest() {
            val actual by collectLastValue(underTest.isAnyCloseAnimationRunning)

            // WHEN transitioning from QS to Gone with user input ongoing
@@ -149,7 +115,7 @@ class ShadeAnimationInteractorSceneContainerImplTest : SysuiTestCase() {

    @Test
    fun updateIsLaunchingActivity() =
        testComponent.runTest {
        testScope.runTest {
            Truth.assertThat(underTest.isLaunchingActivity.value).isEqualTo(false)

            underTest.setIsLaunchingActivity(true)
+65 −124
Original line number Diff line number Diff line
@@ -19,124 +19,65 @@ package com.android.systemui.shade.domain.interactor
import android.app.StatusBarManager.DISABLE2_NONE
import android.app.StatusBarManager.DISABLE2_NOTIFICATION_SHADE
import android.app.StatusBarManager.DISABLE2_QUICK_SETTINGS
import android.content.pm.UserInfo
import android.os.UserManager
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysUITestComponent
import com.android.systemui.SysUITestModule
import com.android.systemui.SysuiTestCase
import com.android.systemui.TestMocksModule
import com.android.systemui.collectLastValue
import com.android.systemui.common.ui.data.repository.FakeConfigurationRepository
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.flags.FakeFeatureFlagsClassicModule
import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.FakeKeyguardTransitionRepository
import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.DozeStateModel
import com.android.systemui.keyguard.shared.model.DozeTransitionModel
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.StatusBarState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.power.data.repository.FakePowerRepository
import com.android.systemui.kosmos.testScope
import com.android.systemui.power.data.repository.fakePowerRepository
import com.android.systemui.power.shared.model.WakeSleepReason
import com.android.systemui.power.shared.model.WakefulnessState
import com.android.systemui.res.R
import com.android.systemui.runCurrent
import com.android.systemui.runTest
import com.android.systemui.scene.domain.interactor.SceneInteractor
import com.android.systemui.shade.data.repository.FakeShadeRepository
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.shade.data.repository.fakeShadeRepository
import com.android.systemui.statusbar.disableflags.data.model.DisableFlagsModel
import com.android.systemui.statusbar.disableflags.data.repository.FakeDisableFlagsRepository
import com.android.systemui.statusbar.phone.DozeParameters
import com.android.systemui.statusbar.policy.data.repository.FakeDeviceProvisioningRepository
import com.android.systemui.statusbar.policy.data.repository.FakeUserSetupRepository
import com.android.systemui.statusbar.disableflags.data.repository.fakeDisableFlagsRepository
import com.android.systemui.statusbar.phone.dozeParameters
import com.android.systemui.statusbar.policy.data.repository.fakeDeviceProvisioningRepository
import com.android.systemui.statusbar.policy.data.repository.fakeUserSetupRepository
import com.android.systemui.testKosmos
import com.android.systemui.user.data.model.UserSwitcherSettingsModel
import com.android.systemui.user.data.repository.FakeUserRepository
import com.android.systemui.user.domain.UserDomainLayerModule
import com.android.systemui.util.mockito.mock
import com.android.systemui.user.data.repository.fakeUserRepository
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import dagger.BindsInstance
import dagger.Component
import kotlinx.coroutines.runBlocking
import org.junit.Before
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
class ShadeInteractorImplTest : SysuiTestCase() {

    @SysUISingleton
    @Component(
        modules =
            [
                SysUITestModule::class,
                UserDomainLayerModule::class,
            ]
    )
    interface TestComponent : SysUITestComponent<ShadeInteractorImpl> {

        val configurationRepository: FakeConfigurationRepository
        val deviceProvisioningRepository: FakeDeviceProvisioningRepository
        val disableFlagsRepository: FakeDisableFlagsRepository
        val keyguardRepository: FakeKeyguardRepository
        val keyguardTransitionRepository: FakeKeyguardTransitionRepository
        val powerRepository: FakePowerRepository
        val sceneInteractor: SceneInteractor
        val shadeRepository: FakeShadeRepository
        val userRepository: FakeUserRepository
        val userSetupRepository: FakeUserSetupRepository

        @Component.Factory
        interface Factory {
            fun create(
                @BindsInstance test: SysuiTestCase,
                featureFlags: FakeFeatureFlagsClassicModule,
                mocks: TestMocksModule,
            ): TestComponent
        }
    }

    private val dozeParameters: DozeParameters = mock()

    private val testComponent: TestComponent =
        DaggerShadeInteractorImplTest_TestComponent.factory()
            .create(
                test = this,
                featureFlags =
                    FakeFeatureFlagsClassicModule { set(Flags.FULL_SCREEN_USER_SWITCHER, true) },
                mocks =
                    TestMocksModule(
                        dozeParameters = dozeParameters,
                    ),
            )

    @Before
    fun setUp() {
        runBlocking {
            val userInfos =
                listOf(
                    UserInfo(
                        /* id= */ 0,
                        /* name= */ "zero",
                        /* iconPath= */ "",
                        /* flags= */ UserInfo.FLAG_PRIMARY or
                            UserInfo.FLAG_ADMIN or
                            UserInfo.FLAG_FULL,
                        UserManager.USER_TYPE_FULL_SYSTEM,
                    ),
                )
            testComponent.apply {
                userRepository.setUserInfos(userInfos)
                userRepository.setSelectedUserInfo(userInfos[0])
            }
        }
    }
    val kosmos = testKosmos()
    val testScope = kosmos.testScope
    val configurationRepository = kosmos.fakeConfigurationRepository
    val deviceProvisioningRepository = kosmos.fakeDeviceProvisioningRepository
    val disableFlagsRepository = kosmos.fakeDisableFlagsRepository
    val keyguardRepository = kosmos.fakeKeyguardRepository
    val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository
    val powerRepository = kosmos.fakePowerRepository
    val sceneInteractor = kosmos.sceneInteractor
    val shadeRepository = kosmos.fakeShadeRepository
    val userRepository = kosmos.fakeUserRepository
    val userSetupRepository = kosmos.fakeUserSetupRepository
    val dozeParameters = kosmos.dozeParameters

    val underTest = kosmos.shadeInteractorImpl

    @Test
    fun isShadeEnabled_matchesDisableFlagsRepo() =
        testComponent.runTest {
        testScope.runTest {
            val actual by collectLastValue(underTest.isShadeEnabled)

            disableFlagsRepository.disableFlags.value =
@@ -150,7 +91,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isExpandToQsEnabled_deviceNotProvisioned_false() =
        testComponent.runTest {
        testScope.runTest {
            deviceProvisioningRepository.setDeviceProvisioned(false)

            val actual by collectLastValue(underTest.isExpandToQsEnabled)
@@ -160,7 +101,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isExpandToQsEnabled_userNotSetupAndSimpleUserSwitcher_false() =
        testComponent.runTest {
        testScope.runTest {
            deviceProvisioningRepository.setDeviceProvisioned(true)

            userSetupRepository.setUserSetUp(false)
@@ -173,7 +114,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isExpandToQsEnabled_shadeNotEnabled_false() =
        testComponent.runTest {
        testScope.runTest {
            deviceProvisioningRepository.setDeviceProvisioned(true)
            userSetupRepository.setUserSetUp(true)

@@ -189,7 +130,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isExpandToQsEnabled_quickSettingsNotEnabled_false() =
        testComponent.runTest {
        testScope.runTest {
            deviceProvisioningRepository.setDeviceProvisioned(true)
            userSetupRepository.setUserSetUp(true)

@@ -204,7 +145,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isExpandToQsEnabled_dozing_false() =
        testComponent.runTest {
        testScope.runTest {
            deviceProvisioningRepository.setDeviceProvisioned(true)
            userSetupRepository.setUserSetUp(true)
            disableFlagsRepository.disableFlags.value =
@@ -221,7 +162,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isExpandToQsEnabled_userSetup_true() =
        testComponent.runTest {
        testScope.runTest {
            deviceProvisioningRepository.setDeviceProvisioned(true)
            keyguardRepository.setIsDozing(false)
            disableFlagsRepository.disableFlags.value =
@@ -238,7 +179,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isExpandToQsEnabled_notSimpleUserSwitcher_true() =
        testComponent.runTest {
        testScope.runTest {
            deviceProvisioningRepository.setDeviceProvisioned(true)
            keyguardRepository.setIsDozing(false)
            disableFlagsRepository.disableFlags.value =
@@ -255,7 +196,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isExpandToQsEnabled_respondsToDozingUpdates() =
        testComponent.runTest {
        testScope.runTest {
            deviceProvisioningRepository.setDeviceProvisioned(true)
            keyguardRepository.setIsDozing(false)
            disableFlagsRepository.disableFlags.value =
@@ -283,7 +224,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isExpandToQsEnabled_respondsToDisableUpdates() =
        testComponent.runTest {
        testScope.runTest {
            deviceProvisioningRepository.setDeviceProvisioned(true)
            keyguardRepository.setIsDozing(false)
            disableFlagsRepository.disableFlags.value =
@@ -315,7 +256,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isExpandToQsEnabled_respondsToUserUpdates() =
        testComponent.runTest {
        testScope.runTest {
            deviceProvisioningRepository.setDeviceProvisioned(true)
            keyguardRepository.setIsDozing(false)
            disableFlagsRepository.disableFlags.value =
@@ -344,7 +285,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun fullShadeExpansionWhenShadeLocked() =
        testComponent.runTest {
        testScope.runTest {
            val actual by collectLastValue(underTest.shadeExpansion)

            keyguardRepository.setStatusBarState(StatusBarState.SHADE_LOCKED)
@@ -355,7 +296,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun fullShadeExpansionWhenStatusBarStateIsNotShadeLocked() =
        testComponent.runTest {
        testScope.runTest {
            val actual by collectLastValue(underTest.shadeExpansion)

            keyguardRepository.setStatusBarState(StatusBarState.KEYGUARD)
@@ -369,7 +310,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun shadeExpansionWhenInSplitShadeAndQsExpanded() =
        testComponent.runTest {
        testScope.runTest {
            val actual by collectLastValue(underTest.shadeExpansion)

            // WHEN split shade is enabled and QS is expanded
@@ -386,7 +327,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun shadeExpansionWhenNotInSplitShadeAndQsExpanded() =
        testComponent.runTest {
        testScope.runTest {
            val actual by collectLastValue(underTest.shadeExpansion)

            // WHEN split shade is not enabled and QS is expanded
@@ -402,7 +343,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun shadeExpansionWhenNotInSplitShadeAndQsCollapsed() =
        testComponent.runTest {
        testScope.runTest {
            val actual by collectLastValue(underTest.shadeExpansion)

            // WHEN split shade is not enabled and QS is expanded
@@ -416,7 +357,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun anyExpansion_shadeGreater() =
        testComponent.runTest() {
        testScope.runTest() {
            // WHEN shade is more expanded than QS
            shadeRepository.setLegacyShadeExpansion(.5f)
            shadeRepository.setQsExpansion(0f)
@@ -428,7 +369,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun anyExpansion_qsGreater() =
        testComponent.runTest() {
        testScope.runTest() {
            // WHEN qs is more expanded than shade
            shadeRepository.setLegacyShadeExpansion(0f)
            shadeRepository.setQsExpansion(.5f)
@@ -440,7 +381,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun userInteractingWithShade_shadeDraggedUpAndDown() =
        testComponent.runTest() {
        testScope.runTest() {
            val actual by collectLastValue(underTest.isUserInteractingWithShade)
            // GIVEN shade collapsed and not tracking input
            shadeRepository.setLegacyShadeExpansion(0f)
@@ -496,7 +437,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun userInteractingWithShade_shadeExpanded() =
        testComponent.runTest() {
        testScope.runTest() {
            val actual by collectLastValue(underTest.isUserInteractingWithShade)
            // GIVEN shade collapsed and not tracking input
            shadeRepository.setLegacyShadeExpansion(0f)
@@ -531,7 +472,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun userInteractingWithShade_shadePartiallyExpanded() =
        testComponent.runTest() {
        testScope.runTest() {
            val actual by collectLastValue(underTest.isUserInteractingWithShade)
            // GIVEN shade collapsed and not tracking input
            shadeRepository.setLegacyShadeExpansion(0f)
@@ -572,7 +513,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun userInteractingWithShade_shadeCollapsed() =
        testComponent.runTest() {
        testScope.runTest() {
            val actual by collectLastValue(underTest.isUserInteractingWithShade)
            // GIVEN shade expanded and not tracking input
            shadeRepository.setLegacyShadeExpansion(1f)
@@ -607,7 +548,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun userInteractingWithQs_qsDraggedUpAndDown() =
        testComponent.runTest() {
        testScope.runTest() {
            val actual by collectLastValue(underTest.isUserInteractingWithQs)
            // GIVEN qs collapsed and not tracking input
            shadeRepository.setQsExpansion(0f)
@@ -663,7 +604,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isShadeTouchable_isFalse_whenFrpIsActive() =
        testComponent.runTest {
        testScope.runTest {
            deviceProvisioningRepository.setFactoryResetProtectionActive(true)
            keyguardTransitionRepository.sendTransitionStep(
                TransitionStep(
@@ -677,7 +618,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isShadeTouchable_isFalse_whenDeviceAsleepAndNotPulsing() =
        testComponent.runTest {
        testScope.runTest {
            powerRepository.updateWakefulness(
                rawState = WakefulnessState.ASLEEP,
                lastWakeReason = WakeSleepReason.POWER_BUTTON,
@@ -704,7 +645,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isShadeTouchable_isTrue_whenDeviceAsleepAndPulsing() =
        testComponent.runTest {
        testScope.runTest {
            powerRepository.updateWakefulness(
                rawState = WakefulnessState.ASLEEP,
                lastWakeReason = WakeSleepReason.POWER_BUTTON,
@@ -731,7 +672,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isShadeTouchable_isFalse_whenStartingToSleepAndNotControlScreenOff() =
        testComponent.runTest {
        testScope.runTest {
            powerRepository.updateWakefulness(
                rawState = WakefulnessState.STARTING_TO_SLEEP,
                lastWakeReason = WakeSleepReason.POWER_BUTTON,
@@ -753,7 +694,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isShadeTouchable_isTrue_whenStartingToSleepAndControlScreenOff() =
        testComponent.runTest {
        testScope.runTest {
            powerRepository.updateWakefulness(
                rawState = WakefulnessState.STARTING_TO_SLEEP,
                lastWakeReason = WakeSleepReason.POWER_BUTTON,
@@ -775,7 +716,7 @@ class ShadeInteractorImplTest : SysuiTestCase() {

    @Test
    fun isShadeTouchable_isTrue_whenNotAsleep() =
        testComponent.runTest {
        testScope.runTest {
            powerRepository.updateWakefulness(
                rawState = WakefulnessState.AWAKE,
                lastWakeReason = WakeSleepReason.POWER_BUTTON,
+35 −98

File changed and moved.

Preview size limit exceeded, changes collapsed.

+42 −109

File changed and moved.

Preview size limit exceeded, changes collapsed.

+2 −2
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ constructor(
     * Returns a flow that uses scene transition progress to and from a scene that is pulled down
     * from the top of the screen to a 0-1 expansion amount float.
     */
    internal fun sceneBasedExpansion(sceneInteractor: SceneInteractor, sceneKey: SceneKey) =
    fun sceneBasedExpansion(sceneInteractor: SceneInteractor, sceneKey: SceneKey) =
        sceneInteractor.transitionState
            .flatMapLatest { state ->
                when (state) {
@@ -135,7 +135,7 @@ constructor(
     * Returns a flow that uses scene transition data to determine whether the user is interacting
     * with a scene that is pulled down from the top of the screen.
     */
    internal fun sceneBasedInteracting(sceneInteractor: SceneInteractor, sceneKey: SceneKey) =
    fun sceneBasedInteracting(sceneInteractor: SceneInteractor, sceneKey: SceneKey) =
        sceneInteractor.transitionState
            .map { state ->
                when (state) {
Loading