Search in sources :

Example 11 with CurrentUserType

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

the class ActivityFeedViewModelTest method testLoginFlow.

@Test
public void testLoginFlow() {
    final ApiClientType apiClient = new MockApiClient();
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().apiClient(apiClient).currentUser(currentUser).build();
    final ActivityFeedViewModel.ViewModel vm = new ActivityFeedViewModel.ViewModel(environment);
    final TestSubscriber<List<Activity>> activities = new TestSubscriber<>();
    vm.outputs.activities().subscribe(activities);
    final TestSubscriber<Boolean> loggedOutEmptyStateIsVisible = new TestSubscriber<>();
    vm.outputs.loggedOutEmptyStateIsVisible().subscribe(loggedOutEmptyStateIsVisible);
    final TestSubscriber<Boolean> loggedInEmptyStateIsVisible = new TestSubscriber<>();
    vm.outputs.loggedInEmptyStateIsVisible().subscribe(loggedInEmptyStateIsVisible);
    final TestSubscriber<Void> goToLogin = new TestSubscriber<>();
    vm.outputs.goToLogin().subscribe(goToLogin);
    // Empty activity feed with login button should be shown.
    loggedOutEmptyStateIsVisible.assertValue(true);
    // Login.
    vm.inputs.emptyActivityFeedLoginClicked(null);
    goToLogin.assertValueCount(1);
    currentUser.refresh(UserFactory.user());
    // Empty states are not shown when activities emit on successful login.
    activities.assertValueCount(1);
    loggedOutEmptyStateIsVisible.assertValues(true, false);
    loggedInEmptyStateIsVisible.assertValue(false);
}
Also used : MockApiClient(com.kickstarter.services.MockApiClient) ApiClientType(com.kickstarter.services.ApiClientType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) List(java.util.List) CurrentUserType(com.kickstarter.libs.CurrentUserType) Test(org.junit.Test)

Example 12 with CurrentUserType

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

the class CommentsViewModelTest method testCommentsViewModel_loggedOutShowDialogFlow.

@Test
public void testCommentsViewModel_loggedOutShowDialogFlow() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().currentUser(currentUser).build();
    final CommentsViewModel vm = new CommentsViewModel(environment);
    final Project project = ProjectFactory.backedProject();
    final TestSubscriber<Pair<Project, Boolean>> showCommentDialogTest = new TestSubscriber<>();
    vm.outputs.showCommentDialog().subscribe(showCommentDialogTest);
    // Start the view model with a project.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    // The comment dialog should be hidden from logged out user.
    showCommentDialogTest.assertNoValues();
    // Login.
    currentUser.refresh(UserFactory.user());
    vm.inputs.loginSuccess();
    // The comment dialog should be shown to backer.
    showCommentDialogTest.assertValue(Pair.create(project, true));
}
Also used : Project(com.kickstarter.models.Project) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Pair(android.util.Pair) Test(org.junit.Test)

Example 13 with CurrentUserType

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

the class DiscoveryFragmentViewModelTest method testShowHeaderViews.

