* Create data for the adapter. If there is already data in the adapter, they will be
* destroyed and recreated.
*/
- private void refreshData() {
+ void refreshData() {
mSupportData.clear();
addEscalationCards();
addMoreHelpItems();
/**
* Data for a single support item.
*/
- private static class SupportData {
+ @VisibleForTesting
+ static class SupportData {
final Intent intent;
final int metricsEvent;
/**
* Data model for escalation cards.
*/
- private static class EscalationData extends SupportData {
+ @VisibleForTesting
+ static class EscalationData extends SupportData {
@StringRes
final int text1;
}
}
}
+
+ @VisibleForTesting
+ List<SupportData> getSupportData() {
+ return mSupportData;
+ }
}
import android.accounts.Account;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.widget.SpinnerAdapter;
import com.android.settings.TestConfig;
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
+import com.android.settings.dashboard.SupportItemAdapter.EscalationData;
import com.android.settings.overlay.SupportFeatureProvider;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.android.settings.R;
import org.robolectric.shadows.ShadowActivity;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.verify;
import static org.robolectric.Shadows.shadowOf;
import static org.mockito.Mockito.when;
verify(mSupportFeatureProvider).getSupportEligibleAccounts(mActivity);
}
+ @Test
+ public void testRefreshData_CardUpdatedOnEnteringOrLeavingSupportHours() {
+ // pretend we have support right now
+ when(mSupportFeatureProvider.isSupportTypeEnabled(any(), anyInt()))
+ .thenReturn(true);
+ when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
+ when(mSupportFeatureProvider.getSupportEligibleAccounts(any())).thenReturn(ONE_ACCOUNT);
+ mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider,
+ mMetricsFeatureProvider, null);
+
+ // If this doesn't return escalation data something has gone wrong
+ EscalationData data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
+
+ // precondition, support is enabled
+ assertThat(data.enabled1).isTrue();
+
+ // pretend we support hours are over
+ when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(false);
+ mSupportItemAdapter.refreshData();
+ data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
+
+ assertThat(data.enabled1).isFalse();
+
+ // pretend support hours have started again
+ when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
+ mSupportItemAdapter.refreshData();
+ data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
+
+ assertThat(data.enabled1).isTrue();
+ }
+
/**
* Check after {@link SupportItemAdapter#bindAccountPicker(SupportItemAdapter.ViewHolder)} is
* invoked, whether the spinner in {@paramref viewHolder} has all the data from {@paramref