Search in sources :

Example 26 with MockCurrentUser

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

the class MessagesViewModelTest method testBackingInfo_NoBacking.

@Test
public void testBackingInfo_NoBacking() {
    final Project project = ProjectFactory.project().toBuilder().isBacking(false).build();
    final MessageThread messageThread = MessageThreadFactory.messageThread().toBuilder().project(project).backing(null).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Backing> fetchProjectBacking(@NonNull final Project project, @NonNull final User user) {
            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(messageThread));
    this.backingAndProject.assertNoValues();
    this.backingInfoViewIsGone.assertValues(true);
}
Also used : Project(com.kickstarter.models.Project) 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) Backing(com.kickstarter.models.Backing) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 27 with MockCurrentUser

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

the class MessagesViewModelTest method testSuccessfullyMarkedAsRead.

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

        @NonNull
        @Override
        public Observable<MessageThread> markAsRead(@NonNull final MessageThread thread) {
            return Observable.just(messageThread);
        }
    };
    setUpEnvironment(environment().toBuilder().currentUser(new MockCurrentUser(UserFactory.user())).apiClient(apiClient).build());
    this.vm.intent(messagesContextIntent(messageThread));
    this.successfullyMarkedAsRead.assertValueCount(1);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MessageThread(com.kickstarter.models.MessageThread) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 28 with MockCurrentUser

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

the class MessagesViewModelTest method testBackButton_IsGone.

@Test
public void testBackButton_IsGone() {
    setUpEnvironment(environment().toBuilder().currentUser(new MockCurrentUser(UserFactory.user())).build());
    this.vm.intent(messagesContextIntent(MessageThreadFactory.messageThread()));
    // Back button is gone if navigating from non-backer modal view.
    this.backButtonIsGone.assertValues(true);
    this.closeButtonIsGone.assertValues(false);
}
Also used : MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 29 with MockCurrentUser

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

the class MessagesViewModelTest method testRecyclerViewBottomPadding.

@Test
public void testRecyclerViewBottomPadding() {
    final int appBarTotalScrolLRange = 327;
    setUpEnvironment(environment().toBuilder().currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a message thread.
    this.vm.intent(messagesContextIntent(MessageThreadFactory.messageThread()));
    // View initially loaded with a 0 (expanded) offset.
    this.vm.inputs.appBarOffset(0);
    this.vm.inputs.appBarTotalScrollRange(appBarTotalScrolLRange);
    // Only initial bottom padding emits.
    this.recyclerViewDefaultBottomPadding.assertNoValues();
    this.recyclerViewInitialBottomPadding.assertValues(appBarTotalScrolLRange);
    // User scrolls.
    this.vm.inputs.appBarOffset(-30);
    this.vm.inputs.appBarTotalScrollRange(appBarTotalScrolLRange);
    // Default padding emits, initial padding does not emit again.
    this.recyclerViewDefaultBottomPadding.assertValueCount(1);
    this.recyclerViewInitialBottomPadding.assertValues(appBarTotalScrolLRange);
    // User scrolls.
    this.vm.inputs.appBarOffset(20);
    this.vm.inputs.appBarTotalScrollRange(appBarTotalScrolLRange);
    // Padding does not change.
    this.recyclerViewDefaultBottomPadding.assertValueCount(1);
    this.recyclerViewInitialBottomPadding.assertValues(appBarTotalScrolLRange);
}
Also used : MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 30 with MockCurrentUser

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

the class MessagesViewModelTest method testBackingAndProject_Participant.

@Test
public void testBackingAndProject_Participant() {
    final Project project = ProjectFactory.project().toBuilder().isBacking(false).build();
    final Backing backing = BackingFactory.backing().toBuilder().project(project).build();
    final MessageThread messageThread = MessageThreadFactory.messageThread().toBuilder().project(project).backing(backing).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForThread(@NonNull final MessageThread messageThread) {
            return Observable.just(MessageThreadEnvelopeFactory.messageThreadEnvelope());
        }

        @Override
        @NonNull
        public Observable<Backing> fetchProjectBacking(@NonNull final Project project, @NonNull final User user) {
            return Observable.just(backing);
        }
    };
    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.backingAndProject.assertValues(Pair.create(backing, backing.project()));
    this.backingInfoViewIsGone.assertValues(false);
}
Also used : Project(com.kickstarter.models.Project) 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) 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