use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class UpdateViewModelTest method testUpdateViewModel_UpdateSequence.
@Test
public void testUpdateViewModel_UpdateSequence() {
final Update initialUpdate = UpdateFactory.update().toBuilder().sequence(1).build();
final Update anotherUpdate = UpdateFactory.update().toBuilder().sequence(2).build();
final Request anotherUpdateRequest = new Request.Builder().url("https://kck.str/projects/param/param/posts/id").build();
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<Update> fetchUpdate(@NonNull final String projectParam, @NonNull final String updateParam) {
return Observable.just(anotherUpdate);
}
};
final Environment environment = environment().toBuilder().apiClient(apiClient).build();
final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
final TestSubscriber<String> updateSequence = new TestSubscriber<>();
vm.outputs.updateSequence().subscribe(updateSequence);
// Start the intent with a project and update.
vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.project()).putExtra(IntentKey.UPDATE, initialUpdate));
// Initial update's sequence number emits.
updateSequence.assertValues(NumberUtils.format(initialUpdate.sequence()));
vm.inputs.goToUpdateRequest(anotherUpdateRequest);
// New sequence should emit for new update page.
updateSequence.assertValues(NumberUtils.format(initialUpdate.sequence()), NumberUtils.format(anotherUpdate.sequence()));
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class UpdateViewModelTest method testUpdateViewModel_StartProjectActivity.
@Test
public void testUpdateViewModel_StartProjectActivity() {
final Update update = UpdateFactory.update().toBuilder().projectId(1234).build();
final Project project = ProjectFactory.project().toBuilder().id(update.projectId()).build();
final Request projectRequest = new Request.Builder().url("https://kck.str/projects/param/param").build();
final ApiClientType apiClient = new MockApiClient() {
@Override
@NonNull
public Observable<Project> fetchProject(@NonNull final String param) {
return Observable.just(project);
}
};
final Environment environment = environment().toBuilder().apiClient(apiClient).build();
final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
final TestSubscriber<Project> startProjectActivity = new TestSubscriber<>();
vm.outputs.startProjectActivity().map(pr -> pr.first).subscribe(startProjectActivity);
// Start the intent with a project and update.
vm.intent(new Intent().putExtra(IntentKey.PROJECT, project).putExtra(IntentKey.UPDATE, update));
vm.inputs.goToProjectRequest(projectRequest);
startProjectActivity.assertValues(project);
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class SettingsViewModelTest method testSettingsViewModel_sendWeeklyNewsletter.
@Test
public void testSettingsViewModel_sendWeeklyNewsletter() {
final User user = UserFactory.user().toBuilder().weeklyNewsletter(false).build();
final CurrentUserType currentUser = new MockCurrentUser(user);
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
final SettingsViewModel vm = new SettingsViewModel(environment);
final TestSubscriber<User> currentUserTest = new TestSubscriber<>();
currentUser.observable().subscribe(currentUserTest);
final TestSubscriber<Newsletter> showOptInPromptTest = new TestSubscriber<>();
vm.outputs.showOptInPrompt().subscribe(showOptInPromptTest);
currentUserTest.assertValues(user);
koalaTest.assertValues("Settings View");
vm.inputs.sendWeeklyNewsletter(true);
koalaTest.assertValues("Settings View", "Newsletter Subscribe");
currentUserTest.assertValues(user, user.toBuilder().weeklyNewsletter(true).build());
vm.inputs.sendWeeklyNewsletter(false);
koalaTest.assertValues("Settings View", "Newsletter Subscribe", "Newsletter Unsubscribe");
currentUserTest.assertValues(user, user.toBuilder().weeklyNewsletter(true).build(), user);
showOptInPromptTest.assertNoValues();
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class SettingsViewModelTest method testSettingsViewModel_sendGamesNewsletter.
@Test
public void testSettingsViewModel_sendGamesNewsletter() {
final User user = UserFactory.user().toBuilder().gamesNewsletter(false).build();
final CurrentUserType currentUser = new MockCurrentUser(user);
final Environment environment = environment().toBuilder().currentUser(currentUser).build();
final SettingsViewModel vm = new SettingsViewModel(environment);
final TestSubscriber<User> currentUserTest = new TestSubscriber<>();
currentUser.observable().subscribe(currentUserTest);
final TestSubscriber<Newsletter> showOptInPromptTest = new TestSubscriber<>();
vm.outputs.showOptInPrompt().subscribe(showOptInPromptTest);
currentUserTest.assertValues(user);
koalaTest.assertValues("Settings View");
vm.inputs.sendGamesNewsletter(true);
koalaTest.assertValues("Settings View", "Newsletter Subscribe");
currentUserTest.assertValues(user, user.toBuilder().gamesNewsletter(true).build());
vm.inputs.sendGamesNewsletter(false);
koalaTest.assertValues("Settings View", "Newsletter Subscribe", "Newsletter Unsubscribe");
currentUserTest.assertValues(user, user.toBuilder().gamesNewsletter(true).build(), user);
showOptInPromptTest.assertNoValues();
}
use of com.kickstarter.libs.Environment in project android-oss by kickstarter.
the class SignupViewModelTest method testSignupViewModel_FormValidation.
@Test
public void testSignupViewModel_FormValidation() {
final Environment environment = environment();
environment.currentConfig().config(ConfigFactory.config());
final SignupViewModel vm = new SignupViewModel(environment);
final TestSubscriber<Boolean> formIsValidTest = new TestSubscriber<>();
vm.outputs.formIsValid().subscribe(formIsValidTest);
vm.inputs.fullName("brandon");
formIsValidTest.assertNoValues();
vm.inputs.email("incorrect@kickstarter");
formIsValidTest.assertNoValues();
vm.inputs.password("danisawesome");
formIsValidTest.assertValues(false);
vm.inputs.email("hello@kickstarter.com");
formIsValidTest.assertValues(false, true);
}
Aggregations