Search in sources :

Example 26 with Backing

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

the class ViewPledgeViewModelTest method testBackingStatus.

@Test
public void testBackingStatus() {
    final Backing backing = BackingFactory.backing();
    final ViewPledgeViewModel vm = vm(backing);
    final TestSubscriber<String> backingStatusTextViewTest = TestSubscriber.create();
    vm.outputs.backingStatus().subscribe(backingStatusTextViewTest);
    vm.intent(intent(backing));
    backingStatusTextViewTest.assertValue(backing.status());
}
Also used : Backing(com.kickstarter.models.Backing) Test(org.junit.Test)

Example 27 with Backing

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

the class MessagesViewModelTest method testToolbarIsExpanded_NoMessages.

@Test
public void testToolbarIsExpanded_NoMessages() {
    final Backing backing = BackingFactory.backing();
    final MessageThreadEnvelope envelope = MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messages(null).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForBacking(@NonNull final Backing backing) {
            return Observable.just(envelope);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a backing and project.
    this.vm.intent(backerModalContextIntent(backing, ProjectFactory.project()));
    this.vm.inputs.messageEditTextIsFocused(true);
    // Toolbar stays expanded when keyboard opens and no messages.
    this.toolbarIsExpanded.assertNoValues();
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Backing(com.kickstarter.models.Backing) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 28 with Backing

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

the class MessagesViewModelTest method testShouldRequestFocus.

@Test
public void testShouldRequestFocus() {
    final Backing backing = BackingFactory.backing();
    final MessageThreadEnvelope envelope = MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messages(null).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForBacking(@NonNull final Backing backing) {
            return Observable.just(envelope);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a backing and project.
    this.vm.intent(backerModalContextIntent(backing, ProjectFactory.project()));
    this.messageEditTextShouldRequestFocus.assertValueCount(1);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Backing(com.kickstarter.models.Backing) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 29 with Backing

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

the class MessagesViewModelTest method testToolbarIsExpanded_WithMessages.

@Test
public void testToolbarIsExpanded_WithMessages() {
    final Backing backing = BackingFactory.backing();
    final MessageThreadEnvelope envelope = MessageThreadEnvelopeFactory.messageThreadEnvelope().toBuilder().messages(Collections.singletonList(MessageFactory.message())).build();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForBacking(@NonNull final Backing backing) {
            return Observable.just(envelope);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a backing and project.
    this.vm.intent(backerModalContextIntent(backing, ProjectFactory.project()));
    this.vm.inputs.messageEditTextIsFocused(true);
    // Toolbar collapsed when keyboard opens and there are messages.
    this.toolbarIsExpanded.assertValues(false);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Backing(com.kickstarter.models.Backing) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 30 with Backing

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

the class MessagesViewModelTest method testNoMessages.

@Test
public void testNoMessages() {
    final Backing backing = BackingFactory.backing();
    final Project project = ProjectFactory.project();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForBacking(@NonNull final Backing backing) {
            return Observable.just(MessageThreadEnvelopeFactory.empty());
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a backing and a project.
    this.vm.intent(backerModalContextIntent(backing, project));
    // All data except for messages should emit.
    this.messageList.assertNoValues();
    this.creatorNameTextViewText.assertValues(project.creator().name());
    this.backingAndProject.assertValues(Pair.create(backing, project));
}
Also used : Project(com.kickstarter.models.Project) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Backing(com.kickstarter.models.Backing) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

Backing (com.kickstarter.models.Backing)30 Test (org.junit.Test)26 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)11 Project (com.kickstarter.models.Project)11 NonNull (androidx.annotation.NonNull)9 MockApiClient (com.kickstarter.mock.services.MockApiClient)9 MessageThreadEnvelope (com.kickstarter.services.apiresponses.MessageThreadEnvelope)8 Reward (com.kickstarter.models.Reward)7 User (com.kickstarter.models.User)6 BackingWrapper (com.kickstarter.models.BackingWrapper)4 MessageThread (com.kickstarter.models.MessageThread)4 NonNull (android.support.annotation.NonNull)3 Pair (android.util.Pair)2 Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2 Location (com.kickstarter.models.Location)1