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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations