Search in sources :

Example 46 with Project

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

the class KoalaUtils method activityProperties.

@NonNull
public static Map<String, Object> activityProperties(@NonNull final Activity activity, @NonNull final String prefix) {
    Map<String, Object> properties = new HashMap<String, Object>() {

        {
            put("category", activity.category());
        }
    };
    properties = MapUtils.prefixKeys(properties, prefix);
    final Project project = activity.project();
    if (project != null) {
        properties.putAll(projectProperties(project));
        final Update update = activity.update();
        if (update != null) {
            properties.putAll(updateProperties(project, update));
        }
    }
    return properties;
}
Also used : Project(com.kickstarter.models.Project) HashMap(java.util.HashMap) Update(com.kickstarter.models.Update) NonNull(android.support.annotation.NonNull)

Example 47 with Project

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

the class ThanksViewModel method relatedProjects.

/**
   * Returns a shuffled list of 3 recommended projects, with fallbacks to similar and staff picked projects
   * for users with fewer than 3 recommendations.
   */
@NonNull
private Observable<List<Project>> relatedProjects(@NonNull final Project project) {
    final DiscoveryParams recommendedParams = DiscoveryParams.builder().backed(-1).recommended(true).perPage(6).build();
    final DiscoveryParams similarToParams = DiscoveryParams.builder().backed(-1).similarTo(project).perPage(3).build();
    final Category category = project.category();
    final DiscoveryParams staffPickParams = DiscoveryParams.builder().category(category == null ? null : category.root()).backed(-1).staffPicks(true).perPage(3).build();
    final Observable<Project> recommendedProjects = apiClient.fetchProjects(recommendedParams).retry(2).map(DiscoverEnvelope::projects).map(ListUtils::shuffle).flatMap(Observable::from).take(3);
    final Observable<Project> similarToProjects = apiClient.fetchProjects(similarToParams).retry(2).map(DiscoverEnvelope::projects).flatMap(Observable::from);
    final Observable<Project> staffPickProjects = apiClient.fetchProjects(staffPickParams).retry(2).map(DiscoverEnvelope::projects).flatMap(Observable::from);
    return Observable.concat(recommendedProjects, similarToProjects, staffPickProjects).compose(neverError()).distinct().take(3).toList();
}
Also used : Project(com.kickstarter.models.Project) Category(com.kickstarter.models.Category) DiscoveryParams(com.kickstarter.services.DiscoveryParams) ListUtils(com.kickstarter.libs.utils.ListUtils) Observable(rx.Observable) NonNull(android.support.annotation.NonNull)

Example 48 with Project

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

the class CommentsViewModelTest method testCommentsViewModel_postCommentError.

@Test
public void testCommentsViewModel_postCommentError() {
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Comment> postComment(@NonNull final Project project, @NonNull final String body) {
            return Observable.error(ApiExceptionFactory.badRequestException());
        }
    };
    final Environment env = environment().toBuilder().apiClient(apiClient).build();
    final CommentsViewModel vm = new CommentsViewModel(env);
    final TestSubscriber<String> showPostCommentErrorToast = new TestSubscriber<>();
    vm.outputs.showPostCommentErrorToast().subscribe(showPostCommentErrorToast);
    final TestSubscriber<Void> showCommentPostedToast = new TestSubscriber<>();
    vm.outputs.showCommentPostedToast().subscribe(showCommentPostedToast);
    // Start the view model with a project.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.backedProject()));
    // Click the comment button and write a comment.
    vm.inputs.commentButtonClicked();
    vm.inputs.commentBodyChanged("Mic check mic check.");
    // Post comment. Error should be shown. Comment posted toast should not be shown.
    vm.inputs.postCommentClicked();
    showPostCommentErrorToast.assertValueCount(1);
    showCommentPostedToast.assertNoValues();
}
Also used : Comment(com.kickstarter.models.Comment) MockApiClient(com.kickstarter.services.MockApiClient) Intent(android.content.Intent) ApiClientType(com.kickstarter.services.ApiClientType) Project(com.kickstarter.models.Project) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Example 49 with Project

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

the class CommentsViewModelTest method testCommentsViewModel_loggedOutShowDialogFlow.

@Test
public void testCommentsViewModel_loggedOutShowDialogFlow() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().currentUser(currentUser).build();
    final CommentsViewModel vm = new CommentsViewModel(environment);
    final Project project = ProjectFactory.backedProject();
    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));
    // The comment dialog should be hidden from logged out user.
    showCommentDialogTest.assertNoValues();
    // Login.
    currentUser.refresh(UserFactory.user());
    vm.inputs.loginSuccess();
    // The comment dialog should be shown to backer.
    showCommentDialogTest.assertValue(Pair.create(project, true));
}
Also used : Project(com.kickstarter.models.Project) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Pair(android.util.Pair) Test(org.junit.Test)

Example 50 with Project

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

the class CommentsViewModelTest method testCommentsViewModel_dismissCommentDialog.

@Test
public void testCommentsViewModel_dismissCommentDialog() {
    final CommentsViewModel vm = new CommentsViewModel(environment());
    final TestSubscriber<Void> dismissCommentDialogTest = new TestSubscriber<>();
    vm.outputs.dismissCommentDialog().subscribe(dismissCommentDialogTest);
    final TestSubscriber<Pair<Project, Boolean>> showCommentDialogTest = new TestSubscriber<>();
    vm.outputs.showCommentDialog().subscribe(showCommentDialogTest);
    final Project project = ProjectFactory.backedProject();
    // Start the view model with a project.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    // The comment dialog should not be shown.
    showCommentDialogTest.assertNoValues();
    dismissCommentDialogTest.assertNoValues();
    // Dismiss the comment dialog.
    vm.inputs.commentDialogDismissed();
    // The comment dialog should be dismissed.
    dismissCommentDialogTest.assertValueCount(1);
    showCommentDialogTest.assertValue(null);
}
Also used : Project(com.kickstarter.models.Project) 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