use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class MessagesViewModelTest method testCreatorViewingProjectMessages.
@Test
public void testCreatorViewingProjectMessages() {
final User creator = UserFactory.creator().toBuilder().name("Sharon").build();
final User participant = UserFactory.user().toBuilder().name("Timothy").build();
final CurrentUserType currentUser = new MockCurrentUser(creator);
final MessageThread messageThread = MessageThreadFactory.messageThread().toBuilder().project(ProjectFactory.project().toBuilder().creator(creator).build()).participant(participant).build();
final MockApiClient apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<MessageThreadEnvelope> fetchMessagesForThread(@NonNull final MessageThread thread) {
return Observable.just(MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messageThread(messageThread).build());
}
};
setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(currentUser).build());
// Start the view model with a message thread.
this.vm.intent(messagesContextIntent(messageThread));
// Creator name is the project creator, edit text hint is always the participant.
this.creatorNameTextViewText.assertValues(creator.name());
this.messageEditTextHint.assertValues(participant.name());
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class FacebookConfimationViewModelTest method testSignupErrorDisplay.
@Test
public void testSignupErrorDisplay() {
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<AccessTokenEnvelope> registerWithFacebook(@NonNull final String fbAccessToken, final boolean sendNewsletters) {
return Observable.error(ApiExceptionFactory.apiError(ErrorEnvelope.builder().httpCode(404).errorMessages(Collections.singletonList("oh no")).build()));
}
};
final Environment environment = environment().toBuilder().apiClient(apiClient).build();
this.vm = new FacebookConfirmationViewModel.ViewModel(environment);
this.vm.intent(new Intent().putExtra(IntentKey.FACEBOOK_TOKEN, "token"));
this.vm.outputs.signupError().subscribe(this.signupError);
this.vm.inputs.sendNewslettersClick(true);
this.vm.inputs.createNewAccountClick();
this.signupError.assertValue("oh no");
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class FacebookConfimationViewModelTest method testSuccessfulUserCreation.
@Test
public void testSuccessfulUserCreation() {
final ApiClientType apiClient = new MockApiClient();
final Environment environment = environment().toBuilder().apiClient(apiClient).build();
this.vm = new FacebookConfirmationViewModel.ViewModel(environment);
this.vm.intent(new Intent().putExtra(IntentKey.FACEBOOK_TOKEN, "token"));
this.vm.outputs.signupSuccess().subscribe(this.signupSuccess);
this.vm.inputs.sendNewslettersClick(true);
this.vm.inputs.createNewAccountClick();
this.signupSuccess.assertValueCount(1);
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class MessageThreadsViewModelTest method testHasUnreadMessages.
@Test
public void testHasUnreadMessages() {
final User user = UserFactory.user().toBuilder().unreadMessagesCount(3).build();
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<User> fetchCurrentUser() {
return Observable.just(user);
}
};
setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
this.vm.intent(new Intent());
this.vm.inputs.onResume();
// Unread count text view is shown.
this.unreadMessagesCount.assertValues(user.unreadMessagesCount());
this.unreadMessagesCountIsGone.assertValues(false);
this.hasNoUnreadMessages.assertValues(false);
this.unreadCountTextViewColorInt.assertValues(R.color.accent);
this.unreadCountTextViewTypefaceInt.assertValues(Typeface.BOLD);
this.unreadCountToolbarTextViewIsGone.assertValues(false);
this.vm.inputs.mailbox(Mailbox.SENT);
this.unreadMessagesCountIsGone.assertValues(false, true);
}
use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.
the class MessageThreadsViewModelTest method testNoMessages.
@Test
public void testNoMessages() {
final User user = UserFactory.user().toBuilder().unreadMessagesCount(null).build();
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<User> fetchCurrentUser() {
return Observable.just(user);
}
};
setUpEnvironment(environment().toBuilder().apiClient(apiClient).build());
this.vm.intent(new Intent());
this.vm.inputs.onResume();
this.hasNoMessages.assertValues(true);
this.unreadMessagesCount.assertNoValues();
this.unreadMessagesCountIsGone.assertValue(false);
this.unreadCountTextViewColorInt.assertValues(R.color.kds_support_400);
this.unreadCountTextViewTypefaceInt.assertValues(Typeface.NORMAL);
this.unreadCountToolbarTextViewIsGone.assertValues(true);
this.vm.inputs.mailbox(Mailbox.SENT);
this.unreadMessagesCountIsGone.assertValues(false, true);
}
Aggregations