Search in sources :

Example 21 with MockCurrentUser

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

the class CreatorDashboardHeaderHolderViewModelTest method testStartMessagesActivity.

@Test
public void testStartMessagesActivity() {
    final User creator = UserFactory.creator();
    final CurrentUserType currentUser = new MockCurrentUser(creator);
    final Project project = ProjectFactory.project().toBuilder().creator(creator).build();
    setUpEnvironment(environment().toBuilder().currentUser(currentUser).build());
    this.vm.inputs.configureWith(new ProjectDashboardData(project, ProjectStatsEnvelopeFactory.projectStatsEnvelope(), false));
    this.vm.inputs.messagesButtonClicked();
    this.startMessageThreadsActivity.assertValue(Pair.create(project, RefTag.dashboard()));
}
Also used : Project(com.kickstarter.models.Project) 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 22 with MockCurrentUser

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

the class CreatorDashboardHeaderHolderViewModelTest method testOtherProjectsButtonIsGone_whenCurrentUserIsMemberOfManyProjects_viewingSingleProject.

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

Example 23 with MockCurrentUser

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

the class CreatorDashboardHeaderHolderViewModelTest method testStartProjectActivity_whenFeatureFlagOn_shouldEmitProjectPage.

@Test
public void testStartProjectActivity_whenFeatureFlagOn_shouldEmitProjectPage() {
    final Project project = ProjectFactory.project();
    final ProjectStatsEnvelope projectStatsEnvelope = ProjectStatsEnvelopeFactory.projectStatsEnvelope();
    final CurrentUserType currentUser = new MockCurrentUser();
    final MockExperimentsClientType mockExperimentsClientType = new MockExperimentsClientType() {

        @Override
        public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature) {
            return true;
        }
    };
    this.setUpEnvironment(environment().toBuilder().currentUser(currentUser).optimizely(mockExperimentsClientType).build());
    this.vm.inputs.configureWith(new ProjectDashboardData(project, projectStatsEnvelope, false));
    this.vm.inputs.projectButtonClicked();
    this.startProjectActivity.assertValueCount(1);
    assertEquals(this.startProjectActivity.getOnNextEvents().get(0).first, project);
    assertEquals(this.startProjectActivity.getOnNextEvents().get(0).second, RefTag.dashboard());
}
Also used : Project(com.kickstarter.models.Project) ProjectStatsEnvelope(com.kickstarter.services.apiresponses.ProjectStatsEnvelope) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) NotNull(org.jetbrains.annotations.NotNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ProjectDashboardData(com.kickstarter.ui.adapters.data.ProjectDashboardData) Test(org.junit.Test)

Example 24 with MockCurrentUser

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

the class DiscoveryViewModelTest method testDrawerMenuIcon_whenUserHasNoUnreadMessagesOrUnseenActivityOrErroredBackings.

@Test
public void testDrawerMenuIcon_whenUserHasNoUnreadMessagesOrUnseenActivityOrErroredBackings() {
    final MockCurrentUser currentUser = new MockCurrentUser(UserFactory.user());
    this.vm = new DiscoveryViewModel.ViewModel(environment().toBuilder().currentUser(currentUser).build());
    this.vm.getOutputs().drawerMenuIcon().subscribe(this.drawerMenuIcon);
    this.drawerMenuIcon.assertValue(R.drawable.ic_menu);
}
Also used : MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 25 with MockCurrentUser

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

the class DiscoveryViewModelTest method testDrawerData.

@Test
public void testDrawerData() {
    final MockCurrentUser currentUser = new MockCurrentUser();
    final Environment env = environment().toBuilder().currentUser(currentUser).build();
    this.vm = new DiscoveryViewModel.ViewModel(env);
    this.vm.getOutputs().navigationDrawerData().compose(Transformers.ignoreValues()).subscribe(this.navigationDrawerDataEmitted);
    this.vm.getOutputs().drawerIsOpen().subscribe(this.drawerIsOpen);
    // Initialize activity.
    final Intent intent = new Intent(Intent.ACTION_MAIN);
    this.vm.intent(intent);
    // Initial MAGIC page selected.
    this.vm.getInputs().discoveryPagerAdapterSetPrimaryPage(Mockito.mock(DiscoveryPagerAdapter.class), 0);
    // Drawer data should emit. Drawer should be closed.
    this.navigationDrawerDataEmitted.assertValueCount(1);
    this.drawerIsOpen.assertNoValues();
    this.segmentTrack.assertNoValues();
    // Open drawer and click the top PWL filter.
    this.vm.getInputs().openDrawer(true);
    this.vm.getInputs().topFilterViewHolderRowClick(Mockito.mock(TopFilterViewHolder.class), NavigationDrawerData.Section.Row.builder().params(DiscoveryParams.builder().staffPicks(true).build()).build());
    // Drawer data should emit. Drawer should open, then close upon selection.
    this.navigationDrawerDataEmitted.assertValueCount(2);
    this.drawerIsOpen.assertValues(true, false);
    this.segmentTrack.assertValue(EventName.CTA_CLICKED.getEventName());
    // Open drawer and click a child filter.
    this.vm.getInputs().openDrawer(true);
    this.vm.getInputs().childFilterViewHolderRowClick(Mockito.mock(ChildFilterViewHolder.class), NavigationDrawerData.Section.Row.builder().params(DiscoveryParams.builder().category(CategoryFactory.artCategory()).build()).build());
    // Drawer data should emit. Drawer should open, then close upon selection.
    this.navigationDrawerDataEmitted.assertValueCount(3);
    this.drawerIsOpen.assertValues(true, false, true, false);
    this.segmentTrack.assertValues(EventName.CTA_CLICKED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
Also used : TopFilterViewHolder(com.kickstarter.ui.viewholders.discoverydrawer.TopFilterViewHolder) ChildFilterViewHolder(com.kickstarter.ui.viewholders.discoverydrawer.ChildFilterViewHolder) DiscoveryPagerAdapter(com.kickstarter.ui.adapters.DiscoveryPagerAdapter) Environment(com.kickstarter.libs.Environment) Intent(android.content.Intent) 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