import React from "react";
import TestUtils from "react-addons-test-utils";
import moment from "moment";
import Calendar from "../src/calendar";
import YearDropdown from "../src/year_dropdown";

describe("Calendar", function() {
  function getCalendar(extraProps) {
    return <Calendar
      weekdays={["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"]}
      locale="en"
      moment={moment}
      dateFormat="MMMM"
      onSelect={() => {}}
      onClickOutside={() => {}}
      hideCalendar={() => {}}
      {...extraProps} />;
  }

  it("should start with the current date in view if no date range", function() {
    var now = moment();
    var calendar = TestUtils.renderIntoDocument(getCalendar());
    assert(calendar.state.date.isSame(now, "day"));
  });

  it("should start with the selected date in view if provided", function() {
    var selected = moment().add(1, "year");
    var calendar = TestUtils.renderIntoDocument(getCalendar({ selected }));
    assert(calendar.state.date.isSame(selected, "day"));
  });

  it("should start with the current date in view if in date range", function() {
    var now = moment();
    var minDate = now.clone().subtract(1, "year");
    var maxDate = now.clone().add(1, "year");
    var calendar = TestUtils.renderIntoDocument(getCalendar({ minDate, maxDate }));
    assert(calendar.state.date.isSame(now, "day"));
  });

  it("should start with the min date in view if after the current date", function() {
    var minDate = moment().add(1, "year");
    var calendar = TestUtils.renderIntoDocument(getCalendar({ minDate }));
    assert(calendar.state.date.isSame(minDate, "day"));
  });

  it("should start with the max date in view if before the current date", function() {
    var maxDate = moment().subtract(1, "year");
    var calendar = TestUtils.renderIntoDocument(getCalendar({ maxDate }));
    assert(calendar.state.date.isSame(maxDate, "day"));
  });

  it("should not show the year dropdown menu by default", function() {
    var calendar = TestUtils.renderIntoDocument(getCalendar());
    var yearReadView = TestUtils.scryRenderedComponentsWithType(calendar, YearDropdown);
    expect(yearReadView).to.be.empty;
  });

  it("should show the year dropdown menu if toggled on", function() {
    var calendar = TestUtils.renderIntoDocument(getCalendar({ showYearDropdown: true }));
    var yearReadView = TestUtils.findRenderedComponentWithType(calendar, YearDropdown);
    expect(yearReadView).to.exist;
  });

  it("should not show the today button by default", function() {
    var calendar = TestUtils.renderIntoDocument(getCalendar());
    var todayButton = TestUtils.scryRenderedDOMComponentsWithClass(calendar, "datepicker__today-button");
    expect(todayButton.length).to.equal(0);
  });

  it("should show the today button if toggled on", function() {
    var calendar = TestUtils.renderIntoDocument(getCalendar({ todayButton: "Vandaag" }));
    var todayButton = TestUtils.findRenderedDOMComponentWithClass(calendar, "datepicker__today-button");
    expect(todayButton).to.exist;
    expect(todayButton.textContent).to.equal("Vandaag");
  });
});

@@ -222,16 +222,49 @@
 ion() %7B%0A
+  var dateFormat = %22MMMM YYYY%22;%0A%0A
   functi
@@ -317,86 +317,8 @@
 dar%0A
-      weekdays=%7B%5B%22Su%22, %22Mo%22, %22Tu%22, %22We%22, %22Th%22, %22Fr%22, %22Sa%22%5D%7D%0A      locale=%22en%22%0A
     
@@ -356,14 +356,20 @@
 mat=
-%22MMMM%22
+%7BdateFormat%7D
 %0A   
@@ -3058,13 +3058,1766 @@
 );%0A  %7D);
+%0A%0A  describe(%22localization%22, function() %7B%0A    function testLocale(calendar, selected, locale) %7B%0A      var localized = selected.clone().locale(locale);%0A%0A      var calendarText = TestUtils.findRenderedDOMComponentWithClass(calendar, %22datepicker__current-month%22);%0A      expect(calendarText.textContent).to.equal(localized.format(dateFormat));%0A%0A      var firstDateOfWeek = localized.clone().startOf(%22week%22);%0A      var firstWeekDayMin = firstDateOfWeek.localeData().weekdaysMin(firstDateOfWeek);%0A      var firstHeader = TestUtils.scryRenderedDOMComponentsWithClass(calendar, %22datepicker__day%22)%5B0%5D;%0A      expect(firstHeader.textContent).to.equal(firstWeekDayMin);%0A    %7D%0A%0A    it(%22should use the globally-defined locale by default%22, function() %7B%0A      var selected = moment();%0A      var calendar = TestUtils.renderIntoDocument(getCalendar(%7B selected %7D));%0A      testLocale(calendar, selected, moment.locale());%0A    %7D);%0A%0A    it(%22should use the locale specified as a prop%22, function() %7B%0A      var locale = %22fr%22;%0A      var selected = moment().locale(locale);%0A      var calendar = TestUtils.renderIntoDocument(getCalendar(%7B selected, locale %7D));%0A      testLocale(calendar, selected, locale);%0A    %7D);%0A%0A    it(%22should override the locale of the date with the globally-defined locale%22, function() %7B%0A      var selected = moment().locale(%22fr%22);%0A      var calendar = TestUtils.renderIntoDocument(getCalendar(%7B selected %7D));%0A      testLocale(calendar, selected, moment.locale());%0A    %7D);%0A%0A    it(%22should override the locale of the date with the locale prop%22, function() %7B%0A      var locale = %22fr%22;%0A      var selected = moment();%0A      var calendar = TestUtils.renderIntoDocument(getCalendar(%7B selected, locale %7D));%0A      testLocale(calendar, selected, locale);%0A    %7D);%0A  %7D);
 %0A%7D);%0A

Add tests for localization