Refresh category title by different time slot condition
Bug: 177406865 Bug: 185187729 Test: make SettingsRoboTests Test: make SettingsGoogleRoboTests Change-Id: Ib124e1cfb9549f838540ff547bc616049f65180d
This commit is contained in:
@@ -52,8 +52,10 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public final class BatteryChartPreferenceControllerTest {
|
||||
@@ -68,6 +70,7 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
@Mock private BatteryHistEntry mBatteryHistEntry;
|
||||
@Mock private BatteryChartView mBatteryChartView;
|
||||
@Mock private PowerGaugePreference mPowerGaugePreference;
|
||||
@Mock private ExpandDividerPreference mExpandDividerPreference;
|
||||
@Mock private BatteryUtils mBatteryUtils;
|
||||
|
||||
private Context mContext;
|
||||
@@ -480,6 +483,94 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
assertThat(mBatteryChartPreferenceController.mPreferenceCache).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshCategoryTitle_appComponent_setHourIntoPreferenceTitle() {
|
||||
setUpBatteryHistoryKeys();
|
||||
mBatteryChartPreferenceController.mCategoryTitleType =
|
||||
BatteryChartPreferenceController.CategoryTitleType.TYPE_APP_COMPONENT;
|
||||
mBatteryChartPreferenceController.mExpandDividerPreference =
|
||||
mExpandDividerPreference;
|
||||
// Simulates select the first slot.
|
||||
mBatteryChartPreferenceController.mTrapezoidIndex = 0;
|
||||
|
||||
mBatteryChartPreferenceController.refreshCategoryTitle();
|
||||
|
||||
final ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
// Verifies the title in the preference group.
|
||||
verify(mAppListGroup).setTitle(captor.capture());
|
||||
assertThat(captor.getValue())
|
||||
.isEqualTo("App usage for 4 pm-7 am");
|
||||
verify(mExpandDividerPreference).setTitle(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshCategoryTitle_systemComponent_setHourIntoPreferenceTitle() {
|
||||
setUpBatteryHistoryKeys();
|
||||
mBatteryChartPreferenceController.mCategoryTitleType =
|
||||
BatteryChartPreferenceController.CategoryTitleType.TYPE_SYSTEM_COMPONENT;
|
||||
mBatteryChartPreferenceController.mExpandDividerPreference =
|
||||
mExpandDividerPreference;
|
||||
// Simulates select the first slot.
|
||||
mBatteryChartPreferenceController.mTrapezoidIndex = 0;
|
||||
|
||||
mBatteryChartPreferenceController.refreshCategoryTitle();
|
||||
|
||||
final ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
// Verifies the title in the preference group.
|
||||
verify(mAppListGroup).setTitle(captor.capture());
|
||||
assertThat(captor.getValue())
|
||||
.isEqualTo("System usage for 4 pm-7 am");
|
||||
verify(mExpandDividerPreference).setTitle(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshCategoryTitle_allComponents_setHourIntoBothTitleTextView() {
|
||||
setUpBatteryHistoryKeys();
|
||||
mBatteryChartPreferenceController.mCategoryTitleType =
|
||||
BatteryChartPreferenceController.CategoryTitleType.TYPE_ALL_COMPONENTS;
|
||||
mBatteryChartPreferenceController.mExpandDividerPreference =
|
||||
mExpandDividerPreference;
|
||||
// Simulates select the first slot.
|
||||
mBatteryChartPreferenceController.mTrapezoidIndex = 0;
|
||||
|
||||
mBatteryChartPreferenceController.refreshCategoryTitle();
|
||||
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
// Verifies the title in the preference group.
|
||||
verify(mAppListGroup).setTitle(captor.capture());
|
||||
assertThat(captor.getValue())
|
||||
.isEqualTo("App usage for 4 pm-7 am");
|
||||
// Verifies the title in the expandable divider.
|
||||
captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(mExpandDividerPreference).setTitle(captor.capture());
|
||||
assertThat(captor.getValue())
|
||||
.isEqualTo("System usage for 4 pm-7 am");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshCategoryTitle_allComponents_setLast24HrIntoBothTitleTextView() {
|
||||
mBatteryChartPreferenceController.mCategoryTitleType =
|
||||
BatteryChartPreferenceController.CategoryTitleType.TYPE_ALL_COMPONENTS;
|
||||
mBatteryChartPreferenceController.mExpandDividerPreference =
|
||||
mExpandDividerPreference;
|
||||
// Simulates select all condition.
|
||||
mBatteryChartPreferenceController.mTrapezoidIndex =
|
||||
BatteryChartView.SELECTED_INDEX_ALL;
|
||||
|
||||
mBatteryChartPreferenceController.refreshCategoryTitle();
|
||||
|
||||
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
|
||||
// Verifies the title in the preference group.
|
||||
verify(mAppListGroup).setTitle(captor.capture());
|
||||
assertThat(captor.getValue())
|
||||
.isEqualTo("App usage for past 24 hr");
|
||||
// Verifies the title in the expandable divider.
|
||||
captor = ArgumentCaptor.forClass(String.class);
|
||||
verify(mExpandDividerPreference).setTitle(captor.capture());
|
||||
assertThat(captor.getValue())
|
||||
.isEqualTo("System usage for past 24 hr");
|
||||
}
|
||||
|
||||
private static Map<Long, List<BatteryHistEntry>> createBatteryHistoryMap(int size) {
|
||||
final Map<Long, List<BatteryHistEntry>> batteryHistoryMap = new HashMap<>();
|
||||
for (int index = 0; index < size; index++) {
|
||||
@@ -497,4 +588,13 @@ public final class BatteryChartPreferenceControllerTest {
|
||||
mContext, foregroundUsageTimeInMs, backgroundUsageTimeInMs,
|
||||
/*consumePower=*/ 0, mBatteryHistEntry);
|
||||
}
|
||||
|
||||
private void setUpBatteryHistoryKeys() {
|
||||
mBatteryChartPreferenceController.mBatteryHistoryKeys =
|
||||
new long[] {1619196786769L, 0L, 1619247636826L};
|
||||
ConvertUtils.utcToLocalTimeHour(/*timestamp=*/ 0);
|
||||
// Simulates the locale in GMT.
|
||||
ConvertUtils.sSimpleDateFormatForHour
|
||||
.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
}
|
||||
}
|
||||
|
@@ -263,10 +263,10 @@ public final class ConvertUtilsTest {
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTime(/*timestamp=*/ 0);
|
||||
ConvertUtils.sSimpleDateFormat
|
||||
.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
|
||||
assertThat(ConvertUtils.utcToLocalTime(timestamp))
|
||||
.isEqualTo("Apr 23,2021 16:53:06");
|
||||
.isEqualTo("Apr 23,2021 09:53:06");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -276,10 +276,10 @@ public final class ConvertUtilsTest {
|
||||
// Invokes the method first to create the SimpleDateFormat.
|
||||
ConvertUtils.utcToLocalTimeHour(/*timestamp=*/ 0);
|
||||
ConvertUtils.sSimpleDateFormatForHour
|
||||
.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||
.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||
|
||||
assertThat(ConvertUtils.utcToLocalTimeHour(timestamp))
|
||||
.isEqualTo("4 pm");
|
||||
.isEqualTo("9 am");
|
||||
}
|
||||
|
||||
private static BatteryHistEntry createBatteryHistEntry(
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.fuelgauge;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -35,7 +36,7 @@ import com.android.settings.R;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
@@ -46,13 +47,15 @@ public final class ExpandDividerPreferenceTest {
|
||||
private Context mContext;
|
||||
private ExpandDividerPreference mExpandDividerPreference;
|
||||
|
||||
@Mock private ImageView mImageView;
|
||||
@Mock private TextView mTextView;
|
||||
private ImageView mImageView;
|
||||
private TextView mTextView;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mImageView = spy(new ImageView(mContext));
|
||||
mTextView = spy(new TextView(mContext));
|
||||
mExpandDividerPreference = new ExpandDividerPreference(mContext);
|
||||
doReturn(R.id.expand_title).when(mTextView).getId();
|
||||
doReturn(R.id.expand_icon).when(mImageView).getId();
|
||||
@@ -72,6 +75,9 @@ public final class ExpandDividerPreferenceTest {
|
||||
mExpandDividerPreference.mTextView = mTextView;
|
||||
|
||||
mExpandDividerPreference.setTitle(titleContent);
|
||||
final ArgumentCaptor<Runnable> captor = ArgumentCaptor.forClass(Runnable.class);
|
||||
verify(mTextView).postDelayed(captor.capture(), eq(50L));
|
||||
captor.getValue().run();
|
||||
verify(mTextView).setText(titleContent);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user