Search in sources :

Example 11 with RoboMenuItem

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

the class ListFragmentViewHolderTest method testVoteItem.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testVoteItem() {
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    adapter.getViewHolder(0).itemView.performLongClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    assertThat(popupMenu.getMenu().findItem(R.id.menu_contextual_vote).isVisible()).isFalse();
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_vote));
    verify(userServices).voteUp(any(Context.class), eq(item.getId()), voteCallback.capture());
}
Also used : Context(android.content.Context) 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 12 with RoboMenuItem

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

the class ListFragmentViewHolderTest method testRefresh.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testRefresh() {
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    reset(itemManager);
    adapter.getViewHolder(0).itemView.performLongClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_refresh));
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), any());
}
Also used : 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 13 with RoboMenuItem

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

the class ListFragmentViewHolderTest method testSaveItem.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Test
public void testSaveItem() {
    ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
    itemListener.getValue().onResponse(item);
    adapter.getViewHolder(0).itemView.performLongClick();
    PopupMenu popupMenu = ShadowPopupMenu.getLatestPopupMenu();
    assertNotNull(popupMenu);
    assertThat(popupMenu.getMenu().findItem(R.id.menu_contextual_save).isVisible()).isFalse();
    shadowOf(popupMenu).getOnMenuItemClickListener().onMenuItemClick(new RoboMenuItem(R.id.menu_contextual_save));
    verify(favoriteManager).add(any(Context.class), eq(item));
    observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("add").appendPath("1").build());
    assertTrue(item.isFavorite());
    View snackbarView = ShadowSnackbar.getLatestView();
    assertThat((TextView) snackbarView.findViewById(R.id.snackbar_text)).isNotNull().containsText(R.string.toast_saved);
    snackbarView.findViewById(R.id.snackbar_action).performClick();
    verify(favoriteManager).remove(any(Context.class), eq("1"));
    observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("1").build());
    assertFalse(item.isFavorite());
}
Also used : Context(android.content.Context) ShadowContentObserver(org.robolectric.shadows.ShadowContentObserver) View(android.view.View) TextView(android.widget.TextView) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) 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 14 with RoboMenuItem

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

the class WebFragmentLocalTest method testMenu.

@Test
public void testMenu() {
    TestWebItem item = new TestWebItem() {

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

        @Override
        public String getId() {
            return "1";
        }

        @Override
        public String getUrl() {
            return String.format(HackerNewsClient.WEB_ITEM_PATH, "1");
        }

        @Override
        public String getDisplayedTitle() {
            return "Ask HN";
        }
    };
    Intent intent = new Intent();
    intent.putExtra(WebActivity.EXTRA_ITEM, item);
    controller.withIntent(intent).create().start().resume().visible();
    verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
    listener.getValue().onResponse(new TestItem() {

        @Override
        public String getText() {
            return "text";
        }
    });
    Fragment fragment = activity.getSupportFragmentManager().findFragmentByTag(WebFragment.class.getName());
    assertTrue(fragment.hasOptionsMenu());
    fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_font_options));
    assertNotNull(ShadowDialog.getLatestDialog());
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_readability_font), "DroidSans.ttf").apply();
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    ShadowWebView shadowWebView = shadowOf(webView);
    shadowWebView.getWebViewClient().onPageFinished(webView, "about:blank");
    assertThat(shadowWebView.getLastLoadDataWithBaseURL().data).contains("text").contains("DroidSans.ttf");
}
Also used : ShadowWebView(org.robolectric.shadows.ShadowWebView) Intent(android.content.Intent) WebView(android.webkit.WebView) ShadowWebView(org.robolectric.shadows.ShadowWebView) Fragment(android.support.v4.app.Fragment) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) TestWebItem(io.github.hidroh.materialistic.test.TestWebItem) TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test)

Example 15 with RoboMenuItem

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

the class ReadabilityFragmentTest method testFontSizeMenu.

@Test
public void testFontSizeMenu() {
    verify(readabilityClient).parse(eq("1"), eq("http://example.com/article.html"), callback.capture());
    callback.getValue().onResponse("<div>content</div>");
    fragment.onOptionsItemSelected(new RoboMenuItem(R.id.menu_font_options));
    assertThat(fragment.getFragmentManager()).hasFragmentWithTag(PopupSettingsFragment.class.getName());
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_readability_text_size), "3").apply();
    WebView webView = (WebView) activity.findViewById(R.id.web_view);
    shadowOf(webView).getWebViewClient().onPageFinished(webView, "about:blank");
    assertThat(shadowOf(webView).getLastLoadDataWithBaseURL().data).contains("20");
    assertEquals(R.style.AppTextSize_XLarge, Preferences.Theme.resolvePreferredReadabilityTextSize(activity));
    controller.pause().stop().destroy();
}
Also used : WebView(android.webkit.WebView) ShadowWebView(io.github.hidroh.materialistic.test.shadow.ShadowWebView) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Test(org.junit.Test)

Aggregations

RoboMenuItem (org.robolectric.fakes.RoboMenuItem)108 Test (org.junit.Test)101 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 Context (android.content.Context)11 Intent (android.content.Intent)8 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 Bundle (android.os.Bundle)2 NonNull (android.support.annotation.NonNull)2 Fragment (android.support.v4.app.Fragment)2 RecyclerView (android.support.v7.widget.RecyclerView)2