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());
}
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()));
}
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);
}
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);
}
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;
}
}
}
Aggregations