Search in sources :

Example 26 with TestScheduler

use of rx.schedulers.TestScheduler in project android-oss by kickstarter.

the class SearchViewModelTest method testPopularRefTags.

@Test
public void testPopularRefTags() {
    final TestScheduler scheduler = new TestScheduler();
    final List<Project> projects = Arrays.asList(ProjectFactory.allTheWayProject(), ProjectFactory.almostCompletedProject(), ProjectFactory.backedProject());
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<DiscoverEnvelope> fetchProjects(@NonNull final DiscoveryParams params) {
            return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(projects));
        }
    };
    final Environment env = environment().toBuilder().scheduler(scheduler).apiClient(apiClient).build();
    setUpEnvironment(env);
    // populate search and overcome debounce
    this.vm.inputs.search("");
    scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
    this.vm.inputs.projectClicked(projects.get(2));
    this.goToRefTag.assertValues(RefTag.searchPopular());
    this.goToProject.assertValues(projects.get(2));
}
Also used : Project(com.kickstarter.models.Project) DiscoverEnvelope(com.kickstarter.services.apiresponses.DiscoverEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestScheduler(rx.schedulers.TestScheduler) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Test(org.junit.Test)

Aggregations

TestScheduler (rx.schedulers.TestScheduler)26 Test (org.junit.Test)23 TestSubscriber (rx.observers.TestSubscriber)12 Environment (com.kickstarter.libs.Environment)11 NonNull (androidx.annotation.NonNull)8 MockApiClient (com.kickstarter.mock.services.MockApiClient)8 Project (com.kickstarter.models.Project)6 DiscoveryParams (com.kickstarter.services.DiscoveryParams)6 DiscoverEnvelope (com.kickstarter.services.apiresponses.DiscoverEnvelope)6 EpisodeHeroNameQuery (com.apollographql.apollo.integration.normalizer.EpisodeHeroNameQuery)3 Override (java.lang.Override)3 List (java.util.List)3 Before (org.junit.Before)3 Subscription (rx.Subscription)3 Action0 (rx.functions.Action0)3 Intent (android.content.Intent)2 Utils.mockResponse (com.apollographql.apollo.Utils.mockResponse)2 Response (com.apollographql.apollo.api.Response)2 Update (com.kickstarter.models.Update)2 ApiClientType (com.kickstarter.services.ApiClientType)2