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 CurrentUserType currentUser = new MockCurrentUser();
    final Environment environment = environment().toBuilder()
      .currentUser(currentUser)
      .build();

    // Settings requires a user
    final User user = UserFactory.user().toBuilder().happeningNewsletter(false).build();
    currentUser.refresh(user);

    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, "Happening Now");

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

@@ -893,16 +893,17 @@
 nment);%0A
+%0A
     fina
@@ -963,25 +963,24 @@
 criber%3C%3E();%0A
-%0A
     currentU
@@ -1169,25 +1169,24 @@
 ning Now%22);%0A
-%0A
     koalaTes
@@ -1333,15 +1333,272 @@
 uild());
+%0A%0A    vm.inputs.sendHappeningNewsletter(false, %22Happening Now%22);%0A    koalaTest.assertValues(%22Settings View%22, %22Newsletter Subscribe%22, %22Newsletter Unsubscribe%22);%0A    currentUserTest.assertValues(user, user.toBuilder().happeningNewsletter(true).build(), user);
 %0A  %7D%0A%7D%0A

Test subscribing and unsubscribing