org.robolectric.shadows.ShadowDialog Java Examples

The following examples show how to use org.robolectric.shadows.ShadowDialog. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NumericOptionItemTest.java    From msdkui-android with Apache License 2.0 6 votes vote down vote up
@Test
public void testValueEditDialogPositive() {
    int newValue = 10;
    mNumericOptionItem.setLabel(getString(R.string.msdkui_violate_truck_options));
    final TextView valueView = mNumericOptionItem.findViewById(R.id.numeric_item_value);

    assertNotNull(valueView);
    valueView.performClick();

    AlertDialog alertDialog = (AlertDialog) ShadowDialog.getLatestDialog();
    assertTrue(alertDialog.isShowing());

    EditText valueEdit = alertDialog.findViewById(R.id.numeric_item_value_text);
    valueEdit.setText(String.valueOf(newValue));
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertEquals(newValue, mNumericOptionItem.getValue().intValue());
}
 
Example #2
Source File: NavFloatingActionButtonTest.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Test
public void testKonami() {
    gestureListener.onFling(null, null, 0f, 1f); // down, invalid, should ignore

    gestureListener.onFling(null, null, 0f, -1f); // up
    gestureListener.onFling(null, null, 0f, 1f); // down, invalid, should reset

    gestureListener.onFling(null, null, 0f, -1f); // up
    gestureListener.onFling(null, null, 0f, -1f); // up
    gestureListener.onFling(null, null, 0f, 1f); // down
    gestureListener.onFling(null, null, 0f, 1f); // down
    gestureListener.onFling(null, null, -1f, 0f); // left
    gestureListener.onFling(null, null, 1f, 0f); // right
    gestureListener.onFling(null, null, -1f, 0f); // left
    gestureListener.onFling(null, null, 1f, 0f); // right
    gestureListener.onDoubleTap(null);
    Dialog dialog = ShadowDialog.getLatestDialog();
    assertNotNull(dialog);
    shadowOf(dialog).clickOn(android.R.id.button1); // BUTTON_POSITIVE
    assertThat(shadowOf(RuntimeEnvironment.application).getNextStartedActivity())
            .hasAction(Intent.ACTION_VIEW);
}
 
Example #3
Source File: DirectoryChooserFragmentTest.java    From droid-stealth with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testCreateDirectoryDialog() {
	final String directoryName = "mydir";
	final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance(
			directoryName, null);

	startFragment(fragment, DirectoryChooserActivityMock.class);

	fragment.onOptionsItemSelected(new TestMenuItem() {
		@Override
		public int getItemId() {
			return R.id.new_folder_item;
		}
	});

	final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog();
	final ShadowAlertDialog shadowAlertDialog = Robolectric.shadowOf(dialog);
	assertEquals(shadowAlertDialog.getTitle(), "Create folder");
	assertEquals(shadowAlertDialog.getMessage(), "Create new folder with name \"mydir\"?");
}
 
Example #4
Source File: NumericOptionItemTest.java    From msdkui-android with Apache License 2.0 5 votes vote down vote up
@Test
public void testValueEditDialogNegative() {
    mNumericOptionItem.setLabel(getString(R.string.msdkui_violate_truck_options));
    final TextView valueView = mNumericOptionItem.findViewById(R.id.numeric_item_value);

    assertNotNull(valueView);
    valueView.performClick();

    AlertDialog alertDialog = (AlertDialog) ShadowDialog.getLatestDialog();
    assertTrue(alertDialog.isShowing());

    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertFalse(alertDialog.isShowing());
}
 
Example #5
Source File: PreferencesActivityTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Test
public void testHelp() {
    ((PreferencesActivity.SettingsFragment) activity.getSupportFragmentManager()
            .findFragmentByTag(PreferencesActivity.SettingsFragment.class.getName()))
            .getPreferenceScreen()
            .findPreference(activity.getString(R.string.pref_volume_help))
            .performClick();
    Dialog dialog = ShadowDialog.getLatestDialog();
    assertNotNull(dialog);
    assertThat((TextView) dialog.findViewById(R.id.alertTitle))
            .hasText(R.string.pref_volume_title);
}
 
Example #6
Source File: PreferencesActivityTest.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Test
public void testLazyLoadHelp() {
    ((PreferencesActivity.SettingsFragment) activity.getSupportFragmentManager()
            .findFragmentByTag(PreferencesActivity.SettingsFragment.class.getName()))
            .getPreferenceScreen()
            .findPreference(activity.getString(R.string.pref_lazy_load_help))
            .performClick();
    Dialog dialog = ShadowDialog.getLatestDialog();
    assertNotNull(dialog);
    assertThat((TextView) dialog.findViewById(R.id.alertTitle))
            .hasText(R.string.pref_lazy_load_title);
}
 
