use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.
the class ItemFragmentMultiPageTest method testRefreshFailed.
@Test
public void testRefreshFailed() {
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).onError(null);
assertThat((SwipeRefreshLayout) fragment.getView().findViewById(R.id.swipe_layout)).isNotRefreshing();
}
use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.
the class ListFragmentTest method testHighlightNewItems.
@Test
public void testHighlightNewItems() {
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();
verify(itemManager).getStories(any(), eq(ItemManager.MODE_DEFAULT), listener.capture());
listener.getValue().onResponse(new Item[] { new TestItem() {
@Override
public String getId() {
return "1";
}
} });
reset(itemManager);
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_NETWORK), listener.capture());
listener.getValue().onResponse(new Item[] { new TestHnItem(1L), new TestHnItem(2L) });
assertEquals(2, ((RecyclerView) activity.findViewById(R.id.recycler_view)).getAdapter().getItemCount());
View snackbarView = ShadowSnackbar.getLatestView();
Assertions.assertThat((TextView) snackbarView.findViewById(R.id.snackbar_text)).isNotNull().containsText(activity.getResources().getQuantityString(R.plurals.new_stories_count, 1, 1));
snackbarView.findViewById(R.id.snackbar_action).performClick();
assertEquals(1, ((RecyclerView) activity.findViewById(R.id.recycler_view)).getAdapter().getItemCount());
snackbarView = ShadowSnackbar.getLatestView();
Assertions.assertThat((TextView) snackbarView.findViewById(R.id.snackbar_text)).isNotNull().containsText(activity.getResources().getQuantityString(R.plurals.showing_new_stories, 1, 1));
snackbarView.findViewById(R.id.snackbar_action).performClick();
assertEquals(2, ((RecyclerView) activity.findViewById(R.id.recycler_view)).getAdapter().getItemCount());
controller.pause().stop().destroy();
}
use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.
the class ListFragmentTest method testRefreshError.
@Test
public void testRefreshError() {
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();
verify(itemManager).getStories(any(), eq(ItemManager.MODE_DEFAULT), listener.capture());
listener.getValue().onResponse(new Item[] { new TestItem() {
} });
Assertions.assertThat(activity.findViewById(R.id.empty)).isNotVisible();
reset(itemManager);
ShadowSwipeRefreshLayout shadowSwipeRefreshLayout = (ShadowSwipeRefreshLayout) ShadowExtractor.extract(activity.findViewById(R.id.swipe_layout));
shadowSwipeRefreshLayout.getOnRefreshListener().onRefresh();
verify(itemManager).getStories(any(), eq(ItemManager.MODE_NETWORK), listener.capture());
listener.getValue().onError(null);
Assertions.assertThat(activity.findViewById(R.id.empty)).isNotVisible();
assertNotNull(ShadowToast.getLatestToast());
controller.pause().stop().destroy();
}
use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testNewStory.
@Test
public void testNewStory() {
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;
}
} });
ShadowSnackbar.getLatestView().findViewById(R.id.snackbar_action).performClick();
verify(itemManager, atLeastOnce()).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*");
}
use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testPromoted.
@Test
public void testPromoted() {
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) {
@Override
public int getRank() {
return 45;
}
} });
verify(itemManager).getItem(any(), eq(ItemManager.MODE_NETWORK), itemListener.capture());
itemListener.getValue().onResponse(new PopulatedStory(1));
RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
assertThat((TextView) holder.itemView.findViewById(R.id.rank)).containsText("+1");
}
Aggregations