use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class CreatorDashboardViewModelTest method testProjectsForBottomSheet_With1Project.
@Test
public void testProjectsForBottomSheet_With1Project() {
final List<Project> projects = Collections.singletonList(ProjectFactory.project());
final MockApiClient apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<ProjectsEnvelope> fetchProjects(final boolean member) {
return Observable.just(ProjectsEnvelopeFactory.projectsEnvelope(projects));
}
};
setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
this.projectsForBottomSheet.assertNoValues();
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class CreatorDashboardViewModelTest method testProjectsForBottomSheet_WithManyProjects.
@Test
public void testProjectsForBottomSheet_WithManyProjects() {
final Project project1 = ProjectFactory.project();
final Project project2 = ProjectFactory.project();
final List<Project> projects = Arrays.asList(project1, project2);
final MockApiClient apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<ProjectsEnvelope> fetchProjects(final boolean member) {
return Observable.just(ProjectsEnvelopeFactory.projectsEnvelope(projects));
}
};
setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
this.vm.intent(new Intent());
this.projectsForBottomSheet.assertValue(Collections.singletonList(project2));
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class CreatorDashboardViewModelTest method testProjectName_whenSingleProject.
@Test
public void testProjectName_whenSingleProject() {
final Project project = ProjectFactory.project().toBuilder().name("Best Project 2K19").build();
final MockApiClient apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<ProjectsEnvelope> fetchProjects(final boolean member) {
return Observable.just(ProjectsEnvelopeFactory.projectsEnvelope(Collections.singletonList(project)));
}
};
setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
this.vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
this.projectName.assertValue("Best Project 2K19");
}
use of com.kickstarter.mock.services.MockApiClient 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);
}
use of com.kickstarter.mock.services.MockApiClient 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);
}
Aggregations