Search in sources :

Example 11 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class ProjectUpdatesViewModelTest method testProjectUpdatesViewModel_LoadsWebViewUrl.

@Test
public void testProjectUpdatesViewModel_LoadsWebViewUrl() {
    final ProjectUpdatesViewModel.ViewModel vm = new ProjectUpdatesViewModel.ViewModel(environment());
    final Project project = ProjectFactory.project();
    final String anotherIndexUrl = "https://kck.str/projects/param/param/posts?page=another";
    final Request anotherIndexRequest = new Request.Builder().url(anotherIndexUrl).build();
    final TestSubscriber<String> webViewUrl = new TestSubscriber<>();
    vm.outputs.webViewUrl().subscribe(webViewUrl);
    // Start the intent with a project.
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    // Initial project updates index emits.
    webViewUrl.assertValues(project.updatesUrl());
    koalaTest.assertValues(KoalaEvent.VIEWED_UPDATES);
    // Make a request for another update index.
    vm.inputs.goToUpdatesRequest(anotherIndexRequest);
    // New updates index url emits. Event is not tracked again.
    webViewUrl.assertValues(project.updatesUrl(), anotherIndexUrl);
    koalaTest.assertValues(KoalaEvent.VIEWED_UPDATES);
}
Also used : Project(com.kickstarter.models.Project) Request(okhttp3.Request) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) Test(org.junit.Test)

Example 12 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class ProjectViewModelTest method testProjectViewModel_LoggedOutStarProjectFlow.

@Test
public void testProjectViewModel_LoggedOutStarProjectFlow() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().currentUser(currentUser).build();
    environment.currentConfig().config(ConfigFactory.config());
    final ProjectViewModel.ViewModel vm = new ProjectViewModel.ViewModel(environment);
    final TestSubscriber<Void> loginToutTest = new TestSubscriber<>();
    vm.outputs.startLoginToutActivity().subscribe(loginToutTest);
    final TestSubscriber<Void> showStarredPromptTest = new TestSubscriber<>();
    vm.outputs.showStarredPrompt().subscribe(showStarredPromptTest);
    final TestSubscriber<Boolean> starredTest = new TestSubscriber<>();
    vm.outputs.projectAndUserCountry().map(pc -> pc.first.isStarred()).subscribe(starredTest);
    // Start the view model with a project
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.halfWayProject()));
    starredTest.assertValues(false, false);
    // Try starring while logged out
    vm.inputs.starButtonClicked();
    // The project shouldn't be starred, and a login prompt should be shown.
    starredTest.assertValues(false, false);
    showStarredPromptTest.assertValueCount(0);
    loginToutTest.assertValueCount(1);
    // A koala event for starring should NOT be tracked
    koalaTest.assertValues(KoalaEvent.PROJECT_PAGE, KoalaEvent.VIEWED_PROJECT_PAGE);
    // Login
    currentUser.refresh(UserFactory.user());
    // The project should be starred, and a star prompt should be shown.
    starredTest.assertValues(false, false, true);
    showStarredPromptTest.assertValueCount(1);
    // A koala event for starring should be tracked
    koalaTest.assertValues(KoalaEvent.PROJECT_PAGE, KoalaEvent.VIEWED_PROJECT_PAGE, KoalaEvent.PROJECT_STAR, KoalaEvent.STARRED_PROJECT);
}
Also used : MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ConfigFactory(com.kickstarter.factories.ConfigFactory) Project(com.kickstarter.models.Project) Intent(android.content.Intent) Test(org.junit.Test) CurrentUserType(com.kickstarter.libs.CurrentUserType) UserFactory(com.kickstarter.factories.UserFactory) KoalaEvent(com.kickstarter.libs.KoalaEvent) KSRobolectricTestCase(com.kickstarter.KSRobolectricTestCase) TestSubscriber(rx.observers.TestSubscriber) Environment(com.kickstarter.libs.Environment) ProjectFactory(com.kickstarter.factories.ProjectFactory) IntentKey(com.kickstarter.ui.IntentKey) Intent(android.content.Intent) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) CurrentUserType(com.kickstarter.libs.CurrentUserType) Test(org.junit.Test)

Example 13 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class ProjectViewModelTest method testProjectViewModel_StarProjectThatIsSuccessful.

@Test
public void testProjectViewModel_StarProjectThatIsSuccessful() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().currentUser(currentUser).build();
    environment.currentConfig().config(ConfigFactory.config());
    final ProjectViewModel.ViewModel vm = new ProjectViewModel.ViewModel(environment);
    final TestSubscriber<Void> showStarredPromptTest = new TestSubscriber<>();
    vm.outputs.showStarredPrompt().subscribe(showStarredPromptTest);
    final TestSubscriber<Boolean> starredTest = new TestSubscriber<>();
    vm.outputs.projectAndUserCountry().map(pc -> pc.first.isStarred()).subscribe(starredTest);
    // Start the view model with a successful project
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, ProjectFactory.successfulProject()));
    // Login
    currentUser.refresh(UserFactory.user());
    // Star the project
    vm.inputs.starButtonClicked();
    // The project should be starred, and a star prompt should NOT be shown.
    starredTest.assertValues(false, false, true);
    showStarredPromptTest.assertValueCount(0);
}
Also used : MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ConfigFactory(com.kickstarter.factories.ConfigFactory) Project(com.kickstarter.models.Project) Intent(android.content.Intent) Test(org.junit.Test) CurrentUserType(com.kickstarter.libs.CurrentUserType) UserFactory(com.kickstarter.factories.UserFactory) KoalaEvent(com.kickstarter.libs.KoalaEvent) KSRobolectricTestCase(com.kickstarter.KSRobolectricTestCase) TestSubscriber(rx.observers.TestSubscriber) Environment(com.kickstarter.libs.Environment) ProjectFactory(com.kickstarter.factories.ProjectFactory) IntentKey(com.kickstarter.ui.IntentKey) Intent(android.content.Intent) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) CurrentUserType(com.kickstarter.libs.CurrentUserType) Test(org.junit.Test)

