Search in sources :

Example 36 with MockApiClient

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

the class UpdateViewModelTest method testUpdateViewModel_DeepLinkPost.

@Test
public void testUpdateViewModel_DeepLinkPost() {
    final String postId = "3254626";
    final Update update = UpdateFactory.update().toBuilder().sequence(2).build();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Update> fetchUpdate(@NonNull final String projectParam, @NonNull final String updateParam) {
            return Observable.just(update);
        }
    };
    final Environment environment = environment().toBuilder().apiClient(apiClient).build();
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
    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_POST_ID, postId));
    // Initial update index url emits.
    webViewUrl.assertValues(update.urls().web().update());
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Update(com.kickstarter.models.Update) ApiClientType(com.kickstarter.services.ApiClientType) Test(org.junit.Test)

Example 37 with MockApiClient

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

the class UpdateViewModelTest method testUpdateViewModel_DeepLinkCommentThread.

@Test
public void testUpdateViewModel_DeepLinkCommentThread() {
    final String postId = "3254626";
    final String commentableId = "Q29tbWVudC0zMzU2MTY4Ng";
    final Update update = UpdateFactory.update();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Update> fetchUpdate(@NonNull final String projectParam, @NonNull final String updateParam) {
            return Observable.just(update);
        }
    };
    final TestScheduler testScheduler = new TestScheduler();
    final Environment environment = environment().toBuilder().apiClient(apiClient).scheduler(testScheduler).build();
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
    final TestSubscriber<Pair<String, Update>> startRootCommentsActivityToDeepLinkThreadActivity = new TestSubscriber<>();
    vm.outputs.startRootCommentsActivityToDeepLinkThreadActivity().subscribe(startRootCommentsActivityToDeepLinkThreadActivity);
    final TestSubscriber<String> webViewUrl = new TestSubscriber<>();
    vm.outputs.webViewUrl().subscribe(webViewUrl);
    final TestSubscriber<Pair<String, Boolean>> deepLinkToThreadActivity = new TestSubscriber<>();
    vm.deepLinkToThreadActivity().subscribe(deepLinkToThreadActivity);
    // Start the intent with a project and update.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.project()).putExtra(IntentKey.UPDATE_POST_ID, postId).putExtra(IntentKey.IS_UPDATE_COMMENT, true).putExtra(IntentKey.COMMENT, commentableId));
    // Initial update index url emits.
    webViewUrl.assertValues(update.urls().web().update());
    deepLinkToThreadActivity.assertValue(Pair.create(commentableId, true));
    vm.inputs.goToCommentsActivityToDeepLinkThreadActivity(commentableId);
    testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    startRootCommentsActivityToDeepLinkThreadActivity.assertValue(Pair.create(commentableId, update));
    startRootCommentsActivityToDeepLinkThreadActivity.assertValueCount(1);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) Update(com.kickstarter.models.Update) ApiClientType(com.kickstarter.services.ApiClientType) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) TestScheduler(rx.schedulers.TestScheduler) Pair(android.util.Pair) Test(org.junit.Test)

Example 38 with MockApiClient

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

the class UpdateViewModelTest method testUpdateViewModel_DeepLinkComment.

@Test
public void testUpdateViewModel_DeepLinkComment() {
    final String postId = "3254626";
    final Update update = UpdateFactory.update();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<Update> fetchUpdate(@NonNull final String projectParam, @NonNull final String updateParam) {
            return Observable.just(update);
        }
    };
    final TestScheduler testScheduler = new TestScheduler();
    final Environment environment = environment().toBuilder().apiClient(apiClient).scheduler(testScheduler).build();
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
    final TestSubscriber<Update> startRootCommentsActivity = new TestSubscriber<>();
    vm.outputs.startRootCommentsActivity().subscribe(startRootCommentsActivity);
    final TestSubscriber<String> webViewUrl = new TestSubscriber<>();
    vm.outputs.webViewUrl().subscribe(webViewUrl);
    final TestSubscriber<Boolean> deepLinkToRootComment = new TestSubscriber<>();
    vm.hasCommentsDeepLinks().subscribe(deepLinkToRootComment);
    // Start the intent with a project and update.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.project()).putExtra(IntentKey.UPDATE_POST_ID, postId).putExtra(IntentKey.IS_UPDATE_COMMENT, true));
    // Initial update index url emits.
    webViewUrl.assertValues(update.urls().web().update());
    deepLinkToRootComment.assertValue(true);
    vm.inputs.goToCommentsActivity();
    testScheduler.advanceTimeBy(2, TimeUnit.SECONDS);
    startRootCommentsActivity.assertValue(update);
    startRootCommentsActivity.assertValueCount(1);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) Update(com.kickstarter.models.Update) ApiClientType(com.kickstarter.services.ApiClientType) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) TestScheduler(rx.schedulers.TestScheduler) Test(org.junit.Test)

Example 39 with MockApiClient

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

the class SearchViewModelTest method testFeaturedSearchRefTags.

@Test
public void testFeaturedSearchRefTags() {
    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);
    this.vm.inputs.search("cat");
    scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
    this.vm.inputs.projectClicked(projects.get(0));
    this.goToRefTag.assertValues(RefTag.searchFeatured());
    this.goToProject.assertValues(projects.get(0));
}
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 40 with MockApiClient

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

the class SearchViewModelTest method testSearchRefTags.

@Test
public void testSearchRefTags() {
    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("cat");
    scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
    this.vm.inputs.projectClicked(projects.get(1));
    this.goToRefTag.assertValues(RefTag.search());
    this.goToProject.assertValues(projects.get(1));
}
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)

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