update "Last full charge" preference

When there is average time estimation, change it to "Full charge lasts
about" and also update the time.

Also update the BatteryInfo to return average time estimation even
though it is charging.

Bug: 73018395
Test: RunSettingsRoboTests
Change-Id: Ib22dadb5716e3034c60aeeb7768fdbf0cc86be0c
This commit is contained in:
Lei Yu
2018-03-16 15:26:33 -07:00
parent 8a022d8693
commit 8b148924de
4 changed files with 53 additions and 28 deletions

View File

@@ -123,6 +123,8 @@ public class PowerUsageSummaryTest {
private MenuInflater mMenuInflater;
@Mock
private MenuItem mAdvancedPageMenu;
@Mock
private BatteryInfo mBatteryInfo;
private List<BatterySipper> mUsageList;
private Context mRealContext;
@@ -185,12 +187,28 @@ public class PowerUsageSummaryTest {
}
@Test
public void testUpdateLastFullChargePreference_showCorrectSummary() {
public void testUpdateLastFullChargePreference_noAverageTime_showLastFullChargeSummary() {
mFragment.mBatteryInfo = null;
when(mFragment.getContext()).thenReturn(mRealContext);
doReturn(TIME_SINCE_LAST_FULL_CHARGE_MS).when(
mFragment.mBatteryUtils).calculateLastFullChargeTime(any(), anyLong());
mFragment.updateLastFullChargePreference();
assertThat(mLastFullChargePref.getTitle()).isEqualTo("Last full charge");
assertThat(mLastFullChargePref.getSubtitle()).isEqualTo("2 hr. ago");
}
@Test
public void testUpdateLastFullChargePreference_hasAverageTime_showFullChargeLastSummary() {
mFragment.mBatteryInfo = mBatteryInfo;
mBatteryInfo.averageTimeToDischarge = TIME_SINCE_LAST_FULL_CHARGE_MS;
when(mFragment.getContext()).thenReturn(mRealContext);
mFragment.updateLastFullChargePreference(TIME_SINCE_LAST_FULL_CHARGE_MS);
mFragment.updateLastFullChargePreference();
assertThat(mLastFullChargePref.getSubtitle()).isEqualTo("2 hr. ago");
assertThat(mLastFullChargePref.getTitle()).isEqualTo("Full charge lasts about");
assertThat(mLastFullChargePref.getSubtitle().toString()).isEqualTo("2h");
}
@Test