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

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

Merge "[battery] rearrange attributions to match old battery" into main

parents 581eb770 8f37f503
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -65,12 +65,12 @@ class BatteryInteractor @Inject constructor(repo: BatteryRepository) {
     */
    val batteryAttributionType =
        combine(isCharging, powerSave, isBatteryDefenderEnabled) { charging, powerSave, defend ->
            if (charging) {
                BatteryAttributionModel.Charging
            } else if (powerSave) {
            if (powerSave) {
                BatteryAttributionModel.PowerSave
            } else if (defend) {
                BatteryAttributionModel.Defend
            } else if (charging) {
                BatteryAttributionModel.Charging
            } else {
                null
            }
+52 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runTest
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.statusbar.policy.batteryController
import com.android.systemui.statusbar.policy.fake
import com.android.systemui.testKosmos
@@ -32,7 +33,7 @@ import org.junit.runner.RunWith
@SmallTest
@RunWith(AndroidJUnit4::class)
class BatteryInteractorTest : SysuiTestCase() {
    val kosmos = testKosmos()
    val kosmos = testKosmos().useUnconfinedTestDispatcher()
    val Kosmos.underTest by Kosmos.Fixture { batteryInteractor }

    @Test
@@ -50,11 +51,61 @@ class BatteryInteractorTest : SysuiTestCase() {

            assertThat(latest).isEqualTo(BatteryAttributionModel.Defend)

            batteryController.fake._isDefender = false
            batteryController.fake._isPowerSave = true

            assertThat(latest).isEqualTo(BatteryAttributionModel.PowerSave)

            batteryController.fake._isPowerSave = false
            batteryController.fake._isPluggedIn = true

            assertThat(latest).isEqualTo(BatteryAttributionModel.Charging)
        }

    @Test
    fun attributionType_prioritizesPowerSaveOverCharging() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.batteryAttributionType)

            batteryController.fake._isPluggedIn = true
            batteryController.fake._isDefender = true
            batteryController.fake._isPowerSave = true

            assertThat(latest).isEqualTo(BatteryAttributionModel.PowerSave)
        }

    @Test
    fun attributionType_prioritizesPowerSaveOverDefender() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.batteryAttributionType)

            batteryController.fake._isPluggedIn = true
            batteryController.fake._isPowerSave = true
            batteryController.fake._isDefender = false

            assertThat(latest).isEqualTo(BatteryAttributionModel.PowerSave)
        }

    @Test
    fun attributionType_prioritizesDefenderOverCharging() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.batteryAttributionType)

            batteryController.fake._isPluggedIn = true
            batteryController.fake._isPowerSave = false
            batteryController.fake._isDefender = true

            assertThat(latest).isEqualTo(BatteryAttributionModel.Defend)
        }

    @Test
    fun attributionType_prioritizesChargingOnly() =
        kosmos.runTest {
            val latest by collectLastValue(underTest.batteryAttributionType)

            batteryController.fake._isPluggedIn = true
            batteryController.fake._isDefender = false
            batteryController.fake._isPowerSave = false

            assertThat(latest).isEqualTo(BatteryAttributionModel.Charging)
        }
+35 −0
Original line number Diff line number Diff line
@@ -97,4 +97,39 @@ class BatteryViewModelTest : SysuiTestCase() {

            assertThat(underTest.glyphList).isEqualTo(listOf(BatteryGlyph.BoltLarge))
        }

    @Test
    fun glyphList_attributionOrdering_prioritizesDefendOverCharging() =
        kosmos.runTest {
            fakeSystemSettingsRepository.setInt(Settings.System.SHOW_BATTERY_PERCENT, 0)
            batteryController.fake._level = 39
            batteryController.fake._isPluggedIn = true
            batteryController.fake._isDefender = true

            assertThat(underTest.glyphList).isEqualTo(listOf(BatteryGlyph.DefendLarge))
        }

    @Test
    fun glyphList_attributionOrdering_prioritizesPowerSaveOverDefend() =
        kosmos.runTest {
            fakeSystemSettingsRepository.setInt(Settings.System.SHOW_BATTERY_PERCENT, 0)
            batteryController.fake._level = 39
            batteryController.fake._isPluggedIn = true
            batteryController.fake._isDefender = true
            batteryController.fake._isPowerSave = true

            assertThat(underTest.glyphList).isEqualTo(listOf(BatteryGlyph.PlusLarge))
        }

    @Test
    fun glyphList_attributionOrdering_prioritizesPowerSaveOverCharging() =
        kosmos.runTest {
            fakeSystemSettingsRepository.setInt(Settings.System.SHOW_BATTERY_PERCENT, 0)
            batteryController.fake._level = 39
            batteryController.fake._isPluggedIn = true
            batteryController.fake._isDefender = false
            batteryController.fake._isPowerSave = true

            assertThat(underTest.glyphList).isEqualTo(listOf(BatteryGlyph.PlusLarge))
        }
}