Search in sources :

Example 76 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class RewardViewModelTest method testUsdConversionNotShownForUSProject.

@Test
public void testUsdConversionNotShownForUSProject() {
    // Set user's country to US.
    final Config config = ConfigFactory.configForUSUser();
    final Environment environment = environment();
    final CurrentConfigType currentConfig = environment.currentConfig();
    environment.currentConfig().config(config);
    final RewardViewModel vm = new RewardViewModel(environment);
    // Set project's country to US.
    final Project project = ProjectFactory.project().toBuilder().country("US").build();
    final Reward reward = RewardFactory.reward();
    final TestSubscriber<String> usdConversionTextViewText = TestSubscriber.create();
    vm.outputs.usdConversionTextViewText().subscribe(usdConversionTextViewText);
    final TestSubscriber<Boolean> usdConversionSectionIsHidden = TestSubscriber.create();
    vm.outputs.usdConversionTextViewIsHidden().subscribe(usdConversionSectionIsHidden);
    // USD conversion should not be shown.
    vm.inputs.projectAndReward(project, reward);
    usdConversionTextViewText.assertNoValues();
    usdConversionSectionIsHidden.assertValue(true);
    // Set user's country to CA.
    currentConfig.config(ConfigFactory.configForCAUser());
    // USD conversion should still not be shown (distinct until changed).
    usdConversionTextViewText.assertNoValues();
    usdConversionSectionIsHidden.assertValues(true);
}
Also used : Project(com.kickstarter.models.Project) Config(com.kickstarter.libs.Config) CurrentConfigType(com.kickstarter.libs.CurrentConfigType) Environment(com.kickstarter.libs.Environment) Reward(com.kickstarter.models.Reward) Test(org.junit.Test)

Example 77 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class RewardViewModelTest method testEstimatedDeliveryDateSectionIsHidden.

@Test
public void testEstimatedDeliveryDateSectionIsHidden() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final Project project = ProjectFactory.project();
    final TestSubscriber<Boolean> estimatedDeliveryDateSectionIsHiddenTest = TestSubscriber.create();
    vm.outputs.estimatedDeliveryDateSectionIsHidden().subscribe(estimatedDeliveryDateSectionIsHiddenTest);
    // Reward with no estimated delivery should not show estimated delivery label.
    vm.inputs.projectAndReward(project, RewardFactory.reward().toBuilder().estimatedDeliveryOn(null).build());
    estimatedDeliveryDateSectionIsHiddenTest.assertValue(true);
    // Reward with estimated delivery should show estimated delivery label.
    vm.inputs.projectAndReward(project, RewardFactory.reward().toBuilder().estimatedDeliveryOn(DateTime.now()).build());
    estimatedDeliveryDateSectionIsHiddenTest.assertValues(true, false);
}
Also used : Project(com.kickstarter.models.Project) Test(org.junit.Test)

Example 78 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class RewardViewModelTest method testIsClickable.

@Test
public void testIsClickable() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final TestSubscriber<Boolean> isClickableTest = TestSubscriber.create();
    vm.outputs.isClickable().subscribe(isClickableTest);
    // A reward from a live project should be clickable.
    vm.inputs.projectAndReward(ProjectFactory.project(), RewardFactory.reward());
    isClickableTest.assertValue(true);
    // A reward from a successful project should not be clickable.
    vm.inputs.projectAndReward(ProjectFactory.successfulProject(), RewardFactory.reward());
    isClickableTest.assertValues(true, false);
    //
    // A backed reward from a live project should be clickable.
    final Project backedLiveProject = ProjectFactory.backedProject();
    vm.inputs.projectAndReward(backedLiveProject, backedLiveProject.backing().reward());
    isClickableTest.assertValues(true, false, true);
    // A backed reward from a finished project should be clickable (distinct until changed).
    final Project backedSuccessfulProject = ProjectFactory.backedProject().toBuilder().state(Project.STATE_SUCCESSFUL).build();
    vm.inputs.projectAndReward(backedSuccessfulProject, backedSuccessfulProject.backing().reward());
    isClickableTest.assertValues(true, false, true);
    // A reward with its limit reached should not be clickable.
    vm.inputs.projectAndReward(ProjectFactory.project(), RewardFactory.limitReached());
    isClickableTest.assertValues(true, false, true, false);
}
Also used : Project(com.kickstarter.models.Project) Test(org.junit.Test)

