Search in sources :

Example 1 with MockExperimentsClientType

use of com.kickstarter.mock.MockExperimentsClientType in project android-oss by kickstarter.

the class SearchViewModelTest method testProjectPage_whenFeatureFlagOn_shouldEmitProjectPage.

@Test
public void testProjectPage_whenFeatureFlagOn_shouldEmitProjectPage() {
    final MockCurrentUser user = new MockCurrentUser();
    final MockExperimentsClientType mockExperimentsClientType = new MockExperimentsClientType() {

        @Override
        public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature) {
            return true;
        }
    };
    final TestScheduler scheduler = new TestScheduler();
    final List<Project> projects = Arrays.asList(ProjectFactory.allTheWayProject(), ProjectFactory.almostCompletedProject(), ProjectFactory.backedProject());
    final MockApiClient apiClient = new MockApiClient() {

        @Override
        @NonNull
        public Observable<DiscoverEnvelope> fetchProjects(@NonNull final DiscoveryParams params) {
            return Observable.just(DiscoverEnvelopeFactory.discoverEnvelope(projects));
        }
    };
    final Environment env = environment().toBuilder().currentUser(user).optimizely(mockExperimentsClientType).scheduler(scheduler).apiClient(apiClient).build();
    setUpEnvironment(env);
    // populate search and overcome debounce
    this.vm.inputs.search("");
    scheduler.advanceTimeBy(300, TimeUnit.MILLISECONDS);
    this.vm.inputs.projectClicked(projects.get(2));
    this.goToProject.assertValues(projects.get(2));
}
Also used : Project(com.kickstarter.models.Project) DiscoverEnvelope(com.kickstarter.services.apiresponses.DiscoverEnvelope) MockApiClient(com.kickstarter.mock.services.MockApiClient) NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) TestScheduler(rx.schedulers.TestScheduler) DiscoveryParams(com.kickstarter.services.DiscoveryParams) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) NotNull(org.jetbrains.annotations.NotNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 2 with MockExperimentsClientType

use of com.kickstarter.mock.MockExperimentsClientType in project android-oss by kickstarter.

the class DiscoveryFragmentViewModelTest method testStartProjectActivity_whenViewingFeatureFlagOn_shouldEmitProjectPageActivity.

@Test
public void testStartProjectActivity_whenViewingFeatureFlagOn_shouldEmitProjectPageActivity() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final MockExperimentsClientType mockExperimentsClientType = new MockExperimentsClientType() {

        @Override
        public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature) {
            return true;
        }
    };
    this.setUpEnvironment(this.environment().toBuilder().currentUser(currentUser).optimizely(mockExperimentsClientType).build());
    // Load editorial params and root categories from activity.
    final DiscoveryParams editorialParams = DiscoveryParams.builder().tagId(Editorial.GO_REWARDLESS.getTagId()).sort(DiscoveryParams.Sort.MAGIC).build();
    this.vm.inputs.paramsFromActivity(editorialParams);
    this.vm.inputs.rootCategories(CategoryFactory.rootCategories());
    // Click on project
    final Project project = ProjectFactory.project();
    this.vm.inputs.projectCardViewHolderClicked(project);
    this.startProjectActivity.assertValueCount(1);
    assertEquals(this.startProjectActivity.getOnNextEvents().get(0).first, project);
    assertEquals(this.startProjectActivity.getOnNextEvents().get(0).second, RefTag.collection(518));
    this.segmentTrack.assertValues(EventName.PAGE_VIEWED.getEventName(), EventName.CARD_CLICKED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
Also used : Project(com.kickstarter.models.Project) CurrentUserType(com.kickstarter.libs.CurrentUserType) DiscoveryParams(com.kickstarter.services.DiscoveryParams) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) NotNull(org.jetbrains.annotations.NotNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 3 with MockExperimentsClientType

use of com.kickstarter.mock.MockExperimentsClientType in project android-oss by kickstarter.

the class DiscoveryFragmentViewModelTest method testShouldShowEditorial_featureDisabled.

@Test
public void testShouldShowEditorial_featureDisabled() {
    final MockCurrentUser user = new MockCurrentUser();
    final MockExperimentsClientType mockExperimentsClientType = new MockExperimentsClientType() {

        @Override
        public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature, @NotNull final ExperimentData experimentData) {
            return false;
        }
    };
    final Environment environment = environment().toBuilder().currentUser(user).optimizely(mockExperimentsClientType).build();
    setUpEnvironment(environment);
    setUpInitialHomeAllProjectsParams();
    this.shouldShowEditorial.assertValue(null);
}
Also used : Environment(com.kickstarter.libs.Environment) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) NotNull(org.jetbrains.annotations.NotNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ExperimentData(com.kickstarter.libs.utils.ExperimentData) Test(org.junit.Test)

Example 4 with MockExperimentsClientType

use of com.kickstarter.mock.MockExperimentsClientType in project android-oss by kickstarter.

the class ActivityFeedViewModelTest method testClickingInterfaceElements_shouldEmitProjectPage.

@Test
public void testClickingInterfaceElements_shouldEmitProjectPage() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final MockExperimentsClientType mockExperimentsClientType = new MockExperimentsClientType() {

        @Override
        public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature) {
            return true;
        }
    };
    this.setUpEnvironment(this.environment().toBuilder().currentUser(currentUser).optimizely(mockExperimentsClientType).build());
    this.goToDiscovery.assertNoValues();
    this.goToLogin.assertNoValues();
    this.goToProject.assertNoValues();
    this.startUpdateActivity.assertNoValues();
    // Empty activity feed clicks do not trigger events yet.
    this.vm.inputs.emptyActivityFeedDiscoverProjectsClicked(null);
    this.goToDiscovery.assertValueCount(1);
    this.vm.inputs.emptyActivityFeedLoginClicked(null);
    this.goToLogin.assertValueCount(1);
    this.vm.inputs.friendBackingClicked(null, ActivityFactory.friendBackingActivity());
    this.vm.inputs.projectStateChangedClicked(null, ActivityFactory.projectStateChangedActivity());
    this.vm.inputs.projectStateChangedPositiveClicked(null, ActivityFactory.projectStateChangedPositiveActivity());
    this.vm.inputs.projectUpdateProjectClicked(null, ActivityFactory.updateActivity());
    this.goToProject.assertValueCount(4);
    // this.goToProject.assertValues(); TODO
    this.vm.inputs.projectUpdateClicked(null, ActivityFactory.activity());
    this.startUpdateActivity.assertValueCount(1);
    this.segmentTrack.assertValues(EventName.PAGE_VIEWED.getEventName(), EventName.CTA_CLICKED.getEventName(), EventName.CARD_CLICKED.getEventName(), EventName.CARD_CLICKED.getEventName(), EventName.CARD_CLICKED.getEventName(), EventName.CARD_CLICKED.getEventName());
}
Also used : CurrentUserType(com.kickstarter.libs.CurrentUserType) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) NotNull(org.jetbrains.annotations.NotNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 5 with MockExperimentsClientType

use of com.kickstarter.mock.MockExperimentsClientType in project android-oss by kickstarter.

the class ActivityFeedViewModelTest method testStartFixPledge_shouldEmitToFixPledgeProjectPage.

@Test
public void testStartFixPledge_shouldEmitToFixPledgeProjectPage() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final MockExperimentsClientType mockExperimentsClientType = new MockExperimentsClientType() {

        @Override
        public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature) {
            return true;
        }
    };
    this.setUpEnvironment(this.environment().toBuilder().currentUser(currentUser).optimizely(mockExperimentsClientType).build());
    final String projectSlug = "slug";
    this.vm.inputs.managePledgeClicked(projectSlug);
    this.startFixPledge.assertValueCount(1);
    assertTrue(this.startFixPledge.getOnNextEvents().get(0) == projectSlug);
}
Also used : CurrentUserType(com.kickstarter.libs.CurrentUserType) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) NotNull(org.jetbrains.annotations.NotNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

MockCurrentUser (com.kickstarter.libs.MockCurrentUser)11 MockExperimentsClientType (com.kickstarter.mock.MockExperimentsClientType)11 Test (org.junit.Test)11 NotNull (org.jetbrains.annotations.NotNull)10 Environment (com.kickstarter.libs.Environment)6 CurrentUserType (com.kickstarter.libs.CurrentUserType)5 Project (com.kickstarter.models.Project)5 ExperimentData (com.kickstarter.libs.utils.ExperimentData)3 NonNull (androidx.annotation.NonNull)2 DiscoveryParams (com.kickstarter.services.DiscoveryParams)2 IntentKey (com.kickstarter.ui.IntentKey)2 Intent (android.content.Intent)1 Pair (android.util.Pair)1 RefTag (com.kickstarter.libs.RefTag)1 MockApiClient (com.kickstarter.mock.services.MockApiClient)1 DiscoverEnvelope (com.kickstarter.services.apiresponses.DiscoverEnvelope)1 ProjectStatsEnvelope (com.kickstarter.services.apiresponses.ProjectStatsEnvelope)1 ProjectDashboardData (com.kickstarter.ui.adapters.data.ProjectDashboardData)1 CheckoutData (com.kickstarter.ui.data.CheckoutData)1 PledgeData (com.kickstarter.ui.data.PledgeData)1