use of io.github.hidroh.materialistic.test.TestLayoutManager in project materialistic by hidroh.
the class ListFragmentViewHolderTest method testAutoMarkAsViewed.
@Test
public void testAutoMarkAsViewed() {
PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_auto_viewed), true).apply();
ShadowRecyclerView shadowRecyclerView = customShadowOf(recyclerView);
TestLayoutManager testLayout = new TestLayoutManager(activity);
recyclerView.setLayoutManager(testLayout);
testLayout.firstVisiblePosition = 0;
shadowRecyclerView.getScrollListener().onScrolled(recyclerView, 0, 1);
verify(sessionManager, never()).view(any(Context.class), any());
verify(itemManager).getItem(any(), eq(ItemManager.MODE_DEFAULT), itemListener.capture());
itemListener.getValue().onResponse(item);
testLayout.firstVisiblePosition = 0;
shadowRecyclerView.getScrollListener().onScrolled(recyclerView, 0, 1);
verify(sessionManager, never()).view(any(Context.class), any());
testLayout.firstVisiblePosition = 1;
shadowRecyclerView.getScrollListener().onScrolled(recyclerView, 0, 1);
verify(sessionManager).view(any(Context.class), any());
item.setIsViewed(true);
testLayout.firstVisiblePosition = 1;
shadowRecyclerView.getScrollListener().onScrolled(recyclerView, 0, 1);
// should not trigger again
verify(sessionManager).view(any(Context.class), any());
PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_auto_viewed), false).apply();
assertNull(shadowRecyclerView.getScrollListener());
}
use of io.github.hidroh.materialistic.test.TestLayoutManager in project materialistic by hidroh.
the class ItemFragmentSinglePageTest method testNavigate.
@Config(shadows = ShadowRecyclerView.class)
@Test
public void testNavigate() {
ShadowRecyclerView shadowRecyclerView = customShadowOf(recyclerView);
TestLayoutManager testLayout = new TestLayoutManager(activity);
recyclerView.setLayoutManager(testLayout);
fragment.onNavigate(Navigable.DIRECTION_DOWN);
assertThat(shadowRecyclerView.getScrollPosition()).isEqualTo(3);
shadowRecyclerView.getScrollListener().onScrollStateChanged(recyclerView, RecyclerView.SCROLL_STATE_IDLE);
testLayout.firstVisiblePosition = 3;
fragment.onNavigate(Navigable.DIRECTION_UP);
assertThat(shadowRecyclerView.getScrollPosition()).isEqualTo(0);
testLayout.firstVisiblePosition = 0;
fragment.onNavigate(Navigable.DIRECTION_RIGHT);
assertThat(shadowRecyclerView.getScrollPosition()).isEqualTo(1);
shadowRecyclerView.getScrollListener().onScrollStateChanged(recyclerView, RecyclerView.SCROLL_STATE_IDLE);
testLayout.firstVisiblePosition = 1;
fragment.onNavigate(Navigable.DIRECTION_LEFT);
assertThat(shadowRecyclerView.getScrollPosition()).isEqualTo(0);
shadowRecyclerView.getScrollListener().onScrollStateChanged(recyclerView, RecyclerView.SCROLL_STATE_IDLE);
}
Aggregations