Search in sources :

Example 71 with MockCurrentUser

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

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

the class DiscoveryFragmentViewModelTest method testErroredResponseForFetchActivitiesWithCount.

@Test
public void testErroredResponseForFetchActivitiesWithCount() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Throwable throwableError = new Throwable();
    final MockApiClient apiClient = new MockApiClient() {

        @NonNull
        @Override
        public Observable<ActivityEnvelope> fetchActivities(@Nullable final Integer count) {
            return Observable.error(throwableError);
        }
    };
    final Environment env = environment().toBuilder().currentUser(currentUser).apiClient(apiClient).build();
    setUpEnvironment(env);
    // Load initial params and root categories from activity.
    setUpInitialHomeAllProjectsParams();
    // Log in.
    logUserIn(currentUser);
    this.activityTest.assertValueCount(1);
    this.activityTest.assertError(throwableError);
    this.activityTest.assertValue(null);
}
Also used : ActivityEnvelope(com.kickstarter.services.apiresponses.ActivityEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) Nullable(androidx.annotation.Nullable) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 73 with MockCurrentUser

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

the class DiscoveryFragmentViewModelTest method testSaveProject.

@Test
public void testSaveProject() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().currentUser(currentUser).scheduler(this.testScheduler).build();
    setUpEnvironment(environment);
    // Login.
    final User user = UserFactory.user();
    currentUser.refresh(user);
    final BehaviorSubject<List<Pair<Project, DiscoveryParams>>> projects = BehaviorSubject.create();
    this.vm.outputs.projectList().subscribe(projects);
    // Initial home all projects params.
    setUpInitialHomeAllProjectsParams();
    // Click on project save
    final Project project = projects.getValue().get(0).first;
    this.vm.inputs.onHeartButtonClicked(project);
    this.startLoginToutActivityToSaveProject.assertNoValues();
    this.projects.assertValueCount(2);
    assertTrue(projects.getValue().get(0).first.isStarred());
    this.showSavedPromptTest.assertValueCount(1);
    this.segmentTrack.assertValues(EventName.PAGE_VIEWED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
Also used : Project(com.kickstarter.models.Project) User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Environment(com.kickstarter.libs.Environment) ArrayList(java.util.ArrayList) List(java.util.List) CurrentUserType(com.kickstarter.libs.CurrentUserType) DiscoveryParams(com.kickstarter.services.DiscoveryParams) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 74 with MockCurrentUser

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

the class DiscoveryFragmentViewModelTest method testStartProjectActivity_whenFeatureFlagEnabled_shouldEmitProjectPageActivity.

@Test
public void testStartProjectActivity_whenFeatureFlagEnabled_shouldEmitProjectPageActivity() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final MockExperimentsClientType mockExperimentsClientType = new MockExperimentsClientType() {

        @Override
        public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature) {
            return true;
        }
    };
    this.setUpEnvironment(this.environment().toBuilder().currentUser(currentUser).optimizely(mockExperimentsClientType).build());
    // Load initial params and root categories from activity.
    setUpInitialHomeAllProjectsParams();
    // Click on project
    final Project project = ProjectFactory.project();
    this.vm.inputs.projectCardViewHolderClicked(project);
    this.startProjectActivity.assertValueCount(1);
    assertEquals(this.startProjectActivity.getOnNextEvents().get(0).first, project);
    assertEquals(this.startProjectActivity.getOnNextEvents().get(0).second, RefTag.discovery());
    this.segmentTrack.assertValues(EventName.PAGE_VIEWED.getEventName(), EventName.CARD_CLICKED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
Also used : Project(com.kickstarter.models.Project) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) NotNull(org.jetbrains.annotations.NotNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 75 with MockCurrentUser

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

the class DiscoveryFragmentViewModelTest method testLoginToutToSaveProject.

@Test
public void testLoginToutToSaveProject() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().currentUser(currentUser).scheduler(this.testScheduler).build();
    setUpEnvironment(environment);
    final BehaviorSubject<List<Pair<Project, DiscoveryParams>>> projects = BehaviorSubject.create();
    this.vm.outputs.projectList().subscribe(projects);
    // Initial home all projects params.
    setUpInitialHomeAllProjectsParams();
    // Click on project save
    final Project project = projects.getValue().get(0).first;
    this.vm.inputs.onHeartButtonClicked(project);
    this.startLoginToutActivityToSaveProject.assertValue(project);
    // Login.
    final User user = UserFactory.user();
    currentUser.refresh(user);
    this.showSavedPromptTest.assertValueCount(1);
    this.segmentTrack.assertValues(EventName.PAGE_VIEWED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
Also used : Project(com.kickstarter.models.Project) User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Environment(com.kickstarter.libs.Environment) ArrayList(java.util.ArrayList) List(java.util.List) CurrentUserType(com.kickstarter.libs.CurrentUserType) DiscoveryParams(com.kickstarter.services.DiscoveryParams) 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