Search in sources :

Example 61 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.

the class MessagesViewModelTest method testViewPledgeButton_IsVisible_creatorBioModal.

@Test
public void testViewPledgeButton_IsVisible_creatorBioModal() {
    setUpEnvironment(environment().toBuilder().currentUser(new MockCurrentUser(UserFactory.user())).build());
    this.vm.intent(creatorBioModalContextIntent(BackingFactory.backing(), ProjectFactory.project()));
    // View pledge button is shown when context is from the creator bio modal.
    this.viewPledgeButtonIsGone.assertValues(false);
}
Also used : MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 62 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.

the class MessagesViewModelTest method testViewPledgeButton_IsVisible.

@Test
public void testViewPledgeButton_IsVisible() {
    setUpEnvironment(environment().toBuilder().currentUser(new MockCurrentUser(UserFactory.user())).build());
    this.vm.intent(messagesContextIntent(MessageThreadFactory.messageThread()));
    // View pledge button is shown when context is from anywhere but the backer modal.
    this.viewPledgeButtonIsGone.assertValues(false);
}
Also used : MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 63 with MockCurrentUser

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

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

Example 65 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.

the class MessagesViewModelTest method testNoMessages.

@Test
public void testNoMessages() {
    final Backing backing = BackingFactory.backing();
    final Project project = ProjectFactory.project();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForBacking(@NonNull final Backing backing) {
            return Observable.just(MessageThreadEnvelopeFactory.empty());
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a backing and a project.
    this.vm.intent(backerModalContextIntent(backing, project));
    // All data except for messages should emit.
    this.messageList.assertNoValues();
    this.creatorNameTextViewText.assertValues(project.creator().name());
    this.backingAndProject.assertValues(Pair.create(backing, project));
}
Also used : Project(com.kickstarter.models.Project) 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)

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