Search in sources :

Example 81 with MockCurrentUser

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

the class CreatorDashboardHeaderHolderViewModelTest method testOtherProjectsButtonIsGone_whenCurrentUserIsMemberOf1Project.

@Test
public void testOtherProjectsButtonIsGone_whenCurrentUserIsMemberOf1Project() {
    final User collaboratorWith1Project = UserFactory.collaborator().toBuilder().memberProjectsCount(1).build();
    final CurrentUserType collaborator = new MockCurrentUser(collaboratorWith1Project);
    setUpEnvironment(environment().toBuilder().currentUser(collaborator).build());
    this.vm.inputs.configureWith(new ProjectDashboardData(ProjectFactory.project(), ProjectStatsEnvelopeFactory.projectStatsEnvelope(), false));
    this.otherProjectsButtonIsGone.assertValue(true);
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ProjectDashboardData(com.kickstarter.ui.adapters.data.ProjectDashboardData) Test(org.junit.Test)

Example 82 with MockCurrentUser

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

the class CreatorDashboardHeaderHolderViewModelTest method testMessagesButtonIsGone_whenCurrentUserIsCollaborator.

@Test
public void testMessagesButtonIsGone_whenCurrentUserIsCollaborator() {
    final User creator = UserFactory.creator();
    final CurrentUserType currentUser = new MockCurrentUser(UserFactory.collaborator());
    final Project project = ProjectFactory.project().toBuilder().creator(creator).build();
    final ProjectStatsEnvelope projectStatsEnvelope = ProjectStatsEnvelopeFactory.projectStatsEnvelope();
    setUpEnvironment(environment().toBuilder().currentUser(currentUser).build());
    this.vm.inputs.configureWith(new ProjectDashboardData(project, projectStatsEnvelope, false));
    // Messages button is gone if current user is not the project creator (e.g. a collaborator).
    this.messagesButtonIsGone.assertValue(true);
}
Also used : Project(com.kickstarter.models.Project) User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ProjectStatsEnvelope(com.kickstarter.services.apiresponses.ProjectStatsEnvelope) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ProjectDashboardData(com.kickstarter.ui.adapters.data.ProjectDashboardData) Test(org.junit.Test)

Example 83 with MockCurrentUser

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

the class ActivityFeedViewModelTest method testUser_LoggedIn_SwipeRefreshed.

@Test
public void testUser_LoggedIn_SwipeRefreshed() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final User initialUser = UserFactory.user().toBuilder().unseenActivityCount(3).build();
    currentUser.login(initialUser, "deadbeef");
    final User updatedUser = UserFactory.user();
    final Environment environment = this.environment().toBuilder().apiClient(new MockApiClient() {

        @NonNull
        @Override
        public Observable<User> fetchCurrentUser() {
            return Observable.just(updatedUser);
        }
    }).currentUser(currentUser).build();
    environment.currentUser().loggedInUser().subscribe(this.user);
    setUpEnvironment(environment);
    this.surveys.assertValueCount(1);
    this.user.assertValues(initialUser, updatedUser);
    this.vm.inputs.refresh();
    this.surveys.assertValueCount(2);
    this.user.assertValues(initialUser, updatedUser);
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) Observable(rx.Observable) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 84 with MockCurrentUser

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

the class ActivityFeedViewModelTest method testUser_whenLoggedInAndResumedWithErroredBackings.

@Test
public void testUser_whenLoggedInAndResumedWithErroredBackings() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final User initialUser = UserFactory.user().toBuilder().erroredBackingsCount(3).build();
    currentUser.login(initialUser, "token");
    final User updatedUser = UserFactory.user();
    final Environment environment = this.environment().toBuilder().apiClient(new MockApiClient() {

        @Override
        @NonNull
        public Observable<User> fetchCurrentUser() {
            return Observable.just(updatedUser);
        }
    }).currentUser(currentUser).build();
    environment.currentUser().loggedInUser().subscribe(this.user);
    setUpEnvironment(environment);
    this.user.assertValues(initialUser, updatedUser);
    this.vm.inputs.resume();
    this.user.assertValues(initialUser, updatedUser);
}
Also used : User(com.kickstarter.models.User) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) Observable(rx.Observable) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 85 with MockCurrentUser

use of com.kickstarter.libs.MockCurrentUser 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 = this.environment().toBuilder().apiClient(apiClient).currentUser(currentUser).build();
    setUpEnvironment(environment);
    // Empty activity feed with login button should be shown.
    this.loggedOutEmptyStateIsVisible.assertValue(true);
    // Login.
    this.vm.inputs.emptyActivityFeedLoginClicked(null);
    this.goToLogin.assertValueCount(1);
    currentUser.refresh(UserFactory.user());
    // Empty states are not shown when activities emit on successful login.
    this.activityList.assertValueCount(1);
    this.loggedOutEmptyStateIsVisible.assertValues(true, false);
    this.loggedInEmptyStateIsVisible.assertValue(false);
}
Also used : MockApiClient(com.kickstarter.mock.services.MockApiClient) Environment(com.kickstarter.libs.Environment) CurrentUserType(com.kickstarter.libs.CurrentUserType) ApiClientType(com.kickstarter.services.ApiClientType) 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