Search in sources :

Example 51 with RoboMenuItem

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")));
}
Also used : Intent(android.content.Intent) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Example 52 with RoboMenuItem

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/*"));
}
Also used : ShadowActivity(org.robolectric.shadows.ShadowActivity) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Example 53 with RoboMenuItem

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());
}
Also used : RoboMenuItem(org.robolectric.fakes.RoboMenuItem) ErrorIntentLauncher(org.odk.collect.testshared.ErrorIntentLauncher) Test(org.junit.Test)

Example 54 with RoboMenuItem

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));
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) ShadowActivity(org.robolectric.shadows.ShadowActivity) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Example 55 with RoboMenuItem

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);
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Aggregations

RoboMenuItem (org.robolectric.fakes.RoboMenuItem)127 Test (org.junit.Test)120 MenuItem (android.view.MenuItem)72 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)23 TargetApi (android.annotation.TargetApi)18 PopupMenu (android.widget.PopupMenu)18 ShadowPopupMenu (org.robolectric.shadows.ShadowPopupMenu)18 RoboMenu (org.robolectric.fakes.RoboMenu)12 Context (android.content.Context)11 Intent (android.content.Intent)9 Before (org.junit.Before)7 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)6 SuppressLint (android.annotation.SuppressLint)4 WebView (android.webkit.WebView)3 TestItem (io.github.hidroh.materialistic.test.TestItem)3 ShadowWebView (io.github.hidroh.materialistic.test.shadow.ShadowWebView)3 IOException (java.io.IOException)3 ShadowActivity (org.robolectric.shadows.ShadowActivity)3 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)2