Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationListViewModelTest.kt +103 −69 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.systemui.statusbar.notification.stack.ui.viewmodel import android.platform.test.flag.junit.FlagsParameterization import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.flags.DisableSceneContainer import com.android.systemui.flags.EnableSceneContainer import com.android.systemui.flags.Flags Loading @@ -27,12 +26,16 @@ import com.android.systemui.flags.andSceneContainer import com.android.systemui.flags.fakeFeatureFlagsClassic import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository import com.android.systemui.keyguard.shared.model.StatusBarState import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runCurrent import com.android.systemui.kosmos.runTest import com.android.systemui.power.data.repository.fakePowerRepository import com.android.systemui.power.shared.model.WakefulnessState import com.android.systemui.scene.shared.flag.SceneContainerFlag import com.android.systemui.shade.domain.interactor.enableDualShade import com.android.systemui.shade.domain.interactor.enableSingleShade import com.android.systemui.shade.domain.interactor.enableSplitShade import com.android.systemui.shade.shadeTestUtil import com.android.systemui.statusbar.data.repository.fakeRemoteInputRepository import com.android.systemui.statusbar.notification.data.repository.FakeHeadsUpRowRepository Loading @@ -45,35 +48,21 @@ import com.android.systemui.testKosmos import com.android.systemui.util.ui.isAnimating import com.android.systemui.util.ui.value import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.map import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import platform.test.runner.parameterized.ParameterizedAndroidJunit4 import platform.test.runner.parameterized.Parameters @OptIn(ExperimentalCoroutinesApi::class) @SmallTest @RunWith(ParameterizedAndroidJunit4::class) class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCase() { private val kosmos = testKosmos().apply { fakeFeatureFlagsClassic.apply { set(Flags.FULL_SCREEN_USER_SWITCHER, false) } } private val testScope = kosmos.testScope private val activeNotificationListRepository = kosmos.activeNotificationListRepository private val fakeKeyguardRepository = kosmos.fakeKeyguardRepository private val fakePowerRepository = kosmos.fakePowerRepository private val fakeRemoteInputRepository = kosmos.fakeRemoteInputRepository private val fakeUserSetupRepository = kosmos.fakeUserSetupRepository private val headsUpRepository = kosmos.headsUpNotificationRepository private val shadeTestUtil by lazy { kosmos.shadeTestUtil } private lateinit var underTest: NotificationListViewModel Loading @@ -99,23 +88,23 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun isImportantForAccessibility_falseWhenNoNotifs() = testScope.runTest { val important by collectLastValue(underTest.isImportantForAccessibility) kosmos.runTest { val isImportant by collectLastValue(underTest.isImportantForAccessibility) // WHEN on lockscreen fakeKeyguardRepository.setStatusBarState(StatusBarState.KEYGUARD) // AND has no notifs activeNotificationListRepository.setActiveNotifs(count = 0) testScope.runCurrent() runCurrent() // THEN not important assertThat(important).isFalse() assertThat(isImportant).isFalse() } @Test fun isImportantForAccessibility_trueWhenNotifs() = testScope.runTest { val important by collectLastValue(underTest.isImportantForAccessibility) kosmos.runTest { val isImportant by collectLastValue(underTest.isImportantForAccessibility) // WHEN on lockscreen fakeKeyguardRepository.setStatusBarState(StatusBarState.KEYGUARD) Loading @@ -124,13 +113,13 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas runCurrent() // THEN is important assertThat(important).isTrue() assertThat(isImportant).isTrue() } @Test fun isImportantForAccessibility_trueWhenNotKeyguard() = testScope.runTest { val important by collectLastValue(underTest.isImportantForAccessibility) kosmos.runTest { val isImportant by collectLastValue(underTest.isImportantForAccessibility) // WHEN not on lockscreen fakeKeyguardRepository.setStatusBarState(StatusBarState.SHADE) Loading @@ -139,14 +128,14 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas runCurrent() // THEN is still important assertThat(important).isTrue() assertThat(isImportant).isTrue() } // NOTE: The empty shade view and the footer view should be mutually exclusive. @Test fun shouldShowEmptyShadeView_trueWhenNoNotifs() = testScope.runTest { kosmos.runTest { val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) val shouldIncludeFooterView by collectFooterViewVisibility() Loading @@ -162,7 +151,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_falseWhenNotifs() = testScope.runTest { kosmos.runTest { val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) Loading @@ -176,7 +165,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_falseWhenQsExpandedDefault() = testScope.runTest { kosmos.runTest { val shouldShow by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) // WHEN has no notifs Loading @@ -191,7 +180,9 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_trueWhenQsExpandedInSplitShade() = testScope.runTest { kosmos.runTest { enableSplitShade() runCurrent() val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) val shouldIncludeFooterView by collectFooterViewVisibility() Loading @@ -202,7 +193,6 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas shadeTestUtil.setQsExpansion(1f) // AND split shade is enabled shadeTestUtil.setShadeExpansion(1f) shadeTestUtil.setSplitShade(true) runCurrent() // THEN empty shade is visible Loading @@ -212,7 +202,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_notAnimatingWhenQsExpandedOnKeyguard() = testScope.runTest { kosmos.runTest { val shouldShow by collectLastValue(underTest.shouldShowEmptyShadeView) // WHEN has no notifs Loading @@ -230,7 +220,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_trueWhenLockedShade() = testScope.runTest { kosmos.runTest { val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) val shouldIncludeFooterView by collectFooterViewVisibility() Loading @@ -248,7 +238,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_falseWhenKeyguard() = testScope.runTest { kosmos.runTest { val shouldShow by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) // WHEN has no notifs Loading @@ -263,7 +253,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_falseWhenStartingToSleep() = testScope.runTest { kosmos.runTest { val shouldShow by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) // WHEN has no notifs Loading @@ -280,7 +270,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_trueWhenShade() = testScope.runTest { kosmos.runTest { val shouldIncludeFooterView by collectFooterViewVisibility() val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) Loading @@ -299,7 +289,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_trueWhenLockedShade() = testScope.runTest { kosmos.runTest { val shouldIncludeFooterView by collectFooterViewVisibility() val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) Loading @@ -318,7 +308,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_falseWhenKeyguard() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -333,7 +323,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_falseWhenUserNotSetUp() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -351,7 +341,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_falseWhenStartingToSleep() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -369,7 +359,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_falseWhenQsExpandedDefault() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -388,7 +378,9 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_trueWhenQsExpandedSplitShade() = testScope.runTest { kosmos.runTest { enableSplitShade() runCurrent() val shouldIncludeFooterView by collectFooterViewVisibility() val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) Loading @@ -400,8 +392,6 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas // AND shade is open fakeKeyguardRepository.setStatusBarState(StatusBarState.SHADE) shadeTestUtil.setShadeExpansion(1f) // AND split shade is enabled shadeTestUtil.setSplitShade(true) runCurrent() // THEN footer is visible Loading @@ -411,7 +401,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_falseWhenRemoteInputActive() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -429,7 +419,9 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_animatesWhenShade() = testScope.runTest { kosmos.runTest { enableSingleShade() runCurrent() val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -443,9 +435,49 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas assertThat(shouldInclude?.isAnimating).isTrue() } @Test @EnableSceneContainer fun shouldShowFooterView_dualShadeWithNotifs_animatesWhenShade() = kosmos.runTest { enableDualShade() runCurrent() val shouldShow by collectLastValue(underTest.shouldShowFooterView) // WHEN has notifs activeNotificationListRepository.setActiveNotifs(count = 2) // AND shade is open and fully expanded fakeKeyguardRepository.setStatusBarState(StatusBarState.SHADE) shadeTestUtil.setShadeExpansion(1f) runCurrent() // THEN footer visibility animates in assertThat(shouldShow?.isAnimating).isTrue() assertThat(shouldShow?.value).isTrue() } @Test @EnableSceneContainer fun shouldShowFooterView_dualShadeWithoutNotifs_animatesWhenShade() = kosmos.runTest { enableDualShade() runCurrent() val shouldShow by collectLastValue(underTest.shouldShowFooterView) // WHEN has no notifs activeNotificationListRepository.setActiveNotifs(count = 0) // AND shade is open and fully expanded fakeKeyguardRepository.setStatusBarState(StatusBarState.SHADE) shadeTestUtil.setShadeExpansion(1f) runCurrent() // THEN footer visibility animates in assertThat(shouldShow?.isAnimating).isTrue() assertThat(shouldShow?.value).isTrue() } @Test fun shouldIncludeFooterView_notAnimatingOnKeyguard() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -462,7 +494,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun shouldShowFooterView_falseWhenShadeIsClosed() = testScope.runTest { kosmos.runTest { val shouldShow by collectLastValue(underTest.shouldShowFooterView) // WHEN shade is closed Loading @@ -477,8 +509,8 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun shouldShowFooterView_dualShade_trueWhenShadeIsExpanded() = testScope.runTest { kosmos.enableDualShade() kosmos.runTest { enableDualShade() runCurrent() val shouldShow by collectLastValue(underTest.shouldShowFooterView) Loading @@ -495,8 +527,10 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun shouldShowFooterView_singleShade_falseWhenNoNotifs() = testScope.runTest { kosmos.enableSingleShade() kosmos.runTest { enableSingleShade() runCurrent() val shouldShow by collectLastValue(underTest.shouldShowFooterView) // WHEN shade is open, has no notifs Loading @@ -512,8 +546,8 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun shouldShowFooterView_dualShade_trueWhenNoNotifs() = testScope.runTest { kosmos.enableDualShade() kosmos.runTest { enableDualShade() runCurrent() val shouldShow by collectLastValue(underTest.shouldShowFooterView) Loading @@ -531,7 +565,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @DisableSceneContainer fun shouldHideFooterView_trueWhenShadeIsClosed() = testScope.runTest { kosmos.runTest { val shouldHide by collectLastValue(underTest.shouldHideFooterView) // WHEN shade is closed Loading @@ -546,7 +580,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @DisableSceneContainer fun shouldHideFooterView_falseWhenShadeIsOpen() = testScope.runTest { kosmos.runTest { val shouldHide by collectLastValue(underTest.shouldHideFooterView) // WHEN shade is open Loading @@ -561,7 +595,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @DisableSceneContainer fun shouldHideFooterView_falseWhenQSPartiallyOpen() = testScope.runTest { kosmos.runTest { val shouldHide by collectLastValue(underTest.shouldHideFooterView) // WHEN QS partially open Loading @@ -577,7 +611,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun pinnedHeadsUpRows_filtersForPinnedItems() = testScope.runTest { kosmos.runTest { val pinnedHeadsUpRows by collectLastValue(underTest.pinnedHeadsUpRowKeys) // WHEN there are no pinned rows Loading @@ -587,7 +621,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas FakeHeadsUpRowRepository(key = "1"), FakeHeadsUpRowRepository(key = "2"), ) headsUpRepository.setNotifications(rows) headsUpNotificationRepository.setNotifications(rows) runCurrent() // THEN the list is empty Loading Loading @@ -618,10 +652,10 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun hasPinnedHeadsUpRows_true() = testScope.runTest { kosmos.runTest { val hasPinnedHeadsUpRow by collectLastValue(underTest.hasPinnedHeadsUpRow) headsUpRepository.setNotifications( headsUpNotificationRepository.setNotifications( FakeHeadsUpRowRepository(key = "0", isPinned = true), FakeHeadsUpRowRepository(key = "1"), ) Loading @@ -633,10 +667,10 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun hasPinnedHeadsUpRows_false() = testScope.runTest { kosmos.runTest { val hasPinnedHeadsUpRow by collectLastValue(underTest.hasPinnedHeadsUpRow) headsUpRepository.setNotifications( headsUpNotificationRepository.setNotifications( FakeHeadsUpRowRepository(key = "0"), FakeHeadsUpRowRepository(key = "1"), ) Loading @@ -648,10 +682,10 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun topHeadsUpRow_emptyList_null() = testScope.runTest { kosmos.runTest { val topHeadsUpRow by collectLastValue(underTest.topHeadsUpRow) headsUpRepository.setNotifications(emptyList()) headsUpNotificationRepository.setNotifications(emptyList()) runCurrent() assertThat(topHeadsUpRow).isNull() Loading @@ -660,7 +694,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun headsUpAnimationsEnabled_true() = testScope.runTest { kosmos.runTest { val animationsEnabled by collectLastValue(underTest.headsUpAnimationsEnabled) shadeTestUtil.setQsExpansion(0.0f) Loading @@ -673,7 +707,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun headsUpAnimationsEnabled_keyguardShowing_true() = testScope.runTest { kosmos.runTest { val animationsEnabled by collectLastValue(underTest.headsUpAnimationsEnabled) shadeTestUtil.setQsExpansion(0.0f) Loading @@ -683,7 +717,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas assertThat(animationsEnabled).isTrue() } private fun TestScope.collectFooterViewVisibility() = private fun Kosmos.collectFooterViewVisibility() = collectLastValue( if (SceneContainerFlag.isEnabled) underTest.shouldShowFooterView else underTest.shouldIncludeFooterView Loading packages/SystemUI/tests/utils/src/com/android/systemui/shade/ShadeTestUtil.kt +7 −5 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.systemui.shade.data.repository.FakeShadeRepository import com.android.systemui.shade.data.repository.ShadeRepository import com.android.systemui.shade.domain.interactor.ShadeInteractor import com.android.systemui.shade.domain.interactor.ShadeModeInteractor import com.android.systemui.shade.shared.model.ShadeMode import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flowOf Loading Loading @@ -227,11 +228,12 @@ class ShadeTestUtilSceneImpl( get() = if (shadeModeInteractor.isDualShade) Overlays.NotificationsShade else Scenes.Shade private val quickSettingsShade: ContentKey get() = if (shadeModeInteractor.isDualShade) { Overlays.QuickSettingsShade } else { Scenes.QuickSettings get() { return when (shadeModeInteractor.shadeMode.value) { is ShadeMode.Dual -> Overlays.QuickSettingsShade is ShadeMode.Single -> Scenes.QuickSettings is ShadeMode.Split -> Scenes.Shade } } override fun setShadeAndQsExpansion(shadeExpansion: Float, qsExpansion: Float) { Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/stack/ui/viewmodel/NotificationListViewModelTest.kt +103 −69 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package com.android.systemui.statusbar.notification.stack.ui.viewmodel import android.platform.test.flag.junit.FlagsParameterization import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.flags.DisableSceneContainer import com.android.systemui.flags.EnableSceneContainer import com.android.systemui.flags.Flags Loading @@ -27,12 +26,16 @@ import com.android.systemui.flags.andSceneContainer import com.android.systemui.flags.fakeFeatureFlagsClassic import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository import com.android.systemui.keyguard.shared.model.StatusBarState import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runCurrent import com.android.systemui.kosmos.runTest import com.android.systemui.power.data.repository.fakePowerRepository import com.android.systemui.power.shared.model.WakefulnessState import com.android.systemui.scene.shared.flag.SceneContainerFlag import com.android.systemui.shade.domain.interactor.enableDualShade import com.android.systemui.shade.domain.interactor.enableSingleShade import com.android.systemui.shade.domain.interactor.enableSplitShade import com.android.systemui.shade.shadeTestUtil import com.android.systemui.statusbar.data.repository.fakeRemoteInputRepository import com.android.systemui.statusbar.notification.data.repository.FakeHeadsUpRowRepository Loading @@ -45,35 +48,21 @@ import com.android.systemui.testKosmos import com.android.systemui.util.ui.isAnimating import com.android.systemui.util.ui.value import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.map import kotlinx.coroutines.test.TestScope import kotlinx.coroutines.test.runCurrent import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import platform.test.runner.parameterized.ParameterizedAndroidJunit4 import platform.test.runner.parameterized.Parameters @OptIn(ExperimentalCoroutinesApi::class) @SmallTest @RunWith(ParameterizedAndroidJunit4::class) class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCase() { private val kosmos = testKosmos().apply { fakeFeatureFlagsClassic.apply { set(Flags.FULL_SCREEN_USER_SWITCHER, false) } } private val testScope = kosmos.testScope private val activeNotificationListRepository = kosmos.activeNotificationListRepository private val fakeKeyguardRepository = kosmos.fakeKeyguardRepository private val fakePowerRepository = kosmos.fakePowerRepository private val fakeRemoteInputRepository = kosmos.fakeRemoteInputRepository private val fakeUserSetupRepository = kosmos.fakeUserSetupRepository private val headsUpRepository = kosmos.headsUpNotificationRepository private val shadeTestUtil by lazy { kosmos.shadeTestUtil } private lateinit var underTest: NotificationListViewModel Loading @@ -99,23 +88,23 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun isImportantForAccessibility_falseWhenNoNotifs() = testScope.runTest { val important by collectLastValue(underTest.isImportantForAccessibility) kosmos.runTest { val isImportant by collectLastValue(underTest.isImportantForAccessibility) // WHEN on lockscreen fakeKeyguardRepository.setStatusBarState(StatusBarState.KEYGUARD) // AND has no notifs activeNotificationListRepository.setActiveNotifs(count = 0) testScope.runCurrent() runCurrent() // THEN not important assertThat(important).isFalse() assertThat(isImportant).isFalse() } @Test fun isImportantForAccessibility_trueWhenNotifs() = testScope.runTest { val important by collectLastValue(underTest.isImportantForAccessibility) kosmos.runTest { val isImportant by collectLastValue(underTest.isImportantForAccessibility) // WHEN on lockscreen fakeKeyguardRepository.setStatusBarState(StatusBarState.KEYGUARD) Loading @@ -124,13 +113,13 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas runCurrent() // THEN is important assertThat(important).isTrue() assertThat(isImportant).isTrue() } @Test fun isImportantForAccessibility_trueWhenNotKeyguard() = testScope.runTest { val important by collectLastValue(underTest.isImportantForAccessibility) kosmos.runTest { val isImportant by collectLastValue(underTest.isImportantForAccessibility) // WHEN not on lockscreen fakeKeyguardRepository.setStatusBarState(StatusBarState.SHADE) Loading @@ -139,14 +128,14 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas runCurrent() // THEN is still important assertThat(important).isTrue() assertThat(isImportant).isTrue() } // NOTE: The empty shade view and the footer view should be mutually exclusive. @Test fun shouldShowEmptyShadeView_trueWhenNoNotifs() = testScope.runTest { kosmos.runTest { val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) val shouldIncludeFooterView by collectFooterViewVisibility() Loading @@ -162,7 +151,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_falseWhenNotifs() = testScope.runTest { kosmos.runTest { val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) Loading @@ -176,7 +165,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_falseWhenQsExpandedDefault() = testScope.runTest { kosmos.runTest { val shouldShow by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) // WHEN has no notifs Loading @@ -191,7 +180,9 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_trueWhenQsExpandedInSplitShade() = testScope.runTest { kosmos.runTest { enableSplitShade() runCurrent() val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) val shouldIncludeFooterView by collectFooterViewVisibility() Loading @@ -202,7 +193,6 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas shadeTestUtil.setQsExpansion(1f) // AND split shade is enabled shadeTestUtil.setShadeExpansion(1f) shadeTestUtil.setSplitShade(true) runCurrent() // THEN empty shade is visible Loading @@ -212,7 +202,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_notAnimatingWhenQsExpandedOnKeyguard() = testScope.runTest { kosmos.runTest { val shouldShow by collectLastValue(underTest.shouldShowEmptyShadeView) // WHEN has no notifs Loading @@ -230,7 +220,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_trueWhenLockedShade() = testScope.runTest { kosmos.runTest { val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) val shouldIncludeFooterView by collectFooterViewVisibility() Loading @@ -248,7 +238,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_falseWhenKeyguard() = testScope.runTest { kosmos.runTest { val shouldShow by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) // WHEN has no notifs Loading @@ -263,7 +253,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldShowEmptyShadeView_falseWhenStartingToSleep() = testScope.runTest { kosmos.runTest { val shouldShow by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) // WHEN has no notifs Loading @@ -280,7 +270,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_trueWhenShade() = testScope.runTest { kosmos.runTest { val shouldIncludeFooterView by collectFooterViewVisibility() val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) Loading @@ -299,7 +289,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_trueWhenLockedShade() = testScope.runTest { kosmos.runTest { val shouldIncludeFooterView by collectFooterViewVisibility() val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) Loading @@ -318,7 +308,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_falseWhenKeyguard() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -333,7 +323,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_falseWhenUserNotSetUp() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -351,7 +341,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_falseWhenStartingToSleep() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -369,7 +359,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_falseWhenQsExpandedDefault() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -388,7 +378,9 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_trueWhenQsExpandedSplitShade() = testScope.runTest { kosmos.runTest { enableSplitShade() runCurrent() val shouldIncludeFooterView by collectFooterViewVisibility() val shouldShowEmptyShadeView by collectLastValue(underTest.shouldShowEmptyShadeView.map { it.value }) Loading @@ -400,8 +392,6 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas // AND shade is open fakeKeyguardRepository.setStatusBarState(StatusBarState.SHADE) shadeTestUtil.setShadeExpansion(1f) // AND split shade is enabled shadeTestUtil.setSplitShade(true) runCurrent() // THEN footer is visible Loading @@ -411,7 +401,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_falseWhenRemoteInputActive() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -429,7 +419,9 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test fun shouldIncludeFooterView_animatesWhenShade() = testScope.runTest { kosmos.runTest { enableSingleShade() runCurrent() val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -443,9 +435,49 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas assertThat(shouldInclude?.isAnimating).isTrue() } @Test @EnableSceneContainer fun shouldShowFooterView_dualShadeWithNotifs_animatesWhenShade() = kosmos.runTest { enableDualShade() runCurrent() val shouldShow by collectLastValue(underTest.shouldShowFooterView) // WHEN has notifs activeNotificationListRepository.setActiveNotifs(count = 2) // AND shade is open and fully expanded fakeKeyguardRepository.setStatusBarState(StatusBarState.SHADE) shadeTestUtil.setShadeExpansion(1f) runCurrent() // THEN footer visibility animates in assertThat(shouldShow?.isAnimating).isTrue() assertThat(shouldShow?.value).isTrue() } @Test @EnableSceneContainer fun shouldShowFooterView_dualShadeWithoutNotifs_animatesWhenShade() = kosmos.runTest { enableDualShade() runCurrent() val shouldShow by collectLastValue(underTest.shouldShowFooterView) // WHEN has no notifs activeNotificationListRepository.setActiveNotifs(count = 0) // AND shade is open and fully expanded fakeKeyguardRepository.setStatusBarState(StatusBarState.SHADE) shadeTestUtil.setShadeExpansion(1f) runCurrent() // THEN footer visibility animates in assertThat(shouldShow?.isAnimating).isTrue() assertThat(shouldShow?.value).isTrue() } @Test fun shouldIncludeFooterView_notAnimatingOnKeyguard() = testScope.runTest { kosmos.runTest { val shouldInclude by collectFooterViewVisibility() // WHEN has notifs Loading @@ -462,7 +494,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun shouldShowFooterView_falseWhenShadeIsClosed() = testScope.runTest { kosmos.runTest { val shouldShow by collectLastValue(underTest.shouldShowFooterView) // WHEN shade is closed Loading @@ -477,8 +509,8 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun shouldShowFooterView_dualShade_trueWhenShadeIsExpanded() = testScope.runTest { kosmos.enableDualShade() kosmos.runTest { enableDualShade() runCurrent() val shouldShow by collectLastValue(underTest.shouldShowFooterView) Loading @@ -495,8 +527,10 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun shouldShowFooterView_singleShade_falseWhenNoNotifs() = testScope.runTest { kosmos.enableSingleShade() kosmos.runTest { enableSingleShade() runCurrent() val shouldShow by collectLastValue(underTest.shouldShowFooterView) // WHEN shade is open, has no notifs Loading @@ -512,8 +546,8 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun shouldShowFooterView_dualShade_trueWhenNoNotifs() = testScope.runTest { kosmos.enableDualShade() kosmos.runTest { enableDualShade() runCurrent() val shouldShow by collectLastValue(underTest.shouldShowFooterView) Loading @@ -531,7 +565,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @DisableSceneContainer fun shouldHideFooterView_trueWhenShadeIsClosed() = testScope.runTest { kosmos.runTest { val shouldHide by collectLastValue(underTest.shouldHideFooterView) // WHEN shade is closed Loading @@ -546,7 +580,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @DisableSceneContainer fun shouldHideFooterView_falseWhenShadeIsOpen() = testScope.runTest { kosmos.runTest { val shouldHide by collectLastValue(underTest.shouldHideFooterView) // WHEN shade is open Loading @@ -561,7 +595,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @DisableSceneContainer fun shouldHideFooterView_falseWhenQSPartiallyOpen() = testScope.runTest { kosmos.runTest { val shouldHide by collectLastValue(underTest.shouldHideFooterView) // WHEN QS partially open Loading @@ -577,7 +611,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun pinnedHeadsUpRows_filtersForPinnedItems() = testScope.runTest { kosmos.runTest { val pinnedHeadsUpRows by collectLastValue(underTest.pinnedHeadsUpRowKeys) // WHEN there are no pinned rows Loading @@ -587,7 +621,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas FakeHeadsUpRowRepository(key = "1"), FakeHeadsUpRowRepository(key = "2"), ) headsUpRepository.setNotifications(rows) headsUpNotificationRepository.setNotifications(rows) runCurrent() // THEN the list is empty Loading Loading @@ -618,10 +652,10 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun hasPinnedHeadsUpRows_true() = testScope.runTest { kosmos.runTest { val hasPinnedHeadsUpRow by collectLastValue(underTest.hasPinnedHeadsUpRow) headsUpRepository.setNotifications( headsUpNotificationRepository.setNotifications( FakeHeadsUpRowRepository(key = "0", isPinned = true), FakeHeadsUpRowRepository(key = "1"), ) Loading @@ -633,10 +667,10 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun hasPinnedHeadsUpRows_false() = testScope.runTest { kosmos.runTest { val hasPinnedHeadsUpRow by collectLastValue(underTest.hasPinnedHeadsUpRow) headsUpRepository.setNotifications( headsUpNotificationRepository.setNotifications( FakeHeadsUpRowRepository(key = "0"), FakeHeadsUpRowRepository(key = "1"), ) Loading @@ -648,10 +682,10 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun topHeadsUpRow_emptyList_null() = testScope.runTest { kosmos.runTest { val topHeadsUpRow by collectLastValue(underTest.topHeadsUpRow) headsUpRepository.setNotifications(emptyList()) headsUpNotificationRepository.setNotifications(emptyList()) runCurrent() assertThat(topHeadsUpRow).isNull() Loading @@ -660,7 +694,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun headsUpAnimationsEnabled_true() = testScope.runTest { kosmos.runTest { val animationsEnabled by collectLastValue(underTest.headsUpAnimationsEnabled) shadeTestUtil.setQsExpansion(0.0f) Loading @@ -673,7 +707,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas @Test @EnableSceneContainer fun headsUpAnimationsEnabled_keyguardShowing_true() = testScope.runTest { kosmos.runTest { val animationsEnabled by collectLastValue(underTest.headsUpAnimationsEnabled) shadeTestUtil.setQsExpansion(0.0f) Loading @@ -683,7 +717,7 @@ class NotificationListViewModelTest(flags: FlagsParameterization) : SysuiTestCas assertThat(animationsEnabled).isTrue() } private fun TestScope.collectFooterViewVisibility() = private fun Kosmos.collectFooterViewVisibility() = collectLastValue( if (SceneContainerFlag.isEnabled) underTest.shouldShowFooterView else underTest.shouldIncludeFooterView Loading
packages/SystemUI/tests/utils/src/com/android/systemui/shade/ShadeTestUtil.kt +7 −5 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ import com.android.systemui.shade.data.repository.FakeShadeRepository import com.android.systemui.shade.data.repository.ShadeRepository import com.android.systemui.shade.domain.interactor.ShadeInteractor import com.android.systemui.shade.domain.interactor.ShadeModeInteractor import com.android.systemui.shade.shared.model.ShadeMode import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flowOf Loading Loading @@ -227,11 +228,12 @@ class ShadeTestUtilSceneImpl( get() = if (shadeModeInteractor.isDualShade) Overlays.NotificationsShade else Scenes.Shade private val quickSettingsShade: ContentKey get() = if (shadeModeInteractor.isDualShade) { Overlays.QuickSettingsShade } else { Scenes.QuickSettings get() { return when (shadeModeInteractor.shadeMode.value) { is ShadeMode.Dual -> Overlays.QuickSettingsShade is ShadeMode.Single -> Scenes.QuickSettings is ShadeMode.Split -> Scenes.Shade } } override fun setShadeAndQsExpansion(shadeExpansion: Float, qsExpansion: Float) { Loading