Search in sources :

Example 1 with Environment

use of com.kickstarter.libs.Environment 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 Environment

use of com.kickstarter.libs.Environment 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 Environment

use of com.kickstarter.libs.Environment 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 Environment

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

the class ThanksViewModelTest method testThanksViewModel_dontShowRatingDialogIfAlreadySeen.

@Test
public void testThanksViewModel_dontShowRatingDialogIfAlreadySeen() {
    final MockBooleanPreference hasSeenAppRatingPreference = new MockBooleanPreference(true);
    final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(true);
    final Environment environment = environment().toBuilder().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();
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    showRatingDialogTest.assertValueCount(0);
}
Also used : Project(com.kickstarter.models.Project) MockBooleanPreference(com.kickstarter.libs.preferences.MockBooleanPreference) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Test(org.junit.Test)

Example 5 with Environment

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

the class TwoFactorViewModelTest method testTwoFactorViewModel_CodeMismatchError.

@Test
public void testTwoFactorViewModel_CodeMismatchError() {
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password, @NonNull final String code) {
            return Observable.error(ApiExceptionFactory.tfaFailed());
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final Intent intent = new Intent();
    intent.putExtra(IntentKey.EMAIL, "gina@kickstarter.com");
    intent.putExtra(IntentKey.PASSWORD, "hello");
    intent.putExtra(IntentKey.FACEBOOK_LOGIN, false);
    intent.putExtra(IntentKey.FACEBOOK_TOKEN, "");
    final TwoFactorViewModel vm = new TwoFactorViewModel(environment);
    vm.intent(intent);
    final TestSubscriber<Void> tfaSuccess = new TestSubscriber<>();
    vm.outputs.tfaSuccess().subscribe(tfaSuccess);
    final TestSubscriber<Boolean> formSubmitting = new TestSubscriber<>();
    vm.outputs.formSubmitting().subscribe(formSubmitting);
    final TestSubscriber<Void> tfaCodeMismatchError = new TestSubscriber<>();
    vm.errors.tfaCodeMismatchError().subscribe(tfaCodeMismatchError);
    vm.inputs.code("88888");
    vm.inputs.loginClick();
    formSubmitting.assertValues(true, false);
    tfaSuccess.assertNoValues();
    tfaCodeMismatchError.assertValueCount(1);
    koalaTest.assertValues("Two-factor Authentication Confirm View", "Errored User Login");
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Aggregations

Environment (com.kickstarter.libs.Environment)50 Test (org.junit.Test)49 TestSubscriber (rx.observers.TestSubscriber)43 Intent (android.content.Intent)23 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)22 MockApiClient (com.kickstarter.services.MockApiClient)21 ApiClientType (com.kickstarter.services.ApiClientType)20 CurrentUserType (com.kickstarter.libs.CurrentUserType)19 Project (com.kickstarter.models.Project)19 User (com.kickstarter.models.User)16 NonNull (android.support.annotation.NonNull)14 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)9 MockBooleanPreference (com.kickstarter.libs.preferences.MockBooleanPreference)8 UserFactory (com.kickstarter.factories.UserFactory)7 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)7 ProjectFactory (com.kickstarter.factories.ProjectFactory)6 IntentKey (com.kickstarter.ui.IntentKey)6 List (java.util.List)6 KoalaEvent (com.kickstarter.libs.KoalaEvent)5 ConfigFactory (com.kickstarter.factories.ConfigFactory)4