@Test public void skipLogin() { ((TextView) loginActivity.findViewById(R.id.skipLogin)).performClick(); AlertDialog latestAlertDialog = ShadowAlertDialog.getLatestAlertDialog(); ShadowAlertDialog dialog = Robolectric.shadowOf(latestAlertDialog); assertEquals(loginActivity.getString(R.string.noLoginWarn), dialog.getMessage()); assertTrue(latestAlertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick()); assertNextActivity(loginActivity, StackNetworkListActivity.class); }
@Test public void skipLoginAndCancel() { ShadowActivity shadowActivity = Robolectric.shadowOf(loginActivity); ((TextView) loginActivity.findViewById(R.id.skipLogin)).performClick(); AlertDialog latestAlertDialog = ShadowAlertDialog.getLatestAlertDialog(); ShadowAlertDialog dialog = Robolectric.shadowOf(latestAlertDialog); assertEquals(loginActivity.getString(R.string.noLoginWarn), dialog.getMessage()); assertTrue(latestAlertDialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick()); assertNull(shadowActivity.getNextStartedActivity()); }
@Test @Ignore("Robolectric does not work with appcompact AlertDialogs yet") public void shouldOpenAboutBoxWhenAboutButtonFromMainMenuSelected() { MenuItem item = new RoboMenuItem(R.id.main_menu_about); activity.onOptionsItemSelected(item); ShadowActivity shadowActivity = shadowOf(activity); Intent startedIntent = shadowActivity.getNextStartedActivity(); assertNull(startedIntent); AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog(); ShadowAlertDialog shadowDialog = shadowOf(dialog); assertEquals("Helsinki Testbed Viewer 2.0.13", shadowDialog.getTitle()); }
@Test public void shouldShowMovementTypeDialogOnClick() { viewModel.setDraft(true); viewHolder.populate(viewModel, stockCard); viewHolder.txReason.performClick(); AlertDialog typeDialog = ShadowAlertDialog.getLatestAlertDialog(); assertNotNull(typeDialog); }