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

Commit 5c7d71dc authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Modernize test to avoid reading flags before the test executes

Flag: TEST_ONLY
Test: atest SystemUITests
Bug: 367705002
Change-Id: I35c5c094d113a8c59158b7b0daae9589bdcf08e2
parent 6bfafc72
Loading
Loading
Loading
Loading
+15 −18
Original line number Diff line number Diff line
@@ -21,8 +21,9 @@ import android.service.notification.StatusBarNotification
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.testScope
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.statusbar.RankingBuilder
import com.android.systemui.statusbar.notification.collection.GroupEntry
import com.android.systemui.statusbar.notification.collection.NotificationEntry
@@ -34,7 +35,6 @@ import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.junit.runner.RunWith

@@ -42,17 +42,14 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
class RenderNotificationsListInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope

    private val notifsRepository = kosmos.activeNotificationListRepository
    private val notifsInteractor = kosmos.activeNotificationsInteractor
    private val underTest =
        RenderNotificationListInteractor(notifsRepository, sectionStyleProvider = mock(), context)
    private val Kosmos.outputInteractor by Kosmos.Fixture { activeNotificationsInteractor }
    private val Kosmos.underTest by Kosmos.Fixture { renderNotificationListInteractor }

    @Test
    fun setRenderedList_preservesOrdering() =
        testScope.runTest {
            val notifs by collectLastValue(notifsInteractor.topLevelRepresentativeNotifications)
        kosmos.runTest {
            val notifs by collectLastValue(outputInteractor.topLevelRepresentativeNotifications)
            val keys = (1..50).shuffled().map { "$it" }
            val entries = keys.map { mockNotificationEntry(key = it) }
            underTest.setRenderedList(entries)
@@ -64,8 +61,8 @@ class RenderNotificationsListInteractorTest : SysuiTestCase() {

    @Test
    fun setRenderList_flatMapsRankings() =
        testScope.runTest {
            val ranks by collectLastValue(notifsInteractor.activeNotificationRanks)
        kosmos.runTest {
            val ranks by collectLastValue(outputInteractor.activeNotificationRanks)

            val single = mockNotificationEntry("single", 0)
            val group =
@@ -89,8 +86,8 @@ class RenderNotificationsListInteractorTest : SysuiTestCase() {

    @Test
    fun setRenderList_singleItems_mapsRankings() =
        testScope.runTest {
            val actual by collectLastValue(notifsInteractor.activeNotificationRanks)
        kosmos.runTest {
            val actual by collectLastValue(outputInteractor.activeNotificationRanks)
            val expected =
                (0..10).shuffled().mapIndexed { index, value -> "$value" to index }.toMap()

@@ -103,8 +100,8 @@ class RenderNotificationsListInteractorTest : SysuiTestCase() {

    @Test
    fun setRenderList_groupWithNoSummary_flatMapsRankings() =
        testScope.runTest {
            val actual by collectLastValue(notifsInteractor.activeNotificationRanks)
        kosmos.runTest {
            val actual by collectLastValue(outputInteractor.activeNotificationRanks)
            val expected =
                (0..10).shuffled().mapIndexed { index, value -> "$value" to index }.toMap()

@@ -123,8 +120,8 @@ class RenderNotificationsListInteractorTest : SysuiTestCase() {
    @Test
    @EnableFlags(PromotedNotificationUi.FLAG_NAME)
    fun setRenderList_setsPromotionContent() =
        testScope.runTest {
            val actual by collectLastValue(notifsInteractor.topLevelRepresentativeNotifications)
        kosmos.runTest {
            val actual by collectLastValue(outputInteractor.topLevelRepresentativeNotifications)

            val notPromoted1 = mockNotificationEntry("key1", promotedContent = null)
            val promoted2 =