Search in sources :

Example 1 with Message

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

the class MessagesViewModelTest method testSendMessage_Error.

@Test
public void testSendMessage_Error() {
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Message> sendMessage(@NonNull final MessageSubject messageSubject, @NonNull final String body) {
            return Observable.error(ApiExceptionFactory.badRequestException());
        }
    };
    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()));
    // Send a message unsuccessfully.
    this.vm.inputs.messageEditTextChanged("Hello there");
    this.vm.inputs.sendMessageButtonClicked();
    // Error toast is displayed, errored message body remains in edit text, no new message is emitted.
    this.showMessageErrorToast.assertValueCount(1);
    this.setMessageEditText.assertNoValues();
}
Also used : MessageSubject(com.kickstarter.ui.data.MessageSubject) Message(com.kickstarter.models.Message) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 2 with Message

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

the class MessagesViewModelTest method testSendMessage_Success.

@Test
public void testSendMessage_Success() {
    final Message sentMessage = MessageFactory.message();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Message> sendMessage(@NonNull final MessageSubject messageSubject, @NonNull final String body) {
            return Observable.just(sentMessage);
        }
    };
    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()));
    // Initial messages emit.
    this.messageList.assertValueCount(1);
    // Send a message successfully.
    this.vm.inputs.messageEditTextChanged("Salutations friend!");
    this.vm.inputs.sendMessageButtonClicked();
    // New message list emits.
    this.messageList.assertValueCount(2);
    // Reply edit text should be cleared and view should be scrolled to new message.
    this.setMessageEditText.assertValues("");
    this.scrollRecyclerViewToBottom.assertValueCount(1);
}
Also used : MessageSubject(com.kickstarter.ui.data.MessageSubject) Message(com.kickstarter.models.Message) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 3 with Message

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

the class MessageHolderViewModelTest method testParticipantAvatarImage_CurrentUserIsRecipient.

@Test
public void testParticipantAvatarImage_CurrentUserIsRecipient() {
    final User recipient = UserFactory.user().toBuilder().name("Ima Backer").id(123L).build();
    final User sender = UserFactory.user().toBuilder().name("Ima Creator").id(456L).build();
    final Message message = MessageFactory.message().toBuilder().recipient(recipient).sender(sender).build();
    final MockCurrentUser currentUser = new MockCurrentUser(recipient);
    setUpEnvironment(environment().toBuilder().currentUser(currentUser).build());
    this.vm.inputs.configureWith(message);
    // Avatar shown for sender who is the creator.
    this.participantAvatarImageHidden.assertValues(false);
    this.participantAvatarImageUrl.assertValues(message.sender().avatar().medium());
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Message(com.kickstarter.models.Message) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 4 with Message

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

the class MessageHolderViewModelTest method testMessageBodyTextViewFormatting_CurrentUserIsRecipient.

@Test
public void testMessageBodyTextViewFormatting_CurrentUserIsRecipient() {
    final User recipient = UserFactory.user().toBuilder().name("Ima Backer").id(123L).build();
    final User sender = UserFactory.user().toBuilder().name("Ima Creator").id(456L).build();
    final Message message = MessageFactory.message().toBuilder().recipient(recipient).sender(sender).build();
    final MockCurrentUser currentUser = new MockCurrentUser(recipient);
    setUpEnvironment(environment().toBuilder().currentUser(currentUser).build());
    this.vm.inputs.configureWith(message);
    this.messageBodyRecipientCardViewIsGone.assertValues(false);
    this.messageBodyRecipientTextViewText.assertValues(message.body());
    this.messageBodySenderCardViewIsGone.assertValues(true);
    this.messageBodySenderTextViewText.assertNoValues();
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Message(com.kickstarter.models.Message) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 5 with Message

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

the class MessageHolderViewModelTest method testMessageBodyTextViewFormatting_CurrentUserIsSender.

@Test
public void testMessageBodyTextViewFormatting_CurrentUserIsSender() {
    final User recipient = UserFactory.user().toBuilder().name("Ima Creator").id(123L).build();
    final User sender = UserFactory.user().toBuilder().name("Ima Backer").id(456L).build();
    final Message message = MessageFactory.message().toBuilder().recipient(recipient).sender(sender).build();
    final MockCurrentUser currentUser = new MockCurrentUser(sender);
    setUpEnvironment(environment().toBuilder().currentUser(currentUser).build());
    this.vm.inputs.configureWith(message);
    this.messageBodyRecipientCardViewIsGone.assertValues(true);
    this.messageBodyRecipientTextViewText.assertNoValues();
    this.messageBodySenderCardViewIsGone.assertValues(false);
    this.messageBodySenderTextViewText.assertValues(message.body());
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Message(com.kickstarter.models.Message) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

MockCurrentUser (com.kickstarter.libs.MockCurrentUser)6 Message (com.kickstarter.models.Message)6 Test (org.junit.Test)6 User (com.kickstarter.models.User)4 NonNull (androidx.annotation.NonNull)2 MockApiClient (com.kickstarter.mock.services.MockApiClient)2 MessageSubject (com.kickstarter.ui.data.MessageSubject)2