Loading packages/SystemUI/multivalentTests/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneContentViewModelTest.kt +37 −43 Original line number Diff line number Diff line Loading @@ -24,14 +24,16 @@ 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.authentication.shared.model.AuthenticationMethodModel.Pin import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository import com.android.systemui.coroutines.collectLastValue import com.android.systemui.deviceentry.domain.interactor.deviceEntryInteractor import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteractor import com.android.systemui.flags.EnableSceneContainer import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.lifecycle.activateIn Loading @@ -40,7 +42,6 @@ import com.android.systemui.media.controls.shared.model.MediaData import com.android.systemui.res.R import com.android.systemui.scene.domain.interactor.sceneInteractor import com.android.systemui.scene.shared.model.Scenes import com.android.systemui.shade.domain.interactor.disableDualShade import com.android.systemui.shade.domain.interactor.enableDualShade import com.android.systemui.shade.domain.interactor.enableSingleShade import com.android.systemui.shade.domain.interactor.enableSplitShade Loading @@ -54,8 +55,6 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.update import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -67,22 +66,19 @@ import org.junit.runner.RunWith class ShadeSceneContentViewModelTest : SysuiTestCase() { private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val testScope = kosmos.testScope private val underTest: ShadeSceneContentViewModel by lazy { kosmos.shadeSceneContentViewModel } @Before fun setUp() { underTest.activateIn(testScope) kosmos.disableDualShade() underTest.activateIn(kosmos.testScope) } @Test fun isEmptySpaceClickable_deviceUnlocked_false() = testScope.runTest { kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.runTest { enableSingleShade() fakeAuthenticationRepository.setAuthenticationMethod(Pin) setDeviceEntered(true) assertThat(underTest.isEmptySpaceClickable).isFalse() Loading @@ -90,21 +86,19 @@ class ShadeSceneContentViewModelTest : SysuiTestCase() { @Test fun isEmptySpaceClickable_deviceLockedSecurely_true() = testScope.runTest { kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.runTest { enableSingleShade() fakeAuthenticationRepository.setAuthenticationMethod(Pin) assertThat(underTest.isEmptySpaceClickable).isTrue() } @Test fun onEmptySpaceClicked_deviceLockedSecurely_switchesToLockscreen() = testScope.runTest { val currentScene by collectLastValue(kosmos.sceneInteractor.currentScene) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.runTest { enableSingleShade() val currentScene by collectLastValue(sceneInteractor.currentScene) fakeAuthenticationRepository.setAuthenticationMethod(Pin) underTest.onEmptySpaceClicked() Loading @@ -113,36 +107,38 @@ class ShadeSceneContentViewModelTest : SysuiTestCase() { @Test fun addAndRemoveMedia_mediaVisibilityIsUpdated() = testScope.runTest { kosmos.runTest { enableSingleShade() val userMedia = MediaData(active = true) assertThat(underTest.isMediaVisible).isFalse() kosmos.mediaFilterRepository.addCurrentUserMediaEntry(userMedia) mediaFilterRepository.addCurrentUserMediaEntry(userMedia) assertThat(underTest.isMediaVisible).isTrue() kosmos.mediaFilterRepository.removeCurrentUserMediaEntry(userMedia.instanceId) mediaFilterRepository.removeCurrentUserMediaEntry(userMedia.instanceId) assertThat(underTest.isMediaVisible).isFalse() } @Test fun shadeMode() = testScope.runTest { kosmos.enableSplitShade() kosmos.runTest { enableSplitShade() assertThat(underTest.shadeMode).isEqualTo(ShadeMode.Split) kosmos.enableSingleShade() enableSingleShade() assertThat(underTest.shadeMode).isEqualTo(ShadeMode.Single) kosmos.enableDualShade() enableDualShade() assertThat(underTest.shadeMode).isEqualTo(ShadeMode.Dual) } @Test fun unfoldTransitionProgress() = testScope.runTest { kosmos.runTest { enableSingleShade() val maxTranslation = prepareConfiguration() val translations by collectLastValue( Loading @@ -154,7 +150,7 @@ class ShadeSceneContentViewModelTest : SysuiTestCase() { } ) val unfoldProvider = kosmos.fakeUnfoldTransitionProgressProvider val unfoldProvider = fakeUnfoldTransitionProgressProvider unfoldProvider.onTransitionStarted() assertThat(translations?.start).isEqualTo(0f) assertThat(translations?.end).isEqualTo(-0f) Loading @@ -177,36 +173,34 @@ class ShadeSceneContentViewModelTest : SysuiTestCase() { @Test fun disable2QuickSettings_isQsEnabledIsFalse() = testScope.runTest { kosmos.runTest { assertThat(underTest.isQsEnabled).isTrue() kosmos.fakeDisableFlagsRepository.disableFlags.update { fakeDisableFlagsRepository.disableFlags.update { it.copy(disable2 = DISABLE2_QUICK_SETTINGS) } assertThat(underTest.isQsEnabled).isFalse() } private fun prepareConfiguration(): Int { private fun Kosmos.prepareConfiguration(): Int { val configuration = context.resources.configuration configuration.setLayoutDirection(Locale.US) kosmos.fakeConfigurationRepository.onConfigurationChange(configuration) fakeConfigurationRepository.onConfigurationChange(configuration) val maxTranslation = 10 kosmos.fakeConfigurationRepository.setDimensionPixelSize( fakeConfigurationRepository.setDimensionPixelSize( R.dimen.notification_side_paddings, maxTranslation, ) return maxTranslation } private fun TestScope.setDeviceEntered(isEntered: Boolean) { private fun Kosmos.setDeviceEntered(isEntered: Boolean) { if (isEntered) { // Unlock the device marking the device has entered. val isDeviceUnlocked by collectLastValue( kosmos.deviceUnlockedInteractor.deviceUnlockStatus.map { it.isUnlocked } ) kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( collectLastValue(deviceUnlockedInteractor.deviceUnlockStatus.map { it.isUnlocked }) fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( SuccessFingerprintAuthenticationStatus(0, true) ) assertThat(isDeviceUnlocked).isTrue() Loading @@ -215,9 +209,9 @@ class ShadeSceneContentViewModelTest : SysuiTestCase() { assertThat(kosmos.deviceEntryInteractor.isDeviceEntered.value).isEqualTo(isEntered) } private fun setScene(key: SceneKey) { kosmos.sceneInteractor.changeScene(key, "test") kosmos.sceneInteractor.setTransitionState(flowOf(ObservableTransitionState.Idle(key))) private fun Kosmos.setScene(key: SceneKey) { sceneInteractor.changeScene(key, "test") sceneInteractor.setTransitionState(flowOf(ObservableTransitionState.Idle(key))) } private data class Translations(val start: Float, val end: Float) Loading packages/SystemUI/multivalentTests/src/com/android/systemui/shade/ui/viewmodel/ShadeUserActionsViewModelTest.kt +50 −59 Original line number Diff line number Diff line Loading @@ -26,15 +26,18 @@ import com.android.compose.animation.scene.SwipeDirection import com.android.compose.animation.scene.UserActionResult 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.coroutines.collectValues import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.None import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Pin import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryRepository import com.android.systemui.deviceentry.domain.interactor.deviceEntryInteractor import com.android.systemui.flags.EnableSceneContainer import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository import com.android.systemui.keyguard.domain.interactor.keyguardEnabledInteractor import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.collectValues import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.lifecycle.activateIn Loading @@ -53,7 +56,6 @@ import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -65,27 +67,24 @@ import org.junit.runner.RunWith class ShadeUserActionsViewModelTest : SysuiTestCase() { private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val testScope = kosmos.testScope private val sceneInteractor by lazy { kosmos.sceneInteractor } private val qsSceneAdapter by lazy { kosmos.fakeQSSceneAdapter } private val underTest: ShadeUserActionsViewModel by lazy { kosmos.shadeUserActionsViewModel } @Before fun setUp() { kosmos.sceneContainerStartable.start() kosmos.disableDualShade() with(kosmos) { sceneContainerStartable.start() disableDualShade() underTest.activateIn(testScope) } } @Test fun upTransitionSceneKey_deviceLocked_lockScreen() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) val homeScene by collectLastValue(homeSceneFamilyResolver.resolvedScene) fakeAuthenticationRepository.setAuthenticationMethod(Pin) assertThat((actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene) .isEqualTo(SceneFamilies.Home) Loading @@ -94,12 +93,10 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_deviceUnlocked_gone() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) val homeScene by collectLastValue(homeSceneFamilyResolver.resolvedScene) fakeAuthenticationRepository.setAuthenticationMethod(Pin) setDeviceEntered(true) assertThat((actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene) Loading @@ -109,13 +106,11 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_keyguardDisabled_gone() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.keyguardEnabledInteractor.notifyKeyguardEnabled(false) fakeAuthenticationRepository.setAuthenticationMethod(Pin) keyguardEnabledInteractor.notifyKeyguardEnabled(false) assertThat((actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene) .isEqualTo(SceneFamilies.Home) Loading @@ -124,13 +119,11 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_authMethodSwipe_lockscreenNotDismissed_goesToLockscreen() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene) kosmos.fakeDeviceEntryRepository.setLockscreenEnabled(true) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.None ) fakeDeviceEntryRepository.setLockscreenEnabled(true) fakeAuthenticationRepository.setAuthenticationMethod(None) sceneInteractor.changeScene(Scenes.Lockscreen, "reason") assertThat((actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene) Loading @@ -140,13 +133,11 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_authMethodSwipe_lockscreenDismissed_goesToGone() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene) kosmos.fakeDeviceEntryRepository.setLockscreenEnabled(true) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.None ) fakeDeviceEntryRepository.setLockscreenEnabled(true) fakeAuthenticationRepository.setAuthenticationMethod(None) sceneInteractor.changeScene(Scenes.Gone, "reason") assertThat((actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene) Loading @@ -156,27 +147,27 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionKey_splitShadeEnabled_isGoneToSplitShade() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) kosmos.enableSplitShade() enableSplitShade() assertThat(actions?.get(Swipe.Up)?.transitionKey).isEqualTo(ToSplitShade) } @Test fun upTransitionKey_splitShadeDisable_isNull() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) kosmos.enableSingleShade() enableSingleShade() assertThat(actions?.get(Swipe.Up)?.transitionKey).isNull() } @Test fun downTransitionSceneKey_inSplitShade_null() = testScope.runTest { kosmos.enableSplitShade() kosmos.shadeStartable.start() kosmos.runTest { enableSplitShade() shadeStartable.start() val actions by collectLastValue(underTest.actions) assertThat((actions?.get(Swipe.Down) as? UserActionResult.ChangeScene)?.toScene) .isNull() Loading @@ -184,9 +175,9 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun downTransitionSceneKey_notSplitShade_quickSettings() = testScope.runTest { kosmos.enableSingleShade() kosmos.shadeStartable.start() kosmos.runTest { enableSingleShade() shadeStartable.start() val actions by collectLastValue(underTest.actions) assertThat((actions?.get(Swipe.Down) as? UserActionResult.ChangeScene)?.toScene) .isEqualTo(Scenes.QuickSettings) Loading @@ -194,10 +185,10 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_customizing_noTransition() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) qsSceneAdapter.setCustomizing(true) fakeQSSceneAdapter.setCustomizing(true) assertThat( actions!!.keys.filterIsInstance<Swipe>().filter { it.direction == SwipeDirection.Up Loading @@ -208,13 +199,13 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_backToCommunal() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val currentScene by collectLastValue(kosmos.sceneInteractor.currentScene) val currentScene by collectLastValue(sceneInteractor.currentScene) assertThat(currentScene).isEqualTo(Scenes.Lockscreen) kosmos.sceneInteractor.changeScene(Scenes.Communal, "") sceneInteractor.changeScene(Scenes.Communal, "") assertThat(currentScene).isEqualTo(Scenes.Communal) kosmos.sceneInteractor.changeScene(Scenes.Shade, "") sceneInteractor.changeScene(Scenes.Shade, "") assertThat(currentScene).isEqualTo(Scenes.Shade) assertThat(actions?.get(Swipe.Up)).isEqualTo(UserActionResult(Scenes.Communal)) Loading @@ -222,14 +213,14 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_neverGoesBackToShadeScene() = testScope.runTest { kosmos.runTest { val actions by collectValues(underTest.actions) val currentScene by collectLastValue(kosmos.sceneInteractor.currentScene) val currentScene by collectLastValue(sceneInteractor.currentScene) assertThat(currentScene).isEqualTo(Scenes.Lockscreen) kosmos.sceneInteractor.changeScene(Scenes.Shade, "") sceneInteractor.changeScene(Scenes.Shade, "") assertThat(currentScene).isEqualTo(Scenes.Shade) kosmos.sceneInteractor.changeScene(Scenes.QuickSettings, "") sceneInteractor.changeScene(Scenes.QuickSettings, "") assertThat(currentScene).isEqualTo(Scenes.QuickSettings) actions.forEachIndexed { index, map -> Loading @@ -241,18 +232,18 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { } } private fun setDeviceEntered(isEntered: Boolean) { private fun Kosmos.setDeviceEntered(isEntered: Boolean) { if (isEntered) { // Unlock the device marking the device has entered. kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( SuccessFingerprintAuthenticationStatus(0, true) ) } setScene(if (isEntered) Scenes.Gone else Scenes.Lockscreen) assertThat(kosmos.deviceEntryInteractor.isDeviceEntered.value).isEqualTo(isEntered) assertThat(deviceEntryInteractor.isDeviceEntered.value).isEqualTo(isEntered) } private fun setScene(key: SceneKey) { private fun Kosmos.setScene(key: SceneKey) { sceneInteractor.changeScene(key, "test") sceneInteractor.setTransitionState(flowOf(ObservableTransitionState.Idle(key))) } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/shade/ui/viewmodel/ShadeSceneContentViewModelTest.kt +37 −43 Original line number Diff line number Diff line Loading @@ -24,14 +24,16 @@ 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.authentication.shared.model.AuthenticationMethodModel.Pin import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository import com.android.systemui.coroutines.collectLastValue import com.android.systemui.deviceentry.domain.interactor.deviceEntryInteractor import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteractor import com.android.systemui.flags.EnableSceneContainer import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.lifecycle.activateIn Loading @@ -40,7 +42,6 @@ import com.android.systemui.media.controls.shared.model.MediaData import com.android.systemui.res.R import com.android.systemui.scene.domain.interactor.sceneInteractor import com.android.systemui.scene.shared.model.Scenes import com.android.systemui.shade.domain.interactor.disableDualShade import com.android.systemui.shade.domain.interactor.enableDualShade import com.android.systemui.shade.domain.interactor.enableSingleShade import com.android.systemui.shade.domain.interactor.enableSplitShade Loading @@ -54,8 +55,6 @@ import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.update import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -67,22 +66,19 @@ import org.junit.runner.RunWith class ShadeSceneContentViewModelTest : SysuiTestCase() { private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val testScope = kosmos.testScope private val underTest: ShadeSceneContentViewModel by lazy { kosmos.shadeSceneContentViewModel } @Before fun setUp() { underTest.activateIn(testScope) kosmos.disableDualShade() underTest.activateIn(kosmos.testScope) } @Test fun isEmptySpaceClickable_deviceUnlocked_false() = testScope.runTest { kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.runTest { enableSingleShade() fakeAuthenticationRepository.setAuthenticationMethod(Pin) setDeviceEntered(true) assertThat(underTest.isEmptySpaceClickable).isFalse() Loading @@ -90,21 +86,19 @@ class ShadeSceneContentViewModelTest : SysuiTestCase() { @Test fun isEmptySpaceClickable_deviceLockedSecurely_true() = testScope.runTest { kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.runTest { enableSingleShade() fakeAuthenticationRepository.setAuthenticationMethod(Pin) assertThat(underTest.isEmptySpaceClickable).isTrue() } @Test fun onEmptySpaceClicked_deviceLockedSecurely_switchesToLockscreen() = testScope.runTest { val currentScene by collectLastValue(kosmos.sceneInteractor.currentScene) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.runTest { enableSingleShade() val currentScene by collectLastValue(sceneInteractor.currentScene) fakeAuthenticationRepository.setAuthenticationMethod(Pin) underTest.onEmptySpaceClicked() Loading @@ -113,36 +107,38 @@ class ShadeSceneContentViewModelTest : SysuiTestCase() { @Test fun addAndRemoveMedia_mediaVisibilityIsUpdated() = testScope.runTest { kosmos.runTest { enableSingleShade() val userMedia = MediaData(active = true) assertThat(underTest.isMediaVisible).isFalse() kosmos.mediaFilterRepository.addCurrentUserMediaEntry(userMedia) mediaFilterRepository.addCurrentUserMediaEntry(userMedia) assertThat(underTest.isMediaVisible).isTrue() kosmos.mediaFilterRepository.removeCurrentUserMediaEntry(userMedia.instanceId) mediaFilterRepository.removeCurrentUserMediaEntry(userMedia.instanceId) assertThat(underTest.isMediaVisible).isFalse() } @Test fun shadeMode() = testScope.runTest { kosmos.enableSplitShade() kosmos.runTest { enableSplitShade() assertThat(underTest.shadeMode).isEqualTo(ShadeMode.Split) kosmos.enableSingleShade() enableSingleShade() assertThat(underTest.shadeMode).isEqualTo(ShadeMode.Single) kosmos.enableDualShade() enableDualShade() assertThat(underTest.shadeMode).isEqualTo(ShadeMode.Dual) } @Test fun unfoldTransitionProgress() = testScope.runTest { kosmos.runTest { enableSingleShade() val maxTranslation = prepareConfiguration() val translations by collectLastValue( Loading @@ -154,7 +150,7 @@ class ShadeSceneContentViewModelTest : SysuiTestCase() { } ) val unfoldProvider = kosmos.fakeUnfoldTransitionProgressProvider val unfoldProvider = fakeUnfoldTransitionProgressProvider unfoldProvider.onTransitionStarted() assertThat(translations?.start).isEqualTo(0f) assertThat(translations?.end).isEqualTo(-0f) Loading @@ -177,36 +173,34 @@ class ShadeSceneContentViewModelTest : SysuiTestCase() { @Test fun disable2QuickSettings_isQsEnabledIsFalse() = testScope.runTest { kosmos.runTest { assertThat(underTest.isQsEnabled).isTrue() kosmos.fakeDisableFlagsRepository.disableFlags.update { fakeDisableFlagsRepository.disableFlags.update { it.copy(disable2 = DISABLE2_QUICK_SETTINGS) } assertThat(underTest.isQsEnabled).isFalse() } private fun prepareConfiguration(): Int { private fun Kosmos.prepareConfiguration(): Int { val configuration = context.resources.configuration configuration.setLayoutDirection(Locale.US) kosmos.fakeConfigurationRepository.onConfigurationChange(configuration) fakeConfigurationRepository.onConfigurationChange(configuration) val maxTranslation = 10 kosmos.fakeConfigurationRepository.setDimensionPixelSize( fakeConfigurationRepository.setDimensionPixelSize( R.dimen.notification_side_paddings, maxTranslation, ) return maxTranslation } private fun TestScope.setDeviceEntered(isEntered: Boolean) { private fun Kosmos.setDeviceEntered(isEntered: Boolean) { if (isEntered) { // Unlock the device marking the device has entered. val isDeviceUnlocked by collectLastValue( kosmos.deviceUnlockedInteractor.deviceUnlockStatus.map { it.isUnlocked } ) kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( collectLastValue(deviceUnlockedInteractor.deviceUnlockStatus.map { it.isUnlocked }) fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( SuccessFingerprintAuthenticationStatus(0, true) ) assertThat(isDeviceUnlocked).isTrue() Loading @@ -215,9 +209,9 @@ class ShadeSceneContentViewModelTest : SysuiTestCase() { assertThat(kosmos.deviceEntryInteractor.isDeviceEntered.value).isEqualTo(isEntered) } private fun setScene(key: SceneKey) { kosmos.sceneInteractor.changeScene(key, "test") kosmos.sceneInteractor.setTransitionState(flowOf(ObservableTransitionState.Idle(key))) private fun Kosmos.setScene(key: SceneKey) { sceneInteractor.changeScene(key, "test") sceneInteractor.setTransitionState(flowOf(ObservableTransitionState.Idle(key))) } private data class Translations(val start: Float, val end: Float) Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/shade/ui/viewmodel/ShadeUserActionsViewModelTest.kt +50 −59 Original line number Diff line number Diff line Loading @@ -26,15 +26,18 @@ import com.android.compose.animation.scene.SwipeDirection import com.android.compose.animation.scene.UserActionResult 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.coroutines.collectValues import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.None import com.android.systemui.authentication.shared.model.AuthenticationMethodModel.Pin import com.android.systemui.deviceentry.data.repository.fakeDeviceEntryRepository import com.android.systemui.deviceentry.domain.interactor.deviceEntryInteractor import com.android.systemui.flags.EnableSceneContainer import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository import com.android.systemui.keyguard.domain.interactor.keyguardEnabledInteractor import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.collectValues import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.lifecycle.activateIn Loading @@ -53,7 +56,6 @@ import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith Loading @@ -65,27 +67,24 @@ import org.junit.runner.RunWith class ShadeUserActionsViewModelTest : SysuiTestCase() { private val kosmos = testKosmos().useUnconfinedTestDispatcher() private val testScope = kosmos.testScope private val sceneInteractor by lazy { kosmos.sceneInteractor } private val qsSceneAdapter by lazy { kosmos.fakeQSSceneAdapter } private val underTest: ShadeUserActionsViewModel by lazy { kosmos.shadeUserActionsViewModel } @Before fun setUp() { kosmos.sceneContainerStartable.start() kosmos.disableDualShade() with(kosmos) { sceneContainerStartable.start() disableDualShade() underTest.activateIn(testScope) } } @Test fun upTransitionSceneKey_deviceLocked_lockScreen() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) val homeScene by collectLastValue(homeSceneFamilyResolver.resolvedScene) fakeAuthenticationRepository.setAuthenticationMethod(Pin) assertThat((actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene) .isEqualTo(SceneFamilies.Home) Loading @@ -94,12 +93,10 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_deviceUnlocked_gone() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) val homeScene by collectLastValue(homeSceneFamilyResolver.resolvedScene) fakeAuthenticationRepository.setAuthenticationMethod(Pin) setDeviceEntered(true) assertThat((actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene) Loading @@ -109,13 +106,11 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_keyguardDisabled_gone() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.Pin ) kosmos.keyguardEnabledInteractor.notifyKeyguardEnabled(false) fakeAuthenticationRepository.setAuthenticationMethod(Pin) keyguardEnabledInteractor.notifyKeyguardEnabled(false) assertThat((actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene) .isEqualTo(SceneFamilies.Home) Loading @@ -124,13 +119,11 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_authMethodSwipe_lockscreenNotDismissed_goesToLockscreen() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene) kosmos.fakeDeviceEntryRepository.setLockscreenEnabled(true) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.None ) fakeDeviceEntryRepository.setLockscreenEnabled(true) fakeAuthenticationRepository.setAuthenticationMethod(None) sceneInteractor.changeScene(Scenes.Lockscreen, "reason") assertThat((actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene) Loading @@ -140,13 +133,11 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_authMethodSwipe_lockscreenDismissed_goesToGone() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val homeScene by collectLastValue(kosmos.homeSceneFamilyResolver.resolvedScene) kosmos.fakeDeviceEntryRepository.setLockscreenEnabled(true) kosmos.fakeAuthenticationRepository.setAuthenticationMethod( AuthenticationMethodModel.None ) fakeDeviceEntryRepository.setLockscreenEnabled(true) fakeAuthenticationRepository.setAuthenticationMethod(None) sceneInteractor.changeScene(Scenes.Gone, "reason") assertThat((actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene) Loading @@ -156,27 +147,27 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionKey_splitShadeEnabled_isGoneToSplitShade() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) kosmos.enableSplitShade() enableSplitShade() assertThat(actions?.get(Swipe.Up)?.transitionKey).isEqualTo(ToSplitShade) } @Test fun upTransitionKey_splitShadeDisable_isNull() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) kosmos.enableSingleShade() enableSingleShade() assertThat(actions?.get(Swipe.Up)?.transitionKey).isNull() } @Test fun downTransitionSceneKey_inSplitShade_null() = testScope.runTest { kosmos.enableSplitShade() kosmos.shadeStartable.start() kosmos.runTest { enableSplitShade() shadeStartable.start() val actions by collectLastValue(underTest.actions) assertThat((actions?.get(Swipe.Down) as? UserActionResult.ChangeScene)?.toScene) .isNull() Loading @@ -184,9 +175,9 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun downTransitionSceneKey_notSplitShade_quickSettings() = testScope.runTest { kosmos.enableSingleShade() kosmos.shadeStartable.start() kosmos.runTest { enableSingleShade() shadeStartable.start() val actions by collectLastValue(underTest.actions) assertThat((actions?.get(Swipe.Down) as? UserActionResult.ChangeScene)?.toScene) .isEqualTo(Scenes.QuickSettings) Loading @@ -194,10 +185,10 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_customizing_noTransition() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) qsSceneAdapter.setCustomizing(true) fakeQSSceneAdapter.setCustomizing(true) assertThat( actions!!.keys.filterIsInstance<Swipe>().filter { it.direction == SwipeDirection.Up Loading @@ -208,13 +199,13 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_backToCommunal() = testScope.runTest { kosmos.runTest { val actions by collectLastValue(underTest.actions) val currentScene by collectLastValue(kosmos.sceneInteractor.currentScene) val currentScene by collectLastValue(sceneInteractor.currentScene) assertThat(currentScene).isEqualTo(Scenes.Lockscreen) kosmos.sceneInteractor.changeScene(Scenes.Communal, "") sceneInteractor.changeScene(Scenes.Communal, "") assertThat(currentScene).isEqualTo(Scenes.Communal) kosmos.sceneInteractor.changeScene(Scenes.Shade, "") sceneInteractor.changeScene(Scenes.Shade, "") assertThat(currentScene).isEqualTo(Scenes.Shade) assertThat(actions?.get(Swipe.Up)).isEqualTo(UserActionResult(Scenes.Communal)) Loading @@ -222,14 +213,14 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { @Test fun upTransitionSceneKey_neverGoesBackToShadeScene() = testScope.runTest { kosmos.runTest { val actions by collectValues(underTest.actions) val currentScene by collectLastValue(kosmos.sceneInteractor.currentScene) val currentScene by collectLastValue(sceneInteractor.currentScene) assertThat(currentScene).isEqualTo(Scenes.Lockscreen) kosmos.sceneInteractor.changeScene(Scenes.Shade, "") sceneInteractor.changeScene(Scenes.Shade, "") assertThat(currentScene).isEqualTo(Scenes.Shade) kosmos.sceneInteractor.changeScene(Scenes.QuickSettings, "") sceneInteractor.changeScene(Scenes.QuickSettings, "") assertThat(currentScene).isEqualTo(Scenes.QuickSettings) actions.forEachIndexed { index, map -> Loading @@ -241,18 +232,18 @@ class ShadeUserActionsViewModelTest : SysuiTestCase() { } } private fun setDeviceEntered(isEntered: Boolean) { private fun Kosmos.setDeviceEntered(isEntered: Boolean) { if (isEntered) { // Unlock the device marking the device has entered. kosmos.fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( fakeDeviceEntryFingerprintAuthRepository.setAuthenticationStatus( SuccessFingerprintAuthenticationStatus(0, true) ) } setScene(if (isEntered) Scenes.Gone else Scenes.Lockscreen) assertThat(kosmos.deviceEntryInteractor.isDeviceEntered.value).isEqualTo(isEntered) assertThat(deviceEntryInteractor.isDeviceEntered.value).isEqualTo(isEntered) } private fun setScene(key: SceneKey) { private fun Kosmos.setScene(key: SceneKey) { sceneInteractor.changeScene(key, "test") sceneInteractor.setTransitionState(flowOf(ObservableTransitionState.Idle(key))) } Loading