use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class ItemFragmentSinglePageTest method testPendingItem.
@Test
public void testPendingItem() {
Bundle args = new Bundle();
args.putParcelable(ItemFragment.EXTRA_ITEM, new TestItem() {
@Override
public Item[] getKidItems() {
return new Item[] { new TestItem() {
@Override
public int getLocalRevision() {
return -1;
}
} };
}
@Override
public int getKidCount() {
return 1;
}
});
Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
SupportFragmentTestUtil.startVisibleFragment(fragment, ItemFragmentMultiPageTest.TestItemActivity.class, R.id.content_frame);
recyclerView = (RecyclerView) fragment.getView().findViewById(R.id.recycler_view);
adapter = (SinglePageItemRecyclerViewAdapter) recyclerView.getAdapter();
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class ItemFragmentSinglePageTest method testDefaultCollapsed.
@Test
public void testDefaultCollapsed() {
PreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application).edit().putString(RuntimeEnvironment.application.getString(R.string.pref_comment_display), RuntimeEnvironment.application.getString(R.string.pref_comment_display_value_collapsed)).apply();
final TestItem item0 = new // level 0
TestItem() {
@Override
public String getId() {
return "1";
}
@Override
public int getKidCount() {
return 1;
}
@Override
public Item[] getKidItems() {
return new Item[] { new TestItem() {
@Override
public String getId() {
return "2";
}
} };
}
};
Bundle args = new Bundle();
args.putParcelable(ItemFragment.EXTRA_ITEM, new TestItem() {
@Override
public Item[] getKidItems() {
return new Item[] { item0 };
}
@Override
public int getKidCount() {
return 1;
}
});
Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application, ItemFragment.class.getName(), args);
SupportFragmentTestUtil.startVisibleFragment(fragment, ItemFragmentMultiPageTest.TestItemActivity.class, R.id.content_frame);
recyclerView = (RecyclerView) fragment.getView().findViewById(R.id.recycler_view);
adapter = (SinglePageItemRecyclerViewAdapter) recyclerView.getAdapter();
// item + footer
assertEquals(2, adapter.getItemCount());
// should not add kid to adapter
assertEquals(2, adapter.getItemCount());
}
use of io.github.hidroh.materialistic.test.TestItem in project materialistic by hidroh.
the class ListFragmentTest method testConfigurationChanged.
@Test
public void testConfigurationChanged() {
Bundle args = new Bundle();
args.putString(ListFragment.EXTRA_ITEM_MANAGER, HackerNewsClient.class.getName());
args.putString(ListFragment.EXTRA_FILTER, ItemManager.TOP_FETCH_MODE);
Fragment fragment = Fragment.instantiate(activity, ListFragment.class.getName(), args);
activity.getSupportFragmentManager().beginTransaction().add(android.R.id.list, fragment).commit();
verify(itemManager).getStories(any(), eq(ItemManager.MODE_DEFAULT), listener.capture());
listener.getValue().onResponse(new Item[] { new TestItem() {
} });
reset(itemManager);
Bundle state = new Bundle();
fragment.onSaveInstanceState(state);
fragment.onActivityCreated(state);
// should not trigger another data request
verify(itemManager, never()).getStories(any(String.class), eq(ItemManager.MODE_DEFAULT), any(ResponseListener.class));
controller.pause().stop().destroy();
}
use of io.github.hidroh.materialistic.test.TestItem 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.TestItem 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();
}
Aggregations