Search in sources :

Example 11 with Category

use of com.kickstarter.models.Category 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

Category (com.kickstarter.models.Category)11 DiscoveryParams (com.kickstarter.services.DiscoveryParams)6 Project (com.kickstarter.models.Project)4 List (java.util.List)4 Test (org.junit.Test)4 TestSubscriber (rx.observers.TestSubscriber)4 Context (android.content.Context)3 Intent (android.content.Intent)3 NonNull (android.support.annotation.NonNull)3 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)3 CategoryFactory (com.kickstarter.factories.CategoryFactory)3 UserFactory (com.kickstarter.factories.UserFactory)3 Environment (com.kickstarter.libs.Environment)3 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)3 Photo (com.kickstarter.models.Photo)3 Arrays (java.util.Arrays)3 InternalBuildEnvelopeFactory (com.kickstarter.factories.InternalBuildEnvelopeFactory)2 Transformers (com.kickstarter.libs.rx.transformers.Transformers)2 CircleTransformation (com.kickstarter.libs.transformations.CircleTransformation)2 DiscoveryUtils (com.kickstarter.libs.utils.DiscoveryUtils)2