Set categories to the adapter if suggestion is not available.

If there's no suggestion, we should set the category to the adapter
before returning.

Bug: none
Test: robotests
Change-Id: I73bb248d17edb3c398a9fb0a8f3913e7233fcc0b
This commit is contained in:
Ben Lin
2018-02-05 15:58:58 -08:00
parent f52ff28511
commit 845e213514
2 changed files with 22 additions and 0 deletions

View File

@@ -268,6 +268,7 @@ public class DashboardSummary extends InstrumentedFragment
mSummaryLoader.updateSummaryToCache(category);
mStagingCategory = category;
if (mSuggestionControllerMixin == null) {
mAdapter.setCategory(mStagingCategory);
return;
}
if (mSuggestionControllerMixin.isSuggestionLoaded()) {

View File

@@ -67,6 +67,8 @@ public class DashboardSummaryTest {
private ConditionManager mConditionManager;
@Mock
private SummaryLoader mSummaryLoader;
@Mock
private SuggestionControllerMixin mSuggestionControllerMixin;
private Context mContext;
private DashboardSummary mSummary;
@@ -111,12 +113,31 @@ public class DashboardSummaryTest {
@Test
public void updateCategory_shouldGetCategoryFromFeatureProvider() {
ReflectionHelpers.setField(mSummary, "mSuggestionControllerMixin",
mSuggestionControllerMixin);
when(mSuggestionControllerMixin.isSuggestionLoaded()).thenReturn(true);
doReturn(mock(Activity.class)).when(mSummary).getActivity();
mSummary.onAttach(mContext);
mSummary.updateCategory();
verify(mSummaryLoader).updateSummaryToCache(nullable(DashboardCategory.class));
verify(mDashboardFeatureProvider).getTilesForCategory(CategoryKey.CATEGORY_HOMEPAGE);
verify(mAdapter).setCategory(any());
}
@Test
public void updateCategory_shouldGetCategoryFromFeatureProvider_evenIfSuggestionDisabled() {
when(mFeatureFactory.suggestionsFeatureProvider.isSuggestionEnabled(any(Context.class)))
.thenReturn(false);
doReturn(mock(Activity.class)).when(mSummary).getActivity();
mSummary.onAttach(mContext);
mSummary.updateCategory();
verify(mSummaryLoader).updateSummaryToCache(nullable(DashboardCategory.class));
verify(mDashboardFeatureProvider).getTilesForCategory(CategoryKey.CATEGORY_HOMEPAGE);
verify(mAdapter).setCategory(any());
}
@Test