Search in sources :

Example 66 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.

the class MessagesViewModelTest method testMessageEditTextHint.

@Test
public void testMessageEditTextHint() {
    final MessageThread messageThread = MessageThreadFactory.messageThread();
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<MessageThreadEnvelope> fetchMessagesForThread(@NonNull final MessageThread thread) {
            return Observable.just(MessageThreadEnvelopeFactory.messageThreadEnvelope());
        }
    };
    setUpEnvironment(environment().toBuilder().apiClient(apiClient).currentUser(new MockCurrentUser(UserFactory.user())).build());
    // Start the view model with a message thread.
    this.vm.intent(messagesContextIntent(messageThread));
    this.messageEditTextHint.assertValues(messageThread.project().creator().name());
}
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 67 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.

the class DiscoveryFragmentViewModelTest method testShouldShowEditorial_featureEnabled.

@Test
public void testShouldShowEditorial_featureEnabled() {
    final MockCurrentUser user = new MockCurrentUser();
    final MockExperimentsClientType mockExperimentsClientType = new MockExperimentsClientType() {

        @Override
        public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature, @NotNull final ExperimentData experimentData) {
            return true;
        }
    };
    final Environment environment = environment().toBuilder().currentUser(user).optimizely(mockExperimentsClientType).build();
    setUpEnvironment(environment);
    setUpInitialHomeAllProjectsParams();
    this.shouldShowEditorial.assertValue(Editorial.LIGHTS_ON);
}
Also used : Environment(com.kickstarter.libs.Environment) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) NotNull(org.jetbrains.annotations.NotNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ExperimentData(com.kickstarter.libs.utils.ExperimentData) Test(org.junit.Test)

Example 68 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.

the class DiscoveryFragmentViewModelTest method testShouldShowEditorial_whenOptimizelyInitializationDelay.

@Test
public void testShouldShowEditorial_whenOptimizelyInitializationDelay() {
    final Environment environment = environment().toBuilder().currentUser(new MockCurrentUser()).optimizely(new MockExperimentsClientType() {

        int enabledCount;

        @Override
        public boolean isFeatureEnabled(@NonNull final OptimizelyFeature.Key feature, @NonNull final ExperimentData experimentData) {
            if (enabledCount == 0) {
                enabledCount += 1;
                return false;
            } else {
                return true;
            }
        }
    }).build();
    setUpEnvironment(environment);
    setUpInitialHomeAllProjectsParams();
    this.shouldShowEditorial.assertValue(null);
    this.vm.optimizelyReady();
    this.shouldShowEditorial.assertValues(null, Editorial.LIGHTS_ON);
}
Also used : NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ExperimentData(com.kickstarter.libs.utils.ExperimentData) Test(org.junit.Test)

Example 69 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser 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)

Example 70 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser in project android-oss by kickstarter.

the class DiscoveryFragmentViewModelTest method testShouldShowEmptySavedView_isFalse_whenUserHasSavedProjects.

@Test
public void testShouldShowEmptySavedView_isFalse_whenUserHasSavedProjects() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().apolloClient(new MockApolloClient()).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());
    // New projects load with updated params.
    this.hasProjects.assertValues(true, true, true, true, true, true);
    this.shouldShowEmptySavedView.assertValues(false);
}
Also used : MockApolloClient(com.kickstarter.mock.services.MockApolloClient) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

MockCurrentUser (com.kickstarter.libs.MockCurrentUser)86 Test (org.junit.Test)85 CurrentUserType (com.kickstarter.libs.CurrentUserType)43 Environment (com.kickstarter.libs.Environment)39 Project (com.kickstarter.models.Project)31 User (com.kickstarter.models.User)31 MockApiClient (com.kickstarter.mock.services.MockApiClient)29 NonNull (androidx.annotation.NonNull)26 Intent (android.content.Intent)16 MockExperimentsClientType (com.kickstarter.mock.MockExperimentsClientType)12 MessageThreadEnvelope (com.kickstarter.services.apiresponses.MessageThreadEnvelope)12 Backing (com.kickstarter.models.Backing)11 NotNull (org.jetbrains.annotations.NotNull)11 MessageThread (com.kickstarter.models.MessageThread)10 TestSubscriber (rx.observers.TestSubscriber)10 ProjectDashboardData (com.kickstarter.ui.adapters.data.ProjectDashboardData)7 MockBooleanPreference (com.kickstarter.libs.preferences.MockBooleanPreference)6 Message (com.kickstarter.models.Message)6 DiscoveryParams (com.kickstarter.services.DiscoveryParams)6 IntentKey (com.kickstarter.ui.IntentKey)6