use of rx.observers.TestSubscriber in project android-oss by kickstarter.
the class CommentsViewModelTest method testCommentsViewModel_EmptyState.
@Test
public void testCommentsViewModel_EmptyState() {
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<CommentsEnvelope> fetchComments(@NonNull final Update update) {
return Observable.empty();
}
};
final Environment env = environment().toBuilder().apiClient(apiClient).build();
final CommentsViewModel vm = new CommentsViewModel(env);
final TestSubscriber<CommentsData> commentsData = new TestSubscriber<>();
vm.outputs.commentsData().subscribe(commentsData);
// Start the view model with an update.
vm.intent(new Intent().putExtra(IntentKey.UPDATE, UpdateFactory.update()));
// Only Viewed Comments event should fire.
koalaTest.assertValues(KoalaEvent.VIEWED_COMMENTS);
commentsData.assertNoValues();
}
use of rx.observers.TestSubscriber in project android-oss by kickstarter.
the class CommentsViewModelTest method testCommentsViewModel_showCommentDialog.
@Test
public void testCommentsViewModel_showCommentDialog() {
final CommentsViewModel vm = new CommentsViewModel(environment());
final TestSubscriber<Pair<Project, Boolean>> showCommentDialogTest = new TestSubscriber<>();
vm.outputs.showCommentDialog().subscribe(showCommentDialogTest);
final Project project = ProjectFactory.backedProject();
// Start the view model with a backed project.
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
showCommentDialogTest.assertNoValues();
// Click the comment button.
vm.inputs.commentButtonClicked();
// The comment dialog should be shown.
showCommentDialogTest.assertValue(Pair.create(project, true));
}
use of rx.observers.TestSubscriber in project android-oss by kickstarter.
the class CommentsViewModelTest method testCommentsViewModel_postCommentFlow.
@Test
public void testCommentsViewModel_postCommentFlow() {
final CommentsViewModel vm = new CommentsViewModel(environment());
final Project project = ProjectFactory.backedProject();
final TestSubscriber<Void> showCommentPostedToastTest = new TestSubscriber<>();
vm.outputs.showCommentPostedToast().subscribe(showCommentPostedToastTest);
final TestSubscriber<Void> dismissCommentDialogTest = new TestSubscriber<>();
vm.outputs.dismissCommentDialog().subscribe(dismissCommentDialogTest);
final TestSubscriber<Boolean> postButtonIsEnabledTest = new TestSubscriber<>();
vm.outputs.enablePostButton().subscribe(postButtonIsEnabledTest);
final TestSubscriber<Boolean> showCommentButtonTest = new TestSubscriber<>();
vm.outputs.showCommentButton().subscribe(showCommentButtonTest);
final TestSubscriber<Pair<Project, Boolean>> showCommentDialogTest = new TestSubscriber<>();
vm.outputs.showCommentDialog().subscribe(showCommentDialogTest);
// Start the view model with a project.
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
koalaTest.assertValues(KoalaEvent.VIEWED_COMMENTS, KoalaEvent.PROJECT_COMMENT_VIEW);
// Comment button should be shown.
showCommentButtonTest.assertValue(true);
// Click comment button. Comment dialog should be shown.
vm.inputs.commentButtonClicked();
showCommentDialogTest.assertValue(Pair.create(project, true));
// Write a comment. The post button should be enabled with valid comment body.
vm.inputs.commentBodyChanged("");
postButtonIsEnabledTest.assertValues(false);
vm.inputs.commentBodyChanged("Some comment");
postButtonIsEnabledTest.assertValues(false, true);
// Post comment. Dialog should be dismissed.
vm.inputs.postCommentClicked();
dismissCommentDialogTest.assertValueCount(1);
// Comment posted toast should be shown.
showCommentPostedToastTest.assertValueCount(1);
// A koala event for commenting should be tracked.
koalaTest.assertValues(KoalaEvent.VIEWED_COMMENTS, KoalaEvent.PROJECT_COMMENT_VIEW, KoalaEvent.POSTED_COMMENT, KoalaEvent.PROJECT_COMMENT_CREATE);
}
use of rx.observers.TestSubscriber in project android-oss by kickstarter.
the class DiscoveryFragmentViewModelTest method testProjectsRefreshAfterLogin.
@Test
public void testProjectsRefreshAfterLogin() {
final CurrentUserType currentUser = new MockCurrentUser();
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
final DiscoveryFragmentViewModel vm = new DiscoveryFragmentViewModel(environment);
final TestSubscriber<List<Project>> projects = new TestSubscriber<>();
vm.outputs.projects().filter(ListUtils::nonEmpty).subscribe(projects);
// Initial load.
vm.inputs.rootCategories(CategoryFactory.rootCategories());
vm.inputs.paramsFromActivity(DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).build());
// Projects should emit.
projects.assertValueCount(1);
// Log in.
currentUser.refresh(UserFactory.user());
// Projects should emit again.
projects.assertValueCount(2);
}
use of rx.observers.TestSubscriber in project android-oss by kickstarter.
the class DiscoveryViewModelTest method testDrawerData.
@Test
public void testDrawerData() {
final MockCurrentUser currentUser = new MockCurrentUser();
final Environment env = environment().toBuilder().currentUser(currentUser).build();
final DiscoveryViewModel vm = new DiscoveryViewModel(env);
final TestSubscriber<Void> navigationDrawerDataEmitted = new TestSubscriber<>();
vm.outputs.navigationDrawerData().compose(Transformers.ignoreValues()).subscribe(navigationDrawerDataEmitted);
final TestSubscriber<Boolean> drawerIsOpen = new TestSubscriber<>();
vm.outputs.drawerIsOpen().subscribe(drawerIsOpen);
// Initialize activity.
final Intent intent = new Intent(Intent.ACTION_MAIN);
vm.intent(intent);
// Drawer data should emit. Drawer should be closed.
navigationDrawerDataEmitted.assertValueCount(1);
drawerIsOpen.assertNoValues();
koalaTest.assertNoValues();
// Open drawer and click the top PWL filter.
vm.inputs.openDrawer(true);
vm.inputs.topFilterViewHolderRowClick(null, NavigationDrawerData.Section.Row.builder().params(DiscoveryParams.builder().staffPicks(true).build()).build());
// Drawer data should emit. Drawer should open, then close upon selection.
navigationDrawerDataEmitted.assertValueCount(2);
drawerIsOpen.assertValues(true, false);
koalaTest.assertValues("Discover Switch Modal", "Discover Modal Selected Filter");
// Open drawer and click a child filter.
vm.inputs.openDrawer(true);
vm.inputs.childFilterViewHolderRowClick(null, NavigationDrawerData.Section.Row.builder().params(DiscoveryParams.builder().category(CategoryFactory.artCategory()).build()).build());
// Drawer data should emit. Drawer should open, then close upon selection.
navigationDrawerDataEmitted.assertValueCount(3);
drawerIsOpen.assertValues(true, false, true, false);
koalaTest.assertValues("Discover Switch Modal", "Discover Modal Selected Filter", "Discover Switch Modal", "Discover Modal Selected Filter");
}
Aggregations