use of org.robolectric.fakes.RoboMenuItem in project collect by opendatakit.
the class QRCodeMenuDelegateTest method clickingOnShare_whenQRCodeIsGenerated_startsShareIntent.
@Test
public void clickingOnShare_whenQRCodeIsGenerated_startsShareIntent() throws Exception {
when(qrCodeGenerator.generateQRCode(any(), any())).thenReturn("qr.png");
when(fileProvider.getURIForFile("qr.png")).thenReturn(Uri.parse("uri"));
fakeScheduler.runBackground();
menuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_item_share));
Intent intent = shadowOf(activity).getNextStartedActivity();
assertThat(intent, notNullValue());
assertThat(intent.getAction(), is(Intent.ACTION_SEND));
assertThat(intent.getType(), is("image/*"));
assertThat(intent.getExtras().getParcelable(Intent.EXTRA_STREAM), is(Uri.parse("uri")));
}
use of org.robolectric.fakes.RoboMenuItem in project collect by opendatakit.
the class QRCodeMenuDelegateTest method clickingOnImportQRCode_startsExternalImagePickerIntent.
@Test
public void clickingOnImportQRCode_startsExternalImagePickerIntent() {
menuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_item_scan_sd_card));
ShadowActivity.IntentForResult intentForResult = shadowOf(activity).getNextStartedActivityForResult();
assertThat(intentForResult, notNullValue());
assertThat(intentForResult.requestCode, is(SELECT_PHOTO));
assertThat(intentForResult.intent.getAction(), is(Intent.ACTION_GET_CONTENT));
assertThat(intentForResult.intent.getType(), is("image/*"));
}
use of org.robolectric.fakes.RoboMenuItem in project collect by opendatakit.
the class QRCodeMenuDelegateTest method clickingOnImportQRCode_whenPickerActivityNotAvailable_showsToast.
@Test
public void clickingOnImportQRCode_whenPickerActivityNotAvailable_showsToast() {
intentLauncher = new ErrorIntentLauncher();
setupMenuDelegate();
menuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_item_scan_sd_card));
assertThat(shadowOf(activity).getNextStartedActivityForResult(), is(nullValue()));
assertThat(ShadowToast.getLatestToast(), notNullValue());
}
use of org.robolectric.fakes.RoboMenuItem in project collect by opendatakit.
the class FormEntryMenuDelegateTest method onItemSelected_whenPreferences_startsPreferencesActivityWithChangeSettingsRequest.
@Test
public void onItemSelected_whenPreferences_startsPreferencesActivityWithChangeSettingsRequest() {
RoboMenu menu = new RoboMenu();
formEntryMenuDelegate.onCreateOptionsMenu(Robolectric.setupActivity(FragmentActivity.class).getMenuInflater(), menu);
formEntryMenuDelegate.onPrepareOptionsMenu(menu);
formEntryMenuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_preferences));
ShadowActivity.IntentForResult nextStartedActivity = shadowOf(activity).getNextStartedActivityForResult();
assertThat(nextStartedActivity, not(nullValue()));
assertThat(nextStartedActivity.intent.getComponent().getClassName(), is(ProjectPreferencesActivity.class.getName()));
assertThat(nextStartedActivity.requestCode, is(ApplicationConstants.RequestCodes.CHANGE_SETTINGS));
}
use of org.robolectric.fakes.RoboMenuItem in project collect by opendatakit.
the class FormEntryMenuDelegateTest method onItemSelected_whenRecordAudio_whenBackgroundRecordingDisabled_enablesBackgroundRecording_andShowsDialog.
@Test
public void onItemSelected_whenRecordAudio_whenBackgroundRecordingDisabled_enablesBackgroundRecording_andShowsDialog() {
RoboMenu menu = new RoboMenu();
formEntryMenuDelegate.onCreateOptionsMenu(Robolectric.setupActivity(FragmentActivity.class).getMenuInflater(), menu);
formEntryMenuDelegate.onPrepareOptionsMenu(menu);
when(backgroundAudioViewModel.isBackgroundRecordingEnabled()).thenReturn(new MutableNonNullLiveData<>(false));
formEntryMenuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_record_audio));
verify(backgroundAudioViewModel).setBackgroundRecordingEnabled(true);
}
Aggregations