use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.
the class BackingViewModelTest method testShowBackingFragmentFacing.
@Test
public void testShowBackingFragmentFacing() {
final User creatorUser = UserFactory.user().toBuilder().name("Kawhi Leonard").build();
final User backerUser = UserFactory.user().toBuilder().name("random backer").build();
final Backing backing = BackingFactory.backing(backerUser);
final Project project = ProjectFactory.project();
final BackingWrapper wrapper = new BackingWrapper(backing, backerUser, project);
setUpEnvironment(envWithBacking(backing).toBuilder().currentUser(new MockCurrentUser(creatorUser)).build());
this.vm.outputs.showBackingFragment().subscribe(it -> {
assertNotNull(it);
assertEquals(backing, it);
});
}
use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.
the class CommentsViewModelTest method testCommentsViewModel_loggedOutShowDialogFlow.
@Test
public void testCommentsViewModel_loggedOutShowDialogFlow() {
final CurrentUserType currentUser = new MockCurrentUser();
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
final CommentsViewModel vm = new CommentsViewModel(environment);
final Project project = ProjectFactory.backedProject();
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));
// The comment dialog should be hidden from logged out user.
showCommentDialogTest.assertNoValues();
// Login.
currentUser.refresh(UserFactory.user());
vm.inputs.loginSuccess();
// The comment dialog should be shown to backer.
showCommentDialogTest.assertValue(Pair.create(project, true));
}
use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.
the class SettingsViewModelTest method testSettingsViewModel_sendPromoNewsletter.
@Test
public void testSettingsViewModel_sendPromoNewsletter() {
final User user = UserFactory.user().toBuilder().promoNewsletter(false).build();
final CurrentUserType currentUser = new MockCurrentUser(user);
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
final SettingsViewModel vm = new SettingsViewModel(environment);
final TestSubscriber<User> currentUserTest = new TestSubscriber<>();
currentUser.observable().subscribe(currentUserTest);
final TestSubscriber<Newsletter> showOptInPromptTest = new TestSubscriber<>();
vm.outputs.showOptInPrompt().subscribe(showOptInPromptTest);
currentUserTest.assertValues(user);
koalaTest.assertValues("Settings View");
vm.inputs.sendPromoNewsletter(true);
koalaTest.assertValues("Settings View", "Newsletter Subscribe");
currentUserTest.assertValues(user, user.toBuilder().promoNewsletter(true).build());
vm.inputs.sendPromoNewsletter(false);
koalaTest.assertValues("Settings View", "Newsletter Subscribe", "Newsletter Unsubscribe");
currentUserTest.assertValues(user, user.toBuilder().promoNewsletter(true).build(), user);
showOptInPromptTest.assertNoValues();
}
use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.
the class SettingsViewModelTest method testSettingsViewModel_sendHappeningNewsletter.
@Test
public void testSettingsViewModel_sendHappeningNewsletter() {
final User user = UserFactory.user().toBuilder().happeningNewsletter(false).build();
final CurrentUserType currentUser = new MockCurrentUser(user);
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
final SettingsViewModel vm = new SettingsViewModel(environment);
final TestSubscriber<User> currentUserTest = new TestSubscriber<>();
currentUser.observable().subscribe(currentUserTest);
final TestSubscriber<Newsletter> showOptInPromptTest = new TestSubscriber<>();
vm.outputs.showOptInPrompt().subscribe(showOptInPromptTest);
currentUserTest.assertValues(user);
koalaTest.assertValues("Settings View");
vm.inputs.sendHappeningNewsletter(true);
koalaTest.assertValues("Settings View", "Newsletter Subscribe");
currentUserTest.assertValues(user, user.toBuilder().happeningNewsletter(true).build());
vm.inputs.sendHappeningNewsletter(false);
koalaTest.assertValues("Settings View", "Newsletter Subscribe", "Newsletter Unsubscribe");
currentUserTest.assertValues(user, user.toBuilder().happeningNewsletter(true).build(), user);
showOptInPromptTest.assertNoValues();
}
use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.
the class DiscoveryViewModelTest method setUpDefaultParamsTest.
private void setUpDefaultParamsTest(@Nullable final User user) {
final Environment.Builder environmentBuilder = environment().toBuilder();
if (user != null) {
final MockCurrentUser currentUser = new MockCurrentUser(user);
environmentBuilder.currentUser(currentUser);
}
this.vm = new DiscoveryViewModel.ViewModel(environmentBuilder.build());
this.vm.getOutputs().updateParamsForPage().subscribe(this.updateParams);
// Start initial activity.
final Intent intent = new Intent(Intent.ACTION_MAIN);
this.vm.intent(intent);
// Initial MAGIC page selected.
this.vm.getInputs().discoveryPagerAdapterSetPrimaryPage(Mockito.mock(DiscoveryPagerAdapter.class), 0);
}
Aggregations