Search in sources :

Example 6 with CurrentUserType

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

the class ThanksViewModelTest method testThanksViewModel_dontShowGamesNewsletterDialogIfUserHasAlreadySeen.

@Test
public void testThanksViewModel_dontShowGamesNewsletterDialogIfUserHasAlreadySeen() {
    final MockBooleanPreference hasSeenGamesNewsletterPreference = new MockBooleanPreference(true);
    final User user = UserFactory.user().toBuilder().gamesNewsletter(false).build();
    final CurrentUserType currentUser = new MockCurrentUser(user);
    final Environment environment = environment().toBuilder().currentUser(currentUser).hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference).build();
    final ThanksViewModel vm = new ThanksViewModel(environment);
    final TestSubscriber<Void> showGamesNewsletterDialogTest = new TestSubscriber<>();
    vm.outputs.showGamesNewsletterDialog().subscribe(showGamesNewsletterDialogTest);
    final Project project = ProjectFactory.project().toBuilder().category(CategoryFactory.tabletopGamesCategory()).build();
    vm.intent(new Intent().putExtra(IntentKey.PROJECT, project));
    showGamesNewsletterDialogTest.assertValueCount(0);
}
Also used : Project(com.kickstarter.models.Project) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) User(com.kickstarter.models.User) MockBooleanPreference(com.kickstarter.libs.preferences.MockBooleanPreference) Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) Intent(android.content.Intent) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Example 7 with CurrentUserType

use of com.kickstarter.libs.CurrentUserType 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 8 with CurrentUserType

use of com.kickstarter.libs.CurrentUserType 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 9 with CurrentUserType

use of com.kickstarter.libs.CurrentUserType 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 10 with CurrentUserType

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

the class DiscoveryFragmentViewModelTest method testProjectsRefreshAfterLogin.

@Test
public void testProjectsRefreshAfterLogin() {
    final CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder().currentUser(currentUser).build();
    final DiscoveryFragmentViewModel vm = new DiscoveryFragmentViewModel(environment);
    final TestSubscriber<List<Project>> projects = new TestSubscriber<>();
    vm.outputs.projects().filter(ListUtils::nonEmpty).subscribe(projects);
    // Initial load.
    vm.inputs.rootCategories(CategoryFactory.rootCategories());
    vm.inputs.paramsFromActivity(DiscoveryParams.builder().sort(DiscoveryParams.Sort.HOME).build());
    // Projects should emit.
    projects.assertValueCount(1);
    // Log in.
    currentUser.refresh(UserFactory.user());
    // Projects should emit again.
    projects.assertValueCount(2);
}
Also used : Environment(com.kickstarter.libs.Environment) TestSubscriber(rx.observers.TestSubscriber) List(java.util.List) CurrentUserType(com.kickstarter.libs.CurrentUserType) MockCurrentUser(com.kickstarter.libs.MockCurrentUser) Test(org.junit.Test)

Aggregations

CurrentUserType (com.kickstarter.libs.CurrentUserType)18 Environment (com.kickstarter.libs.Environment)18 MockCurrentUser (com.kickstarter.libs.MockCurrentUser)18 Test (org.junit.Test)18 TestSubscriber (rx.observers.TestSubscriber)17 Intent (android.content.Intent)11 Project (com.kickstarter.models.Project)11 User (com.kickstarter.models.User)11 MockBooleanPreference (com.kickstarter.libs.preferences.MockBooleanPreference)6 KSRobolectricTestCase (com.kickstarter.KSRobolectricTestCase)4 ProjectFactory (com.kickstarter.factories.ProjectFactory)4 UserFactory (com.kickstarter.factories.UserFactory)4 IntentKey (com.kickstarter.ui.IntentKey)4 Newsletter (com.kickstarter.ui.data.Newsletter)4 ConfigFactory (com.kickstarter.factories.ConfigFactory)3 KoalaEvent (com.kickstarter.libs.KoalaEvent)3 MockApiClient (com.kickstarter.services.MockApiClient)3 List (java.util.List)3 Pair (android.util.Pair)2 ApiClientType (com.kickstarter.services.ApiClientType)2