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

Commit 845e2135 authored by Ben Lin's avatar Ben Lin
Browse files

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
parent f52ff285
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -268,6 +268,7 @@ public class DashboardSummary extends InstrumentedFragment
        mSummaryLoader.updateSummaryToCache(category);
        mStagingCategory = category;
        if (mSuggestionControllerMixin == null) {
            mAdapter.setCategory(mStagingCategory);
            return;
        }
        if (mSuggestionControllerMixin.isSuggestionLoaded()) {
+21 −0
Original line number Diff line number Diff line
@@ -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