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

Commit 811e8581 authored by Candice's avatar Candice
Browse files

Fix the StockTilesRepository tests with different feature configs

We were filtering out the reduce brightness tile in the code, but the
corresponding tests were not updated. Therefore, we fix the tests with
testing different EvenDimmer feature flag status and configs.

Bug: 383266971
Test: atest StockTilesRepositoryTest
Flag: com.android.server.display.feature.flags.even_dimmer
Change-Id: Ia8531c8864649233487b5e98666324405a614307
parent 70778387
Loading
Loading
Loading
Loading
+43 −3
Original line number Diff line number Diff line
@@ -17,8 +17,11 @@
package com.android.systemui.qs.panels.data.repository

import android.content.res.mainResources
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.server.display.feature.flags.Flags
import com.android.systemui.SysuiTestCase
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.res.R
@@ -30,12 +33,49 @@ import org.junit.runner.RunWith
@RunWith(AndroidJUnit4::class)
@SmallTest
class StockTilesRepositoryTest : SysuiTestCase() {
    private val kosmos = testKosmos()
    private val kosmos =
        testKosmos().apply { mainResources = mContext.orCreateTestableResources.resources }

    private val underTest = StockTilesRepository(kosmos.mainResources)
    @Test
    @EnableFlags(Flags.FLAG_EVEN_DIMMER)
    fun stockTilesMatchesResources_evenDimmerFlagOn_configOn() {
        // Enable the EvenDimmer config
        mContext
            .getOrCreateTestableResources()
            .addOverride(com.android.internal.R.bool.config_evenDimmerEnabled, true)
        val underTest = StockTilesRepository(kosmos.mainResources)

        val expected =
            kosmos.mainResources
                .getString(R.string.quick_settings_tiles_stock)
                .split(",")
                .filterNot { it.equals("reduce_brightness") }
                .map(TileSpec::create)
        assertThat(underTest.stockTiles).isEqualTo(expected)
    }

    @Test
    @EnableFlags(Flags.FLAG_EVEN_DIMMER)
    fun stockTilesMatchesResources_evenDimmerFlagOn_configOff() {
        // Disable the EvenDimmer config
        mContext
            .getOrCreateTestableResources()
            .addOverride(com.android.internal.R.bool.config_evenDimmerEnabled, false)
        val underTest = StockTilesRepository(kosmos.mainResources)

        val expected =
            kosmos.mainResources
                .getString(R.string.quick_settings_tiles_stock)
                .split(",")
                .map(TileSpec::create)
        assertThat(underTest.stockTiles).isEqualTo(expected)
    }

    @Test
    fun stockTilesMatchesResources() {
    @DisableFlags(Flags.FLAG_EVEN_DIMMER)
    fun stockTilesMatchesResources_evenDimmerFlagOff() {
        val underTest = StockTilesRepository(kosmos.mainResources)

        val expected =
            kosmos.mainResources
                .getString(R.string.quick_settings_tiles_stock)