@Test
public void testShowHeaderViews() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Activity activity = ActivityFactory.activity();
    final ApiClientType apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<ActivityEnvelope> fetchActivities() {
            return Observable.just(ActivityEnvelopeFactory.activityEnvelope(Collections.singletonList(activity)));
        }
    };
    final MockIntPreference activitySamplePreference = new MockIntPreference(987654321);
    final Environment environment = environment().toBuilder().activitySamplePreference(activitySamplePreference).apiClient(apiClient).currentUser(currentUser).build();
    final DiscoveryFragmentViewModel vm = new DiscoveryFragmentViewModel(environment);
    final TestSubscriber<Activity> activityTest = new TestSubscriber<>();
    vm.outputs.activity().subscribe(activityTest);
    final TestSubscriber<Boolean> shouldShowOnboardingViewTest = new TestSubscriber<>();
    vm.outputs.shouldShowOnboardingView().subscribe(shouldShowOnboardingViewTest);
    // Initial home all projects params.
    vm.inputs.paramsFromActivity(DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).build());
    vm.inputs.rootCategories(CategoryFactory.rootCategories());
    // Should show onboarding view.
    shouldShowOnboardingViewTest.assertValues(true);
    activityTest.assertValue(null);
    // Change params. Onboarding view should not be shown.
    vm.inputs.paramsFromActivity(DiscoveryParams.builder().build());
    shouldShowOnboardingViewTest.assertValues(true, false);
    activityTest.assertValues(null, null);
    // Login.
    currentUser.refresh(UserFactory.user());
    // Activity sampler should be shown rather than onboarding view.
    shouldShowOnboardingViewTest.assertValues(true, false, false);
    activityTest.assertValues(null, null, activity);
    // Change params. Activity sampler should not be shown.
    vm.inputs.paramsFromActivity(DiscoveryParams.builder().build());
    activityTest.assertValues(null, null, activity, null);
}
Also used : MockIntPreference(com.kickstarter.libs.preferences.MockIntPreference) MockApiClient(com.kickstarter.services.MockApiClient) Activity(com.kickstarter.models.Activity) ApiClientType(com.kickstarter.services.ApiClientType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ActivityEnvelope(com.kickstarter.services.apiresponses.ActivityEnvelope) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) CurrentUserType(com.kickstarter.libs.CurrentUserType) Test(org.junit.Test)

Example 14 with CurrentUserType

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

the class SettingsViewModelTest method testSettingsViewModel_sendPromoNewsletter.

@Test
public void testSettingsViewModel_sendPromoNewsletter() {
    final User user = UserFactory.user().toBuilder().promoNewsletter(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.sendPromoNewsletter(true);
    koalaTest.assertValues("Settings View", "Newsletter Subscribe");
    currentUserTest.assertValues(user, user.toBuilder().promoNewsletter(true).build());
    vm.inputs.sendPromoNewsletter(false);
    koalaTest.assertValues("Settings View", "Newsletter Subscribe", "Newsletter Unsubscribe");
    currentUserTest.assertValues(user, user.toBuilder().promoNewsletter(true).build(), user);
    showOptInPromptTest.assertNoValues();
}
Also used : Newsletter(com.kickstarter.ui.data.Newsletter) User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 15 with CurrentUserType

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

the class SettingsViewModelTest method testSettingsViewModel_sendHappeningNewsletter.

@Test
public void testSettingsViewModel_sendHappeningNewsletter() {
    final User user = UserFactory.user().toBuilder().happeningNewsletter(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.sendHappeningNewsletter(true);
    koalaTest.assertValues("Settings View", "Newsletter Subscribe");
    currentUserTest.assertValues(user, user.toBuilder().happeningNewsletter(true).build());
    vm.inputs.sendHappeningNewsletter(false);
    koalaTest.assertValues("Settings View", "Newsletter Subscribe", "Newsletter Unsubscribe");
    currentUserTest.assertValues(user, user.toBuilder().happeningNewsletter(true).build(), user);
    showOptInPromptTest.assertNoValues();
}
Also used : Newsletter(com.kickstarter.ui.data.Newsletter) User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

CurrentUserType (com.kickstarter.libs.CurrentUserType)18 Environment (com.kickstarter.libs.Environment)18 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)18 Test (org.junit.Test)18 TestSubscriber (rx.observers.TestSubscriber)17 Intent (android.content.Intent)11 Project (com.kickstarter.models.Project)11 User (com.kickstarter.models.User)11 MockBooleanPreference (com.kickstarter.libs.preferences.MockBooleanPreference)6 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)4 ProjectFactory (com.kickstarter.factories.ProjectFactory)4 UserFactory (com.kickstarter.factories.UserFactory)4 IntentKey (com.kickstarter.ui.IntentKey)4 Newsletter (com.kickstarter.ui.data.Newsletter)4 ConfigFactory (com.kickstarter.factories.ConfigFactory)3 KoalaEvent (com.kickstarter.libs.KoalaEvent)3 MockApiClient (com.kickstarter.services.MockApiClient)3 List (java.util.List)3 Pair (android.util.Pair)2 ApiClientType (com.kickstarter.services.ApiClientType)2