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

Commit cdbee107 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Clean up EmptyShade- and FooterViewModel" into main

parents 417a86aa a52ce8d1
Loading
Loading
Loading
Loading
+16 −45
Original line number Diff line number Diff line
@@ -27,17 +27,17 @@ import com.android.settingslib.notification.data.repository.updateNotificationPo
import com.android.settingslib.notification.modes.TestModeBuilder
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.andSceneContainer
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.shared.settings.data.repository.fakeSecureSettingsRepository
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.policy.data.repository.zenModeRepository
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import java.util.Locale
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.After
import org.junit.Before
import org.junit.Test
@@ -48,11 +48,7 @@ import platform.test.runner.parameterized.Parameters
@RunWith(ParameterizedAndroidJunit4::class)
@SmallTest
class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
    private val zenModeRepository = kosmos.zenModeRepository
    private val activeNotificationListRepository = kosmos.activeNotificationListRepository
    private val fakeSecureSettingsRepository = kosmos.fakeSecureSettingsRepository
    private val kosmos = testKosmos().apply { useUnconfinedTestDispatcher() }
    private val fakeConfigurationRepository = kosmos.fakeConfigurationRepository

    /** Backup of the current locales, to be restored at the end of the test if they are changed. */
@@ -86,70 +82,58 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {

    @Test
    fun areNotificationsHiddenInShade_true() =
        testScope.runTest {
        kosmos.runTest {
            val hidden by collectLastValue(underTest.areNotificationsHiddenInShade)

            zenModeRepository.updateNotificationPolicy(
                suppressedVisualEffects = Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST
            )
            zenModeRepository.updateZenMode(Settings.Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS)
            runCurrent()

            assertThat(hidden).isTrue()
        }

    @Test
    fun areNotificationsHiddenInShade_false() =
        testScope.runTest {
        kosmos.runTest {
            val hidden by collectLastValue(underTest.areNotificationsHiddenInShade)

            zenModeRepository.updateNotificationPolicy(
                suppressedVisualEffects = Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST
            )
            zenModeRepository.updateZenMode(Settings.Global.ZEN_MODE_OFF)
            runCurrent()

            assertThat(hidden).isFalse()
        }

    @Test
    fun hasFilteredOutSeenNotifications_true() =
        testScope.runTest {
        kosmos.runTest {
            val hasFilteredNotifs by collectLastValue(underTest.hasFilteredOutSeenNotifications)

            activeNotificationListRepository.hasFilteredOutSeenNotifications.value = true
            runCurrent()

            assertThat(hasFilteredNotifs).isTrue()
        }

    @Test
    fun hasFilteredOutSeenNotifications_false() =
        testScope.runTest {
        kosmos.runTest {
            val hasFilteredNotifs by collectLastValue(underTest.hasFilteredOutSeenNotifications)

            activeNotificationListRepository.hasFilteredOutSeenNotifications.value = false
            runCurrent()

            assertThat(hasFilteredNotifs).isFalse()
        }

    @Test
    fun text_changesWhenLocaleChanges() =
        testScope.runTest {
        kosmos.runTest {
            val text by collectLastValue(underTest.text)

            zenModeRepository.updateNotificationPolicy(
                suppressedVisualEffects = Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST
            )
            zenModeRepository.updateZenMode(Settings.Global.ZEN_MODE_OFF)
            runCurrent()

            assertThat(text).isEqualTo("No notifications")

            updateLocales(LocaleList(Locale.GERMAN))
            runCurrent()

            assertThat(text).isEqualTo("Keine Benachrichtigungen")

            // Make sure we restore the original locales
@@ -158,7 +142,7 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {

    @Test
    fun text_reflectsModesHidingNotifications() =
        testScope.runTest {
        kosmos.runTest {
            val text by collectLastValue(underTest.text)

            assertThat(text).isEqualTo("No notifications")
@@ -171,7 +155,6 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
                    .build()
            )
            runCurrent()
            assertThat(text).isEqualTo("Notifications paused by Do not disturb")

            zenModeRepository.addMode(
@@ -182,7 +165,6 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
                    .build()
            )
            runCurrent()
            assertThat(text).isEqualTo("Notifications paused by Do not disturb and one other mode")

            zenModeRepository.addMode(
@@ -193,36 +175,29 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
                    .build()
            )
            runCurrent()
            assertThat(text).isEqualTo("Notifications paused by Do not disturb and 2 other modes")

            zenModeRepository.deactivateMode("Do not disturb")
            zenModeRepository.deactivateMode("Work")
            runCurrent()
            assertThat(text).isEqualTo("Notifications paused by Gym")
        }

    @Test
    fun footer_isVisibleWhenSeenNotifsAreFilteredOut() =
        testScope.runTest {
        kosmos.runTest {
            val footerVisible by collectLastValue(underTest.footer.isVisible)

            activeNotificationListRepository.hasFilteredOutSeenNotifications.value = false
            runCurrent()

            assertThat(footerVisible).isFalse()

            activeNotificationListRepository.hasFilteredOutSeenNotifications.value = true
            runCurrent()

            assertThat(footerVisible).isTrue()
        }

    @Test
    fun onClick_whenHistoryDisabled_leadsToSettingsPage() =
        testScope.runTest {
        kosmos.runTest {
            val onClick by collectLastValue(underTest.onClick)
            runCurrent()

            fakeSecureSettingsRepository.setInt(Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0)

@@ -233,9 +208,8 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {

    @Test
    fun onClick_whenHistoryEnabled_leadsToHistoryPage() =
        testScope.runTest {
        kosmos.runTest {
            val onClick by collectLastValue(underTest.onClick)
            runCurrent()

            fakeSecureSettingsRepository.setInt(Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 1)

@@ -247,7 +221,7 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {

    @Test
    fun onClick_whenOneModeHidingNotifications_leadsToModeSettings() =
        testScope.runTest {
        kosmos.runTest {
            val onClick by collectLastValue(underTest.onClick)
            runCurrent()

@@ -258,7 +232,6 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
                    .build()
            )
            runCurrent()

            assertThat(onClick?.targetIntent?.action)
                .isEqualTo(Settings.ACTION_AUTOMATIC_ZEN_RULE_SETTINGS)
@@ -272,9 +245,8 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {

    @Test
    fun onClick_whenMultipleModesHidingNotifications_leadsToGeneralModesSettings() =
        testScope.runTest {
        kosmos.runTest {
            val onClick by collectLastValue(underTest.onClick)
            runCurrent()

            zenModeRepository.addMode(
                TestModeBuilder()
@@ -288,7 +260,6 @@ class EmptyShadeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    .setVisualEffect(VISUAL_EFFECT_NOTIFICATION_LIST, /* allowed= */ false)
                    .build()
            )
            runCurrent()

            assertThat(onClick?.targetIntent?.action).isEqualTo(Settings.ACTION_ZEN_MODE_SETTINGS)
            assertThat(onClick?.backStack).isEmpty()
+19 −45
Original line number Diff line number Diff line
@@ -28,7 +28,9 @@ 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.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.power.data.repository.powerRepository
import com.android.systemui.power.shared.model.WakeSleepReason
import com.android.systemui.power.shared.model.WakefulnessState
@@ -42,7 +44,6 @@ 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.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
@@ -56,14 +57,8 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    private val kosmos =
        testKosmos().apply {
            fakeFeatureFlagsClassic.apply { set(Flags.FULL_SCREEN_USER_SWITCHER, false) }
            useUnconfinedTestDispatcher()
        }
    private val testScope = kosmos.testScope
    private val activeNotificationListRepository = kosmos.activeNotificationListRepository
    private val fakeKeyguardRepository = kosmos.fakeKeyguardRepository
    private val powerRepository = kosmos.powerRepository
    private val fakeSecureSettingsRepository = kosmos.fakeSecureSettingsRepository

    private val shadeTestUtil by lazy { kosmos.shadeTestUtil }

    private lateinit var underTest: FooterViewModel

@@ -86,27 +81,23 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {

    @Test
    fun messageVisible_whenFilteredNotifications() =
        testScope.runTest {
        kosmos.runTest {
            val visible by collectLastValue(underTest.message.isVisible)

            activeNotificationListRepository.hasFilteredOutSeenNotifications.value = true

            assertThat(visible).isTrue()
        }

    @Test
    fun messageVisible_whenNoFilteredNotifications() =
        testScope.runTest {
        kosmos.runTest {
            val visible by collectLastValue(underTest.message.isVisible)

            activeNotificationListRepository.hasFilteredOutSeenNotifications.value = false

            assertThat(visible).isFalse()
        }

    @Test
    fun clearAllButtonVisible_whenHasClearableNotifs() =
        testScope.runTest {
        kosmos.runTest {
            val visible by collectLastValue(underTest.clearAllButton.isVisible)

            activeNotificationListRepository.notifStats.value =
@@ -116,14 +107,13 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    hasNonClearableSilentNotifs = false,
                    hasClearableSilentNotifs = true,
                )
            runCurrent()

            assertThat(visible?.value).isTrue()
        }

    @Test
    fun clearAllButtonVisible_whenHasNoClearableNotifs() =
        testScope.runTest {
        kosmos.runTest {
            val visible by collectLastValue(underTest.clearAllButton.isVisible)

            activeNotificationListRepository.notifStats.value =
@@ -133,14 +123,13 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    hasNonClearableSilentNotifs = false,
                    hasClearableSilentNotifs = false,
                )
            runCurrent()

            assertThat(visible?.value).isFalse()
        }

    @Test
    fun clearAllButtonVisible_whenMessageVisible() =
        testScope.runTest {
        kosmos.runTest {
            val visible by collectLastValue(underTest.clearAllButton.isVisible)

            activeNotificationListRepository.notifStats.value =
@@ -151,16 +140,14 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    hasClearableSilentNotifs = true,
                )
            activeNotificationListRepository.hasFilteredOutSeenNotifications.value = true
            runCurrent()

            assertThat(visible?.value).isFalse()
        }

    @Test
    fun clearAllButtonAnimating_whenShadeExpandedAndTouchable() =
        testScope.runTest {
        kosmos.runTest {
            val visible by collectLastValue(underTest.clearAllButton.isVisible)
            runCurrent()

            // WHEN shade is expanded AND QS not expanded
            fakeKeyguardRepository.setStatusBarState(StatusBarState.SHADE)
@@ -171,7 +158,6 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                lastWakeReason = WakeSleepReason.POWER_BUTTON,
                lastSleepReason = WakeSleepReason.OTHER,
            )
            runCurrent()

            // AND there are clearable notifications
            activeNotificationListRepository.notifStats.value =
@@ -181,7 +167,6 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    hasNonClearableSilentNotifs = false,
                    hasClearableSilentNotifs = true,
                )
            runCurrent()

            // THEN button visibility should animate
            assertThat(visible?.isAnimating).isTrue()
@@ -189,9 +174,8 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {

    @Test
    fun clearAllButtonAnimating_whenShadeNotExpanded() =
        testScope.runTest {
        kosmos.runTest {
            val visible by collectLastValue(underTest.clearAllButton.isVisible)
            runCurrent()

            // WHEN shade is collapsed
            fakeKeyguardRepository.setStatusBarState(StatusBarState.SHADE)
@@ -204,7 +188,6 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                lastWakeReason = WakeSleepReason.POWER_BUTTON,
                lastSleepReason = WakeSleepReason.OTHER,
            )
            runCurrent()

            // AND there are clearable notifications
            activeNotificationListRepository.notifStats.value =
@@ -214,7 +197,6 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    hasNonClearableSilentNotifs = false,
                    hasClearableSilentNotifs = true,
                )
            runCurrent()

            // THEN button visibility should not animate
            assertThat(visible?.isAnimating).isFalse()
@@ -223,9 +205,8 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    @Test
    @DisableFlags(NotifRedesignFooter.FLAG_NAME)
    fun manageButton_whenHistoryDisabled() =
        testScope.runTest {
        kosmos.runTest {
            val buttonLabel by collectLastValue(underTest.manageOrHistoryButton.labelId)
            runCurrent()

            // WHEN notification history is disabled
            fakeSecureSettingsRepository.setInt(Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0)
@@ -237,9 +218,8 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    @Test
    @DisableFlags(NotifRedesignFooter.FLAG_NAME)
    fun historyButton_whenHistoryEnabled() =
        testScope.runTest {
        kosmos.runTest {
            val buttonLabel by collectLastValue(underTest.manageOrHistoryButton.labelId)
            runCurrent()

            // WHEN notification history is disabled
            fakeSecureSettingsRepository.setInt(Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 1)
@@ -251,9 +231,8 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    @Test
    @DisableFlags(NotifRedesignFooter.FLAG_NAME)
    fun manageButtonOnClick_whenHistoryDisabled() =
        testScope.runTest {
        kosmos.runTest {
            val onClick by collectLastValue(underTest.manageOrHistoryButtonClick)
            runCurrent()

            // WHEN notification history is disabled
            fakeSecureSettingsRepository.setInt(Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 0)
@@ -267,9 +246,8 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    @Test
    @DisableFlags(NotifRedesignFooter.FLAG_NAME)
    fun historyButtonOnClick_whenHistoryEnabled() =
        testScope.runTest {
        kosmos.runTest {
            val onClick by collectLastValue(underTest.manageOrHistoryButtonClick)
            runCurrent()

            // WHEN notification history is enabled
            fakeSecureSettingsRepository.setInt(Settings.Secure.NOTIFICATION_HISTORY_ENABLED, 1)
@@ -284,29 +262,25 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    @Test
    @DisableFlags(NotifRedesignFooter.FLAG_NAME)
    fun manageButtonVisible_whenMessageVisible() =
        testScope.runTest {
        kosmos.runTest {
            val visible by collectLastValue(underTest.manageOrHistoryButton.isVisible)

            activeNotificationListRepository.hasFilteredOutSeenNotifications.value = true

            assertThat(visible?.value).isFalse()
        }

    @Test
    @DisableFlags(NotifRedesignFooter.FLAG_NAME)
    fun manageButtonVisible_whenMessageNotVisible() =
        testScope.runTest {
        kosmos.runTest {
            val visible by collectLastValue(underTest.manageOrHistoryButton.isVisible)

            activeNotificationListRepository.hasFilteredOutSeenNotifications.value = false

            assertThat(visible?.value).isTrue()
        }

    @Test
    @EnableFlags(NotifRedesignFooter.FLAG_NAME)
    fun settingsAndHistoryButtonsNotVisible_whenMessageVisible() =
        testScope.runTest {
        kosmos.runTest {
            val settingsVisible by collectLastValue(underTest.settingsButtonVisible)
            val historyVisible by collectLastValue(underTest.historyButtonVisible)

@@ -319,7 +293,7 @@ class FooterViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    @Test
    @EnableFlags(NotifRedesignFooter.FLAG_NAME)
    fun settingsAndHistoryButtonsNotVisible_whenMessageNotVisible() =
        testScope.runTest {
        kosmos.runTest {
            val settingsVisible by collectLastValue(underTest.settingsButtonVisible)
            val historyVisible by collectLastValue(underTest.historyButtonVisible)

+2 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.notification.emptyshade.ui.viewmodel

import android.annotation.SuppressLint
import android.content.Context
import android.icu.text.MessageFormat
import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
@@ -45,6 +46,7 @@ import kotlinx.coroutines.flow.onStart
 * ViewModel for the empty shade (aka the "No notifications" text shown when there are no
 * notifications.
 */
@SuppressLint("FlowExposedFromViewModel")
class EmptyShadeViewModel
@AssistedInject
constructor(
+2 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.notification.footer.ui.viewmodel

import android.annotation.SuppressLint
import com.android.internal.jank.InteractionJankMonitor
import com.android.systemui.res.R
import com.android.systemui.shade.domain.interactor.ShadeInteractor
@@ -39,6 +40,7 @@ import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onStart

/** ViewModel for [FooterView]. */
@SuppressLint("FlowExposedFromViewModel")
class FooterViewModel
@AssistedInject
constructor(
@@ -96,9 +98,6 @@ constructor(
    val settingsButtonVisible: Flow<Boolean> = message.isVisible.map { !it }
    val historyButtonVisible: Flow<Boolean> = message.isVisible.map { !it }

    val manageButtonShouldLaunchHistory =
        notificationSettingsInteractor.isNotificationHistoryEnabled

    val manageOrHistoryButtonClick: Flow<SettingsIntent> by lazy {
        notificationSettingsInteractor.isNotificationHistoryEnabled.map {
            isNotificationHistoryEnabled ->