Search in sources :

Example 1 with MockIntPreference

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);
}
Also used : MockIntPreference(com.kickstarter.libs.preferences.MockIntPreference) MockApiClient(com.kickstarter.services.MockApiClient) Activity(com.kickstarter.models.Activity) ApiClientType(com.kickstarter.services.ApiClientType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ActivityEnvelope(com.kickstarter.services.apiresponses.ActivityEnvelope) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) CurrentUserType(com.kickstarter.libs.CurrentUserType) Test(org.junit.Test)

Aggregations

CurrentUserType (com.kickstarter.libs.CurrentUserType)1 Environment (com.kickstarter.libs.Environment)1 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)1 MockIntPreference (com.kickstarter.libs.preferences.MockIntPreference)1 Activity (com.kickstarter.models.Activity)1 ApiClientType (com.kickstarter.services.ApiClientType)1 MockApiClient (com.kickstarter.services.MockApiClient)1 ActivityEnvelope (com.kickstarter.services.apiresponses.ActivityEnvelope)1 Test (org.junit.Test)1 TestSubscriber (rx.observers.TestSubscriber)1