use of com.kickstarter.libs.CurrentUserType in project android-oss by kickstarter.
the class ThanksViewModelTest method testThanksViewModel_signupToGamesNewsletterOnClick.
@Test
public void testThanksViewModel_signupToGamesNewsletterOnClick() {
final User user = UserFactory.user().toBuilder().gamesNewsletter(false).build();
final CurrentUserType currentUser = new MockCurrentUser(user);
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
final ThanksViewModel vm = new ThanksViewModel(environment);
final TestSubscriber<User> updateUserSettingsTest = new TestSubscriber<>();
((MockApiClient) environment.apiClient()).observable().filter(e -> "update_user_settings".equals(e.first)).map(e -> (User) e.second.get("user")).subscribe(updateUserSettingsTest);
final TestSubscriber<Void> showConfirmGamesNewsletterDialogTest = TestSubscriber.create();
vm.outputs.showConfirmGamesNewsletterDialog().subscribe(showConfirmGamesNewsletterDialogTest);
final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
vm.signupToGamesNewsletterClick();
updateUserSettingsTest.assertValues(user.toBuilder().gamesNewsletter(true).build());
showConfirmGamesNewsletterDialogTest.assertValueCount(0);
koalaTest.assertValues("Newsletter Subscribe");
}
use of com.kickstarter.libs.CurrentUserType in project android-oss by kickstarter.
the class ThanksViewModelTest method testThanksViewModel_showGamesNewsletterDialog.
@Test
public void testThanksViewModel_showGamesNewsletterDialog() {
final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(false);
final User user = UserFactory.user().toBuilder().gamesNewsletter(false).build();
final CurrentUserType currentUser = new MockCurrentUser(user);
final Environment environment = environment().toBuilder().currentUser(currentUser).hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference).build();
final ThanksViewModel vm = new ThanksViewModel(environment);
final TestSubscriber<Void> showGamesNewsletterDialogTest = new TestSubscriber<>();
vm.outputs.showGamesNewsletterDialog().subscribe(showGamesNewsletterDialogTest);
final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
showGamesNewsletterDialogTest.assertValueCount(1);
assertEquals(Arrays.asList(false, true), hasSeenGamesNewsletterPreference.values());
koalaTest.assertValueCount(0);
}
use of com.kickstarter.libs.CurrentUserType in project android-oss by kickstarter.
the class ThanksViewModelTest method testThanksViewModel_showNewsletterConfirmationPromptAfterSignupForGermanUser.
@Test
public void testThanksViewModel_showNewsletterConfirmationPromptAfterSignupForGermanUser() {
final User user = UserFactory.user().toBuilder().gamesNewsletter(false).location(LocationFactory.germany()).build();
final CurrentUserType currentUser = new MockCurrentUser(user);
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
final ThanksViewModel vm = new ThanksViewModel(environment);
final TestSubscriber<Void> showConfirmGamesNewsletterDialogTest = TestSubscriber.create();
vm.outputs.showConfirmGamesNewsletterDialog().subscribe(showConfirmGamesNewsletterDialogTest);
final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
vm.signupToGamesNewsletterClick();
showConfirmGamesNewsletterDialogTest.assertValueCount(1);
koalaTest.assertValues("Newsletter Subscribe");
}
use of com.kickstarter.libs.CurrentUserType in project android-oss by kickstarter.
the class SettingsViewModelTest method testSettingsViewModel_sendWeeklyNewsletter.
@Test
public void testSettingsViewModel_sendWeeklyNewsletter() {
final User user = UserFactory.user().toBuilder().weeklyNewsletter(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.sendWeeklyNewsletter(true);
koalaTest.assertValues("Settings View", "Newsletter Subscribe");
currentUserTest.assertValues(user, user.toBuilder().weeklyNewsletter(true).build());
vm.inputs.sendWeeklyNewsletter(false);
koalaTest.assertValues("Settings View", "Newsletter Subscribe", "Newsletter Unsubscribe");
currentUserTest.assertValues(user, user.toBuilder().weeklyNewsletter(true).build(), user);
showOptInPromptTest.assertNoValues();
}
use of com.kickstarter.libs.CurrentUserType in project android-oss by kickstarter.
the class SettingsViewModelTest method testSettingsViewModel_sendGamesNewsletter.
@Test
public void testSettingsViewModel_sendGamesNewsletter() {
final User user = UserFactory.user().toBuilder().gamesNewsletter(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.sendGamesNewsletter(true);
koalaTest.assertValues("Settings View", "Newsletter Subscribe");
currentUserTest.assertValues(user, user.toBuilder().gamesNewsletter(true).build());
vm.inputs.sendGamesNewsletter(false);
koalaTest.assertValues("Settings View", "Newsletter Subscribe", "Newsletter Unsubscribe");
currentUserTest.assertValues(user, user.toBuilder().gamesNewsletter(true).build(), user);
showOptInPromptTest.assertNoValues();
}
Aggregations