use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class DiscoveryViewModelTest method testRootCategoriesEmitWithPosition.
@Test
public void testRootCategoriesEmitWithPosition() {
final DiscoveryViewModel vm = new DiscoveryViewModel(environment());
final TestSubscriber<List<Category>> rootCategories = new TestSubscriber<>();
final TestSubscriber<Integer> position = new TestSubscriber<>();
vm.outputs.rootCategoriesAndPosition().map(cp -> cp.first).subscribe(rootCategories);
vm.outputs.rootCategoriesAndPosition().map(cp -> cp.second).subscribe(position);
// Start initial activity.
vm.intent(new Intent(Intent.ACTION_MAIN));
// Initial HOME page selected.
vm.inputs.discoveryPagerAdapterSetPrimaryPage(null, 0);
// Root categories should emit for the initial HOME sort position.
rootCategories.assertValueCount(1);
position.assertValues(0);
// Select POPULAR sort position.
vm.inputs.discoveryPagerAdapterSetPrimaryPage(null, 1);
// Root categories should emit for the POPULAR sort position.
rootCategories.assertValueCount(2);
position.assertValues(0, 1);
// Select ART category from the drawer.
vm.inputs.childFilterViewHolderRowClick(null, NavigationDrawerData.Section.Row.builder().params(DiscoveryParams.builder().category(CategoryFactory.artCategory()).build()).build());
// Root categories should not emit again for the same position.
rootCategories.assertValueCount(2);
position.assertValues(0, 1);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class DiscoveryViewModelTest method testInteractionBetweenParamsAndPageAdapter.
@Test
public void testInteractionBetweenParamsAndPageAdapter() {
final DiscoveryViewModel vm = new DiscoveryViewModel(environment());
final TestSubscriber<DiscoveryParams> updateParams = new TestSubscriber<>();
vm.outputs.updateParamsForPage().subscribe(updateParams);
final TestSubscriber<Integer> updatePage = new TestSubscriber<>();
vm.outputs.updateParamsForPage().map(params -> DiscoveryUtils.positionFromSort(params.sort())).subscribe(updatePage);
// Start initial activity.
final Intent intent = new Intent(Intent.ACTION_MAIN);
vm.intent(intent);
// Initial HOME page selected.
vm.inputs.discoveryPagerAdapterSetPrimaryPage(null, 0);
// Initial params should emit. Page should not be updated yet.
updateParams.assertValues(DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).build());
updatePage.assertValues(0);
// Select POPULAR sort position.
vm.inputs.discoveryPagerAdapterSetPrimaryPage(null, 1);
// Params and page should update with new POPULAR sort values.
updateParams.assertValues(DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).build(), DiscoveryParams.builder().sort(DiscoveryParams.Sort.POPULAR).build());
updatePage.assertValues(0, 1);
// Select ART category from the drawer.
vm.inputs.childFilterViewHolderRowClick(null, NavigationDrawerData.Section.Row.builder().params(DiscoveryParams.builder().category(CategoryFactory.artCategory()).build()).build());
// Params should update with new category; page should remain the same.
updateParams.assertValues(DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).build(), DiscoveryParams.builder().sort(DiscoveryParams.Sort.POPULAR).build(), DiscoveryParams.builder().sort(DiscoveryParams.Sort.POPULAR).category(CategoryFactory.artCategory()).build());
updatePage.assertValues(0, 1, 1);
koalaTest.assertValues("Discover Modal Selected Filter");
// Select HOME sort position.
vm.inputs.discoveryPagerAdapterSetPrimaryPage(null, 0);
// Params and page should update with new HOME sort value.
updateParams.assertValues(DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).build(), DiscoveryParams.builder().sort(DiscoveryParams.Sort.POPULAR).build(), DiscoveryParams.builder().sort(DiscoveryParams.Sort.POPULAR).category(CategoryFactory.artCategory()).build(), DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).category(CategoryFactory.artCategory()).build());
updatePage.assertValues(0, 1, 1, 0);
// Simulate rotating the device and hitting initial inputs again.
final TestSubscriber<DiscoveryParams> rotatedUpdateParams = new TestSubscriber<>();
vm.outputs.updateParamsForPage().subscribe(rotatedUpdateParams);
final TestSubscriber<Integer> rotatedUpdatePage = new TestSubscriber<>();
vm.outputs.updateParamsForPage().map(params -> DiscoveryUtils.positionFromSort(params.sort())).subscribe(rotatedUpdatePage);
// Should emit again with same params.
rotatedUpdateParams.assertValues(DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).category(CategoryFactory.artCategory()).build());
rotatedUpdatePage.assertValues(0);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class LoginViewModelTest method testLoginTfaChallenge.
@Test
public void testLoginTfaChallenge() {
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<AccessTokenEnvelope> login(@NonNull final String email, @NonNull final String password) {
return Observable.error(ApiExceptionFactory.tfaRequired());
}
};
final Environment environment = environment().toBuilder().apiClient(apiClient).build();
final LoginViewModel vm = new LoginViewModel(environment);
final TestSubscriber<Void> tfaChallenge = new TestSubscriber<>();
vm.errors.tfaChallenge().subscribe(tfaChallenge);
final TestSubscriber<Void> loginSuccess = new TestSubscriber<>();
vm.outputs.loginSuccess().subscribe(loginSuccess);
vm.inputs.email("hello@kickstarter.com");
vm.inputs.password("danisawesome");
vm.inputs.loginClick();
loginSuccess.assertNoValues();
tfaChallenge.assertValueCount(1);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ProfileViewModelTest method testProfileViewModel_EmitsUserNameAndAvatar.
@Test
public void testProfileViewModel_EmitsUserNameAndAvatar() {
final User user = UserFactory.user();
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<String> avatarImageViewUrl = new TestSubscriber<>();
vm.outputs.avatarImageViewUrl().subscribe(avatarImageViewUrl);
final TestSubscriber<String> userNameTextViewText = new TestSubscriber<>();
vm.outputs.userNameTextViewText().subscribe(userNameTextViewText);
avatarImageViewUrl.assertValues(user.avatar().medium());
userNameTextViewText.assertValues(user.name());
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class ProfileViewModelTest method testProfileViewModel_EmitsCreatedProjectsData.
@Test
public void testProfileViewModel_EmitsCreatedProjectsData() {
final User user = UserFactory.user().toBuilder().backedProjectsCount(0).createdProjectsCount(2).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 hidden.
backedCountTextViewHidden.assertValues(true);
backedCountTextViewText.assertNoValues();
backedTextViewHidden.assertValues(true);
// Created text views are displayed.
createdCountTextViewHidden.assertValues(false);
createdCountTextViewText.assertValues(NumberUtils.format(user.createdProjectsCount()));
createdTextViewHidden.assertValues(false);
// Divider view is hidden.
dividerViewHidden.assertValues(true);
}
Aggregations