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

Commit 9a6c1872 authored by David Saff's avatar David Saff
Browse files

Convert AccessibilityQsShortcutsRepositoryImplTest

Also introduce Kosmos.collectLastValue

Bug: 342622417
Test: local
Flag: TEST_ONLY
Change-Id: I196fadbb6c62c81e0efdd343901d611a0dfba1ce
parent 0da1304d
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -22,12 +22,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.android.systemui.util.settings.fakeSettings
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@@ -40,8 +41,6 @@ import org.mockito.junit.MockitoRule
@RunWith(AndroidJUnit4::class)
class AccessibilityQsShortcutsRepositoryImplTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testDispatcher = kosmos.testDispatcher
    private val testScope = kosmos.testScope
    private val secureSettings = kosmos.fakeSettings

    @Rule @JvmField val mockitoRule: MockitoRule = MockitoJUnit.rule()
@@ -55,8 +54,8 @@ class AccessibilityQsShortcutsRepositoryImplTest : SysuiTestCase() {
                return UserA11yQsShortcutsRepository(
                    userId,
                    secureSettings,
                    testScope.backgroundScope,
                    testDispatcher,
                    kosmos.testScope.backgroundScope,
                    kosmos.testDispatcher,
                )
            }
        }
@@ -69,13 +68,13 @@ class AccessibilityQsShortcutsRepositoryImplTest : SysuiTestCase() {
            AccessibilityQsShortcutsRepositoryImpl(
                a11yManager,
                userA11yQsShortcutsRepositoryFactory,
                testDispatcher
                kosmos.testDispatcher,
            )
    }

    @Test
    fun a11yQsShortcutTargetsForCorrectUsers() =
        testScope.runTest {
        kosmos.runTest {
            val user0 = 0
            val targetsForUser0 = setOf("a", "b", "c")
            val user1 = 1
@@ -94,7 +93,7 @@ class AccessibilityQsShortcutsRepositoryImplTest : SysuiTestCase() {
        secureSettings.putStringForUser(
            SETTING_NAME,
            a11yQsTargets.joinToString(separator = ":"),
            forUser
            forUser,
        )
    }

+14 −15
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import com.android.systemui.flags.Flags
import com.android.systemui.flags.fakeFeatureFlagsClassic
import com.android.systemui.keyguard.ui.viewmodel.lockscreenUserActionsViewModel
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.kosmos.testScope
@@ -153,7 +154,7 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() {
    @Test
    fun swipeUpOnLockscreen_enterCorrectPin_unlocksDevice() =
        kosmos.runTest {
            val actions by testScope.collectLastValue(kosmos.lockscreenUserActionsViewModel.actions)
            val actions by collectLastValue(kosmos.lockscreenUserActionsViewModel.actions)
            val upDestinationSceneKey =
                (actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene
            assertThat(upDestinationSceneKey).isEqualTo(Scenes.Bouncer)
@@ -170,7 +171,7 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() {
        kosmos.runTest {
            setAuthMethod(AuthenticationMethodModel.None, enableLockscreen = true)

            val actions by testScope.collectLastValue(lockscreenUserActionsViewModel.actions)
            val actions by collectLastValue(lockscreenUserActionsViewModel.actions)
            val upDestinationSceneKey =
                (actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene
            assertThat(upDestinationSceneKey).isEqualTo(Scenes.Gone)
@@ -180,7 +181,7 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() {
    @Test
    fun swipeUpOnShadeScene_withAuthMethodSwipe_lockscreenNotDismissed_goesToLockscreen() =
        kosmos.runTest {
            val actions by testScope.collectLastValue(shadeUserActionsViewModel.actions)
            val actions by collectLastValue(shadeUserActionsViewModel.actions)
            setAuthMethod(AuthenticationMethodModel.None, enableLockscreen = true)
            assertCurrentScene(Scenes.Lockscreen)

@@ -197,8 +198,8 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() {
    @Test
    fun swipeUpOnShadeScene_withAuthMethodSwipe_lockscreenDismissed_goesToGone() =
        kosmos.runTest {
            val actions by testScope.collectLastValue(shadeUserActionsViewModel.actions)
            val canSwipeToEnter by testScope.collectLastValue(deviceEntryInteractor.canSwipeToEnter)
            val actions by collectLastValue(shadeUserActionsViewModel.actions)
            val canSwipeToEnter by collectLastValue(deviceEntryInteractor.canSwipeToEnter)

            setAuthMethod(AuthenticationMethodModel.None, enableLockscreen = true)

@@ -279,7 +280,7 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() {
    fun swipeUpOnLockscreenWhileUnlocked_dismissesLockscreen() =
        kosmos.runTest {
            unlockDevice()
            val actions by testScope.collectLastValue(lockscreenUserActionsViewModel.actions)
            val actions by collectLastValue(lockscreenUserActionsViewModel.actions)
            val upDestinationSceneKey =
                (actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene
            assertThat(upDestinationSceneKey).isEqualTo(Scenes.Gone)
@@ -302,7 +303,7 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() {
    fun dismissingIme_whileOnPasswordBouncer_navigatesToLockscreen() =
        kosmos.runTest {
            setAuthMethod(AuthenticationMethodModel.Password)
            val actions by testScope.collectLastValue(lockscreenUserActionsViewModel.actions)
            val actions by collectLastValue(lockscreenUserActionsViewModel.actions)
            val upDestinationSceneKey =
                (actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene
            assertThat(upDestinationSceneKey).isEqualTo(Scenes.Bouncer)
@@ -319,14 +320,13 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() {
    fun bouncerActionButtonClick_opensEmergencyServicesDialer() =
        kosmos.runTest {
            setAuthMethod(AuthenticationMethodModel.Password)
            val actions by testScope.collectLastValue(lockscreenUserActionsViewModel.actions)
            val actions by collectLastValue(lockscreenUserActionsViewModel.actions)
            val upDestinationSceneKey =
                (actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene
            assertThat(upDestinationSceneKey).isEqualTo(Scenes.Bouncer)
            emulateUserDrivenTransition(to = upDestinationSceneKey)

            val bouncerActionButton by
                testScope.collectLastValue(bouncerSceneContentViewModel.actionButton)
            val bouncerActionButton by collectLastValue(bouncerSceneContentViewModel.actionButton)
            assertWithMessage("Bouncer action button not visible")
                .that(bouncerActionButton)
                .isNotNull()
@@ -341,14 +341,13 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() {
        kosmos.runTest {
            setAuthMethod(AuthenticationMethodModel.Password)
            startPhoneCall()
            val actions by testScope.collectLastValue(lockscreenUserActionsViewModel.actions)
            val actions by collectLastValue(lockscreenUserActionsViewModel.actions)
            val upDestinationSceneKey =
                (actions?.get(Swipe.Up) as? UserActionResult.ChangeScene)?.toScene
            assertThat(upDestinationSceneKey).isEqualTo(Scenes.Bouncer)
            emulateUserDrivenTransition(to = upDestinationSceneKey)

            val bouncerActionButton by
                testScope.collectLastValue(bouncerSceneContentViewModel.actionButton)
            val bouncerActionButton by collectLastValue(bouncerSceneContentViewModel.actionButton)
            assertWithMessage("Bouncer action button not visible during call")
                .that(bouncerActionButton)
                .isNotNull()
@@ -574,7 +573,7 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() {
            .that(getCurrentSceneInUi())
            .isEqualTo(Scenes.Bouncer)
        val authMethodViewModel by
            testScope.collectLastValue(bouncerSceneContentViewModel.authMethodViewModel)
            collectLastValue(bouncerSceneContentViewModel.authMethodViewModel)
        assertWithMessage("Cannot enter PIN when not using a PIN authentication method!")
            .that(authMethodViewModel)
            .isInstanceOf(PinBouncerViewModel::class.java)
@@ -603,7 +602,7 @@ class SceneFrameworkIntegrationTest : SysuiTestCase() {
            .that(getCurrentSceneInUi())
            .isEqualTo(Scenes.Bouncer)
        val authMethodViewModel by
            testScope.collectLastValue(bouncerSceneContentViewModel.authMethodViewModel)
            collectLastValue(bouncerSceneContentViewModel.authMethodViewModel)
        assertWithMessage("Cannot enter PIN when not using a PIN authentication method!")
            .that(authMethodViewModel)
            .isInstanceOf(PinBouncerViewModel::class.java)
+4 −0
Original line number Diff line number Diff line
package com.android.systemui.kosmos

import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.Kosmos.Fixture
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.test.StandardTestDispatcher
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.UnconfinedTestDispatcher
@@ -45,3 +47,5 @@ fun Kosmos.runTest(testBody: suspend Kosmos.() -> Unit) =
    testScope.runTest { this@runTest.testBody() }

fun Kosmos.runCurrent() = testScope.runCurrent()

fun <T> Kosmos.collectLastValue(flow: Flow<T>) = testScope.collectLastValue(flow)