Search in sources :

Example 1 with ShadowRecyclerView

use of io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView 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());
}
Also used : Context(android.content.Context) TestLayoutManager(io.github.hidroh.materialistic.test.TestLayoutManager) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 2 with ShadowRecyclerView

use of io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView 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);
}
Also used : TestLayoutManager(io.github.hidroh.materialistic.test.TestLayoutManager) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

TestLayoutManager (io.github.hidroh.materialistic.test.TestLayoutManager)2 ShadowRecyclerView (io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView)2 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)2 Test (org.junit.Test)2 Context (android.content.Context)1 Config (org.robolectric.annotation.Config)1