Search in sources :

Example 41 with MockApiClient

use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.

the class SearchViewModelTest method testPopularRefTags.

@Test
public void testPopularRefTags() {
    final TestScheduler scheduler = new TestScheduler();
    final List<Project> projects = Arrays.asList(ProjectFactory.allTheWayProject(), ProjectFactory.almostCompletedProject(), ProjectFactory.backedProject());
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<DiscoverEnvelope> fetchProjects(@NonNull final DiscoveryParams params) {
            return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(projects));
        }
    };
    final Environment env = environment().toBuilder().scheduler(scheduler).apiClient(apiClient).build();
    setUpEnvironment(env);
    // populate search and overcome debounce
    this.vm.inputs.search("");
    scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
    this.vm.inputs.projectClicked(projects.get(2));
    this.goToRefTag.assertValues(RefTag.searchPopular());
    this.goToProject.assertValues(projects.get(2));
}
Also used : Project(com.kickstarter.models.Project) DiscoverEnvelope(com.kickstarter.services.apiresponses.DiscoverEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestScheduler(rx.schedulers.TestScheduler) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Test(org.junit.Test)

Example 42 with MockApiClient

use of com.kickstarter.mock.services.MockApiClient 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 43 with MockApiClient

use of com.kickstarter.mock.services.MockApiClient in project android-oss by kickstarter.

the class MessagesViewModelTest method testMessagesEmit.

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

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForThread(@NonNull final MessageThread messageThread) {
            return Observable.just(envelope);
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a message thread.
    this.vm.intent(messagesContextIntent(MessageThreadFactory.messageThread()));
    // Messages emit, keyboard not shown.
    this.messageList.assertValueCount(1);
    this.messageEditTextShouldRequestFocus.assertNoValues();
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) MessageThread(com.kickstarter.models.MessageThread) MessageThreadEnvelope(com.kickstarter.services.apiresponses.MessageThreadEnvelope) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 44 with MockApiClient

use of com.kickstarter.mock.services.MockApiClient 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 45 with MockApiClient

use of com.kickstarter.mock.services.MockApiClient 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)

Aggregations

MockApiClient (com.kickstarter.mock.services.MockApiClient)66 Test (org.junit.Test)64 NonNull (androidx.annotation.NonNull)47 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)33 Environment (com.kickstarter.libs.Environment)29 Intent (android.content.Intent)28 Project (com.kickstarter.models.Project)25 ApiClientType (com.kickstarter.services.ApiClientType)19 User (com.kickstarter.models.User)14 CurrentUserType (com.kickstarter.libs.CurrentUserType)12 DiscoveryParams (com.kickstarter.services.DiscoveryParams)12 MessageThreadEnvelope (com.kickstarter.services.apiresponses.MessageThreadEnvelope)12 Backing (com.kickstarter.models.Backing)9 MessageThread (com.kickstarter.models.MessageThread)9 TestScheduler (rx.schedulers.TestScheduler)8 TestSubscriber (rx.observers.TestSubscriber)7 Update (com.kickstarter.models.Update)6 AccessTokenEnvelope (com.kickstarter.services.apiresponses.AccessTokenEnvelope)6 DiscoverEnvelope (com.kickstarter.services.apiresponses.DiscoverEnvelope)6 ProjectsEnvelope (com.kickstarter.services.apiresponses.ProjectsEnvelope)6