Search in sources :

Example 6 with Project

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

the class RewardViewModelTest method testEstimatedDeliveryDateTextViewText.

@Test
public void testEstimatedDeliveryDateTextViewText() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final Project project = ProjectFactory.project();
    final Reward reward = RewardFactory.reward().toBuilder().estimatedDeliveryOn(null).build();
    final TestSubscriber<DateTime> estimatedDeliveryDateTextViewTextTest = TestSubscriber.create();
    vm.outputs.estimatedDeliveryDateTextViewText().subscribe(estimatedDeliveryDateTextViewTextTest);
    vm.inputs.projectAndReward(project, reward);
    // If reward has no estimated delivery, no value should be emitted.
    estimatedDeliveryDateTextViewTextTest.assertNoValues();
    // Reward with estimated delivery should emit.
    final DateTime estimatedDelivery = DateTime.now();
    vm.inputs.projectAndReward(project, reward.toBuilder().estimatedDeliveryOn(estimatedDelivery).build());
    estimatedDeliveryDateTextViewTextTest.assertValue(estimatedDelivery);
}
Also used : Project(com.kickstarter.models.Project) Reward(com.kickstarter.models.Reward) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 7 with Project

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

the class RewardViewModelTest method testGoToCheckoutWhenProjectIsSuccessful.

@Test
public void testGoToCheckoutWhenProjectIsSuccessful() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final Project project = ProjectFactory.successfulProject();
    final Reward reward = RewardFactory.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 8 with Project

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

the class ThanksViewModelTest method testThanksViewModel_dontShowGamesNewsletterDialogIfUserHasAlreadySeen.

@Test
public void testThanksViewModel_dontShowGamesNewsletterDialogIfUserHasAlreadySeen() {
    final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(true);
    final User user = UserFactory.user().toBuilder().gamesNewsletter(false).build();
    final CurrentUserType currentUser = new MockCurrentUser(user);
    final Environment environment = environment().toBuilder().currentUser(currentUser).hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference).build();
    final ThanksViewModel vm = new ThanksViewModel(environment);
    final TestSubscriber<Void> showGamesNewsletterDialogTest = new TestSubscriber<>();
    vm.outputs.showGamesNewsletterDialog().subscribe(showGamesNewsletterDialogTest);
    final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    showGamesNewsletterDialogTest.assertValueCount(0);
}
Also used : Project(com.kickstarter.models.Project) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) User(com.kickstarter.models.User) MockBooleanPreference(com.kickstarter.libs.preferences.MockBooleanPreference) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 9 with Project

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

the class ThanksViewModelTest method testThanksViewModel_share.

@Test
public void testThanksViewModel_share() {
    final ThanksViewModel vm = new ThanksViewModel(environment());
    final Project project = ProjectFactory.project();
    final TestSubscriber<Project> startShareTest = new TestSubscriber<>();
    vm.outputs.startShare().subscribe(startShareTest);
    final TestSubscriber<Project> startShareOnFacebookTest = new TestSubscriber<>();
    vm.outputs.startShareOnFacebook().subscribe(startShareOnFacebookTest);
    final TestSubscriber<Project> startShareOnTwitterTest = new TestSubscriber<>();
    vm.outputs.startShareOnTwitter().subscribe(startShareOnTwitterTest);
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    vm.inputs.shareClick();
    startShareTest.assertValues(project);
    koalaTest.assertValues("Checkout Show Share Sheet");
    vm.inputs.shareOnFacebookClick();
    startShareOnFacebookTest.assertValues(project);
    koalaTest.assertValues("Checkout Show Share Sheet", "Checkout Show Share");
    vm.inputs.shareOnTwitterClick();
    startShareOnTwitterTest.assertValues(project);
    koalaTest.assertValues("Checkout Show Share Sheet", "Checkout Show Share", "Checkout Show Share");
}
Also used : Project(com.kickstarter.models.Project) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Test(org.junit.Test)

Example 10 with Project

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

the class ProjectUpdatesViewModelTest method testProjectUpdatesViewModel_StartUpdateActivity.

@Test
public void testProjectUpdatesViewModel_StartUpdateActivity() {
    final ProjectUpdatesViewModel.ViewModel vm = new ProjectUpdatesViewModel.ViewModel(environment());
    final Project project = ProjectFactory.project();
    final Request updateRequest = new Request.Builder().url("https://kck.str/projects/param/param/posts/id").build();
    final TestSubscriber<Pair<Project, Update>> startUpdateActivity = new TestSubscriber<>();
    vm.outputs.startUpdateActivity().subscribe(startUpdateActivity);
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    vm.inputs.goToUpdateRequest(updateRequest);
    startUpdateActivity.assertValueCount(1);
    koalaTest.assertValues(KoalaEvent.VIEWED_UPDATES, KoalaEvent.VIEWED_UPDATE);
}
Also used : Project(com.kickstarter.models.Project) Request(okhttp3.Request) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Pair(android.util.Pair) 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