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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations