Search in sources :

Example 46 with MockCurrentUser

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

the class DiscoveryViewModelTest method testDrawerMenuIcon_afterLogInRefreshAndLogOut.

@Test
public void testDrawerMenuIcon_afterLogInRefreshAndLogOut() {
    final MockCurrentUser currentUser = new MockCurrentUser();
    this.vm = new DiscoveryViewModel.ViewModel(environment().toBuilder().currentUser(currentUser).build());
    this.vm.getOutputs().drawerMenuIcon().subscribe(this.drawerMenuIcon);
    this.drawerMenuIcon.assertValue(R.drawable.ic_menu);
    currentUser.refresh(UserFactory.user().toBuilder().unreadMessagesCount(4).build());
    this.drawerMenuIcon.assertValues(R.drawable.ic_menu, R.drawable.ic_menu_indicator);
    currentUser.refresh(UserFactory.user().toBuilder().erroredBackingsCount(2).build());
    this.drawerMenuIcon.assertValues(R.drawable.ic_menu, R.drawable.ic_menu_indicator, R.drawable.ic_menu_error_indicator);
    currentUser.refresh(UserFactory.user().toBuilder().unreadMessagesCount(4).unseenActivityCount(3).erroredBackingsCount(2).build());
    this.drawerMenuIcon.assertValues(R.drawable.ic_menu, R.drawable.ic_menu_indicator, R.drawable.ic_menu_error_indicator);
    currentUser.logout();
    this.drawerMenuIcon.assertValues(R.drawable.ic_menu, R.drawable.ic_menu_indicator, R.drawable.ic_menu_error_indicator, R.drawable.ic_menu);
}
Also used : MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 47 with MockCurrentUser

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

the class LoginToutViewModelTest method facebookLogin_error.

@Test
public void facebookLogin_error() {
    final MockCurrentUser currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().currentUser(currentUser).apiClient(new MockApiClient() {

        @Override
        @NonNull
        public Observable<AccessTokenEnvelope> loginWithFacebook(@NonNull final String accessToken) {
            return Observable.error(new Throwable("error"));
        }
    }).build();
    setUpEnvironment(environment, LoginReason.DEFAULT);
    this.currentUser.assertValuesAndClear(null);
    this.vm.inputs.facebookLoginClick(null, Arrays.asList("public_profile", "user_friends", "email"));
    this.vm.facebookAccessToken.onNext("token");
    this.currentUser.assertNoValues();
    this.finishWithSuccessfulResult.assertNoValues();
    this.segmentTrack.assertValues(EventName.PAGE_VIEWED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
Also used : AccessTokenEnvelope(com.kickstarter.services.apiresponses.AccessTokenEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 48 with MockCurrentUser

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

the class LoginToutViewModelTest method facebookLogin_success.

@Test
public void facebookLogin_success() {
    final MockCurrentUser currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().currentUser(currentUser).build();
    setUpEnvironment(environment, LoginReason.DEFAULT);
    this.currentUser.assertValuesAndClear(null);
    this.vm.inputs.facebookLoginClick(null, Arrays.asList("public_profile", "user_friends", "email"));
    this.vm.facebookAccessToken.onNext("token");
    this.currentUser.assertValueCount(1);
    this.finishWithSuccessfulResult.assertValueCount(1);
    this.segmentTrack.assertValues(EventName.PAGE_VIEWED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
Also used : Environment(com.kickstarter.libs.Environment) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 49 with MockCurrentUser

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

the class ThanksViewModelTest method testThanksViewModel_dontShowGamesNewsletterDialogIfUserHasAlreadySignedUp.

@Test
public void testThanksViewModel_dontShowGamesNewsletterDialogIfUserHasAlreadySignedUp() {
    final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(false);
    final User user = UserFactory.user().toBuilder().gamesNewsletter(true).build();
    final CurrentUserType currentUser = new MockCurrentUser(user);
    final Environment environment = environment().toBuilder().currentUser(currentUser).hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference).build();
    setUpEnvironment(environment);
    final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
    this.vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    this.showGamesNewsletterDialogTest.assertValueCount(0);
}
Also used : Project(com.kickstarter.models.Project) User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockBooleanPreference(com.kickstarter.libs.preferences.MockBooleanPreference) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 50 with MockCurrentUser

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

the class ThanksViewModelTest method testThanksViewModel_dontShowRatingDialogIfGamesNewsletterWillDisplay.

@Test
public void testThanksViewModel_dontShowRatingDialogIfGamesNewsletterWillDisplay() {
    final MockBooleanPreference hasSeenAppRatingPreference = new MockBooleanPreference(false);
    final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(false);
    final User user = UserFactory.user().toBuilder().gamesNewsletter(false).build();
    final CurrentUserType currentUser = new MockCurrentUser(user);
    final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
    final Environment environment = environment().toBuilder().currentUser(currentUser).hasSeenAppRatingPreference(hasSeenAppRatingPreference).hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference).build();
    setUpEnvironment(environment);
    this.vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    this.showRatingDialogTest.assertValueCount(0);
}
Also used : Project(com.kickstarter.models.Project) User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockBooleanPreference(com.kickstarter.libs.preferences.MockBooleanPreference) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) 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