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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations