Search in sources :

Example 6 with MessageThreadEnvelope

use of com.kickstarter.services.apiresponses.MessageThreadEnvelope in project android-oss by kickstarter.

the class MessagesViewModelTest method testToolbarIsExpanded_NoMessages.

@Test
public void testToolbarIsExpanded_NoMessages() {
    final Backing backing = BackingFactory.backing();
    final MessageThreadEnvelope envelope = MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messages(null).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForBacking(@NonNull final Backing backing) {
            return Observable.just(envelope);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a backing and project.
    this.vm.intent(backerModalContextIntent(backing, ProjectFactory.project()));
    this.vm.inputs.messageEditTextIsFocused(true);
    // Toolbar stays expanded when keyboard opens and no messages.
    this.toolbarIsExpanded.assertNoValues();
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Backing(com.kickstarter.models.Backing) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 7 with MessageThreadEnvelope

use of com.kickstarter.services.apiresponses.MessageThreadEnvelope in project android-oss by kickstarter.

the class MessagesViewModelTest method testMessagesEmit.

@Test
public void testMessagesEmit() {
    final MessageThreadEnvelope envelope = MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messages(Collections.singletonList(MessageFactory.message())).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForThread(@NonNull final MessageThread messageThread) {
            return Observable.just(envelope);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a message thread.
    this.vm.intent(messagesContextIntent(MessageThreadFactory.messageThread()));
    // Messages emit, keyboard not shown.
    this.messageList.assertValueCount(1);
    this.messageEditTextShouldRequestFocus.assertNoValues();
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MessageThread(com.kickstarter.models.MessageThread) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 8 with MessageThreadEnvelope

use of com.kickstarter.services.apiresponses.MessageThreadEnvelope in project android-oss by kickstarter.

the class MessagesViewModelTest method testShouldRequestFocus.

@Test
public void testShouldRequestFocus() {
    final Backing backing = BackingFactory.backing();
    final MessageThreadEnvelope envelope = MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messages(null).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForBacking(@NonNull final Backing backing) {
            return Observable.just(envelope);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a backing and project.
    this.vm.intent(backerModalContextIntent(backing, ProjectFactory.project()));
    this.messageEditTextShouldRequestFocus.assertValueCount(1);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Backing(com.kickstarter.models.Backing) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 9 with MessageThreadEnvelope

use of com.kickstarter.services.apiresponses.MessageThreadEnvelope in project android-oss by kickstarter.

the class MessagesViewModelTest method testToolbarIsExpanded_WithMessages.

@Test
public void testToolbarIsExpanded_WithMessages() {
    final Backing backing = BackingFactory.backing();
    final MessageThreadEnvelope envelope = MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messages(Collections.singletonList(MessageFactory.message())).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForBacking(@NonNull final Backing backing) {
            return Observable.just(envelope);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a backing and project.
    this.vm.intent(backerModalContextIntent(backing, ProjectFactory.project()));
    this.vm.inputs.messageEditTextIsFocused(true);
    // Toolbar collapsed when keyboard opens and there are messages.
    this.toolbarIsExpanded.assertValues(false);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Backing(com.kickstarter.models.Backing) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 10 with MessageThreadEnvelope

use of com.kickstarter.services.apiresponses.MessageThreadEnvelope in project android-oss by kickstarter.

the class MessagesViewModelTest method testProjectData_ExistingMessages.

@Test
public void testProjectData_ExistingMessages() {
    final MessageThread messageThread = MessageThreadFactory.messageThread();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForThread(@NonNull final MessageThread thread) {
            return Observable.just(MessageThreadEnvelopeFactory.messageThreadEnvelope());
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a message thread.
    this.vm.intent(messagesContextIntent(messageThread));
    this.creatorNameTextViewText.assertValues(messageThread.project().creator().name());
    this.projectNameTextViewText.assertValues(messageThread.project().name());
    this.projectNameToolbarTextViewText.assertValues(messageThread.project().name());
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MessageThread(com.kickstarter.models.MessageThread) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

NonNull (androidx.annotation.NonNull)12 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)12 MockApiClient (com.kickstarter.mock.services.MockApiClient)12 MessageThreadEnvelope (com.kickstarter.services.apiresponses.MessageThreadEnvelope)12 Test (org.junit.Test)12 Backing (com.kickstarter.models.Backing)8 MessageThread (com.kickstarter.models.MessageThread)7 Project (com.kickstarter.models.Project)5 User (com.kickstarter.models.User)5 BackingWrapper (com.kickstarter.models.BackingWrapper)3 CurrentUserType (com.kickstarter.libs.CurrentUserType)1