Search in sources :

Example 26 with ApiClientType

use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.

the class DiscoveryFragmentViewModelTest method testShowHeaderViews.

@Test
public void testShowHeaderViews() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Activity activity = ActivityFactory.activity();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<ActivityEnvelope> fetchActivities() {
            return Observable.just(ActivityEnvelopeFactory.activityEnvelope(Collections.singletonList(activity)));
        }
    };
    final MockIntPreference activitySamplePreference = new MockIntPreference(987654321);
    final Environment environment = environment().toBuilder().activitySamplePreference(activitySamplePreference).apiClient(apiClient).currentUser(currentUser).build();
    setUpEnvironment(environment);
    // Initial home all projects params.
    setUpInitialHomeAllProjectsParams();
    // Should show onboarding view.
    this.shouldShowOnboardingViewTest.assertValues(true);
    this.activityTest.assertNoValues();
    // Change params. Onboarding view should not be shown.
    this.vm.inputs.paramsFromActivity(DiscoveryParams.builder().sort(DiscoveryParams.Sort.NEWEST).build());
    this.shouldShowOnboardingViewTest.assertValues(true, false);
    this.activityTest.assertNoValues();
    // Login.
    logUserIn(currentUser);
    // Activity sampler should be shown rather than onboarding view.
    this.shouldShowOnboardingViewTest.assertValues(true, false, false, false);
    this.activityTest.assertValues(null, activity);
    // Change params. Activity sampler should not be shown.
    this.vm.inputs.paramsFromActivity(DiscoveryParams.builder().build());
    this.activityTest.assertValues(null, activity, null);
}
Also used : ActivityEnvelope(com.kickstarter.services.apiresponses.ActivityEnvelope) MockIntPreference(com.kickstarter.libs.preferences.MockIntPreference) MockApiClient(com.kickstarter.mock.services.MockApiClient) Activity(com.kickstarter.models.Activity) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) ApiClientType(com.kickstarter.services.ApiClientType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 27 with ApiClientType

use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.

the class MessageThreadsViewModelTest method testMailboxTitle.

@Test
public void testMailboxTitle() {
    final User user = UserFactory.user();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<User> fetchCurrentUser() {
            return Observable.just(user);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
    this.vm.intent(new Intent());
    this.vm.inputs.onResume();
    this.mailboxTitle.assertValue(R.string.messages_navigation_inbox);
    this.vm.inputs.mailbox(Mailbox.SENT);
    this.mailboxTitle.assertValues(R.string.messages_navigation_inbox, R.string.messages_navigation_sent);
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 28 with ApiClientType

use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.

the class MessageThreadsViewModelTest method testMessageThreadsEmit_WithProjectIntent.

@Test
public void testMessageThreadsEmit_WithProjectIntent() {
    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 Project project = ProjectFactory.project().toBuilder().unreadMessagesCount(5).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);
        }

        @Override
        @NonNull
        public Observable<Project> fetchProject(@NonNull final String param) {
            return Observable.just(project);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(currentUser).build());
    final Intent intent = new Intent().putExtra(IntentKey.PROJECT, project);
    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)

Example 29 with ApiClientType

use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.

the class MessageThreadsViewModelTest method testNoUnreadMessages.

@Test
public void testNoUnreadMessages() {
    final User user = UserFactory.user().toBuilder().unreadMessagesCount(0).build();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<User> fetchCurrentUser() {
            return Observable.just(user);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
    this.vm.intent(new Intent());
    this.vm.inputs.onResume();
    this.hasNoUnreadMessages.assertValues(true);
    this.unreadMessagesCount.assertNoValues();
    this.unreadMessagesCountIsGone.assertValue(false);
    this.unreadCountTextViewColorInt.assertValues(R.color.kds_support_400);
    this.unreadCountTextViewTypefaceInt.assertValues(Typeface.NORMAL);
    this.unreadCountToolbarTextViewIsGone.assertValues(true);
    this.vm.inputs.mailbox(Mailbox.SENT);
    this.unreadMessagesCountIsGone.assertValues(false, true);
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 30 with ApiClientType

use of com.kickstarter.services.ApiClientType in project android-oss by kickstarter.

the class ProjectNotificationsViewModelTest method testShowUnableToSaveNotificationError.

@Test
public void testShowUnableToSaveNotificationError() {
    final ApiClientType client = new MockApiClient() {

        @Override
        @NonNull
        public Observable<ProjectNotification> updateProjectNotifications(@NonNull final ProjectNotification projectNotification, final boolean checked) {
            return Observable.error(ApiExceptionFactory.badRequestException());
        }
    };
    final Environment environment = environment().toBuilder().apiClient(client).build();
    this.vm = new ProjectNotificationViewModel.ViewModel(environment);
    this.vm.outputs.showUnableToSaveProjectNotificationError().subscribe(this.showUnableToSaveNotificationErrorTest);
    this.vm.outputs.enabledSwitch().subscribe(this.enabledSwitchTest);
    // Start with a disabled notification.
    final ProjectNotification projectNotification = ProjectNotificationFactory.disabled();
    this.vm.inputs.projectNotification(projectNotification);
    // Switch should be disabled.
    this.enabledSwitchTest.assertValue(false);
    // Attempt to toggle the notification to true. This should error, and the switch should still be disabled.
    this.vm.enabledSwitchClick(true);
    this.showUnableToSaveNotificationErrorTest.assertValueCount(1);
    this.enabledSwitchTest.assertValue(false);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) ProjectNotification(com.kickstarter.models.ProjectNotification) Environment(com.kickstarter.libs.Environment) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Aggregations

ApiClientType (com.kickstarter.services.ApiClientType)31 Test (org.junit.Test)31 Environment (com.kickstarter.libs.Environment)25 MockApiClient (com.kickstarter.mock.services.MockApiClient)19 TestSubscriber (rx.observers.TestSubscriber)18 Intent (android.content.Intent)16 NonNull (androidx.annotation.NonNull)12 MockApiClient (com.kickstarter.services.MockApiClient)12 User (com.kickstarter.models.User)9 NonNull (android.support.annotation.NonNull)8 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)8 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)8 Update (com.kickstarter.models.Update)5 CurrentUserType (com.kickstarter.libs.CurrentUserType)4 Project (com.kickstarter.models.Project)3 Nullable (androidx.annotation.Nullable)2 ProjectNotification (com.kickstarter.models.ProjectNotification)2 MessageThreadsEnvelope (com.kickstarter.services.apiresponses.MessageThreadsEnvelope)2 Mailbox (com.kickstarter.ui.data.Mailbox)2 TestScheduler (rx.schedulers.TestScheduler)2