Search in sources :

Example 6 with ShadowSwipeRefreshLayout

use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.

the class ListFragmentViewHolderTest method testPreferenceChange.

@Test
public void testPreferenceChange() {
    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;
        }
    } });
    verify(itemManager).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*");
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putBoolean(activity.getString(R.string.pref_highlight_updated), false).apply();
    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 7 with ShadowSwipeRefreshLayout

use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.

the class ListFragmentTest method testRefresh.

@Test
public void testRefresh() {
    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();
    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_DEFAULT), any(ResponseListener.class));
    verify(itemManager).getStories(any(String.class), eq(ItemManager.MODE_NETWORK), any(ResponseListener.class));
    controller.pause().stop().destroy();
}
Also used : ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) Bundle(android.os.Bundle) ResponseListener(io.github.hidroh.materialistic.data.ResponseListener) HackerNewsClient(io.github.hidroh.materialistic.data.HackerNewsClient) Test(org.junit.Test) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest)

Example 8 with ShadowSwipeRefreshLayout

use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.

the class ListFragmentViewHolderTest method testNewComments.

@Test
public void testNewComments() {
    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) });
    verify(itemManager).getItem(any(), eq(ItemManager.MODE_NETWORK), itemListener.capture());
    itemListener.getValue().onResponse(new PopulatedStory(1) {

        @Override
        public int getDescendants() {
            return 2;
        }

        @Override
        public long[] getKids() {
            return new long[] { 2, 3 };
        }
    });
    RecyclerView.ViewHolder holder = adapter.getViewHolder(0);
    assertThat((TextView) holder.itemView.findViewById(R.id.comment)).hasTextString("2*");
}
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 9 with ShadowSwipeRefreshLayout

use of io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout in project materialistic by hidroh.

the class ItemFragmentMultiPageTest method testRefresh.

@Test
public void testRefresh() {
    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).onResponse(new TestHnItem(1L));
    assertThat((SwipeRefreshLayout) fragment.getView().findViewById(R.id.swipe_layout)).isNotRefreshing();
    verify(((TestItemActivity) fragment.getActivity()).itemChangedListener).onItemChanged(any(Item.class));
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) WebItem(io.github.hidroh.materialistic.data.WebItem) Item(io.github.hidroh.materialistic.data.Item) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) ShadowSwipeRefreshLayout(io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout) Bundle(android.os.Bundle) WebItem(io.github.hidroh.materialistic.data.WebItem) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) 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)

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