Search in sources :

Example 16 with MockCurrentUser

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();
}
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 17 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.

the class ThanksViewModelTest method testThanksViewModel_dontShowGamesNewsletterDialogIfUserHasAlreadySignedUp.

@Test
public void testThanksViewModel_dontShowGamesNewsletterDialogIfUserHasAlreadySignedUp() {
    final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(false);
    final User user = UserFactory.user().toBuilder().gamesNewsletter(true).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(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 18 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.

the class ThanksViewModelTest method testThanksViewModel_dontShowGamesNewsletterDialogIfRootCategoryIsNotGames.

@Test
public void testThanksViewModel_dontShowGamesNewsletterDialogIfRootCategoryIsNotGames() {
    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.ceramicsCategory()).build();
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    showGamesNewsletterDialogTest.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 19 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.

the class ThanksViewModelTest method testThanksViewModel_dontShowRatingDialogIfGamesNewsletterWillDisplay.

@Test
public void testThanksViewModel_dontShowRatingDialogIfGamesNewsletterWillDisplay() {
    final MockBooleanPreference hasSeenAppRatingPreference = new MockBooleanPreference(false);
    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).hasSeenAppRatingPreference(hasSeenAppRatingPreference).hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference).build();
    final ThanksViewModel vm = new ThanksViewModel(environment);
    final TestSubscriber<Void> showRatingDialogTest = new TestSubscriber<>();
    vm.outputs.showRatingDialog().subscribe(showRatingDialogTest);
    final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    showRatingDialogTest.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)

Aggregations

Environment (com.kickstarter.libs.Environment)19 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)19 Test (org.junit.Test)19 CurrentUserType (com.kickstarter.libs.CurrentUserType)18 TestSubscriber (rx.observers.TestSubscriber)18 Intent (android.content.Intent)12 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