Search in sources :

Example 1 with Comment

use of com.kickstarter.models.Comment in project android-oss by kickstarter.

the class CommentsAdapter method takeData.

public void takeData(@NonNull final CommentsData data) {
    final Project project = data.project();
    final List<Comment> comments = data.comments();
    final User user = data.user();
    sections().clear();
    sections().add(Collections.singletonList(project));
    addSection(Observable.from(comments).map(comment -> Pair.create(project, comment)).toList().toBlocking().single());
    if (comments.size() == 0) {
        sections().add(Collections.singletonList(new Pair<>(project, user)));
    } else {
        sections().add(Collections.emptyList());
    }
    notifyDataSetChanged();
}
Also used : Project(com.kickstarter.models.Project) Comment(com.kickstarter.models.Comment) User(com.kickstarter.models.User) Pair(android.util.Pair)

Example 2 with Comment

use of com.kickstarter.models.Comment in project android-oss by kickstarter.

the class CommentsViewModelTest method testCommentsViewModel_postCommentError.

@Test
public void testCommentsViewModel_postCommentError() {
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Comment> postComment(@NonNull final Project project, @NonNull final String body) {
            return Observable.error(ApiExceptionFactory.badRequestException());
        }
    };
    final Environment env = environment().toBuilder().apiClient(apiClient).build();
    final CommentsViewModel vm = new CommentsViewModel(env);
    final TestSubscriber<String> showPostCommentErrorToast = new TestSubscriber<>();
    vm.outputs.showPostCommentErrorToast().subscribe(showPostCommentErrorToast);
    final TestSubscriber<Void> showCommentPostedToast = new TestSubscriber<>();
    vm.outputs.showCommentPostedToast().subscribe(showCommentPostedToast);
    // Start the view model with a project.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.backedProject()));
    // Click the comment button and write a comment.
    vm.inputs.commentButtonClicked();
    vm.inputs.commentBodyChanged("Mic check mic check.");
    // Post comment. Error should be shown. Comment posted toast should not be shown.
    vm.inputs.postCommentClicked();
    showPostCommentErrorToast.assertValueCount(1);
    showCommentPostedToast.assertNoValues();
}
Also used : Comment(com.kickstarter.models.Comment) MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Project(com.kickstarter.models.Project) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Aggregations

Comment (com.kickstarter.models.Comment)2 Project (com.kickstarter.models.Project)2 Intent (android.content.Intent)1 NonNull (android.support.annotation.NonNull)1 Pair (android.util.Pair)1 Environment (com.kickstarter.libs.Environment)1 User (com.kickstarter.models.User)1 ApiClientType (com.kickstarter.services.ApiClientType)1 MockApiClient (com.kickstarter.services.MockApiClient)1 Test (org.junit.Test)1 TestSubscriber (rx.observers.TestSubscriber)1