Search in sources :

Example 6 with RoboMenu

use of org.robolectric.fakes.RoboMenu 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 7 with RoboMenu

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

the class FormEntryMenuDelegateTest method onPrepare_whenFormControllerIsNull_hidesAddRepeat.

@Test
public void onPrepare_whenFormControllerIsNull_hidesAddRepeat() {
    formEntryMenuDelegate.formLoaded(null);
    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(false));
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) Test(org.junit.Test)

Example 8 with RoboMenu

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

the class FormEntryMenuDelegateTest method onPrepare_whenFormDoesNotHaveBackgroundRecording_hidesRecordAudio.

@Test
public void onPrepare_whenFormDoesNotHaveBackgroundRecording_hidesRecordAudio() {
    when(formEntryViewModel.hasBackgroundRecording()).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).isVisible(), equalTo(false));
}
Also used : RoboMenu(org.robolectric.fakes.RoboMenu) Test(org.junit.Test)

Example 9 with RoboMenu

use of org.robolectric.fakes.RoboMenu 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)

Example 10 with RoboMenu

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

the class FormEntryMenuDelegateTest method onPrepare_whenBackgroundRecodingEnabled_checksRecordAudio.

@Test
public void onPrepare_whenBackgroundRecodingEnabled_checksRecordAudio() {
    when(backgroundAudioViewModel.isBackgroundRecordingEnabled()).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).isChecked(), equalTo(true));
}
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