Example 79 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class RewardViewModelTest method testLimitAndRemaining.

@Test
public void testLimitAndRemaining() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final Project project = ProjectFactory.project();
    final TestSubscriber<Pair<String, String>> limitAndRemainingTextViewTextTest = TestSubscriber.create();
    vm.outputs.limitAndRemainingTextViewText().subscribe(limitAndRemainingTextViewTextTest);
    final TestSubscriber<Boolean> limitAndRemainingTextViewIsHiddenTest = TestSubscriber.create();
    vm.outputs.limitAndRemainingTextViewIsHidden().subscribe(limitAndRemainingTextViewIsHiddenTest);
    // When reward is limited, quantity should be shown.
    final Reward limitedReward = RewardFactory.reward().toBuilder().limit(10).remaining(5).build();
    vm.inputs.projectAndReward(project, limitedReward);
    limitAndRemainingTextViewTextTest.assertValue(Pair.create("10", "5"));
    limitAndRemainingTextViewIsHiddenTest.assertValue(false);
    // When reward's limit has been reached, don't show quantity.
    vm.inputs.projectAndReward(project, RewardFactory.limitReached());
    limitAndRemainingTextViewIsHiddenTest.assertValues(false, true);
    // When reward has no limit, don't show quantity (distinct until changed).
    vm.inputs.projectAndReward(project, RewardFactory.reward());
    limitAndRemainingTextViewIsHiddenTest.assertValues(false, true);
}
Also used : Project(com.kickstarter.models.Project) Reward(com.kickstarter.models.Reward) Pair(android.util.Pair) Test(org.junit.Test)

Example 80 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class RewardViewModelTest method testSelectedHeaderAndOverlay.

@Test
public void testSelectedHeaderAndOverlay() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final TestSubscriber<Boolean> selectedHeaderIsHidden = TestSubscriber.create();
    vm.outputs.selectedHeaderIsHidden().subscribe(selectedHeaderIsHidden);
    final TestSubscriber<Boolean> selectedOverlayIsHidden = TestSubscriber.create();
    vm.outputs.selectedOverlayIsHidden().subscribe(selectedOverlayIsHidden);
    final Project backedProject = ProjectFactory.backedProject();
    vm.inputs.projectAndReward(backedProject, backedProject.backing().reward());
    selectedHeaderIsHidden.assertValue(false);
    selectedOverlayIsHidden.assertValue(false);
    vm.inputs.projectAndReward(backedProject, RewardFactory.reward());
    selectedHeaderIsHidden.assertValues(false, true);
    selectedOverlayIsHidden.assertValues(false, true);
}
Also used : Project(com.kickstarter.models.Project) Test(org.junit.Test)

Aggregations

Project (com.kickstarter.models.Project)85 Test (org.junit.Test)68 Intent (android.content.Intent)36 TestSubscriber (rx.observers.TestSubscriber)33 Environment (com.kickstarter.libs.Environment)19 Reward (com.kickstarter.models.Reward)19 User (com.kickstarter.models.User)14 Pair (android.util.Pair)12 CurrentUserType (com.kickstarter.libs.CurrentUserType)12 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)12 NonNull (android.support.annotation.NonNull)9 MockBooleanPreference (com.kickstarter.libs.preferences.MockBooleanPreference)8 MockApiClient (com.kickstarter.services.MockApiClient)7 Context (android.content.Context)6 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)6 ProjectFactory (com.kickstarter.factories.ProjectFactory)6 UserFactory (com.kickstarter.factories.UserFactory)5 KoalaEvent (com.kickstarter.libs.KoalaEvent)5 Photo (com.kickstarter.models.Photo)5 Update (com.kickstarter.models.Update)5