Search in sources :

Example 6 with MockExperimentsClientType

use of com.kickstarter.mock.MockExperimentsClientType 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 7 with MockExperimentsClientType

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

the class ThanksViewModelTest method testThanksViewModel_whenFeatureFlagOn_shouldEmitProjectPage.

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

        @Override
        public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature) {
            return true;
        }
    };
    final Environment environment = environment().toBuilder().currentUser(user).optimizely(mockExperimentsClientType).build();
    setUpEnvironment(environment);
    final Project project = ProjectFactory.project();
    final CheckoutData checkoutData = CheckoutDataFactory.Companion.checkoutData(3L, 20.0, 30.0);
    final PledgeData pledgeData = PledgeData.Companion.with(PledgeFlowContext.NEW_PLEDGE, ProjectDataFactory.Companion.project(project), RewardFactory.reward(), Collections.emptyList(), null);
    final Intent intent = new Intent().putExtra(IntentKey.CHECKOUT_DATA, checkoutData).putExtra(IntentKey.PLEDGE_DATA, pledgeData).putExtra(IntentKey.PROJECT, project);
    this.vm.intent(intent);
    this.vm.inputs.projectCardViewHolderClicked(project);
    final Pair<Project, RefTag> projectPageParams = this.startProjectTest.getOnNextEvents().get(0);
    assertEquals(projectPageParams.first, project);
    assertEquals(projectPageParams.second, RefTag.thanks());
    this.segmentTrack.assertValues(EventName.PAGE_VIEWED.getEventName(), EventName.CTA_CLICKED.getEventName());
}
Also used : Project(com.kickstarter.models.Project) CheckoutData(com.kickstarter.ui.data.CheckoutData) Environment(com.kickstarter.libs.Environment) PledgeData(com.kickstarter.ui.data.PledgeData) Intent(android.content.Intent) RefTag(com.kickstarter.libs.RefTag) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) NotNull(org.jetbrains.annotations.NotNull) IntentKey(com.kickstarter.ui.IntentKey) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 8 with MockExperimentsClientType

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

the class UpdateViewModelTest method testUpdateViewModel_whenFeatureFlagOn_shouldEmitProjectPage.

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

        @Override
        public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature) {
            return true;
        }
    };
    final Environment environment = environment().toBuilder().currentUser(user).optimizely(mockExperimentsClientType).build();
    final UpdateViewModel.ViewModel vm = new UpdateViewModel.ViewModel(environment);
    final TestSubscriber<Pair<Uri, RefTag>> startProjectActivity = new TestSubscriber<>();
    vm.outputs.startProjectActivity().subscribe(startProjectActivity);
    // Start the intent with a project and update.
    vm.intent(this.defaultIntent);
    final String url = "https://www.kickstarter.com/projects/smithsonian/smithsonian-anthology-of-hip-hop-and-rap";
    final Request projectRequest = new Request.Builder().url(url).build();
    vm.inputs.goToProjectRequest(projectRequest);
    startProjectActivity.assertValueCount(1);
    assertEquals(startProjectActivity.getOnNextEvents().get(0).first, Uri.parse(url));
    assertEquals(startProjectActivity.getOnNextEvents().get(0).second, RefTag.update());
}
Also used : Request(okhttp3.Request) NotNull(org.jetbrains.annotations.NotNull) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) IntentKey(com.kickstarter.ui.IntentKey) Pair(android.util.Pair) Test(org.junit.Test)

Example 9 with MockExperimentsClientType

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

the class DiscoveryFragmentViewModelTest method testShouldShowEditorial_featureEnabled.

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

        @Override
        public boolean isFeatureEnabled(@NotNull final OptimizelyFeature.Key feature, @NotNull final ExperimentData experimentData) {
            return true;
        }
    };
    final Environment environment = environment().toBuilder().currentUser(user).optimizely(mockExperimentsClientType).build();
    setUpEnvironment(environment);
    setUpInitialHomeAllProjectsParams();
    this.shouldShowEditorial.assertValue(Editorial.LIGHTS_ON);
}
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 10 with MockExperimentsClientType

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

the class DiscoveryFragmentViewModelTest method testShouldShowEditorial_whenOptimizelyInitializationDelay.

@Test
public void testShouldShowEditorial_whenOptimizelyInitializationDelay() {
    final Environment environment = environment().toBuilder().currentUser(new MockCurrentUser()).optimizely(new MockExperimentsClientType() {

        int enabledCount;

        @Override
        public boolean isFeatureEnabled(@NonNull final OptimizelyFeature.Key feature, @NonNull final ExperimentData experimentData) {
            if (enabledCount == 0) {
                enabledCount += 1;
                return false;
            } else {
                return true;
            }
        }
    }).build();
    setUpEnvironment(environment);
    setUpInitialHomeAllProjectsParams();
    this.shouldShowEditorial.assertValue(null);
    this.vm.optimizelyReady();
    this.shouldShowEditorial.assertValues(null, Editorial.LIGHTS_ON);
}
Also used : NonNull(androidx.annotation.NonNull) Environment(com.kickstarter.libs.Environment) MockExperimentsClientType(com.kickstarter.mock.MockExperimentsClientType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ExperimentData(com.kickstarter.libs.utils.ExperimentData) 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