Search in sources :

Example 11 with MessageThread

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

the class MessagesViewModelTest method testCreatorViewingProjectMessages.

@Test
public void testCreatorViewingProjectMessages() {
    final User creator = UserFactory.creator().toBuilder().name("Sharon").build();
    final User participant = UserFactory.user().toBuilder().name("Timothy").build();
    final CurrentUserType currentUser = new MockCurrentUser(creator);
    final MessageThread messageThread = MessageThreadFactory.messageThread().toBuilder().project(ProjectFactory.project().toBuilder().creator(creator).build()).participant(participant).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForThread(@NonNull final MessageThread thread) {
            return Observable.just(MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messageThread(messageThread).build());
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(currentUser).build());
    // Start the view model with a message thread.
    this.vm.intent(messagesContextIntent(messageThread));
    // Creator name is the project creator, edit text hint is always the participant.
    this.creatorNameTextViewText.assertValues(creator.name());
    this.messageEditTextHint.assertValues(participant.name());
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MessageThread(com.kickstarter.models.MessageThread) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) Test(org.junit.Test)

Example 12 with MessageThread

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

the class MessageThreadHolderViewModelTest method testMessageThread_HasNoUnreadMessages.

@Test
public void testMessageThread_HasNoUnreadMessages() {
    final MessageThread messageThreadWithNoUnread = MessageThreadFactory.messageThread().toBuilder().unreadMessagesCount(0).build();
    setUpEnvironment(environment());
    // Configure the view model with a message thread with no unread messages.
    this.vm.inputs.configureWith(messageThreadWithNoUnread);
    this.dateTextViewIsBold.assertValues(false);
    this.messageBodyTextIsBold.assertValues(false);
    this.participantNameTextViewIsBold.assertValues(false);
    this.unreadCountTextViewIsGone.assertValues(true);
    this.unreadCountTextViewText.assertValues(NumberUtils.format(messageThreadWithNoUnread.unreadMessagesCount()));
}
Also used : MessageThread(com.kickstarter.models.MessageThread) Test(org.junit.Test)

Example 13 with MessageThread

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

the class MessageThreadHolderViewModelTest method testMessageThread_Clicked.

@Test
public void testMessageThread_Clicked() {
    final MessageThread messageThread = MessageThreadFactory.messageThread().toBuilder().id(12345).unreadMessagesCount(1).build();
    setUpEnvironment(environment());
    this.vm.inputs.configureWith(messageThread);
    this.cardViewIsElevated.assertValues(true);
    this.dateTextViewIsBold.assertValues(true);
    this.messageBodyTextIsBold.assertValues(true);
    this.unreadCountTextViewIsGone.assertValues(false);
    this.vm.inputs.messageThreadCardViewClicked();
    this.cardViewIsElevated.assertValues(true, false);
    this.dateTextViewIsBold.assertValues(true, false);
    this.messageBodyTextIsBold.assertValues(true, false);
    this.unreadCountTextViewIsGone.assertValues(false, true);
}
Also used : MessageThread(com.kickstarter.models.MessageThread) Test(org.junit.Test)

Example 14 with MessageThread

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

the class MessageThreadHolderViewModelTest method testMessageThread_HasUnreadMessages.

@Test
public void testMessageThread_HasUnreadMessages() {
    final MessageThread messageThreadWithUnread = MessageThreadFactory.messageThread().toBuilder().unreadMessagesCount(2).build();
    setUpEnvironment(environment());
    // Configure the view model with a message thread with unread messages.
    this.vm.inputs.configureWith(messageThreadWithUnread);
    this.dateTextViewIsBold.assertValues(true);
    this.messageBodyTextIsBold.assertValues(true);
    this.participantNameTextViewIsBold.assertValues(true);
    this.unreadCountTextViewIsGone.assertValues(false);
    this.unreadCountTextViewText.assertValues(NumberUtils.format(messageThreadWithUnread.unreadMessagesCount()));
}
Also used : MessageThread(com.kickstarter.models.MessageThread) Test(org.junit.Test)

Example 15 with MessageThread

use of com.kickstarter.models.MessageThread 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)

Aggregations

MessageThread (com.kickstarter.models.MessageThread)17 Test (org.junit.Test)17 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)10 NonNull (androidx.annotation.NonNull)9 MockApiClient (com.kickstarter.mock.services.MockApiClient)9 MessageThreadEnvelope (com.kickstarter.services.apiresponses.MessageThreadEnvelope)7 User (com.kickstarter.models.User)5 Backing (com.kickstarter.models.Backing)4 Project (com.kickstarter.models.Project)4 BackingWrapper (com.kickstarter.models.BackingWrapper)2 CurrentUserType (com.kickstarter.libs.CurrentUserType)1