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