Search in sources :

Example 26 with Reward

use of com.kickstarter.models.Reward 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 27 with Reward

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

Example 28 with Reward

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

the class ViewPledgeViewModelTest method testRewardMinimumAndDescriptionTextViewText.

@Test
public void testRewardMinimumAndDescriptionTextViewText() {
    final Reward reward = RewardFactory.reward().toBuilder().minimum(100.0f).build();
    final Backing backing = BackingFactory.backing().toBuilder().reward(reward).build();
    final ViewPledgeViewModel vm = vm(backing);
    final TestSubscriber<Pair<String, String>> rewardMinimumAndDescriptionTextViewTextTest = TestSubscriber.create();
    vm.outputs.rewardMinimumAndDescriptionTextViewText().subscribe(rewardMinimumAndDescriptionTextViewTextTest);
    vm.intent(intent(backing));
    rewardMinimumAndDescriptionTextViewTextTest.assertValues(Pair.create("$100", backing.reward().description()));
}
Also used : Reward(com.kickstarter.models.Reward) Backing(com.kickstarter.models.Backing) Pair(android.util.Pair) Test(org.junit.Test)

Aggregations

Reward (com.kickstarter.models.Reward)28 Project (com.kickstarter.models.Project)19 Test (org.junit.Test)19 Backing (com.kickstarter.models.Backing)7 Pair (android.util.Pair)5 NonNull (android.support.annotation.NonNull)3 Config (com.kickstarter.libs.Config)3 Environment (com.kickstarter.libs.Environment)3 Collections.emptyList (java.util.Collections.emptyList)3 List (java.util.List)3 CurrentConfigType (com.kickstarter.libs.CurrentConfigType)2 Location (com.kickstarter.models.Location)1 DateTime (org.joda.time.DateTime)1