Search in sources :

Example 56 with RoboMenuItem

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

the class FormEntryMenuDelegateTest method onItemSelected_whenAddRepeat_savesScreenAnswers.

@Test
public void onItemSelected_whenAddRepeat_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_add_repeat));
    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 57 with RoboMenuItem

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

the class FormEntryMenuDelegateTest method onItemSelected_whenAddRepeat_whenRecording_showsWarning.

@Test
public void onItemSelected_whenAddRepeat_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_add_repeat));
    verify(formEntryViewModel, never()).promptForNewRepeat();
    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)

Example 58 with RoboMenuItem

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

the class BlankFormListMenuDelegateTest method onOptionsSelected_forSync_showsSuccessToast.

@Test
public void onOptionsSelected_forSync_showsSuccessToast() {
    when(viewModel.syncWithServer()).thenReturn(new MutableLiveData<>(true));
    BlankFormListMenuDelegate menuDelegate = new BlankFormListMenuDelegate(activity, viewModel, networkStateProvider);
    menuDelegate.onOptionsItemSelected(new RoboMenuItem(R.id.menu_refresh));
    assertThat(ShadowToast.getTextOfLatestToast(), is(activity.getString(R.string.form_update_succeeded)));
}
Also used : RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Example 59 with RoboMenuItem

use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.

the class WebFragmentTest method testWebControls.

@SuppressLint("NewApi")
@Test
public void testWebControls() {
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    ShadowWebView shadowWebView = (ShadowWebView) ShadowExtractor.extract(activity.findViewById(R.id.web_view));
    activity.findViewById(R.id.button_more).performClick();
    shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_zoom_in));
    assertThat(shadowWebView.getZoomDegree()).isEqualTo(1);
    activity.findViewById(R.id.button_more).performClick();
    shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_zoom_out));
    assertThat(shadowWebView.getZoomDegree()).isEqualTo(0);
    activity.findViewById(R.id.button_forward).performClick();
    assertThat(shadowWebView.getPageIndex()).isEqualTo(1);
    activity.findViewById(R.id.button_back).performClick();
    assertThat(shadowWebView.getPageIndex()).isEqualTo(0);
}
Also used : ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) Intent(android.content.Intent) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test) SuppressLint(android.annotation.SuppressLint)

Example 60 with RoboMenuItem

use of org.robolectric.fakes.RoboMenuItem in project materialistic by hidroh.

the class WebFragmentTest method testReadabilityToggle.

@Test
public void testReadabilityToggle() {
    activity.fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_readability));
    verify(readabilityClient).parse(any(), eq("http://example.com"), any());
}
Also used : 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