Search in sources :

Example 6 with DiscoveryParams

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);
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Uri(android.net.Uri) Test(org.junit.Test)

Example 7 with DiscoveryParams

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();
}
Also used : Project(com.kickstarter.models.Project) Category(com.kickstarter.models.Category) DiscoveryParams(com.kickstarter.services.DiscoveryParams) ListUtils(com.kickstarter.libs.utils.ListUtils) Observable(rx.Observable) NonNull(android.support.annotation.NonNull)

Example 8 with DiscoveryParams

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());
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Uri(android.net.Uri) Test(org.junit.Test)

Example 9 with DiscoveryParams

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());
}
Also used : TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Test(org.junit.Test)

Example 10 with DiscoveryParams

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);
}
Also used : Transformers(com.kickstarter.libs.rx.transformers.Transformers) Category(com.kickstarter.models.Category) Arrays(java.util.Arrays) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) CategoryFactory(com.kickstarter.factories.CategoryFactory) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Intent(android.content.Intent) Test(org.junit.Test) UserFactory(com.kickstarter.factories.UserFactory) DiscoveryUtils(com.kickstarter.libs.utils.DiscoveryUtils) KSRobolectricTestCase(com.kickstarter.KSRobolectricTestCase) InternalBuildEnvelope(com.kickstarter.services.apiresponses.InternalBuildEnvelope) List(java.util.List) TestSubscriber(rx.observers.TestSubscriber) Environment(com.kickstarter.libs.Environment) NavigationDrawerData(com.kickstarter.ui.adapters.data.NavigationDrawerData) InternalBuildEnvelopeFactory(com.kickstarter.factories.InternalBuildEnvelopeFactory) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Test(org.junit.Test)

Aggregations

DiscoveryParams (com.kickstarter.services.DiscoveryParams)10 Test (org.junit.Test)9 Intent (android.content.Intent)7 MockApiClient (com.kickstarter.services.MockApiClient)6 Uri (android.net.Uri)4 TestSubscriber (rx.observers.TestSubscriber)4 Category (com.kickstarter.models.Category)3 NonNull (android.support.annotation.NonNull)2 Environment (com.kickstarter.libs.Environment)2 List (java.util.List)2 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)1 CategoryFactory (com.kickstarter.factories.CategoryFactory)1 InternalBuildEnvelopeFactory (com.kickstarter.factories.InternalBuildEnvelopeFactory)1 UserFactory (com.kickstarter.factories.UserFactory)1 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)1 Transformers (com.kickstarter.libs.rx.transformers.Transformers)1 DiscoveryUtils (com.kickstarter.libs.utils.DiscoveryUtils)1 ListUtils (com.kickstarter.libs.utils.ListUtils)1 Project (com.kickstarter.models.Project)1 ApiClientType (com.kickstarter.services.ApiClientType)1