Search in sources :

Example 16 with ShadowAlertDialogCompat

use of com.android.settings.testutils.shadow.ShadowAlertDialogCompat in project android_packages_apps_Settings by DirtyUnicorns.

the class BatteryTipDialogFragmentTest method testOnCreateDialog_restrictSixAppsTip_fireRestrictSixAppsDialog.

@Test
public void testOnCreateDialog_restrictSixAppsTip_fireRestrictSixAppsDialog() {
    Robolectric.getForegroundThreadScheduler().pause();
    final List<AppInfo> appInfos = new ArrayList<>();
    for (int i = 0; i < 6; i++) {
        appInfos.add(mAppInfo);
    }
    final RestrictAppTip restrictSixAppsTip = new RestrictAppTip(BatteryTip.StateType.NEW, appInfos);
    mDialogFragment = BatteryTipDialogFragment.newInstance(restrictSixAppsTip, METRICS_KEY);
    FragmentController.setupFragment(mDialogFragment, FragmentActivity.class, 0, /* containerViewId */
    null);
    Robolectric.getForegroundThreadScheduler().advanceToLastPostedRunnable();
    final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
    ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
    assertThat(shadowDialog.getTitle()).isEqualTo("Restrict 6 apps?");
    assertThat(shadowDialog.getMessage()).isEqualTo("To save battery, stop these apps from using battery in the background. " + "Restricted apps may not work properly and notifications may be" + " delayed.\n\nApps:\napp, app, app, app, app, and app.");
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) RestrictAppTip(com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip) ArrayList(java.util.ArrayList) ShadowAlertDialogCompat(com.android.settings.testutils.shadow.ShadowAlertDialogCompat) Test(org.junit.Test)

Example 17 with ShadowAlertDialogCompat

use of com.android.settings.testutils.shadow.ShadowAlertDialogCompat in project android_packages_apps_Settings by DirtyUnicorns.

the class BatteryTipDialogFragmentTest method testOnCreateDialog_highUsageTip_fireHighUsageDialog.

@Test
public void testOnCreateDialog_highUsageTip_fireHighUsageDialog() {
    Robolectric.getForegroundThreadScheduler().pause();
    mDialogFragment = BatteryTipDialogFragment.newInstance(mHighUsageTip, METRICS_KEY);
    FragmentController.setupFragment(mDialogFragment, FragmentActivity.class, 0, /* containerViewId */
    null);
    Robolectric.getForegroundThreadScheduler().advanceToLastPostedRunnable();
    final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
    ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
    assertThat(shadowDialog.getMessage()).isEqualTo(mContext.getString(R.string.battery_tip_dialog_message, 1));
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ShadowAlertDialogCompat(com.android.settings.testutils.shadow.ShadowAlertDialogCompat) Test(org.junit.Test)

Example 18 with ShadowAlertDialogCompat

use of com.android.settings.testutils.shadow.ShadowAlertDialogCompat in project android_packages_apps_Settings by DirtyUnicorns.

the class ButtonActionDialogFragmentTest method testOnCreateDialog_specialDisableDialog.

@Test
public void testOnCreateDialog_specialDisableDialog() {
    ButtonActionDialogFragment fragment = ButtonActionDialogFragment.newInstance(SPECIAL_DISABLE_ID);
    FragmentController.setupFragment(fragment, FragmentActivity.class, 0, /* containerViewId */
    null);
    final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
    assertThat(dialog).isNotNull();
    ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
    assertThat(shadowDialog.getMessage()).isEqualTo(mShadowContext.getString(R.string.app_disable_dlg_text));
    assertThat(dialog.getButton(DialogInterface.BUTTON_POSITIVE).getText()).isEqualTo(mShadowContext.getString(R.string.app_disable_dlg_positive));
    assertThat(dialog.getButton(DialogInterface.BUTTON_NEGATIVE).getText()).isEqualTo(mShadowContext.getString(R.string.dlg_cancel));
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ShadowAlertDialogCompat(com.android.settings.testutils.shadow.ShadowAlertDialogCompat) Test(org.junit.Test)

Example 19 with ShadowAlertDialogCompat

use of com.android.settings.testutils.shadow.ShadowAlertDialogCompat in project android_packages_apps_Settings by DirtyUnicorns.

the class LocaleListEditorTest method showRemoveLocaleWarningDialog_mainLocaleNotSelected_shouldShowConfirmDialog.

@Test
public void showRemoveLocaleWarningDialog_mainLocaleNotSelected_shouldShowConfirmDialog() {
    // pre-condition
    when(mAdapter.getCheckedCount()).thenReturn(1);
    when(mAdapter.getItemCount()).thenReturn(2);
    when(mAdapter.isFirstLocaleChecked()).thenReturn(false);
    ReflectionHelpers.setField(mLocaleListEditor, "mRemoveMode", true);
    ReflectionHelpers.setField(mLocaleListEditor, "mShowingRemoveDialog", true);
    // launch dialog
    mLocaleListEditor.showRemoveLocaleWarningDialog();
    final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
    assertThat(dialog).isNotNull();
    final ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
    assertThat(shadowDialog.getMessage()).isNull();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ShadowAlertDialogCompat(com.android.settings.testutils.shadow.ShadowAlertDialogCompat) Test(org.junit.Test)

Example 20 with ShadowAlertDialogCompat

use of com.android.settings.testutils.shadow.ShadowAlertDialogCompat in project android_packages_apps_Settings by DirtyUnicorns.

the class LocaleListEditorTest method showRemoveLocaleWarningDialog_allLocaleSelected_shouldShowErrorDialog.

@Test
public void showRemoveLocaleWarningDialog_allLocaleSelected_shouldShowErrorDialog() {
    // pre-condition
    when(mAdapter.getCheckedCount()).thenReturn(1);
    when(mAdapter.getItemCount()).thenReturn(1);
    when(mAdapter.isFirstLocaleChecked()).thenReturn(true);
    ReflectionHelpers.setField(mLocaleListEditor, "mRemoveMode", true);
    ReflectionHelpers.setField(mLocaleListEditor, "mShowingRemoveDialog", true);
    // launch dialog
    mLocaleListEditor.showRemoveLocaleWarningDialog();
    final AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
    assertThat(dialog).isNotNull();
    final ShadowAlertDialogCompat shadowDialog = ShadowAlertDialogCompat.shadowOf(dialog);
    assertThat(shadowDialog.getTitle()).isEqualTo(mContext.getString(R.string.dlg_remove_locales_error_title));
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) ShadowAlertDialogCompat(com.android.settings.testutils.shadow.ShadowAlertDialogCompat) Test(org.junit.Test)

Aggregations

AlertDialog (androidx.appcompat.app.AlertDialog)496 ShadowAlertDialogCompat (com.android.settings.testutils.shadow.ShadowAlertDialogCompat)496 Test (org.junit.Test)496 BatteryTipDialogFragment (com.android.settings.fuelgauge.batterytip.BatteryTipDialogFragment)28 Intent (android.content.Intent)14 Bundle (android.os.Bundle)14 RestrictAppTip (com.android.settings.fuelgauge.batterytip.tips.RestrictAppTip)14 OnLockTypeSelectedListener (com.android.settings.password.ChooseLockTypeDialogFragment.OnLockTypeSelectedListener)14 PartnerCustomizationLayout (com.google.android.setupcompat.PartnerCustomizationLayout)14 ArrayList (java.util.ArrayList)14 Config (org.robolectric.annotation.Config)14