Search in sources :

Example 61 with RoboMenuItem

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

the class ItemFragmentSinglePageTest method testVoteItemFailed.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItemFailed() {
    viewHolder.itemView.findViewById(R.id.button_more).performClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote));
    verify(userServices).voteUp(any(Context.class), any(), voteCallback.capture());
    voteCallback.getValue().onError(new IOException());
    assertEquals(activity.getString(R.string.vote_failed), ShadowToast.getTextOfLatestToast());
}
Also used : Context(android.content.Context) IOException(java.io.IOException) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) PopupMenu(android.widget.PopupMenu) ShadowPopupMenu(org.robolectric.shadows.ShadowPopupMenu) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 62 with RoboMenuItem

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

the class ListFragmentTest method testListMenu.

@Test
public void testListMenu() {
    Bundle args = new Bundle();
    args.putString(ListFragment.EXTRA_ITEM_MANAGER, HackerNewsClient.class.getName());
    args.putString(ListFragment.EXTRA_FILTER, ItemManager.TOP_FETCH_MODE);
    activity.getSupportFragmentManager().beginTransaction().add(android.R.id.list, Fragment.instantiate(activity, ListFragment.class.getName(), args), ListFragment.class.getName()).commit();
    activity.getSupportFragmentManager().findFragmentByTag(ListFragment.class.getName()).onOptionsItemSelected(new RoboMenuItem(R.id.menu_list));
    assertThat(activity.getSupportFragmentManager()).hasFragmentWithTag(PopupSettingsFragment.class.getName());
}
Also used : Bundle(android.os.Bundle) HackerNewsClient(io.github.hidroh.materialistic.data.HackerNewsClient) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 63 with RoboMenuItem

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

the class ReadabilityFragmentTest method testWebToggle.

@Test
public void testWebToggle() {
    fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_readability));
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    shadowOf(webView).getWebViewClient().onPageFinished(webView, "about:blank");
    assertThat(shadowOf(webView).getLastLoadedUrl()).isEqualTo("http://example.com/article.html");
}
Also used : WebView(android.webkit.WebView) ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Example 64 with RoboMenuItem

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

the class ReadabilityFragmentTest method testFullscreenMenu.

@SuppressLint("NewApi")
@Test
public void testFullscreenMenu() {
    verify(readabilityClient).parse(eq("1"), eq("http://example.com/article.html"), callback.capture());
    callback.getValue().onResponse("<div>content</div>");
    ShadowLocalBroadcastManager.getInstance(activity).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
    activity.findViewById(R.id.button_more).performClick();
    shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_font_options));
    assertThat(fragment.getFragmentManager()).hasFragmentWithTag(PopupSettingsFragment.class.getName());
}
Also used : Intent(android.content.Intent) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test) SuppressLint(android.annotation.SuppressLint)

Example 65 with RoboMenuItem

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

the class ItemActivityTest method testShare.

@SuppressLint("NewApi")
@Test
public void testShare() {
    TestApplication.addResolver(new Intent(Intent.ACTION_SEND));
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestItem() {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }

        @Override
        public String getUrl() {
            return "http://example.com";
        }

        @Override
        public boolean isStoryType() {
            return true;
        }

        @Override
        public String getId() {
            return "1";
        }
    });
    controller.withIntent(intent).create().start().resume();
    // inflate menu, see https://github.com/robolectric/robolectric/issues/1326
    ShadowLooper.pauseMainLooper();
    controller.visible();
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    // share article
    shadowOf(activity).clickMenuItem(R.id.menu_share);
    shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_article));
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    Intent actual = shadowOf(activity).getNextStartedActivity();
    assertThat(actual).hasAction(Intent.ACTION_SEND);
    // share item
    shadowOf(activity).clickMenuItem(R.id.menu_share);
    shadowOf(ShadowPopupMenu.getLatestPopupMenu()).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_comments));
    ShadowApplication.getInstance().getForegroundThreadScheduler().advanceToLastPostedRunnable();
    actual = shadowOf(activity).getNextStartedActivity();
    assertThat(actual).hasAction(Intent.ACTION_SEND);
}
Also used : NonNull(android.support.annotation.NonNull) Intent(android.content.Intent) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) TestItem(io.github.hidroh.materialistic.test.TestItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) SuppressLint(android.annotation.SuppressLint)

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