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

Commit cfe69e76 authored by András Kurucz's avatar András Kurucz
Browse files

[flexiglass] Parameterize NotificationLoggerViewModelTest

Some tests were failing, because they way to determine
WindowRootViewVisibilityInteractor#isLockscreenOrShadeVisible has
changed in flexiglass.

Bug: 376236758
Test: atest NotificationLoggerViewModelTest
Flag: com.android.systemui.scene_container
Change-Id: If331945fc7a8c255e109e016196a198a42d4d1c7
parent 48ba57a6
Loading
Loading
Loading
Loading
+76 −4
Original line number Diff line number Diff line
@@ -16,16 +16,22 @@

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

import androidx.test.ext.junit.runners.AndroidJUnit4
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.andSceneContainer
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.kosmos.testScope
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAsleepForTest
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setAwakeForTest
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.scene.data.repository.Idle
import com.android.systemui.scene.data.repository.setSceneTransition
import com.android.systemui.scene.data.repository.windowRootViewVisibilityRepository
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.statusbar.notification.data.repository.activeNotificationListRepository
import com.android.systemui.statusbar.notification.data.repository.setActiveNotifs
import com.android.systemui.testKosmos
@@ -33,10 +39,12 @@ import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters

@SmallTest
@RunWith(AndroidJUnit4::class)
class NotificationLoggerViewModelTest : SysuiTestCase() {
@RunWith(ParameterizedAndroidJunit4::class)
class NotificationLoggerViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {

    private val kosmos = testKosmos()

@@ -46,9 +54,22 @@ class NotificationLoggerViewModelTest : SysuiTestCase() {
    private val powerInteractor = kosmos.powerInteractor
    private val windowRootViewVisibilityRepository = kosmos.windowRootViewVisibilityRepository

    private val underTest = kosmos.notificationListLoggerViewModel
    private val underTest by lazy { kosmos.notificationListLoggerViewModel }

    companion object {
        @JvmStatic
        @Parameters(name = "{0}")
        fun getParams(): List<FlagsParameterization> {
            return FlagsParameterization.allCombinationsOf().andSceneContainer()
        }
    }

    init {
        mSetFlagsRule.setFlagsParameterization(flags)
    }

    @Test
    @DisableSceneContainer
    fun isLockscreenOrShadeInteractive_deviceActiveAndShadeIsInteractive_true() =
        testScope.runTest {
            powerInteractor.setAwakeForTest()
@@ -60,6 +81,7 @@ class NotificationLoggerViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableSceneContainer
    fun isLockscreenOrShadeInteractive_deviceIsAsleepAndShadeIsInteractive_false() =
        testScope.runTest {
            powerInteractor.setAsleepForTest()
@@ -71,6 +93,7 @@ class NotificationLoggerViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableSceneContainer
    fun isLockscreenOrShadeInteractive_deviceActiveAndShadeIsNotInteractive_false() =
        testScope.runTest {
            powerInteractor.setAwakeForTest()
@@ -81,6 +104,54 @@ class NotificationLoggerViewModelTest : SysuiTestCase() {
            assertThat(actual).isFalse()
        }

    @Test
    @EnableSceneContainer
    fun isLockscreenOrShadeInteractive_deviceAwakeAndShadeIsDisplayed_true() =
        testScope.runTest {
            powerInteractor.setAwakeForTest()
            kosmos.setSceneTransition(Idle(Scenes.Shade))

            val actual by collectLastValue(underTest.isLockscreenOrShadeInteractive)

            assertThat(actual).isTrue()
        }

    @Test
    @EnableSceneContainer
    fun isLockscreenOrShadeInteractive_deviceAwakeAndLockScreenIsDisplayed_true() =
        testScope.runTest {
            powerInteractor.setAwakeForTest()
            kosmos.setSceneTransition(Idle(Scenes.Lockscreen))

            val actual by collectLastValue(underTest.isLockscreenOrShadeInteractive)

            assertThat(actual).isTrue()
        }

    @Test
    @EnableSceneContainer
    fun isLockscreenOrShadeInteractive_deviceIsAsleepOnLockscreen_false() =
        testScope.runTest {
            powerInteractor.setAsleepForTest()
            kosmos.setSceneTransition(Idle(Scenes.Lockscreen))

            val actual by collectLastValue(underTest.isLockscreenOrShadeInteractive)

            assertThat(actual).isFalse()
        }

    @Test
    @EnableSceneContainer
    fun isLockscreenOrShadeInteractive_deviceActiveAndShadeIsClosed() =
        testScope.runTest {
            powerInteractor.setAwakeForTest()
            kosmos.setSceneTransition(Idle(Scenes.Gone))

            val actual by collectLastValue(underTest.isLockscreenOrShadeInteractive)

            assertThat(actual).isFalse()
        }

    @Test
    fun activeNotifications_hasNotifications() =
        testScope.runTest {
@@ -135,6 +206,7 @@ class NotificationLoggerViewModelTest : SysuiTestCase() {

            assertThat(isOnLockScreen).isTrue()
        }

    @Test
    fun isOnLockScreen_false() =
        testScope.runTest {