Search in sources :

Example 1 with Update

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

the class UpdateViewModelTest method testUpdateViewModel_WebViewUrl.

@Test
public void testUpdateViewModel_WebViewUrl() {
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment());
    final Update update = UpdateFactory.update();
    final TestSubscriber<String> webViewUrl = new TestSubscriber<>();
    vm.outputs.webViewUrl().subscribe(webViewUrl);
    // Start the intent with a project and update.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.project()).putExtra(IntentKey.UPDATE, update));
    // Initial update index url emits.
    webViewUrl.assertValues(update.urls().web().update());
}
Also used : TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Update(com.kickstarter.models.Update) Test(org.junit.Test)

Example 2 with Update

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

the class UpdateViewModelTest method testUpdateViewModel_UpdateSequence.

@Test
public void testUpdateViewModel_UpdateSequence() {
    final Update initialUpdate = UpdateFactory.update().toBuilder().sequence(1).build();
    final Update anotherUpdate = UpdateFactory.update().toBuilder().sequence(2).build();
    final Request anotherUpdateRequest = new Request.Builder().url("https://kck.str/projects/param/param/posts/id").build();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Update> fetchUpdate(@NonNull final String projectParam, @NonNull final String updateParam) {
            return Observable.just(anotherUpdate);
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
    final TestSubscriber<String> updateSequence = new TestSubscriber<>();
    vm.outputs.updateSequence().subscribe(updateSequence);
    // Start the intent with a project and update.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.project()).putExtra(IntentKey.UPDATE, initialUpdate));
    // Initial update's sequence number emits.
    updateSequence.assertValues(NumberUtils.format(initialUpdate.sequence()));
    vm.inputs.goToUpdateRequest(anotherUpdateRequest);
    // New sequence should emit for new update page.
    updateSequence.assertValues(NumberUtils.format(initialUpdate.sequence()), NumberUtils.format(anotherUpdate.sequence()));
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) Request(okhttp3.Request) Intent(android.content.Intent) Update(com.kickstarter.models.Update) ApiClientType(com.kickstarter.services.ApiClientType) NonNull(android.support.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Test(org.junit.Test)

Example 3 with Update

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

the class UpdateViewModelTest method testUpdateViewModel_StartCommentsActivity.

@Test
public void testUpdateViewModel_StartCommentsActivity() {
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment());
    final Update update = UpdateFactory.update();
    final Request commentsRequest = new Request.Builder().url("https://kck.str/projects/param/param/posts/id/comments").build();
    final TestSubscriber<Update> startCommentsActivity = new TestSubscriber<>();
    vm.outputs.startCommentsActivity().subscribe(startCommentsActivity);
    // Start the intent with a project and update.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.project()).putExtra(IntentKey.UPDATE, update));
    vm.inputs.goToCommentsRequest(commentsRequest);
    startCommentsActivity.assertValues(update);
}
Also used : Request(okhttp3.Request) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Update(com.kickstarter.models.Update) Test(org.junit.Test)

Example 4 with Update

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

the class UpdateViewModelTest method testUpdateViewModel_StartProjectActivity.

@Test
public void testUpdateViewModel_StartProjectActivity() {
    final Update update = UpdateFactory.update().toBuilder().projectId(1234).build();
    final Project project = ProjectFactory.project().toBuilder().id(update.projectId()).build();
    final Request projectRequest = new Request.Builder().url("https://kck.str/projects/param/param").build();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Project> fetchProject(@NonNull final String param) {
            return Observable.just(project);
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
    final TestSubscriber<Project> startProjectActivity = new TestSubscriber<>();
    vm.outputs.startProjectActivity().map(pr -> pr.first).subscribe(startProjectActivity);
    // Start the intent with a project and update.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project).putExtra(IntentKey.UPDATE, update));
    vm.inputs.goToProjectRequest(projectRequest);
    startProjectActivity.assertValues(project);
}
Also used : Request(okhttp3.Request) Project(com.kickstarter.models.Project) UpdateFactory(com.kickstarter.factories.UpdateFactory) Intent(android.content.Intent) Test(org.junit.Test) NonNull(android.support.annotation.NonNull) KoalaEvent(com.kickstarter.libs.KoalaEvent) Observable(rx.Observable) KSRobolectricTestCase(com.kickstarter.KSRobolectricTestCase) TestSubscriber(rx.observers.TestSubscriber) Update(com.kickstarter.models.Update) ApiClientType(com.kickstarter.services.ApiClientType) Environment(com.kickstarter.libs.Environment) NumberUtils(com.kickstarter.libs.utils.NumberUtils) ProjectFactory(com.kickstarter.factories.ProjectFactory) IntentKey(com.kickstarter.ui.IntentKey) MockApiClient(com.kickstarter.services.MockApiClient) MockApiClient(com.kickstarter.services.MockApiClient) Request(okhttp3.Request) Intent(android.content.Intent) Update(com.kickstarter.models.Update) 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 5 with Update

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

the class ActivitySampleProjectViewHolder method onBind.

public void onBind() {
    final Context context = context();
    final Project project = activity.project();
    if (project != null) {
        final Photo photo = project.photo();
        if (photo != null) {
            Picasso.with(context).load(photo.little()).into(activityImageView);
        }
        activityTitleTextView.setText(project.name());
        switch(activity.category()) {
            case Activity.CATEGORY_FAILURE:
                activitySubtitleTextView.setText(categoryFailureString);
                break;
            case Activity.CATEGORY_CANCELLATION:
                activitySubtitleTextView.setText(categoryCancellationString);
                break;
            case Activity.CATEGORY_LAUNCH:
                final User user = activity.user();
                if (user != null) {
                    activitySubtitleTextView.setText(ksString.format(categoryLaunchString, "user_name", user.name()));
                }
                break;
            case Activity.CATEGORY_SUCCESS:
                activitySubtitleTextView.setText(categorySuccessString);
                break;
            case Activity.CATEGORY_UPDATE:
                final Update update = activity.update();
                if (update != null) {
                    activitySubtitleTextView.setText(ksString.format(categoryUpdateString, "update_number", String.valueOf(update.sequence()), "update_title", update.title()));
                }
                break;
            default:
                break;
        }
    }
}
Also used : Context(android.content.Context) Project(com.kickstarter.models.Project) User(com.kickstarter.models.User) Photo(com.kickstarter.models.Photo) Update(com.kickstarter.models.Update)

Aggregations

Update (com.kickstarter.models.Update)12 Test (org.junit.Test)8 TestSubscriber (rx.observers.TestSubscriber)8 Intent (android.content.Intent)7 Project (com.kickstarter.models.Project)5 Request (okhttp3.Request)5 NonNull (android.support.annotation.NonNull)4 Environment (com.kickstarter.libs.Environment)3 ApiClientType (com.kickstarter.services.ApiClientType)3 MockApiClient (com.kickstarter.services.MockApiClient)3 Context (android.content.Context)2 Photo (com.kickstarter.models.Photo)2 User (com.kickstarter.models.User)2 Nullable (android.support.annotation.Nullable)1 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)1 ProjectFactory (com.kickstarter.factories.ProjectFactory)1 UpdateFactory (com.kickstarter.factories.UpdateFactory)1 KoalaEvent (com.kickstarter.libs.KoalaEvent)1 NumberUtils (com.kickstarter.libs.utils.NumberUtils)1 Activity (com.kickstarter.models.pushdata.Activity)1