Search in sources :

Example 16 with Environment

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

the class ResetPasswordViewModelTest method testResetPasswordViewModel_resetFailure.

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

        @Override
        @NonNull
        public Observable<User> resetPassword(@NonNull final String email) {
            return Observable.error(ApiExceptionFactory.badRequestException());
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final ResetPasswordViewModel vm = new ResetPasswordViewModel(environment);
    final TestSubscriber<String> errorTest = new TestSubscriber<>();
    koalaTest.assertValues("Forgot Password View");
    vm.errors.resetError().subscribe(errorTest);
    vm.inputs.email("hello@kickstarter.com");
    vm.inputs.resetPasswordClick();
    errorTest.assertValue("bad request");
    koalaTest.assertValues("Forgot Password View", "Forgot Password Errored");
}
Also used : User(com.kickstarter.models.User) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 17 with Environment

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

the class CheckoutViewModelTest method test_AndroidPayIsAvailable_WhenNotCapable.

@Test
public void test_AndroidPayIsAvailable_WhenNotCapable() {
    final Environment env = environment().toBuilder().androidPayCapability(new AndroidPayCapability(false)).build();
    final CheckoutViewModel vm = new CheckoutViewModel(env);
    vm.outputs.isAndroidPayAvailable().subscribe(Assert::assertFalse);
}
Also used : Assert(junit.framework.Assert) AndroidPayCapability(com.kickstarter.libs.AndroidPayCapability) Environment(com.kickstarter.libs.Environment) Test(org.junit.Test)

Example 18 with Environment

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

the class CheckoutViewModelTest method test_AndroidPayIsAvailable_WhenCapable.

@Test
public void test_AndroidPayIsAvailable_WhenCapable() {
    final Environment env = environment().toBuilder().androidPayCapability(new AndroidPayCapability(true)).build();
    final CheckoutViewModel vm = new CheckoutViewModel(env);
    vm.outputs.isAndroidPayAvailable().subscribe(Assert::assertTrue);
}
Also used : Assert(junit.framework.Assert) AndroidPayCapability(com.kickstarter.libs.AndroidPayCapability) Environment(com.kickstarter.libs.Environment) Test(org.junit.Test)

Example 19 with Environment

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

the class CommentsViewModelTest method testCommentsViewModel_EmptyState.

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

        @Override
        @NonNull
        public Observable<CommentsEnvelope> fetchComments(@NonNull final Update update) {
            return Observable.empty();
        }
    };
    final Environment env = environment().toBuilder().apiClient(apiClient).build();
    final CommentsViewModel vm = new CommentsViewModel(env);
    final TestSubscriber<CommentsData> commentsData = new TestSubscriber<>();
    vm.outputs.commentsData().subscribe(commentsData);
    // Start the view model with an update.
    vm.intent(new Intent().putExtra(IntentKey.UPDATE, UpdateFactory.update()));
    // Only Viewed Comments event should fire.
    koalaTest.assertValues(KoalaEvent.VIEWED_COMMENTS);
    commentsData.assertNoValues();
}
Also used : CommentsEnvelope(com.kickstarter.services.apiresponses.CommentsEnvelope) CommentsData(com.kickstarter.ui.adapters.data.CommentsData) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Update(com.kickstarter.models.Update) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 20 with Environment

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

the class DiscoveryFragmentViewModelTest method testProjectsRefreshAfterLogin.

@Test
public void testProjectsRefreshAfterLogin() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().currentUser(currentUser).build();
    final DiscoveryFragmentViewModel vm = new DiscoveryFragmentViewModel(environment);
    final TestSubscriber<List<Project>> projects = new TestSubscriber<>();
    vm.outputs.projects().filter(ListUtils::nonEmpty).subscribe(projects);
    // Initial load.
    vm.inputs.rootCategories(CategoryFactory.rootCategories());
    vm.inputs.paramsFromActivity(DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).build());
    // Projects should emit.
    projects.assertValueCount(1);
    // Log in.
    currentUser.refresh(UserFactory.user());
    // Projects should emit again.
    projects.assertValueCount(2);
}
Also used : Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) List(java.util.List) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) 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