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