Search in sources :

Example 36 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser 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 37 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser 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 38 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser 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 39 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser 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)

Example 40 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser 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)

Aggregations

MockCurrentUser (com.kickstarter.libs.MockCurrentUser)86 Test (org.junit.Test)85 CurrentUserType (com.kickstarter.libs.CurrentUserType)43 Environment (com.kickstarter.libs.Environment)39 Project (com.kickstarter.models.Project)31 User (com.kickstarter.models.User)31 MockApiClient (com.kickstarter.mock.services.MockApiClient)29 NonNull (androidx.annotation.NonNull)26 Intent (android.content.Intent)16 MockExperimentsClientType (com.kickstarter.mock.MockExperimentsClientType)12 MessageThreadEnvelope (com.kickstarter.services.apiresponses.MessageThreadEnvelope)12 Backing (com.kickstarter.models.Backing)11 NotNull (org.jetbrains.annotations.NotNull)11 MessageThread (com.kickstarter.models.MessageThread)10 TestSubscriber (rx.observers.TestSubscriber)10 ProjectDashboardData (com.kickstarter.ui.adapters.data.ProjectDashboardData)7 MockBooleanPreference (com.kickstarter.libs.preferences.MockBooleanPreference)6 Message (com.kickstarter.models.Message)6 DiscoveryParams (com.kickstarter.services.DiscoveryParams)6 IntentKey (com.kickstarter.ui.IntentKey)6