Search in sources :

Example 1 with Mailbox

use of com.kickstarter.ui.data.Mailbox 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 2 with Mailbox

use of com.kickstarter.ui.data.Mailbox in project android-oss by kickstarter.

the class MessageThreadsViewModelTest method testMessageThreadsEmit_WithProjectIntent.

@Test
public void testMessageThreadsEmit_WithProjectIntent() {
    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 Project project = ProjectFactory.project().toBuilder().unreadMessagesCount(5).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);
        }

        @Override
        @NonNull
        public Observable<Project> fetchProject(@NonNull final String param) {
            return Observable.just(project);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(currentUser).build());
    final Intent intent = new Intent().putExtra(IntentKey.PROJECT, project);
    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)

Aggregations

Intent (android.content.Intent)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 CurrentUserType (com.kickstarter.libs.CurrentUserType)2 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)2 MockApiClient (com.kickstarter.mock.services.MockApiClient)2 Project (com.kickstarter.models.Project)2 ApiClientType (com.kickstarter.services.ApiClientType)2 MessageThreadsEnvelope (com.kickstarter.services.apiresponses.MessageThreadsEnvelope)2 Mailbox (com.kickstarter.ui.data.Mailbox)2 Test (org.junit.Test)2