Search in sources :

Example 11 with ApiClientType

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);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 12 with ApiClientType

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);
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 13 with ApiClientType

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);
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 14 with ApiClientType

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);
}
Also used : Project(com.kickstarter.models.Project) Mailbox(com.kickstarter.ui.data.Mailbox) MessageThreadsEnvelope(com.kickstarter.services.apiresponses.MessageThreadsEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) CurrentUserType(com.kickstarter.libs.CurrentUserType) ApiClientType(com.kickstarter.services.ApiClientType) Nullable(androidx.annotation.Nullable) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 15 with ApiClientType

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

ApiClientType (com.kickstarter.services.ApiClientType)31 Test (org.junit.Test)31 Environment (com.kickstarter.libs.Environment)25 MockApiClient (com.kickstarter.mock.services.MockApiClient)19 TestSubscriber (rx.observers.TestSubscriber)18 Intent (android.content.Intent)16 NonNull (androidx.annotation.NonNull)12 MockApiClient (com.kickstarter.services.MockApiClient)12 User (com.kickstarter.models.User)9 NonNull (android.support.annotation.NonNull)8 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)8 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)8 Update (com.kickstarter.models.Update)5 CurrentUserType (com.kickstarter.libs.CurrentUserType)4 Project (com.kickstarter.models.Project)3 Nullable (androidx.annotation.Nullable)2 ProjectNotification (com.kickstarter.models.ProjectNotification)2 MessageThreadsEnvelope (com.kickstarter.services.apiresponses.MessageThreadsEnvelope)2 Mailbox (com.kickstarter.ui.data.Mailbox)2 TestScheduler (rx.schedulers.TestScheduler)2