Search in sources :

Example 36 with Project

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

the class CommentsViewModelTest method testCommentsViewModel_postCommentFlow.

@Test
public void testCommentsViewModel_postCommentFlow() {
    final CommentsViewModel vm = new CommentsViewModel(environment());
    final Project project = ProjectFactory.backedProject();
    final TestSubscriber<Void> showCommentPostedToastTest = new TestSubscriber<>();
    vm.outputs.showCommentPostedToast().subscribe(showCommentPostedToastTest);
    final TestSubscriber<Void> dismissCommentDialogTest = new TestSubscriber<>();
    vm.outputs.dismissCommentDialog().subscribe(dismissCommentDialogTest);
    final TestSubscriber<Boolean> postButtonIsEnabledTest = new TestSubscriber<>();
    vm.outputs.enablePostButton().subscribe(postButtonIsEnabledTest);
    final TestSubscriber<Boolean> showCommentButtonTest = new TestSubscriber<>();
    vm.outputs.showCommentButton().subscribe(showCommentButtonTest);
    final TestSubscriber<Pair<Project, Boolean>> showCommentDialogTest = new TestSubscriber<>();
    vm.outputs.showCommentDialog().subscribe(showCommentDialogTest);
    // Start the view model with a project.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    koalaTest.assertValues(KoalaEvent.VIEWED_COMMENTS, KoalaEvent.PROJECT_COMMENT_VIEW);
    // Comment button should be shown.
    showCommentButtonTest.assertValue(true);
    // Click comment button. Comment dialog should be shown.
    vm.inputs.commentButtonClicked();
    showCommentDialogTest.assertValue(Pair.create(project, true));
    // Write a comment. The post button should be enabled with valid comment body.
    vm.inputs.commentBodyChanged("");
    postButtonIsEnabledTest.assertValues(false);
    vm.inputs.commentBodyChanged("Some comment");
    postButtonIsEnabledTest.assertValues(false, true);
    // Post comment. Dialog should be dismissed.
    vm.inputs.postCommentClicked();
    dismissCommentDialogTest.assertValueCount(1);
    // Comment posted toast should be shown.
    showCommentPostedToastTest.assertValueCount(1);
    // A koala event for commenting should be tracked.
    koalaTest.assertValues(KoalaEvent.VIEWED_COMMENTS, KoalaEvent.PROJECT_COMMENT_VIEW, KoalaEvent.POSTED_COMMENT, KoalaEvent.PROJECT_COMMENT_CREATE);
}
Also used : Project(com.kickstarter.models.Project) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Pair(android.util.Pair) Test(org.junit.Test)

Example 37 with Project

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

the class ProjectFactory method backedProjectWithRewardLimited.

@NonNull
public static Project backedProjectWithRewardLimited() {
    final Project project = project();
    final Reward reward = RewardFactory.limited();
    final Backing backing = Backing.builder().amount(10.0f).backerId(IdFactory.id()).id(IdFactory.id()).sequence(1).reward(reward).rewardId(reward.id()).pledgedAt(DateTime.now()).projectCountry(project.country()).projectId(project.id()).shippingAmount(0.0f).status(Backing.STATUS_PLEDGED).build();
    return project.toBuilder().backing(backing).isBacking(true).build();
}
Also used : Project(com.kickstarter.models.Project) Reward(com.kickstarter.models.Reward) Backing(com.kickstarter.models.Backing) NonNull(android.support.annotation.NonNull)

Example 38 with Project

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

the class UpdateFactory method update.

public static Update update() {
    final Project project = ProjectFactory.project();
    final String updatesUrl = "https://www.kck.str/projects/" + project.creator().param() + "/" + project.param() + "/posts";
    final Update.Urls.Web web = Update.Urls.Web.builder().update(updatesUrl + "id").likes(updatesUrl + "/likes").build();
    return Update.builder().body("Update body").id(1234).projectId(5678).sequence(11111).title("First update").urls(Update.Urls.builder().web(web).build()).build();
}
Also used : Project(com.kickstarter.models.Project)

Example 39 with Project

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

the class BackingUtilsTest method testIsBacked.

@Test
public void testIsBacked() {
    final Project backedProject = ProjectFactory.backedProject();
    assertTrue(BackingUtils.isBacked(backedProject, backedProject.backing().reward()));
    assertFalse(BackingUtils.isBacked(backedProject, RewardFactory.reward()));
}
Also used : Project(com.kickstarter.models.Project) Test(org.junit.Test)

Example 40 with Project

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

the class RefTagUtilsTest method testCookieNameForProject.

@Test
public void testCookieNameForProject() {
    final Project project = ProjectFactory.project();
    assertEquals("ref_" + String.valueOf(project.id()), RefTagUtils.cookieNameForProject(project));
}
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