diff options
| author | 2024-01-25 13:40:54 -0500 | |
|---|---|---|
| committer | 2024-01-26 14:25:47 +0000 | |
| commit | 08d21955bce995eafe94eb19060d7ad147c20e08 (patch) | |
| tree | b614e888a4e037c478b9b281ae9230962a51f74a | |
| parent | 9f2f3960f4490f306f282a2ce0e47678b63496ce (diff) | |
Migrate tests to Kosmos and deviceless
Bug: 307719099
Flag: NONE
Test: yes, these are tests
Change-Id: I1f2165e71a3ea8e12b5885e8fedcb42c59792a79
6 files changed, 169 insertions, 387 deletions
diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeAnimationInteractorSceneContainerImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeAnimationInteractorSceneContainerImplTest.kt index 6bbe900c8779..1ef07facf8d1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeAnimationInteractorSceneContainerImplTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeAnimationInteractorSceneContainerImplTest.kt @@ -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) diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImplTest.kt index 71a7420636cc..4e82feb3a2c6 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImplTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorImplTest.kt @@ -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, diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImplTest.kt index 6e6e4384b7b3..682c4ef0b8e7 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImplTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorLegacyImplTest.kt @@ -16,108 +16,45 @@ package com.android.systemui.shade.domain.interactor -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.StatusBarState -import com.android.systemui.power.data.repository.FakePowerRepository +import com.android.systemui.kosmos.testScope 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.statusbar.phone.DozeParameters -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.scene.domain.interactor.sceneInteractor +import com.android.systemui.shade.data.repository.fakeShadeRepository +import com.android.systemui.testKosmos +import com.android.systemui.user.data.repository.fakeUserRepository 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 ShadeInteractorLegacyImplTest : SysuiTestCase() { + val kosmos = testKosmos() + val testScope = kosmos.testScope + val configurationRepository = kosmos.fakeConfigurationRepository + val keyguardRepository = kosmos.fakeKeyguardRepository + val keyguardTransitionRepository = kosmos.fakeKeyguardTransitionRepository + val sceneInteractor = kosmos.sceneInteractor + val shadeRepository = kosmos.fakeShadeRepository + val userRepository = kosmos.fakeUserRepository - @SysUISingleton - @Component( - modules = - [ - SysUITestModule::class, - UserDomainLayerModule::class, - ] - ) - interface TestComponent : SysUITestComponent<ShadeInteractorLegacyImpl> { - - val configurationRepository: FakeConfigurationRepository - val keyguardRepository: FakeKeyguardRepository - val keyguardTransitionRepository: FakeKeyguardTransitionRepository - val powerRepository: FakePowerRepository - val sceneInteractor: SceneInteractor - val shadeRepository: FakeShadeRepository - val userRepository: FakeUserRepository - - @Component.Factory - interface Factory { - fun create( - @BindsInstance test: SysuiTestCase, - featureFlags: FakeFeatureFlagsClassicModule, - mocks: TestMocksModule, - ): TestComponent - } - } - - private val dozeParameters: DozeParameters = mock() - - private val testComponent: TestComponent = - DaggerShadeInteractorLegacyImplTest_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 underTest = kosmos.shadeInteractorLegacyImpl @Test fun fullShadeExpansionWhenShadeLocked() = - testComponent.runTest() { + testScope.runTest { val actual by collectLastValue(underTest.shadeExpansion) keyguardRepository.setStatusBarState(StatusBarState.SHADE_LOCKED) @@ -128,7 +65,7 @@ class ShadeInteractorLegacyImplTest : SysuiTestCase() { @Test fun fullShadeExpansionWhenStatusBarStateIsNotShadeLocked() = - testComponent.runTest() { + testScope.runTest { val actual by collectLastValue(underTest.shadeExpansion) keyguardRepository.setStatusBarState(StatusBarState.KEYGUARD) @@ -142,7 +79,7 @@ class ShadeInteractorLegacyImplTest : SysuiTestCase() { @Test fun shadeExpansionWhenInSplitShadeAndQsExpanded() = - testComponent.runTest() { + testScope.runTest { val actual by collectLastValue(underTest.shadeExpansion) // WHEN split shade is enabled and QS is expanded @@ -159,7 +96,7 @@ class ShadeInteractorLegacyImplTest : SysuiTestCase() { @Test fun shadeExpansionWhenNotInSplitShadeAndQsExpanded() = - testComponent.runTest() { + testScope.runTest { val actual by collectLastValue(underTest.shadeExpansion) // WHEN split shade is not enabled and QS is expanded @@ -175,7 +112,7 @@ class ShadeInteractorLegacyImplTest : SysuiTestCase() { @Test fun shadeExpansionWhenNotInSplitShadeAndQsCollapsed() = - testComponent.runTest() { + testScope.runTest { val actual by collectLastValue(underTest.shadeExpansion) // WHEN split shade is not enabled and QS is expanded @@ -189,7 +126,7 @@ class ShadeInteractorLegacyImplTest : 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) @@ -245,7 +182,7 @@ class ShadeInteractorLegacyImplTest : 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) @@ -280,7 +217,7 @@ class ShadeInteractorLegacyImplTest : 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) @@ -321,7 +258,7 @@ class ShadeInteractorLegacyImplTest : 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) @@ -356,7 +293,7 @@ class ShadeInteractorLegacyImplTest : 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) diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImplTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImplTest.kt index 310b86f908c5..bf136cdd817e 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImplTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImplTest.kt @@ -16,114 +16,48 @@ package com.android.systemui.shade.domain.interactor -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.keyguardTransitionRepository import com.android.systemui.keyguard.shared.model.StatusBarState -import com.android.systemui.power.data.repository.FakePowerRepository +import com.android.systemui.kosmos.testScope 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.scene.domain.interactor.sceneInteractor import com.android.systemui.scene.shared.model.ObservableTransitionState import com.android.systemui.scene.shared.model.SceneKey -import com.android.systemui.shade.data.repository.FakeShadeRepository -import com.android.systemui.statusbar.phone.DozeParameters -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.testKosmos +import com.android.systemui.user.data.repository.userRepository 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.runBlocking -import org.junit.Before -import org.junit.Ignore +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 ShadeInteractorSceneContainerImplTest : SysuiTestCase() { - @SysUISingleton - @Component( - modules = - [ - SysUITestModule::class, - UserDomainLayerModule::class, - ] - ) - interface TestComponent : SysUITestComponent<ShadeInteractorSceneContainerImpl> { - - val configurationRepository: FakeConfigurationRepository - val keyguardRepository: FakeKeyguardRepository - val keyguardTransitionRepository: FakeKeyguardTransitionRepository - val powerRepository: FakePowerRepository - val sceneInteractor: SceneInteractor - val shadeRepository: FakeShadeRepository - val userRepository: FakeUserRepository - - @Component.Factory - interface Factory { - fun create( - @BindsInstance test: SysuiTestCase, - featureFlags: FakeFeatureFlagsClassicModule, - mocks: TestMocksModule, - ): TestComponent - } - } - - private val dozeParameters: DozeParameters = mock() - - private val testComponent: TestComponent = - DaggerShadeInteractorSceneContainerImplTest_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 testComponent = kosmos.testScope + val configurationRepository = kosmos.fakeConfigurationRepository + val keyguardRepository = kosmos.fakeKeyguardRepository + val keyguardTransitionRepository = kosmos.keyguardTransitionRepository + val sceneInteractor = kosmos.sceneInteractor + val userRepository = kosmos.userRepository + + val underTest = kosmos.shadeInteractorSceneContainerImpl - @Ignore("b/309825977") @Test fun qsExpansionWhenInSplitShadeAndQsExpanded() = - testComponent.runTest() { + testComponent.runTest { val actual by collectLastValue(underTest.qsExpansion) // WHEN split shade is enabled and QS is expanded @@ -148,10 +82,9 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { Truth.assertThat(actual).isEqualTo(.3f) } - @Ignore("b/309825977") @Test fun qsExpansionWhenNotInSplitShadeAndQsExpanded() = - testComponent.runTest() { + testComponent.runTest { val actual by collectLastValue(underTest.qsExpansion) // WHEN split shade is not enabled and QS is expanded @@ -179,7 +112,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun qsFullscreen_falseWhenTransitioning() = - testComponent.runTest() { + testComponent.runTest { val actual by collectLastValue(underTest.isQsFullscreen) // WHEN scene transition active @@ -203,7 +136,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun qsFullscreen_falseWhenIdleNotQS() = - testComponent.runTest() { + testComponent.runTest { val actual by collectLastValue(underTest.isQsFullscreen) // WHEN Idle but not on QuickSettings scene @@ -221,7 +154,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun qsFullscreen_trueWhenIdleQS() = - testComponent.runTest() { + testComponent.runTest { val actual by collectLastValue(underTest.isQsFullscreen) // WHEN Idle on QuickSettings scene @@ -239,7 +172,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun lockscreenShadeExpansion_idle_onScene() = - testComponent.runTest() { + testComponent.runTest { // GIVEN an expansion flow based on transitions to and from a scene val key = SceneKey.Shade val expansion = underTest.sceneBasedExpansion(sceneInteractor, key) @@ -256,7 +189,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun lockscreenShadeExpansion_idle_onDifferentScene() = - testComponent.runTest() { + testComponent.runTest { // GIVEN an expansion flow based on transitions to and from a scene val expansion = underTest.sceneBasedExpansion(sceneInteractor, SceneKey.Shade) val expansionAmount by collectLastValue(expansion) @@ -274,7 +207,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun lockscreenShadeExpansion_transitioning_toScene() = - testComponent.runTest() { + testComponent.runTest { // GIVEN an expansion flow based on transitions to and from a scene val key = SceneKey.QuickSettings val expansion = underTest.sceneBasedExpansion(sceneInteractor, key) @@ -312,7 +245,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun lockscreenShadeExpansion_transitioning_fromScene() = - testComponent.runTest() { + testComponent.runTest { // GIVEN an expansion flow based on transitions to and from a scene val key = SceneKey.QuickSettings val expansion = underTest.sceneBasedExpansion(sceneInteractor, key) @@ -349,7 +282,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { } fun isQsBypassingShade_goneToQs() = - testComponent.runTest() { + testComponent.runTest { val actual by collectLastValue(underTest.isQsBypassingShade) // WHEN transitioning from QS directly to Gone @@ -372,7 +305,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { } fun isQsBypassingShade_shadeToQs() = - testComponent.runTest() { + testComponent.runTest { val actual by collectLastValue(underTest.isQsBypassingShade) // WHEN transitioning from QS to Shade @@ -396,7 +329,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun lockscreenShadeExpansion_transitioning_toAndFromDifferentScenes() = - testComponent.runTest() { + testComponent.runTest { // GIVEN an expansion flow based on transitions to and from a scene val expansion = underTest.sceneBasedExpansion(sceneInteractor, SceneKey.QuickSettings) val expansionAmount by collectLastValue(expansion) @@ -433,7 +366,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun userInteracting_idle() = - testComponent.runTest() { + testComponent.runTest { // GIVEN an interacting flow based on transitions to and from a scene val key = SceneKey.Shade val interactingFlow = underTest.sceneBasedInteracting(sceneInteractor, key) @@ -450,7 +383,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun userInteracting_transitioning_toScene_programmatic() = - testComponent.runTest() { + testComponent.runTest { // GIVEN an interacting flow based on transitions to and from a scene val key = SceneKey.QuickSettings val interactingFlow = underTest.sceneBasedInteracting(sceneInteractor, key) @@ -488,7 +421,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun userInteracting_transitioning_toScene_userInputDriven() = - testComponent.runTest() { + testComponent.runTest { // GIVEN an interacting flow based on transitions to and from a scene val key = SceneKey.QuickSettings val interactingFlow = underTest.sceneBasedInteracting(sceneInteractor, key) @@ -526,7 +459,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun userInteracting_transitioning_fromScene_programmatic() = - testComponent.runTest() { + testComponent.runTest { // GIVEN an interacting flow based on transitions to and from a scene val key = SceneKey.QuickSettings val interactingFlow = underTest.sceneBasedInteracting(sceneInteractor, key) @@ -564,7 +497,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun userInteracting_transitioning_fromScene_userInputDriven() = - testComponent.runTest() { + testComponent.runTest { // GIVEN an interacting flow based on transitions to and from a scene val key = SceneKey.QuickSettings val interactingFlow = underTest.sceneBasedInteracting(sceneInteractor, key) @@ -602,7 +535,7 @@ class ShadeInteractorSceneContainerImplTest : SysuiTestCase() { @Test fun userInteracting_transitioning_toAndFromDifferentScenes() = - testComponent.runTest() { + testComponent.runTest { // GIVEN an interacting flow based on transitions to and from a scene val interactingFlow = underTest.sceneBasedInteracting(sceneInteractor, SceneKey.Shade) val interacting by collectLastValue(interactingFlow) diff --git a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImpl.kt b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImpl.kt index 3fd070c7146e..08f2c402f9e9 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/domain/interactor/ShadeInteractorSceneContainerImpl.kt @@ -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) { diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/domain/interactor/ShadeAnimationInteractorKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/domain/interactor/ShadeAnimationInteractorKosmos.kt index 57b272f10c67..d2dd200faa07 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/shade/domain/interactor/ShadeAnimationInteractorKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/shade/domain/interactor/ShadeAnimationInteractorKosmos.kt @@ -17,7 +17,12 @@ package com.android.systemui.shade.domain.interactor import com.android.systemui.kosmos.Kosmos +import com.android.systemui.scene.domain.interactor.sceneInteractor import com.android.systemui.shade.data.repository.shadeAnimationRepository var Kosmos.shadeAnimationInteractor: ShadeAnimationInteractor by Kosmos.Fixture { ShadeAnimationInteractorEmptyImpl(shadeAnimationRepository) } +var Kosmos.shadeAnimationInteractorSceneContainerImpl: ShadeAnimationInteractorSceneContainerImpl by + Kosmos.Fixture { + ShadeAnimationInteractorSceneContainerImpl(shadeAnimationRepository, sceneInteractor) + } |