File size: 2,269 Bytes
cbc76af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import React from "react";
import TestUtils from "react-addons-test-utils";
import moment from "moment";
import DateUtil from "../src/util/date";
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={() => {}}
      handleClick={() => {}}
      hideCalendar={() => {}}
      {...extraProps} />;
  }

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

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

  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.sameDay(new DateUtil(minDate)));
  });

  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.sameDay(new DateUtil(maxDate)));
  });

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