Example #7
Source File: DirectoryChooserFragmentTest.java    From Android-DirectoryChooser with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateDirectoryDialogAllowFolderNameModification() {
    final String directoryName = "mydir";
    final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance(
            DirectoryChooserConfig.builder()
                    .newDirectoryName(directoryName)
                    .initialDirectory("")
                    .allowReadOnlyDirectory(false)
                    .allowNewDirectoryNameModification(true)
                    .build());

    startFragment(fragment, DirectoryChooserActivityMock.class);

    fragment.onOptionsItemSelected(new TestMenuItem() {
        @Override
        public int getItemId() {
            return R.id.new_folder_item;
        }
    });

    final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog();
    final ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(dialog);
    assertThat(shadowAlertDialog.getTitle()).isEqualTo("Create folder");
    assertThat(ShadowDialog.getShownDialogs()).contains(dialog);

    final TextView msgView = (TextView) dialog.findViewById(R.id.msgText);
    assertThat(msgView).hasText("Create new folder with name \"mydir\"?");

    final EditText editText = (EditText) dialog.findViewById(R.id.editText);
    assertThat(editText).isVisible();
    assertThat(editText).hasTextString(directoryName);
}
 
Example #8
Source File: DirectoryChooserFragmentTest.java    From Android-DirectoryChooser with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateDirectoryDialogDisallowFolderNameModification() {
    final String directoryName = "mydir";
    final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance(
            DirectoryChooserConfig.builder()
                    .newDirectoryName(directoryName)
                    .initialDirectory("")
                    .allowReadOnlyDirectory(false)
                    .allowNewDirectoryNameModification(false)
                    .build());

    startFragment(fragment, DirectoryChooserActivityMock.class);

    fragment.onOptionsItemSelected(new TestMenuItem() {
        @Override
        public int getItemId() {
            return R.id.new_folder_item;
        }
    });

    final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog();
    final ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(dialog);
    assertThat(shadowAlertDialog.getTitle()).isEqualTo("Create folder");
    assertThat(ShadowDialog.getShownDialogs()).contains(dialog);

    final TextView msgView = (TextView) dialog.findViewById(R.id.msgText);
    assertThat(msgView).hasText("Create new folder with name \"mydir\"?");

    final EditText editText = (EditText) dialog.findViewById(R.id.editText);
    assertThat(editText).isGone();
}
 
Example #9
Source File: WebFragmentLocalTest.java    From materialistic with Apache License 2.0 4 votes vote down vote up
@Test
public void testMenu() {
    TestWebItem item = new TestWebItem() {
        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }

        @Override
        public String getId() {
            return "1";
        }

        @Override
        public String getUrl() {
            return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
        }

        @Override
        public String getDisplayedTitle() {
            return "Ask HN";
        }
    };
    Intent intent = new Intent();
    intent.putExtra(WebActivity.EXTRA_ITEM, item);
    controller = Robolectric.buildActivity(WebActivity.class, intent);
    controller.create().start().resume().visible();
    activity = controller.get();
    verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
    listener.getValue().onResponse(new TestItem() {
        @Override
        public String getText() {
            return "text";
        }
    });
    Fragment fragment = activity.getSupportFragmentManager()
            .findFragmentByTag(WebFragment.class.getName());
    assertTrue(fragment.hasOptionsMenu());
    fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_font_options));
    assertNotNull(ShadowDialog.getLatestDialog());
    PreferenceManager.getDefaultSharedPreferences(activity)
            .edit()
            .putString(activity.getString(R.string.pref_readability_font), "DroidSans.ttf")
            .apply();
    WebView webView = activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = shadowOf(webView);
    shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
    assertThat(shadowWebView.getLastLoadDataWithBaseURL().data)
            .contains("text")
            .contains("DroidSans.ttf");
}
 
Example #10
Source File: ShadowAlertDialogSupport.java    From openwebnet-android with MIT License 4 votes vote down vote up
public static ShadowAlertDialogSupport getShadowAlertDialog(){
    ShadowDialog dialog = shadowOf(RuntimeEnvironment.application).getLatestDialog();
    AlertDialog alertDialog = getPrivateField(dialog, "realDialog", AlertDialog.class);
    AlertController alert = ReflectionHelpers.getField(alertDialog, "mAlert");
    return new ShadowAlertDialogSupport(alert);
}