Example 14 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class ProjectViewModelTest method testProjectViewModel_StarProjectThatIsAlmostCompleted.

@Test
public void testProjectViewModel_StarProjectThatIsAlmostCompleted() {
    final Project project = ProjectFactory.almostCompletedProject();
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().currentUser(currentUser).build();
    environment.currentConfig().config(ConfigFactory.config());
    final ProjectViewModel.ViewModel vm = new ProjectViewModel.ViewModel(environment);
    final TestSubscriber<Void> showStarredPromptTest = new TestSubscriber<>();
    vm.outputs.showStarredPrompt().subscribe(showStarredPromptTest);
    final TestSubscriber<Boolean> starredTest = new TestSubscriber<>();
    vm.outputs.projectAndUserCountry().map(pc -> pc.first.isStarred()).subscribe(starredTest);
    // Start the view model with an almost completed project
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    // Login
    currentUser.refresh(UserFactory.user());
    // Star the project
    vm.inputs.starButtonClicked();
    // The project should be starred, and a star prompt should NOT be shown.
    starredTest.assertValues(false, false, true);
    showStarredPromptTest.assertValueCount(0);
}
Also used : MockCurrentUser(com.kickstarter.libs.MockCurrentUser) ConfigFactory(com.kickstarter.factories.ConfigFactory) Project(com.kickstarter.models.Project) Intent(android.content.Intent) Test(org.junit.Test) CurrentUserType(com.kickstarter.libs.CurrentUserType) UserFactory(com.kickstarter.factories.UserFactory) KoalaEvent(com.kickstarter.libs.KoalaEvent) KSRobolectricTestCase(com.kickstarter.KSRobolectricTestCase) TestSubscriber(rx.observers.TestSubscriber) Environment(com.kickstarter.libs.Environment) ProjectFactory(com.kickstarter.factories.ProjectFactory) IntentKey(com.kickstarter.ui.IntentKey) Intent(android.content.Intent) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Project(com.kickstarter.models.Project) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) CurrentUserType(com.kickstarter.libs.CurrentUserType) Test(org.junit.Test)

Example 15 with Project

use of com.kickstarter.models.Project in project android-oss by kickstarter.

the class RewardViewModelTest method testTitleTextViewText.

@Test
public void testTitleTextViewText() {
    final RewardViewModel vm = new RewardViewModel(environment());
    final Project project = ProjectFactory.project();
    final TestSubscriber<Boolean> titleTextViewIsHidden = TestSubscriber.create();
    vm.outputs.titleTextViewIsHidden().subscribe(titleTextViewIsHidden);
    final TestSubscriber<String> titleTextViewTextTest = TestSubscriber.create();
    vm.outputs.titleTextViewText().subscribe(titleTextViewTextTest);
    // Reward with no title should be hidden.
    final Reward rewardWithNoTitle = RewardFactory.reward().toBuilder().title(null).build();
    vm.inputs.projectAndReward(project, rewardWithNoTitle);
    titleTextViewIsHidden.assertValues(true);
    titleTextViewTextTest.assertNoValues();
    // Reward with title should be visible.
    final String title = "Digital bundle";
    final Reward rewardWithTitle = RewardFactory.reward().toBuilder().title(title).build();
    vm.inputs.projectAndReward(project, rewardWithTitle);
    titleTextViewIsHidden.assertValues(true, false);
    titleTextViewTextTest.assertValue(title);
}
Also used : Project(com.kickstarter.models.Project) Reward(com.kickstarter.models.Reward) Test(org.junit.Test)

Aggregations

Project (com.kickstarter.models.Project)85 Test (org.junit.Test)68 Intent (android.content.Intent)36 TestSubscriber (rx.observers.TestSubscriber)33 Environment (com.kickstarter.libs.Environment)19 Reward (com.kickstarter.models.Reward)19 User (com.kickstarter.models.User)14 Pair (android.util.Pair)12 CurrentUserType (com.kickstarter.libs.CurrentUserType)12 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)12 NonNull (android.support.annotation.NonNull)9 MockBooleanPreference (com.kickstarter.libs.preferences.MockBooleanPreference)8 MockApiClient (com.kickstarter.services.MockApiClient)7 Context (android.content.Context)6 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)6 ProjectFactory (com.kickstarter.factories.ProjectFactory)6 UserFactory (com.kickstarter.factories.UserFactory)5 KoalaEvent (com.kickstarter.libs.KoalaEvent)5 Photo (com.kickstarter.models.Photo)5 Update (com.kickstarter.models.Update)5