Search in sources :

Example 21 with Environment

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

the class DiscoveryViewModelTest method testDrawerData.

@Test
public void testDrawerData() {
    final MockCurrentUser currentUser = new MockCurrentUser();
    final Environment env = environment().toBuilder().currentUser(currentUser).build();
    final DiscoveryViewModel vm = new DiscoveryViewModel(env);
    final TestSubscriber<Void> navigationDrawerDataEmitted = new TestSubscriber<>();
    vm.outputs.navigationDrawerData().compose(Transformers.ignoreValues()).subscribe(navigationDrawerDataEmitted);
    final TestSubscriber<Boolean> drawerIsOpen = new TestSubscriber<>();
    vm.outputs.drawerIsOpen().subscribe(drawerIsOpen);
    // Initialize activity.
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    vm.intent(intent);
    // Drawer data should emit. Drawer should be closed.
    navigationDrawerDataEmitted.assertValueCount(1);
    drawerIsOpen.assertNoValues();
    koalaTest.assertNoValues();
    // Open drawer and click the top PWL filter.
    vm.inputs.openDrawer(true);
    vm.inputs.topFilterViewHolderRowClick(null, NavigationDrawerData.Section.Row.builder().params(DiscoveryParams.builder().staffPicks(true).build()).build());
    // Drawer data should emit. Drawer should open, then close upon selection.
    navigationDrawerDataEmitted.assertValueCount(2);
    drawerIsOpen.assertValues(true, false);
    koalaTest.assertValues("Discover Switch Modal", "Discover Modal Selected Filter");
    // Open drawer and click a child filter.
    vm.inputs.openDrawer(true);
    vm.inputs.childFilterViewHolderRowClick(null, NavigationDrawerData.Section.Row.builder().params(DiscoveryParams.builder().category(CategoryFactory.artCategory()).build()).build());
    // Drawer data should emit. Drawer should open, then close upon selection.
    navigationDrawerDataEmitted.assertValueCount(3);
    drawerIsOpen.assertValues(true, false, true, false);
    koalaTest.assertValues("Discover Switch Modal", "Discover Modal Selected Filter", "Discover Switch Modal", "Discover Modal Selected Filter");
}
Also used : Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 22 with Environment

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

the class LoginViewModelTest method testLoginApiValidationError.

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

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password) {
            return Observable.error(ApiExceptionFactory.invalidLoginException());
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final LoginViewModel vm = new LoginViewModel(environment);
    final TestSubscriber<String> invalidLoginError = new TestSubscriber<>();
    vm.errors.invalidLoginError().subscribe(invalidLoginError);
    final TestSubscriber<Void> loginSuccess = new TestSubscriber<>();
    vm.outputs.loginSuccess().subscribe(loginSuccess);
    vm.inputs.email("typo@kickstartr.com");
    vm.inputs.password("danisawesome");
    vm.inputs.loginClick();
    loginSuccess.assertNoValues();
    invalidLoginError.assertValueCount(1);
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) 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 23 with Environment

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

the class LoginViewModelTest method testLoginApiError.

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

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password) {
            return Observable.error(ApiExceptionFactory.badRequestException());
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final LoginViewModel vm = new LoginViewModel(environment);
    final TestSubscriber<Void> loginSuccess = new TestSubscriber<>();
    vm.outputs.loginSuccess().subscribe(loginSuccess);
    final TestSubscriber<String> genericLoginError = new TestSubscriber<>();
    vm.errors.genericLoginError().subscribe(genericLoginError);
    vm.inputs.email("incorrect@kickstarter.com");
    vm.inputs.password("danisawesome");
    vm.inputs.loginClick();
    loginSuccess.assertNoValues();
    genericLoginError.assertValueCount(1);
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) 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 24 with Environment

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

the class ProfileViewModelTest method testProfileViewModel_EmitsProjects.

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

        @Override
        @NonNull
        public Observable<DiscoverEnvelope> fetchProjects(@NonNull final DiscoveryParams params) {
            return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(Collections.singletonList(ProjectFactory.project())));
        }
    };
    final Environment env = environment().toBuilder().apiClient(apiClient).build();
    final ProfileViewModel.ViewModel vm = new ProfileViewModel.ViewModel(env);
    final TestSubscriber<List<Project>> projects = new TestSubscriber<>();
    vm.outputs.projects().subscribe(projects);
    koalaTest.assertValues(KoalaEvent.PROFILE_VIEW_MY, KoalaEvent.VIEWED_PROFILE);
    projects.assertValueCount(1);
}
Also used : DiscoverEnvelope(com.kickstarter.services.apiresponses.DiscoverEnvelope) MockApiClient(com.kickstarter.services.MockApiClient) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) List(java.util.List) DiscoveryParams(com.kickstarter.services.DiscoveryParams) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 25 with Environment

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

the class ProfileViewModelTest method testProfileViewModel_EmitsBackedProjectsData.

@Test
public void testProfileViewModel_EmitsBackedProjectsData() {
    final User user = UserFactory.user().toBuilder().backedProjectsCount(5).createdProjectsCount(0).build();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<User> fetchCurrentUser() {
            return Observable.just(user);
        }
    };
    final Environment env = environment().toBuilder().apiClient(apiClient).build();
    final ProfileViewModel.ViewModel vm = new ProfileViewModel.ViewModel(env);
    final TestSubscriber<Boolean> backedCountTextViewHidden = new TestSubscriber<>();
    vm.outputs.backedCountTextViewHidden().subscribe(backedCountTextViewHidden);
    final TestSubscriber<String> backedCountTextViewText = new TestSubscriber<>();
    vm.outputs.backedCountTextViewText().subscribe(backedCountTextViewText);
    final TestSubscriber<Boolean> backedTextViewHidden = new TestSubscriber<>();
    vm.outputs.backedTextViewHidden().subscribe(backedTextViewHidden);
    final TestSubscriber<Boolean> createdCountTextViewHidden = new TestSubscriber<>();
    vm.outputs.createdCountTextViewHidden().subscribe(createdCountTextViewHidden);
    final TestSubscriber<String> createdCountTextViewText = new TestSubscriber<>();
    vm.outputs.createdCountTextViewText().subscribe(createdCountTextViewText);
    final TestSubscriber<Boolean> createdTextViewHidden = new TestSubscriber<>();
    vm.outputs.createdTextViewHidden().subscribe(createdTextViewHidden);
    final TestSubscriber<Boolean> dividerViewHidden = new TestSubscriber<>();
    vm.outputs.dividerViewHidden().subscribe(dividerViewHidden);
    // Backed text views are displayed.
    backedCountTextViewHidden.assertValues(false);
    backedCountTextViewText.assertValues(NumberUtils.format(user.backedProjectsCount()));
    backedTextViewHidden.assertValues(false);
    // Created text views are hidden.
    createdCountTextViewHidden.assertValues(true);
    createdCountTextViewText.assertNoValues();
    createdTextViewHidden.assertValues(true);
    // Divider view is hidden.
    dividerViewHidden.assertValues(true);
}
Also used : User(com.kickstarter.models.User) MockApiClient(com.kickstarter.services.MockApiClient) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) ApiClientType(com.kickstarter.services.ApiClientType) 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