use of com.kickstarter.services.DiscoveryParams in project android-oss by kickstarter.
the class DiscoveryIntentMapperTest method emitsFromAdvancedCategoryIdAndLocationIdUri.
@Test
public void emitsFromAdvancedCategoryIdAndLocationIdUri() {
final Uri uri = Uri.parse("https://www.kickstarter.com/discover/advanced?category_id=1&location_id=1");
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
DiscoveryIntentMapper.params(intent, new MockApiClient()).subscribe(resultTest);
resultTest.assertValueCount(1);
}
use of com.kickstarter.services.DiscoveryParams in project android-oss by kickstarter.
the class ThanksViewModel method relatedProjects.
/**
* Returns a shuffled list of 3 recommended projects, with fallbacks to similar and staff picked projects
* for users with fewer than 3 recommendations.
*/
@NonNull
private Observable<List<Project>> relatedProjects(@NonNull final Project project) {
final DiscoveryParams recommendedParams = DiscoveryParams.builder().backed(-1).recommended(true).perPage(6).build();
final DiscoveryParams similarToParams = DiscoveryParams.builder().backed(-1).similarTo(project).perPage(3).build();
final Category category = project.category();
final DiscoveryParams staffPickParams = DiscoveryParams.builder().category(category == null ? null : category.root()).backed(-1).staffPicks(true).perPage(3).build();
final Observable<Project> recommendedProjects = apiClient.fetchProjects(recommendedParams).retry(2).map(DiscoverEnvelope::projects).map(ListUtils::shuffle).flatMap(Observable::from).take(3);
final Observable<Project> similarToProjects = apiClient.fetchProjects(similarToParams).retry(2).map(DiscoverEnvelope::projects).flatMap(Observable::from);
final Observable<Project> staffPickProjects = apiClient.fetchProjects(staffPickParams).retry(2).map(DiscoverEnvelope::projects).flatMap(Observable::from);
return Observable.concat(recommendedProjects, similarToProjects, staffPickProjects).compose(neverError()).distinct().take(3).toList();
}
use of com.kickstarter.services.DiscoveryParams in project android-oss by kickstarter.
the class DiscoveryIntentMapperTest method emitsFromDiscoveryUri.
@Test
public void emitsFromDiscoveryUri() {
final Uri uri = Uri.parse("https://www.kickstarter.com/discover");
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
DiscoveryIntentMapper.params(intent, new MockApiClient()).subscribe(resultTest);
resultTest.assertValues(DiscoveryParams.builder().build());
}
use of com.kickstarter.services.DiscoveryParams in project android-oss by kickstarter.
the class DiscoveryViewModelTest method testUpdateInterfaceElementsWithParams.
@Test
public void testUpdateInterfaceElementsWithParams() {
final DiscoveryViewModel vm = new DiscoveryViewModel(environment());
final TestSubscriber<DiscoveryParams> updateToolbarWithParams = new TestSubscriber<>();
vm.outputs.updateToolbarWithParams().subscribe(updateToolbarWithParams);
final TestSubscriber<Boolean> expandSortTabLayout = new TestSubscriber<>();
vm.outputs.expandSortTabLayout().subscribe(expandSortTabLayout);
// Initialize activity.
final Intent intent = new Intent(Intent.ACTION_MAIN);
vm.intent(intent);
// Initial HOME page selected.
vm.inputs.discoveryPagerAdapterSetPrimaryPage(null, 0);
// Sort tab should be expanded.
expandSortTabLayout.assertValues(true);
// Toolbar params should be loaded with initial params.
updateToolbarWithParams.assertValues(DiscoveryParams.builder().build());
// Select POPULAR sort.
vm.inputs.discoveryPagerAdapterSetPrimaryPage(null, 1);
// Sort tab should be expanded.
expandSortTabLayout.assertValues(true, true);
// Unchanged toolbar params should not emit.
updateToolbarWithParams.assertValues(DiscoveryParams.builder().build());
// Select ALL PROJECTS filter from drawer.
vm.inputs.topFilterViewHolderRowClick(null, NavigationDrawerData.Section.Row.builder().params(DiscoveryParams.builder().build()).build());
// Sort tab should be expanded.
expandSortTabLayout.assertValues(true, true, true);
koalaTest.assertValues("Discover Modal Selected Filter");
// Select ART category from drawer.
vm.inputs.childFilterViewHolderRowClick(null, NavigationDrawerData.Section.Row.builder().params(DiscoveryParams.builder().category(CategoryFactory.artCategory()).build()).build());
// Sort tab should be expanded.
expandSortTabLayout.assertValues(true, true, true, true);
koalaTest.assertValues("Discover Modal Selected Filter", "Discover Modal Selected Filter");
// Simulate rotating the device and hitting initial inputs again.
final TestSubscriber<DiscoveryParams> rotatedUpdateToolbarWithParams = new TestSubscriber<>();
vm.outputs.updateToolbarWithParams().subscribe(rotatedUpdateToolbarWithParams);
final TestSubscriber<Boolean> rotatedExpandSortTabLayout = new TestSubscriber<>();
vm.outputs.expandSortTabLayout().subscribe(rotatedExpandSortTabLayout);
// Simulate recreating and setting POPULAR fragment, the previous position before rotation.
vm.inputs.discoveryPagerAdapterSetPrimaryPage(null, 1);
// Sort tab and toolbar params should emit again with same params.
rotatedExpandSortTabLayout.assertValues(true);
rotatedUpdateToolbarWithParams.assertValues(DiscoveryParams.builder().category(CategoryFactory.artCategory()).build());
}
use of com.kickstarter.services.DiscoveryParams 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);
}
Aggregations