Search in sources :

Example 1 with ShadowSwipeRefreshLayout

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();
}
Also used : ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) Bundle(android.os.Bundle) WebItem(io.github.hidroh.materialistic.data.WebItem) Fragment(android.support.v4.app.Fragment) ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 2 with ShadowSwipeRefreshLayout

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();
}
Also used : ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) Bundle(android.os.Bundle) RecyclerView(android.support.v7.widget.RecyclerView) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) HackerNewsClient(io.github.hidroh.materialistic.data.HackerNewsClient) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 3 with ShadowSwipeRefreshLayout

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();
}
Also used : ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) Bundle(android.os.Bundle) HackerNewsClient(io.github.hidroh.materialistic.data.HackerNewsClient) TestItem(io.github.hidroh.materialistic.test.TestItem) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 4 with ShadowSwipeRefreshLayout

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*");
}
Also used : ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) TextView(android.widget.TextView) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 5 with ShadowSwipeRefreshLayout

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");
}
Also used : ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) ShadowRecyclerView(io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView) TextView(android.widget.TextView) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Aggregations

ShadowSwipeRefreshLayout (io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout)9 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)9 Test (org.junit.Test)9 TestHnItem (io.github.hidroh.materialistic.data.TestHnItem)6 Bundle (android.os.Bundle)5 RecyclerView (android.support.v7.widget.RecyclerView)5 TextView (android.widget.TextView)5 ShadowRecyclerView (io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView)4 HackerNewsClient (io.github.hidroh.materialistic.data.HackerNewsClient)3 TestItem (io.github.hidroh.materialistic.test.TestItem)3 Fragment (android.support.v4.app.Fragment)2 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)2 WebItem (io.github.hidroh.materialistic.data.WebItem)2 View (android.view.View)1 Item (io.github.hidroh.materialistic.data.Item)1 ResponseListener (io.github.hidroh.materialistic.data.ResponseListener)1 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)1