Search in sources :

Example 1 with MockApolloClient

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

the class DiscoveryIntentMapperTest method emitsFromParamsExtra.

@Test
public void emitsFromParamsExtra() {
    final DiscoveryParams params = DiscoveryParams.builder().build();
    final Intent intent = new Intent().putExtra(IntentKey.DISCOVERY_PARAMS, params);
    final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
    DiscoveryIntentMapper.params(intent, new MockApiClient(), new MockApolloClient()).subscribe(resultTest);
    resultTest.assertValues(params);
}
Also used : MockApolloClient(com.kickstarter.mock.services.MockApolloClient) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Test(org.junit.Test)

Example 2 with MockApolloClient

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

the class DiscoveryIntentMapperTest method emitsFromDiscoveryCategoryUri.

@Test
public void emitsFromDiscoveryCategoryUri() {
    final Uri uri = Uri.parse("https://www.kickstarter.com/discover/categories/music");
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
    DiscoveryIntentMapper.params(intent, new MockApiClient(), new MockApolloClient()).subscribe(resultTest);
    resultTest.assertValueCount(1);
}
Also used : MockApolloClient(com.kickstarter.mock.services.MockApolloClient) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Uri(android.net.Uri) Test(org.junit.Test)

Example 3 with MockApolloClient

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

the class DiscoveryIntentMapperTest method emitsFromDiscoveryLocationUri.

@Test
public void emitsFromDiscoveryLocationUri() {
    final Uri uri = Uri.parse("https://www.kickstarter.com/discover/places/sydney-au");
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
    DiscoveryIntentMapper.params(intent, new MockApiClient(), new MockApolloClient()).subscribe(resultTest);
    resultTest.assertValueCount(1);
}
Also used : MockApolloClient(com.kickstarter.mock.services.MockApolloClient) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Uri(android.net.Uri) Test(org.junit.Test)

Example 4 with MockApolloClient

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

the class DiscoveryIntentMapperTest method emitsFromAdvancedCategoryIdAndLocationIdUri.

@Test
public void emitsFromAdvancedCategoryIdAndLocationIdUri() {
    final Uri uri = Uri.parse("https://www.kickstarter.com/discover/advanced?category_id=1&location_id=1");
    final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
    final TestSubscriber<DiscoveryParams> resultTest = TestSubscriber.create();
    DiscoveryIntentMapper.params(intent, new MockApiClient(), new MockApolloClient()).subscribe(resultTest);
    resultTest.assertValueCount(1);
}
Also used : MockApolloClient(com.kickstarter.mock.services.MockApolloClient) MockApiClient(com.kickstarter.mock.services.MockApiClient) Intent(android.content.Intent) DiscoveryParams(com.kickstarter.services.DiscoveryParams) Uri(android.net.Uri) Test(org.junit.Test)

Example 5 with MockApolloClient

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

the class DiscoveryFragmentViewModelTest method testShouldShowEmptySavedView_isTrue_whenUserHasNoSavedProjects.

@Test
public void testShouldShowEmptySavedView_isTrue_whenUserHasNoSavedProjects() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final ApolloClientType apiClient = new MockApolloClient() {

        @Override
        @NonNull
        public Observable<DiscoverEnvelope> getProjects(@NonNull final DiscoveryParams params, final String cursor) {
            if (params.isSavedProjects()) {
                return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(new ArrayList<>()));
            } else {
                return super.getProjects(params, cursor);
            }
        }
    };
    final Environment environment = environment().toBuilder().apolloClient(apiClient).currentUser(currentUser).build();
    setUpEnvironment(environment);
    // Initial home all projects params.
    setUpInitialHomeAllProjectsParams();
    this.hasProjects.assertValue(true);
    this.shouldShowEmptySavedView.assertValue(false);
    // Login.
    logUserIn(currentUser);
    // New projects load.
    this.hasProjects.assertValues(true, true, true, true);
    this.shouldShowEmptySavedView.assertValues(false);
    // Saved projects params.
    this.vm.inputs.paramsFromActivity(DiscoveryParams.builder().starred(1).build());
    // Projects are cleared, new projects load with updated params.
    this.hasProjects.assertValues(true, true, true, true, false, false);
    this.shouldShowEmptySavedView.assertValues(false, true);
}
Also used : MockApolloClient(com.kickstarter.mock.services.MockApolloClient) DiscoverEnvelope(com.kickstarter.services.apiresponses.DiscoverEnvelope) NonNull(androidx.annotation.NonNull) ApolloClientType(com.kickstarter.services.ApolloClientType) ArrayList(java.util.ArrayList) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) DiscoveryParams(com.kickstarter.services.DiscoveryParams) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

MockApolloClient (com.kickstarter.mock.services.MockApolloClient)7 Test (org.junit.Test)7 DiscoveryParams (com.kickstarter.services.DiscoveryParams)6 Intent (android.content.Intent)5 MockApiClient (com.kickstarter.mock.services.MockApiClient)5 Uri (android.net.Uri)4 CurrentUserType (com.kickstarter.libs.CurrentUserType)2 Environment (com.kickstarter.libs.Environment)2 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)2 NonNull (androidx.annotation.NonNull)1 ApolloClientType (com.kickstarter.services.ApolloClientType)1 DiscoverEnvelope (com.kickstarter.services.apiresponses.DiscoverEnvelope)1 ArrayList (java.util.ArrayList)1