Search in sources :

Example 21 with RoboMenu

use of org.robolectric.fakes.RoboMenu in project collect by opendatakit.

the class FormEntryMenuDelegateTest method onItemSelected_whenHierarchy_startsHierarchyActivity.

@Test
public void onItemSelected_whenHierarchy_startsHierarchyActivity() {
    RoboMenu menu = new RoboMenu();
    formEntryMenuDelegate.onCreateOptionsMenu(Robolectric.setupActivity(FragmentActivity.class).getMenuInflater(), menu);
    formEntryMenuDelegate.onPrepareOptionsMenu(menu);
    formEntryMenuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_goto));
    ShadowActivity.IntentForResult nextStartedActivity = shadowOf(activity).getNextStartedActivityForResult();
    assertThat(nextStartedActivity, not(nullValue()));
    assertThat(nextStartedActivity.intent.getComponent().getClassName(), is(FormHierarchyActivity.class.getName()));
    assertThat(nextStartedActivity.requestCode, is(ApplicationConstants.RequestCodes.HIERARCHY_ACTIVITY));
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) ShadowActivity(org.robolectric.shadows.ShadowActivity) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Example 22 with RoboMenu

use of org.robolectric.fakes.RoboMenu in project collect by opendatakit.

the class FormEntryMenuDelegateTest method onPrepare_whenFormHasBackgroundRecording_showsRecordAudio.

@Test
public void onPrepare_whenFormHasBackgroundRecording_showsRecordAudio() {
    when(formEntryViewModel.hasBackgroundRecording()).thenReturn(new MutableNonNullLiveData<>(true));
    RoboMenu menu = new RoboMenu();
    formEntryMenuDelegate.onCreateOptionsMenu(Robolectric.setupActivity(FragmentActivity.class).getMenuInflater(), menu);
    formEntryMenuDelegate.onPrepareOptionsMenu(menu);
    assertThat(menu.findItem(R.id.menu_record_audio).isVisible(), equalTo(true));
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) Test(org.junit.Test)

Example 23 with RoboMenu

use of org.robolectric.fakes.RoboMenu in project collect by opendatakit.

the class FormEntryMenuDelegateTest method onItemSelected_whenAddRepeat_whenRecordingInTheBackground_doesNotShowWarning.

@Test
public void onItemSelected_whenAddRepeat_whenRecordingInTheBackground_doesNotShowWarning() {
    RoboMenu menu = new RoboMenu();
    formEntryMenuDelegate.onCreateOptionsMenu(Robolectric.setupActivity(FragmentActivity.class).getMenuInflater(), menu);
    formEntryMenuDelegate.onPrepareOptionsMenu(menu);
    when(audioRecorder.isRecording()).thenReturn(true);
    when(backgroundAudioViewModel.isBackgroundRecording()).thenReturn(true);
    formEntryMenuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_add_repeat));
    verify(formEntryViewModel).promptForNewRepeat();
    RecordingWarningDialogFragment dialog = getFragmentByClass(activity.getSupportFragmentManager(), RecordingWarningDialogFragment.class);
    assertThat(dialog, is(nullValue()));
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Example 24 with RoboMenu

use of org.robolectric.fakes.RoboMenu in project collect by opendatakit.

the class FormEntryMenuDelegateTest method onPrepare_inRepeatQuestion_showsAddRepeat.

@Test
public void onPrepare_inRepeatQuestion_showsAddRepeat() {
    when(formEntryViewModel.canAddRepeat()).thenReturn(true);
    RoboMenu menu = new RoboMenu();
    formEntryMenuDelegate.onCreateOptionsMenu(Robolectric.setupActivity(FragmentActivity.class).getMenuInflater(), menu);
    formEntryMenuDelegate.onPrepareOptionsMenu(menu);
    assertThat(menu.findItem(R.id.menu_add_repeat).isVisible(), equalTo(true));
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) Test(org.junit.Test)

Example 25 with RoboMenu

use of org.robolectric.fakes.RoboMenu in project collect by opendatakit.

the class FormEntryMenuDelegateTest method onItemSelected_whenPreferences_whenRecording_showsWarning.

@Test
public void onItemSelected_whenPreferences_whenRecording_showsWarning() {
    RoboMenu menu = new RoboMenu();
    formEntryMenuDelegate.onCreateOptionsMenu(Robolectric.setupActivity(FragmentActivity.class).getMenuInflater(), menu);
    formEntryMenuDelegate.onPrepareOptionsMenu(menu);
    when(audioRecorder.isRecording()).thenReturn(true);
    formEntryMenuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_preferences));
    assertThat(shadowOf(activity).getNextStartedActivityForResult(), is(nullValue()));
    RecordingWarningDialogFragment dialog = getFragmentByClass(activity.getSupportFragmentManager(), RecordingWarningDialogFragment.class);
    assertThat(dialog, is(notNullValue()));
    assertThat(dialog.getDialog().isShowing(), is(true));
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Aggregations

RoboMenu (org.robolectric.fakes.RoboMenu)33 Test (org.junit.Test)31 MenuInflater (android.view.MenuInflater)14 MenuItem (android.view.MenuItem)12 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)12 Fragment (android.app.Fragment)6 FragmentManager (android.app.FragmentManager)6 FragmentTransaction (android.app.FragmentTransaction)6 Bundle (android.os.Bundle)2 FragmentManager (androidx.fragment.app.FragmentManager)2 FragmentTransaction (androidx.fragment.app.FragmentTransaction)2 HashMap (java.util.HashMap)2 Before (org.junit.Before)2 ShadowActivity (org.robolectric.shadows.ShadowActivity)2