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");
}
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);
}
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);
}
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);
}
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);
}
Aggregations