Search in sources :

Example 26 with RoboMenu

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

the class FormEntryMenuDelegateTest method onItemSelected_whenHierarchy_savesScreenAnswers.

@Test
public void onItemSelected_whenHierarchy_savesScreenAnswers() {
    RoboMenu menu = new RoboMenu();
    formEntryMenuDelegate.onCreateOptionsMenu(Robolectric.setupActivity(FragmentActivity.class).getMenuInflater(), menu);
    formEntryMenuDelegate.onPrepareOptionsMenu(menu);
    HashMap answers = new HashMap();
    when(answersProvider.getAnswers()).thenReturn(answers);
    formEntryMenuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_goto));
    verify(formSaveViewModel).saveAnswersForScreen(answers);
}
Also used : HashMap(java.util.HashMap) RoboMenu(org.robolectric.fakes.RoboMenu) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Example 27 with RoboMenu

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

the class FormEntryMenuDelegateTest method onItemSelected_whenHierarchy_callsOpenHierarchy.

@Test
public void onItemSelected_whenHierarchy_callsOpenHierarchy() {
    RoboMenu menu = new RoboMenu();
    formEntryMenuDelegate.onCreateOptionsMenu(Robolectric.setupActivity(FragmentActivity.class).getMenuInflater(), menu);
    formEntryMenuDelegate.onPrepareOptionsMenu(menu);
    formEntryMenuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_goto));
    verify(formEntryViewModel).openHierarchy();
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Example 28 with RoboMenu

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

the class FormEntryMenuDelegateTest method onItemSelected_whenHierarchy_whenRecordingInBackground_doesNotShowWarning.

@Test
public void onItemSelected_whenHierarchy_whenRecordingInBackground_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_goto));
    assertThat(shadowOf(activity).getNextStartedActivity(), is(notNullValue()));
    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 29 with RoboMenu

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

the class FormEntryMenuDelegateTest method onItemSelected_whenAddRepeat_callsPromptForNewRepeat.

@Test
public void onItemSelected_whenAddRepeat_callsPromptForNewRepeat() {
    RoboMenu menu = new RoboMenu();
    formEntryMenuDelegate.onCreateOptionsMenu(Robolectric.setupActivity(FragmentActivity.class).getMenuInflater(), menu);
    formEntryMenuDelegate.onPrepareOptionsMenu(menu);
    formEntryMenuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_add_repeat));
    verify(formEntryViewModel).promptForNewRepeat();
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Example 30 with RoboMenu

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

the class FormEntryMenuDelegateTest method onPrepare_whenNotRecordingInBackground_unchecksRecordAudio.

@Test
public void onPrepare_whenNotRecordingInBackground_unchecksRecordAudio() {
    when(backgroundAudioViewModel.isBackgroundRecordingEnabled()).thenReturn(new MutableNonNullLiveData<>(false));
    RoboMenu menu = new RoboMenu();
    formEntryMenuDelegate.onCreateOptionsMenu(Robolectric.setupActivity(FragmentActivity.class).getMenuInflater(), menu);
    formEntryMenuDelegate.onPrepareOptionsMenu(menu);
    assertThat(menu.findItem(R.id.menu_record_audio).isChecked(), equalTo(false));
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) 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