Search in sources :

Example 81 with Project

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

the class RewardViewModelTest method testGoToCheckoutWhenProjectIsSuccessfulAndHasBeenBacked.

@Test
public void testGoToCheckoutWhenProjectIsSuccessfulAndHasBeenBacked() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final Project project = ProjectFactory.backedProject().toBuilder().state(Project.STATE_SUCCESSFUL).build();
    final Reward reward = project.backing().reward();
    final TestSubscriber<Pair<Project, Reward>> goToCheckoutTest = TestSubscriber.create();
    vm.outputs.goToCheckout().subscribe(goToCheckoutTest);
    vm.inputs.projectAndReward(project, reward);
    goToCheckoutTest.assertNoValues();
    vm.inputs.rewardClicked();
    goToCheckoutTest.assertNoValues();
}
Also used : Project(com.kickstarter.models.Project) Reward(com.kickstarter.models.Reward) Pair(android.util.Pair) Test(org.junit.Test)

Example 82 with Project

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

the class RewardViewModelTest method testWhiteOverlayIsHidden.

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

Example 83 with Project

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

the class RewardViewModelTest method testUsdConversionForNonUSProject.

@Test
public void testUsdConversionForNonUSProject() {
    // 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 CA.
    final Project project = ProjectFactory.caProject();
    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 be shown.
    vm.inputs.projectAndReward(project, reward);
    usdConversionTextViewText.assertValueCount(1);
    usdConversionSectionIsHidden.assertValue(false);
    // Set user's country to CA (any country except the US is fine).
    currentConfig.config(ConfigFactory.configForCAUser());
    // USD conversion should now be hidden.
    usdConversionTextViewText.assertValueCount(1);
    usdConversionSectionIsHidden.assertValues(false, 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 84 with Project

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

the class RewardViewModelTest method testAllGoneTextViewIsHidden.

@Test
public void testAllGoneTextViewIsHidden() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final Project project = ProjectFactory.backedProjectWithRewardLimitReached();
    final TestSubscriber<Boolean> allGoneTextViewIsHidden = TestSubscriber.create();
    vm.outputs.allGoneTextViewIsHidden().subscribe(allGoneTextViewIsHidden);
    // When an unlimited reward is not backed, hide the 'all gone' header.
    vm.inputs.projectAndReward(project, RewardFactory.reward());
    allGoneTextViewIsHidden.assertValues(true);
    // When an unlimited reward is backed, hide the 'all gone' header (distinct until changed).
    final Reward backedReward = project.backing().reward();
    vm.inputs.projectAndReward(project, backedReward);
    allGoneTextViewIsHidden.assertValues(true);
    // When a backed reward's limit has been reached, hide the 'all gone' header – the selected banner will be shown instead.
    final Reward backedRewardWithLimitReached = backedReward.toBuilder().limit(1).remaining(0).build();
    vm.inputs.projectAndReward(project, backedRewardWithLimitReached);
    allGoneTextViewIsHidden.assertValues(true);
    // When a reward's limit has been reached and it has not been backed, show the 'all gone' header.
    vm.inputs.projectAndReward(project, RewardFactory.limitReached());
    allGoneTextViewIsHidden.assertValues(true, false);
}
Also used : Project(com.kickstarter.models.Project) Reward(com.kickstarter.models.Reward) Test(org.junit.Test)

Example 85 with Project

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

the class RewardViewModelTest method testUsdConversionTextRoundsUp.

@Test
public void testUsdConversionTextRoundsUp() {
    // Set user's country to US.
    final Config config = ConfigFactory.configForUSUser();
    final Environment environment = environment();
    environment.currentConfig().config(config);
    final RewardViewModel vm = new RewardViewModel(environment);
    // Set project's country to CA and reward minimum to $0.30.
    final Project project = ProjectFactory.caProject();
    final Reward reward = RewardFactory.reward().toBuilder().minimum(0.3f).build();
    final TestSubscriber<String> usdConversionTextViewText = TestSubscriber.create();
    vm.outputs.usdConversionTextViewText().subscribe(usdConversionTextViewText);
    // USD conversion should be rounded up.
    vm.inputs.projectAndReward(project, reward);
    usdConversionTextViewText.assertValue("$1");
}
Also used : Project(com.kickstarter.models.Project) Config(com.kickstarter.libs.Config) Environment(com.kickstarter.libs.Environment) Reward(com.kickstarter.models.Reward) 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