use of rx.schedulers.TestScheduler in project android-oss by kickstarter.
the class UpdateViewModelTest method testUpdateViewModel_DeepLinkComment.
@Test
public void testUpdateViewModel_DeepLinkComment() {
final String postId = "3254626";
final Update update = UpdateFactory.update();
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<Update> fetchUpdate(@NonNull final String projectParam, @NonNull final String updateParam) {
return Observable.just(update);
}
};
final TestScheduler testScheduler = new TestScheduler();
final Environment environment = environment().toBuilder().apiClient(apiClient).scheduler(testScheduler).build();
final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
final TestSubscriber<Update> startRootCommentsActivity = new TestSubscriber<>();
vm.outputs.startRootCommentsActivity().subscribe(startRootCommentsActivity);
final TestSubscriber<String> webViewUrl = new TestSubscriber<>();
vm.outputs.webViewUrl().subscribe(webViewUrl);
final TestSubscriber<Boolean> deepLinkToRootComment = new TestSubscriber<>();
vm.hasCommentsDeepLinks().subscribe(deepLinkToRootComment);
// Start the intent with a project and update.
vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.project()).putExtra(IntentKey.UPDATE_POST_ID, postId).putExtra(IntentKey.IS_UPDATE_COMMENT, true));
// Initial update index url emits.
webViewUrl.assertValues(update.urls().web().update());
deepLinkToRootComment.assertValue(true);
vm.inputs.goToCommentsActivity();
testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
startRootCommentsActivity.assertValue(update);
startRootCommentsActivity.assertValueCount(1);
}
use of rx.schedulers.TestScheduler in project android-oss by kickstarter.
the class SearchViewModelTest method testFeaturedSearchRefTags.
@Test
public void testFeaturedSearchRefTags() {
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);
this.vm.inputs.search("cat");
scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
this.vm.inputs.projectClicked(projects.get(0));
this.goToRefTag.assertValues(RefTag.searchFeatured());
this.goToProject.assertValues(projects.get(0));
}
use of rx.schedulers.TestScheduler in project android-oss by kickstarter.
the class SearchViewModelTest method testSearchRefTags.
@Test
public void testSearchRefTags() {
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("cat");
scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
this.vm.inputs.projectClicked(projects.get(1));
this.goToRefTag.assertValues(RefTag.search());
this.goToProject.assertValues(projects.get(1));
}
use of rx.schedulers.TestScheduler in project android-oss by kickstarter.
the class SearchViewModelTest method init_whenProjectCardClicked_shouldTrackProjectEvent.
@Test
public void init_whenProjectCardClicked_shouldTrackProjectEvent() {
final TestScheduler scheduler = new TestScheduler();
final Environment env = environment().toBuilder().scheduler(scheduler).build();
setUpEnvironment(env);
this.vm.inputs.search("hello");
this.segmentTrack.assertValues(EventName.CTA_CLICKED.getEventName());
this.vm.inputs.projectClicked(ProjectFactory.project());
this.segmentTrack.assertValues(EventName.CTA_CLICKED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
use of rx.schedulers.TestScheduler in project android-oss by kickstarter.
the class SearchViewModelTest method testSearchPagination.
@Test
public void testSearchPagination() {
final TestScheduler scheduler = new TestScheduler();
final Environment env = environment().toBuilder().scheduler(scheduler).build();
setUpEnvironment(env);
this.searchProjectsPresent.assertNoValues();
this.segmentTrack.assertValues(EventName.CTA_CLICKED.getEventName());
this.vm.inputs.search("cats");
scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
this.searchProjectsPresent.assertValues(false, true);
this.vm.inputs.nextPage();
this.searchProjectsPresent.assertValues(false, true);
}
Aggregations