use of com.kickstarter.libs.preferences.MockIntPreference 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();
final DiscoveryFragmentViewModel vm = new DiscoveryFragmentViewModel(environment);
final TestSubscriber<Activity> activityTest = new TestSubscriber<>();
vm.outputs.activity().subscribe(activityTest);
final TestSubscriber<Boolean> shouldShowOnboardingViewTest = new TestSubscriber<>();
vm.outputs.shouldShowOnboardingView().subscribe(shouldShowOnboardingViewTest);
// Initial home all projects params.
vm.inputs.paramsFromActivity(DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).build());
vm.inputs.rootCategories(CategoryFactory.rootCategories());
// Should show onboarding view.
shouldShowOnboardingViewTest.assertValues(true);
activityTest.assertValue(null);
// Change params. Onboarding view should not be shown.
vm.inputs.paramsFromActivity(DiscoveryParams.builder().build());
shouldShowOnboardingViewTest.assertValues(true, false);
activityTest.assertValues(null, null);
// Login.
currentUser.refresh(UserFactory.user());
// Activity sampler should be shown rather than onboarding view.
shouldShowOnboardingViewTest.assertValues(true, false, false);
activityTest.assertValues(null, null, activity);
// Change params. Activity sampler should not be shown.
vm.inputs.paramsFromActivity(DiscoveryParams.builder().build());
activityTest.assertValues(null, null, activity, null);
}
Aggregations