use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.
the class FacebookConfimationViewModelTest method testSuccessfulUserCreation.
@Test
public void testSuccessfulUserCreation() {
final ApiClientType apiClient = new MockApiClient();
final Environment environment = environment().toBuilder().apiClient(apiClient).build();
this.vm = new FacebookConfirmationViewModel.ViewModel(environment);
this.vm.intent(new Intent().putExtra(IntentKey.FACEBOOK_TOKEN, "token"));
this.vm.outputs.signupSuccess().subscribe(this.signupSuccess);
this.vm.inputs.sendNewslettersClick(true);
this.vm.inputs.createNewAccountClick();
this.signupSuccess.assertValueCount(1);
}
use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.
the class MessageThreadsViewModelTest method testHasUnreadMessages.
@Test
public void testHasUnreadMessages() {
final User user = UserFactory.user().toBuilder().unreadMessagesCount(3).build();
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<User> fetchCurrentUser() {
return Observable.just(user);
}
};
setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
this.vm.intent(new Intent());
this.vm.inputs.onResume();
// Unread count text view is shown.
this.unreadMessagesCount.assertValues(user.unreadMessagesCount());
this.unreadMessagesCountIsGone.assertValues(false);
this.hasNoUnreadMessages.assertValues(false);
this.unreadCountTextViewColorInt.assertValues(R.color.accent);
this.unreadCountTextViewTypefaceInt.assertValues(Typeface.BOLD);
this.unreadCountToolbarTextViewIsGone.assertValues(false);
this.vm.inputs.mailbox(Mailbox.SENT);
this.unreadMessagesCountIsGone.assertValues(false, true);
}
use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.
the class MessageThreadsViewModelTest method testNoMessages.
@Test
public void testNoMessages() {
final User user = UserFactory.user().toBuilder().unreadMessagesCount(null).build();
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<User> fetchCurrentUser() {
return Observable.just(user);
}
};
setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
this.vm.intent(new Intent());
this.vm.inputs.onResume();
this.hasNoMessages.assertValues(true);
this.unreadMessagesCount.assertNoValues();
this.unreadMessagesCountIsGone.assertValue(false);
this.unreadCountTextViewColorInt.assertValues(R.color.kds_support_400);
this.unreadCountTextViewTypefaceInt.assertValues(Typeface.NORMAL);
this.unreadCountToolbarTextViewIsGone.assertValues(true);
this.vm.inputs.mailbox(Mailbox.SENT);
this.unreadMessagesCountIsGone.assertValues(false, true);
}
use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.
the class MessageThreadsViewModelTest method testMessageThreadsEmit_NoProjectIntent.
@Test
public void testMessageThreadsEmit_NoProjectIntent() {
final CurrentUserType currentUser = new MockCurrentUser();
currentUser.login(UserFactory.user().toBuilder().unreadMessagesCount(0).build(), "beefbod5");
final MessageThreadsEnvelope inboxEnvelope = MessageThreadsEnvelopeFactory.messageThreadsEnvelope().toBuilder().messageThreads(Collections.singletonList(MessageThreadFactory.messageThread())).build();
final MessageThreadsEnvelope sentEnvelope = MessageThreadsEnvelopeFactory.messageThreadsEnvelope().toBuilder().messageThreads(Arrays.asList(MessageThreadFactory.messageThread(), MessageThreadFactory.messageThread())).build();
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<MessageThreadsEnvelope> fetchMessageThreads(@Nullable final Project project, @NonNull final Mailbox mailbox) {
return Observable.just(mailbox == Mailbox.INBOX ? inboxEnvelope : sentEnvelope);
}
};
setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(currentUser).build());
final Intent intent = new Intent().putExtra(IntentKey.PROJECT, Empty.INSTANCE);
this.vm.intent(intent);
this.messageThreadList.assertValueCount(2);
this.messageThreadListCount.assertValues(0, 1);
// Same message threads should not emit again.
this.vm.inputs.onResume();
this.messageThreadList.assertValueCount(2);
this.messageThreadListCount.assertValues(0, 1);
this.vm.inputs.mailbox(Mailbox.SENT);
this.messageThreadList.assertValueCount(4);
this.messageThreadListCount.assertValues(0, 1, 0, 2);
}
use of com.kickstarter.services.ApiClientType 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();
}
Aggregations