Search in sources :

Example 21 with Project

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

the class RewardViewModelTest method testMinimumTextViewText.

@Test
public void testMinimumTextViewText() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final Project project = ProjectFactory.project();
    final Reward reward = RewardFactory.reward().toBuilder().minimum(10).build();
    final TestSubscriber<String> minimumTextViewTextTest = TestSubscriber.create();
    vm.outputs.minimumTextViewText().subscribe(minimumTextViewTextTest);
    vm.inputs.projectAndReward(project, reward);
    minimumTextViewTextTest.assertValue("$10");
}
Also used : Project(com.kickstarter.models.Project) Reward(com.kickstarter.models.Reward) Test(org.junit.Test)

Example 22 with Project

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

the class RewardViewModelTest method testLimitAndBackersSeparatorIsHidden.

@Test
public void testLimitAndBackersSeparatorIsHidden() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final Project project = ProjectFactory.project();
    final TestSubscriber<Boolean> limitAndBackersSeparatorIsHiddenTest = TestSubscriber.create();
    vm.outputs.limitAndBackersSeparatorIsHidden().subscribe(limitAndBackersSeparatorIsHiddenTest);
    // When reward has no limit or backers, separator should be hidden.
    vm.inputs.projectAndReward(project, RewardFactory.noBackers());
    limitAndBackersSeparatorIsHiddenTest.assertValues(true);
    // When reward has no limit and backers, separator should be hidden.
    vm.inputs.projectAndReward(project, RewardFactory.reward());
    limitAndBackersSeparatorIsHiddenTest.assertValues(true);
    // When reward has limit and no backers, separator should be hidden.
    vm.inputs.projectAndReward(project, RewardFactory.limited().toBuilder().backersCount(0).build());
    limitAndBackersSeparatorIsHiddenTest.assertValues(true);
    // When reward has limit and backers, separator should be visible.
    vm.inputs.projectAndReward(project, RewardFactory.limited().toBuilder().build());
    limitAndBackersSeparatorIsHiddenTest.assertValues(true, false);
}
Also used : Project(com.kickstarter.models.Project) Test(org.junit.Test)

Example 23 with Project

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

the class RewardViewModelTest method testShippingSummary.

@Test
public void testShippingSummary() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final Project project = ProjectFactory.project();
    final TestSubscriber<String> shippingSummaryTextViewTextTest = TestSubscriber.create();
    vm.outputs.shippingSummaryTextViewText().subscribe(shippingSummaryTextViewTextTest);
    final TestSubscriber<Boolean> shippingSummarySectionIsHiddenTest = TestSubscriber.create();
    vm.outputs.shippingSummarySectionIsHidden().subscribe(shippingSummarySectionIsHiddenTest);
    // Reward with no shipping should hide shipping summary section and not emit a shipping summary string.
    vm.inputs.projectAndReward(project, RewardFactory.reward());
    shippingSummaryTextViewTextTest.assertNoValues();
    shippingSummarySectionIsHiddenTest.assertValue(true);
    // Reward with shipping should show shipping summary section and emit a shipping summary string.
    final Reward rewardWithShipping = RewardFactory.rewardWithShipping();
    vm.inputs.projectAndReward(project, rewardWithShipping);
    shippingSummaryTextViewTextTest.assertValue(rewardWithShipping.shippingSummary());
    shippingSummarySectionIsHiddenTest.assertValues(true, false);
}
Also used : Project(com.kickstarter.models.Project) Reward(com.kickstarter.models.Reward) Test(org.junit.Test)

Example 24 with Project

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

the class RewardViewModelTest method testLimitHeaderIsHidden.

@Test
public void testLimitHeaderIsHidden() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final TestSubscriber<Boolean> limitHeaderIsHiddenTest = TestSubscriber.create();
    vm.outputs.limitHeaderIsHidden().subscribe(limitHeaderIsHiddenTest);
    // If the reward is limited and has not been backed, show the limit header.
    final Project backedProjectWithLimitedReward = ProjectFactory.backedProjectWithRewardLimited();
    vm.inputs.projectAndReward(backedProjectWithLimitedReward, RewardFactory.limited());
    limitHeaderIsHiddenTest.assertValues(false);
    // If the reward is limited and has been backed, don't show the limit header.
    vm.inputs.projectAndReward(backedProjectWithLimitedReward, backedProjectWithLimitedReward.backing().reward());
    limitHeaderIsHiddenTest.assertValues(false, true);
    // If the reward is not limited, don't show the limit header.
    vm.inputs.projectAndReward(ProjectFactory.project(), RewardFactory.reward());
    limitHeaderIsHiddenTest.assertValues(false, true);
}
Also used : Project(com.kickstarter.models.Project) Test(org.junit.Test)

Example 25 with Project

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

the class RewardViewModelTest method testBackersTextView.

@Test
public void testBackersTextView() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final Project project = ProjectFactory.project();
    final Reward rewardWithBackers = RewardFactory.reward().toBuilder().backersCount(100).build();
    final TestSubscriber<Integer> backersTextViewTextTest = TestSubscriber.create();
    vm.outputs.backersTextViewText().subscribe(backersTextViewTextTest);
    // Show reward backer count.
    vm.inputs.projectAndReward(project, rewardWithBackers);
    backersTextViewTextTest.assertValue(100);
}
Also used : Project(com.kickstarter.models.Project) 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