Search in sources :

Example 1 with CurrentUserType

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");
}
Also used : Category(com.kickstarter.models.Category) Arrays(java.util.Arrays) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) CategoryFactory(com.kickstarter.factories.CategoryFactory) Project(com.kickstarter.models.Project) LocationFactory(com.kickstarter.factories.LocationFactory) Pair(android.util.Pair) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Intent(android.content.Intent) Test(org.junit.Test) CurrentUserType(com.kickstarter.libs.CurrentUserType) UserFactory(com.kickstarter.factories.UserFactory) User(com.kickstarter.models.User) KSRobolectricTestCase(com.kickstarter.KSRobolectricTestCase) List(java.util.List) TestSubscriber(rx.observers.TestSubscriber) Environment(com.kickstarter.libs.Environment) MockBooleanPreference(com.kickstarter.libs.preferences.MockBooleanPreference) ProjectFactory(com.kickstarter.factories.ProjectFactory) IntentKey(com.kickstarter.ui.IntentKey) MockApiClient(com.kickstarter.services.MockApiClient) Project(com.kickstarter.models.Project) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) User(com.kickstarter.models.User) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 2 with CurrentUserType

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);
}
Also used : Project(com.kickstarter.models.Project) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) User(com.kickstarter.models.User) MockBooleanPreference(com.kickstarter.libs.preferences.MockBooleanPreference) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 3 with CurrentUserType

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");
}
Also used : Project(com.kickstarter.models.Project) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) User(com.kickstarter.models.User) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 4 with CurrentUserType

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();
}
Also used : Newsletter(com.kickstarter.ui.data.Newsletter) User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 5 with CurrentUserType

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();
}
Also used : Newsletter(com.kickstarter.ui.data.Newsletter) User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

CurrentUserType (com.kickstarter.libs.CurrentUserType)18 Environment (com.kickstarter.libs.Environment)18 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)18 Test (org.junit.Test)18 TestSubscriber (rx.observers.TestSubscriber)17 Intent (android.content.Intent)11 Project (com.kickstarter.models.Project)11 User (com.kickstarter.models.User)11 MockBooleanPreference (com.kickstarter.libs.preferences.MockBooleanPreference)6 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)4 ProjectFactory (com.kickstarter.factories.ProjectFactory)4 UserFactory (com.kickstarter.factories.UserFactory)4 IntentKey (com.kickstarter.ui.IntentKey)4 Newsletter (com.kickstarter.ui.data.Newsletter)4 ConfigFactory (com.kickstarter.factories.ConfigFactory)3 KoalaEvent (com.kickstarter.libs.KoalaEvent)3 MockApiClient (com.kickstarter.services.MockApiClient)3 List (java.util.List)3 Pair (android.util.Pair)2 ApiClientType (com.kickstarter.services.ApiClientType)2