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

Commit 19913e1a authored by Beverly's avatar Beverly
Browse files

[flexiglass] Update AltBouncerToGoneTransitionViewModelTest

- Disable tests that don't need to run when flexi is enabled.
For example, when flexiglass is enabled, there are no consumers
of the lockscreenAlpha, so we don't need to test that.
- Create flexi-specific new test for the notificationAlpha
which is currently still used when flexi is enabled. In the test,
fake the scene transition in addition to the keyguard transition.

Test: atest AlternateBouncerToGoneTransitionViewModelTest
Bug: 409851925
Flag: EXEMPT test change only
Change-Id: I15025ceb0ce3e3a22bc63816267af08b42c9d7e9
parent b44031a2
Loading
Loading
Loading
Loading
+66 −1
Original line number Diff line number Diff line
@@ -18,25 +18,46 @@ package com.android.systemui.keyguard.ui.viewmodel

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.compose.animation.scene.ContentKey
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.OverlayKey
import com.android.compose.animation.scene.SceneKey
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
import com.android.systemui.deviceentry.domain.interactor.deviceUnlockedInteractor
import com.android.systemui.flags.DisableSceneContainer
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.flags.Flags
import com.android.systemui.flags.fakeFeatureFlagsClassic
import com.android.systemui.keyguard.data.repository.fakeDeviceEntryFingerprintAuthRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
import com.android.systemui.keyguard.shared.model.SuccessFingerprintAuthenticationStatus
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionState.RUNNING
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.kosmos.currentValue
import com.android.systemui.kosmos.testScope
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.scene.shared.model.Scenes
import com.android.systemui.statusbar.sysuiStatusBarStateController
import com.android.systemui.testKosmos
import com.android.systemui.user.domain.interactor.selectedUserInteractor
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertWithMessage
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith
import kotlinx.coroutines.flow.emptyFlow
import com.android.systemui.scene.data.repository.sceneContainerRepository

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -52,6 +73,46 @@ class AlternateBouncerToGoneTransitionViewModelTest : SysuiTestCase() {
    private val underTest by lazy { kosmos.alternateBouncerToGoneTransitionViewModel }

    @Test
    @EnableSceneContainer
    fun notificationAlpha() =
        testScope.runTest {
            val transitionState =
                MutableStateFlow<ObservableTransitionState>(
                    ObservableTransitionState.Idle(Scenes.Lockscreen)
                )
            kosmos.sceneContainerRepository.setTransitionState(transitionState)
            transitionState.value =
                ObservableTransitionState.Transition(
                    fromScene = Scenes.Lockscreen,
                    toScene = Scenes.Gone,
                    emptyFlow(),
                    emptyFlow(),
                    false,
                    emptyFlow()
                )
            val viewState = ViewStateAccessor(alpha = { 1f })
            val values by collectValues(underTest.notificationAlpha(ViewStateAccessor()))
            runCurrent()

            sysuiStatusBarStateController.setLeaveOpenOnKeyguardHide(false)
            keyguardTransitionRepository.sendTransitionSteps(
                listOf(
                    step(0f, TransitionState.STARTED),
                    step(0f),
                    step(0.3f),
                    step(1f),
                ),
                testScope,
            )
            runCurrent()

            // Assert alpha value goes to 0
            assertThat(values.size).isGreaterThan(0)
            assertThat(values[values.size - 1]).isEqualTo(0f)
        }

    @Test
    @DisableSceneContainer
    fun deviceEntryParentViewDisappear() =
        testScope.runTest {
            val values by collectValues(underTest.deviceEntryParentViewAlpha)
@@ -72,6 +133,7 @@ class AlternateBouncerToGoneTransitionViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableSceneContainer
    fun lockscreenAlpha() =
        testScope.runTest {
            val startAlpha = 0.6f
@@ -110,6 +172,7 @@ class AlternateBouncerToGoneTransitionViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableSceneContainer
    fun notificationAlpha_leaveShadeOpen() =
        testScope.runTest {
            val values by collectValues(underTest.notificationAlpha(ViewStateAccessor()))
@@ -125,6 +188,7 @@ class AlternateBouncerToGoneTransitionViewModelTest : SysuiTestCase() {
        }

    @Test
    @DisableSceneContainer
    fun lockscreenAlpha_zeroInitialAlpha() =
        testScope.runTest {
            // ViewState starts at 0 alpha.
@@ -144,7 +208,8 @@ class AlternateBouncerToGoneTransitionViewModelTest : SysuiTestCase() {
    private fun step(value: Float, state: TransitionState = RUNNING): TransitionStep {
        return TransitionStep(
            from = KeyguardState.ALTERNATE_BOUNCER,
            to = GONE,
            to = if (SceneContainerFlag.isEnabled) KeyguardState.UNDEFINED
                else GONE,
            value = value,
            transitionState = state,
            ownerName = "AlternateBouncerToGoneTransitionViewModelTest"