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

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

Merge "Avoid changing scenes if already on the desired scene" into main

parents 13d424b6 346b11ff
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.compose.animation.scene.ObservableTransitionState
import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.communal.data.repository.communalSceneRepository
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor.OnSceneAboutToChangeListener
import com.android.systemui.communal.domain.model.CommunalTransitionProgressModel
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.shared.model.EditModeState
@@ -36,6 +37,11 @@ import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.verify

@SmallTest
@RunWith(AndroidJUnit4::class)
@@ -57,6 +63,36 @@ class CommunalSceneInteractorTest : SysuiTestCase() {
            assertThat(currentScene).isEqualTo(CommunalScenes.Communal)
        }

    @Test
    fun changeScene_callsSceneStateProcessor() =
        testScope.runTest {
            val callback: OnSceneAboutToChangeListener = mock()
            underTest.registerSceneStateProcessor(callback)

            val currentScene by collectLastValue(underTest.currentScene)
            assertThat(currentScene).isEqualTo(CommunalScenes.Blank)
            verify(callback, never()).onSceneAboutToChange(any(), anyOrNull())

            underTest.changeScene(CommunalScenes.Communal, "test")
            assertThat(currentScene).isEqualTo(CommunalScenes.Communal)
            verify(callback).onSceneAboutToChange(CommunalScenes.Communal, null)
        }

    @Test
    fun changeScene_doesNotCallSceneStateProcessorForDuplicateState() =
        testScope.runTest {
            val callback: OnSceneAboutToChangeListener = mock()
            underTest.registerSceneStateProcessor(callback)

            val currentScene by collectLastValue(underTest.currentScene)
            assertThat(currentScene).isEqualTo(CommunalScenes.Blank)

            underTest.changeScene(CommunalScenes.Blank, "test")
            assertThat(currentScene).isEqualTo(CommunalScenes.Blank)

            verify(callback, never()).onSceneAboutToChange(any(), anyOrNull())
        }

    @Test
    fun snapToScene() =
        testScope.runTest {
+12 −7
Original line number Diff line number Diff line
@@ -36,11 +36,15 @@ import com.android.systemui.testKosmos
import com.android.systemui.user.data.repository.FakeUserRepository
import com.android.systemui.user.data.repository.fakeUserRepository
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
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

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
class CommunalTutorialInteractorTest : SysuiTestCase() {
@@ -50,14 +54,14 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
    private lateinit var underTest: CommunalTutorialInteractor
    private lateinit var keyguardRepository: FakeKeyguardRepository
    private lateinit var communalTutorialRepository: FakeCommunalTutorialRepository
    private lateinit var communalInteractor: CommunalInteractor
    private lateinit var communalSceneInteractor: CommunalSceneInteractor
    private lateinit var userRepository: FakeUserRepository

    @Before
    fun setUp() {
        keyguardRepository = kosmos.fakeKeyguardRepository
        communalTutorialRepository = kosmos.fakeCommunalTutorialRepository
        communalInteractor = kosmos.communalInteractor
        communalSceneInteractor = kosmos.communalSceneInteractor
        userRepository = kosmos.fakeUserRepository

        kosmos.fakeFeatureFlagsClassic.set(Flags.COMMUNAL_SERVICE_ENABLED, true)
@@ -158,7 +162,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            kosmos.setCommunalAvailable(true)
            communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_NOT_STARTED)

            communalInteractor.changeScene(CommunalScenes.Blank, "test")
            communalSceneInteractor.changeScene(CommunalScenes.Blank, "test")

            assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_NOT_STARTED)
        }
@@ -171,7 +175,7 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            goToCommunal()
            communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_STARTED)

            communalInteractor.changeScene(CommunalScenes.Blank, "test")
            communalSceneInteractor.changeScene(CommunalScenes.Blank, "test")

            assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_COMPLETED)
        }
@@ -184,13 +188,14 @@ class CommunalTutorialInteractorTest : SysuiTestCase() {
            goToCommunal()
            communalTutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_COMPLETED)

            communalInteractor.changeScene(CommunalScenes.Blank, "test")
            communalSceneInteractor.changeScene(CommunalScenes.Blank, "test")

            assertThat(tutorialSettingState).isEqualTo(HUB_MODE_TUTORIAL_COMPLETED)
        }

    private suspend fun goToCommunal() {
    private suspend fun TestScope.goToCommunal() {
        kosmos.setCommunalAvailable(true)
        communalInteractor.changeScene(CommunalScenes.Communal, "test")
        communalSceneInteractor.changeScene(CommunalScenes.Communal, "test")
        runCurrent()
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -88,6 +88,7 @@ constructor(
        keyguardState: KeyguardState? = null,
    ) {
        applicationScope.launch("$TAG#changeScene") {
            if (currentScene.value == newScene) return@launch
            logger.logSceneChangeRequested(
                from = currentScene.value,
                to = newScene,
@@ -108,6 +109,7 @@ constructor(
    ) {
        applicationScope.launch("$TAG#snapToScene") {
            delay(delayMillis)
            if (currentScene.value == newScene) return@launch
            logger.logSceneChangeRequested(
                from = currentScene.value,
                to = newScene,