package com.kickstarter.viewmodels;

import com.kickstarter.KSRobolectricTestCase;
import com.kickstarter.factories.UserFactory;
import com.kickstarter.libs.CurrentUserType;
import com.kickstarter.libs.Environment;
import com.kickstarter.libs.MockCurrentUser;
import com.kickstarter.models.User;

import org.junit.Test;

import rx.observers.TestSubscriber;

public final class SettingsViewModelTest extends KSRobolectricTestCase {

  @Test
  public void testSettingsViewModel_sendHappeningNewsletter() {
    final User user = UserFactory.user().toBuilder().happeningNewsletter(false).build();
    final CurrentUserType currentUser = new MockCurrentUser(user);
    final Environment environment = environment().toBuilder()
      .currentUser(currentUser)
      .build();

    final SettingsViewModel vm = new SettingsViewModel(environment);

    final TestSubscriber<User> currentUserTest = new TestSubscriber<>();
    currentUser.observable().subscribe(currentUserTest);

    currentUserTest.assertValues(user);
    koalaTest.assertValues("Settings View");

    vm.inputs.sendHappeningNewsletter(true);
    koalaTest.assertValues("Settings View", "Newsletter Subscribe");
    currentUserTest.assertValues(user, user.toBuilder().happeningNewsletter(true).build());

    vm.inputs.sendHappeningNewsletter(false);
    koalaTest.assertValues("Settings View", "Newsletter Subscribe", "Newsletter Unsubscribe");
    currentUserTest.assertValues(user, user.toBuilder().happeningNewsletter(true).build(), user);
  }

  @Test
  public void testSettingsViewModel_sendProjectsWeLoveNewsletter() {
    final User user = UserFactory.user().toBuilder().weeklyNewsletter(false).build();
    final CurrentUserType currentUser = new MockCurrentUser(user);
    final Environment environment = environment().toBuilder()
      .currentUser(currentUser)
      .build();

    final SettingsViewModel vm = new SettingsViewModel(environment);

    final TestSubscriber<User> currentUserTest = new TestSubscriber<>();
    currentUser.observable().subscribe(currentUserTest);

    currentUserTest.assertValues(user);
    koalaTest.assertValues("Settings View");

    vm.inputs.sendHappeningNewsletter(true);
    koalaTest.assertValues("Settings View", "Newsletter Subscribe");
    currentUserTest.assertValues(user, user.toBuilder().happeningNewsletter(true).build());

    vm.inputs.sendHappeningNewsletter(false);
    koalaTest.assertValues("Settings View", "Newsletter Subscribe", "Newsletter Unsubscribe");
    currentUserTest.assertValues(user, user.toBuilder().happeningNewsletter(true).build(), user);
  }
}

@@ -1557,19 +1557,1064 @@
 dPro
-jectsWeLove
+moNewsletter() %7B%0A    final User user = UserFactory.user().toBuilder().promoNewsletter(false).build();%0A    final CurrentUserType currentUser = new MockCurrentUser(user);%0A    final Environment environment = environment().toBuilder()%0A      .currentUser(currentUser)%0A      .build();%0A%0A    final SettingsViewModel vm = new SettingsViewModel(environment);%0A%0A    final TestSubscriber%3CUser%3E currentUserTest = new TestSubscriber%3C%3E();%0A    currentUser.observable().subscribe(currentUserTest);%0A%0A    currentUserTest.assertValues(user);%0A    koalaTest.assertValues(%22Settings View%22);%0A%0A    vm.inputs.sendPromoNewsletter(true);%0A    koalaTest.assertValues(%22Settings View%22, %22Newsletter Subscribe%22);%0A    currentUserTest.assertValues(user, user.toBuilder().promoNewsletter(true).build());%0A%0A    vm.inputs.sendPromoNewsletter(false);%0A    koalaTest.assertValues(%22Settings View%22, %22Newsletter Subscribe%22, %22Newsletter Unsubscribe%22);%0A    currentUserTest.assertValues(user, user.toBuilder().promoNewsletter(true).build(), user);%0A  %7D%0A%0A  @Test%0A  public void testSettingsViewModel_sendWeekly
 News
@@ -3189,33 +3189,30 @@
 .inputs.send
-Happening
+Weekly
 Newsletter(t
@@ -3338,33 +3338,30 @@
 toBuilder().
-happening
+weekly
 Newsletter(t
@@ -3390,33 +3390,30 @@
 .inputs.send
-Happening
+Weekly
 Newsletter(f
@@ -3566,33 +3566,30 @@
 toBuilder().
-happening
+weekly
 Newsletter(t

Add tests for all newsletters