use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testPreferenceChange.
@Test
public void testPreferenceChange() {
reset(itemManager);
ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout) ShadowExtractor.extract(activity.findViewById(R.id.swipe_layout));
shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
verify(itemManager).getStories(any(), eq(ItemManager.MODE_NETWORK), storiesListener.capture());
storiesListener.getValue().onResponse(new Item[] { new TestHnItem(2) {
@Override
public int getRank() {
return 46;
}
} });
verify(itemManager).getItem(any(), eq(ItemManager.MODE_NETWORK), itemListener.capture());
itemListener.getValue().onResponse(new PopulatedStory(2));
RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
assertThat((TextView) holder.itemView.findViewById(R.id.rank)).hasTextString("46*");
PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_highlight_updated), false).apply();
holder = adapter.getViewHolder(0);
assertThat((TextView) holder.itemView.findViewById(R.id.rank)).hasTextString("46");
}
use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.
the class ListFragmentTest method testRefresh.
@Test
public void testRefresh() {
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)).commit();
ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout) ShadowExtractor.extract(activity.findViewById(R.id.swipe_layout));
shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
// should trigger another data request
verify(itemManager).getStories(any(String.class), eq(ItemManager.MODE_DEFAULT), any(ResponseListener.class));
verify(itemManager).getStories(any(String.class), eq(ItemManager.MODE_NETWORK), any(ResponseListener.class));
controller.pause().stop().destroy();
}
use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testNewComments.
@Test
public void testNewComments() {
reset(itemManager);
ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout) ShadowExtractor.extract(activity.findViewById(R.id.swipe_layout));
shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
verify(itemManager).getStories(any(), eq(ItemManager.MODE_NETWORK), storiesListener.capture());
storiesListener.getValue().onResponse(new Item[] { new TestHnItem(1) });
verify(itemManager).getItem(any(), eq(ItemManager.MODE_NETWORK), itemListener.capture());
itemListener.getValue().onResponse(new PopulatedStory(1) {
@Override
public int getDescendants() {
return 2;
}
@Override
public long[] getKids() {
return new long[] { 2, 3 };
}
});
RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
assertThat((TextView) holder.itemView.findViewById(R.id.comment)).hasTextString("2*");
}
use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.
the class ItemFragmentMultiPageTest method testRefresh.
@Test
public void testRefresh() {
WebItem webItem = mock(WebItem.class);
when(webItem.getId()).thenReturn("1");
Bundle args = new Bundle();
args.putParcelable(ItemFragment.EXTRA_ITEM, webItem);
Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
makeVisible(fragment);
ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout) ShadowExtractor.extract(fragment.getView().findViewById(R.id.swipe_layout));
shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), listener.capture());
verify(hackerNewsClient).getItem(eq("1"), eq(ItemManager.MODE_NETWORK), listener.capture());
listener.getAllValues().get(1).onResponse(new TestHnItem(1L));
assertThat((SwipeRefreshLayout) fragment.getView().findViewById(R.id.swipe_layout)).isNotRefreshing();
verify(((TestItemActivity) fragment.getActivity()).itemChangedListener).onItemChanged(any(Item.class));
}
Aggregations