Search in sources :

Example 1 with ApolloClientType

use of com.kickstarter.services.ApolloClientType in project android-oss by kickstarter.

the class DiscoveryFragmentViewModelTest method testShouldShowEmptySavedView_isTrue_whenUserHasNoSavedProjects.

@Test
public void testShouldShowEmptySavedView_isTrue_whenUserHasNoSavedProjects() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final ApolloClientType apiClient = new MockApolloClient() {

        @Override
        @NonNull
        public Observable<DiscoverEnvelope> getProjects(@NonNull final DiscoveryParams params, final String cursor) {
            if (params.isSavedProjects()) {
                return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(new ArrayList<>()));
            } else {
                return super.getProjects(params, cursor);
            }
        }
    };
    final Environment environment = environment().toBuilder().apolloClient(apiClient).currentUser(currentUser).build();
    setUpEnvironment(environment);
    // Initial home all projects params.
    setUpInitialHomeAllProjectsParams();
    this.hasProjects.assertValue(true);
    this.shouldShowEmptySavedView.assertValue(false);
    // Login.
    logUserIn(currentUser);
    // New projects load.
    this.hasProjects.assertValues(true, true, true, true);
    this.shouldShowEmptySavedView.assertValues(false);
    // Saved projects params.
    this.vm.inputs.paramsFromActivity(DiscoveryParams.builder().starred(1).build());
    // Projects are cleared, new projects load with updated params.
    this.hasProjects.assertValues(true, true, true, true, false, false);
    this.shouldShowEmptySavedView.assertValues(false, true);
}
Also used : MockApolloClient(com.kickstarter.mock.services.MockApolloClient) DiscoverEnvelope(com.kickstarter.services.apiresponses.DiscoverEnvelope) NonNull(androidx.annotation.NonNull) ApolloClientType(com.kickstarter.services.ApolloClientType) ArrayList(java.util.ArrayList) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) DiscoveryParams(com.kickstarter.services.DiscoveryParams) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

NonNull (androidx.annotation.NonNull)1 CurrentUserType (com.kickstarter.libs.CurrentUserType)1 Environment (com.kickstarter.libs.Environment)1 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)1 MockApolloClient (com.kickstarter.mock.services.MockApolloClient)1 ApolloClientType (com.kickstarter.services.ApolloClientType)1 DiscoveryParams (com.kickstarter.services.DiscoveryParams)1 DiscoverEnvelope (com.kickstarter.services.apiresponses.DiscoverEnvelope)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1