Search in sources :

Example 6 with TestItem

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

Example 7 with TestItem

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());
}
Also used : TestItem(io.github.hidroh.materialistic.test.TestItem) Item(io.github.hidroh.materialistic.data.Item) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) RoboMenuItem(org.robolectric.fakes.RoboMenuItem) Bundle(android.os.Bundle) Fragment(android.support.v4.app.Fragment) TestItem(io.github.hidroh.materialistic.test.TestItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 8 with TestItem

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

Example 9 with TestItem

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();
}
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 10 with TestItem

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();
}
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)

Aggregations

TestItem (io.github.hidroh.materialistic.test.TestItem)40 Test (org.junit.Test)38 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)15 Intent (android.content.Intent)12 Bundle (android.os.Bundle)9 NonNull (android.support.annotation.NonNull)8 Fragment (android.support.v4.app.Fragment)7 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)5 TextView (android.widget.TextView)4 TestHnItem (io.github.hidroh.materialistic.data.TestHnItem)4 RecyclerView (android.support.v7.widget.RecyclerView)3 WebView (android.webkit.WebView)3 HackerNewsClient (io.github.hidroh.materialistic.data.HackerNewsClient)3 ShadowWebView (org.robolectric.shadows.ShadowWebView)3 SuppressLint (android.annotation.SuppressLint)2 Parcel (android.os.Parcel)2 TabLayout (android.support.design.widget.TabLayout)2 Item (io.github.hidroh.materialistic.data.Item)2 ResponseListener (io.github.hidroh.materialistic.data.ResponseListener)2 WebItem (io.github.hidroh.materialistic.data.WebItem)2