Search in sources :

Example 21 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class ThreadPreviewActivityTest method testBinding.

@Test
public void testBinding() {
    RecyclerView recyclerView = (RecyclerView) activity.findViewById(R.id.recycler_view);
    verify(itemManager).getItem(eq("2"), eq(ItemManager.MODE_DEFAULT), itemCaptor.capture());
    itemCaptor.getValue().onResponse(new TestHnItem(2L) {

        @NonNull
        @Override
        public String getRawType() {
            return Item.COMMENT_TYPE;
        }

        @Override
        public String getText() {
            return "comment";
        }

        @Override
        public String getParent() {
            return "1";
        }

        @Override
        public String getBy() {
            return "username";
        }
    });
    verify(itemManager).getItem(eq("1"), eq(ItemManager.MODE_DEFAULT), itemCaptor.capture());
    itemCaptor.getValue().onResponse(new TestHnItem(1L) {

        @NonNull
        @Override
        public String getRawType() {
            return Item.STORY_TYPE;
        }

        @Override
        public String getTitle() {
            return "story";
        }

        @Override
        public String getBy() {
            return "author";
        }
    });
    RecyclerView.ViewHolder viewHolder1 = CustomShadows.customShadowOf(recyclerView.getAdapter()).getViewHolder(0);
    // TODO should not need this
    recyclerView.getAdapter().bindViewHolder(viewHolder1, 0);
    assertThat(viewHolder1.itemView.findViewById(R.id.comment)).isVisible();
    assertEquals(0, recyclerView.getAdapter().getItemViewType(0));
    RecyclerView.ViewHolder viewHolder2 = CustomShadows.customShadowOf(recyclerView.getAdapter()).getViewHolder(1);
    assertThat(viewHolder2.itemView.findViewById(R.id.comment)).isNotVisible();
    assertEquals(1, recyclerView.getAdapter().getItemViewType(1));
    viewHolder1.itemView.findViewById(R.id.comment).performClick();
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, ItemActivity.class).hasExtra(ItemActivity.EXTRA_ITEM);
}
Also used : NonNull(android.support.annotation.NonNull) RecyclerView(android.support.v7.widget.RecyclerView) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) Test(org.junit.Test)

Example 22 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class ItemActivityTest method testFavoriteStory.

@Test
public void testFavoriteStory() {
    Intent intent = new Intent();
    TestHnItem item = new TestHnItem(1L) {

        @NonNull
        @Override
        public String getType() {
            return STORY_TYPE;
        }
    };
    item.setFavorite(true);
    intent.putExtra(ItemActivity.EXTRA_ITEM, item);
    controller.withIntent(intent).create().start().resume();
    assertTrue(item.isFavorite());
    ShadowContentObserver observer = shadowOf(shadowOf(activity.getContentResolver()).getContentObservers(MaterialisticProvider.URI_FAVORITE).iterator().next());
    activity.findViewById(R.id.bookmarked).performClick();
    verify(favoriteManager).remove(any(Context.class), eq("1"));
    observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("remove").appendPath("1").build());
    assertFalse(item.isFavorite());
    assertThat((TextView) activity.findViewById(R.id.snackbar_text)).isNotNull().containsText(R.string.toast_removed);
    activity.findViewById(R.id.snackbar_action).performClick();
    observer.dispatchChange(false, MaterialisticProvider.URI_FAVORITE.buildUpon().appendPath("add").appendPath("1").build());
    assertTrue(item.isFavorite());
}
Also used : Context(android.content.Context) ShadowContentObserver(org.robolectric.shadows.ShadowContentObserver) Intent(android.content.Intent) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 23 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class ItemActivityTest method testVotePromptToLogin.

@Test
public void testVotePromptToLogin() {
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestHnItem(1));
    controller.withIntent(intent).create().start().resume();
    activity.findViewById(R.id.vote_button).performClick();
    verify(userServices).voteUp(any(Context.class), eq("1"), userServicesCallback.capture());
    userServicesCallback.getValue().onDone(false);
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, LoginActivity.class);
}
Also used : Context(android.content.Context) Intent(android.content.Intent) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 24 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class ItemActivityTest method testVote.

@Test
public void testVote() {
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestHnItem(1));
    controller.withIntent(intent).create().start().resume();
    activity.findViewById(R.id.vote_button).performClick();
    verify(userServices).voteUp(any(Context.class), eq("1"), userServicesCallback.capture());
    userServicesCallback.getValue().onDone(true);
    assertEquals(activity.getString(R.string.voted), ShadowToast.getTextOfLatestToast());
}
Also used : Context(android.content.Context) Intent(android.content.Intent) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Example 25 with TestHnItem

use of io.github.hidroh.materialistic.data.TestHnItem in project materialistic by hidroh.

the class ItemActivityTest method testReply.

@Test
public void testReply() {
    PreferenceManager.getDefaultSharedPreferences(activity).edit().putString(activity.getString(R.string.pref_story_display), activity.getString(R.string.pref_story_display_value_comments)).apply();
    Intent intent = new Intent();
    intent.putExtra(ItemActivity.EXTRA_ITEM, new TestHnItem(1L));
    controller.withIntent(intent).create().start().resume();
    activity.findViewById(R.id.reply_button).performClick();
    assertThat(shadowOf(activity).getNextStartedActivity()).hasComponent(activity, ComposeActivity.class);
}
Also used : Intent(android.content.Intent) TestHnItem(io.github.hidroh.materialistic.data.TestHnItem) SlowTest(io.github.hidroh.materialistic.test.suite.SlowTest) Test(org.junit.Test)

Aggregations

TestHnItem (io.github.hidroh.materialistic.data.TestHnItem)35 Test (org.junit.Test)31 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)23 RecyclerView (android.support.v7.widget.RecyclerView)12 TextView (android.widget.TextView)9 Intent (android.content.Intent)8 Bundle (android.os.Bundle)8 NonNull (android.support.annotation.NonNull)8 ShadowRecyclerView (io.github.hidroh.materialistic.test.shadow.ShadowRecyclerView)8 ShadowSwipeRefreshLayout (io.github.hidroh.materialistic.test.shadow.ShadowSwipeRefreshLayout)6 Context (android.content.Context)5 TestItem (io.github.hidroh.materialistic.test.TestItem)5 Before (org.junit.Before)4 Fragment (android.support.v4.app.Fragment)3 View (android.view.View)3 HackerNewsClient (io.github.hidroh.materialistic.data.HackerNewsClient)3 Item (io.github.hidroh.materialistic.data.Item)3 WebItem (io.github.hidroh.materialistic.data.WebItem)3 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)3 ShadowContentObserver (org.robolectric.shadows.ShadowContentObserver)3