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

Commit ce2a0d13 authored by Jeff DeCew's avatar Jeff DeCew Committed by Android (Google) Code Review
Browse files

Merge "Modernize test to avoid reading flags before the test executes" into main

parents eda9207e 5c7d71dc
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
@@ -35,7 +36,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

@@ -43,17 +43,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)
@@ -65,8 +62,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 =
@@ -90,8 +87,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()

@@ -104,8 +101,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()

@@ -124,8 +121,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 =