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());
}
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());
}
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());
}
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");
}
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();
}
Aggregations