"use strict";

var _react = _interopRequireDefault(require("react"));

var _enzyme = require("enzyme");

var _sinon = _interopRequireDefault(require("sinon"));

var _DatePicker = require("../DatePicker");

var _DatePicker2 = _interopRequireDefault(require("../DatePicker.less"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

describe('DatePicker', function () {
  // Suite-wide setup
  it('should not generate a label when value is undefined', function () {
    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePicker, {
      title: "Date"
    }));
    var expected = null;
    var actual = subject.find('ExpandableItem').prop('label');
    expect(actual).to.equal(expected);
  });
  it('should emit an onChange event when changing a component picker', function () {
    var handleChange = _sinon.default.spy();

    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePicker, {
      onChange: handleChange,
      open: true,
      title: "Date",
      value: new Date(2000, 6, 15)
    }));
    var base = subject.find('DateComponentRangePicker').first();
    base.prop('onChange')({
      value: 0
    });
    var expected = true;
    var actual = handleChange.calledOnce;
    expect(actual).to.equal(expected);
  });
  it('should omit labels when noLabels is true', function () {
    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePickerBase, {
      day: 1,
      maxDays: 31,
      maxMonths: 12,
      month: 1,
      noLabels: true,
      open: true,
      order: ['m', 'd'],
      title: "Date",
      year: 2000
    }));
    var expected = 2;
    var actual = subject.find('DateComponentRangePicker').filterWhere(function (c) {
      return !c.prop('label');
    }).length;
    expect(actual).to.equal(expected);
  });
  it('should create pickers arranged by order', function () {
    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePickerBase, {
      title: "Date",
      day: 1,
      maxDays: 31,
      month: 1,
      maxMonths: 12,
      year: 2000,
      order: ['m', 'd'],
      open: true
    }));
    var expected = ['month', 'day'];
    var actual = subject.find('DateComponentRangePicker').map(function (c) {
      return c.prop('label');
    });
    expect(actual).to.deep.equal(expected);
  });
  it('should accept a JavaScript Date for its value prop', function () {
    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePicker, {
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1)
    }));
    var yearPicker = subject.find("DateComponentRangePicker.".concat(_DatePicker2.default.year));
    var expected = 2000;
    var actual = yearPicker.prop('value');
    expect(actual).to.equal(expected);
  });
  it('should accept an updated JavaScript Date for its value prop', function () {
    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePicker, {
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1)
    }));
    subject.setProps({
      value: new Date(1900, 0, 1)
    });
    var yearPicker = subject.find("DateComponentRangePicker.".concat(_DatePicker2.default.year));
    var expected = 1900;
    var actual = yearPicker.prop('value');
    expect(actual).to.equal(expected);
  });
  it('should set "dayAriaLabel" to day picker', function () {
    var label = 'custom day aria-label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePicker, {
      dayAriaLabel: label,
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1)
    }));
    var dayPicker = subject.find("DateComponentRangePicker.".concat(_DatePicker2.default.day));
    var expected = label;
    var actual = dayPicker.prop('aria-label');
    expect(actual).to.equal(expected);
  });
  it('should set "monthAriaLabel" to month picker', function () {
    var label = 'custom month aria-label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePicker, {
      monthAriaLabel: label,
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1)
    }));
    var monthPicker = subject.find("DateComponentRangePicker.".concat(_DatePicker2.default.month));
    var expected = label;
    var actual = monthPicker.prop('aria-label');
    expect(actual).to.equal(expected);
  });
  it('should set "yearAriaLabel" to year picker', function () {
    var label = 'custom year aria-label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePicker, {
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1),
      yearAriaLabel: label
    }));
    var yearPicker = subject.find("DateComponentRangePicker.".concat(_DatePicker2.default.year));
    var expected = label;
    var actual = yearPicker.prop('aria-label');
    expect(actual).to.equal(expected);
  });
  it('should set "dayLabel" to day label', function () {
    var label = 'custom day label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePicker, {
      dayLabel: label,
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1)
    }));
    var dayPicker = subject.find("DateComponentRangePicker.".concat(_DatePicker2.default.day));
    var expected = label;
    var actual = dayPicker.prop('label');
    expect(actual).to.equal(expected);
  });
  it('should set "monthAriaLabel" to month picker', function () {
    var label = 'custom month label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePicker, {
      monthLabel: label,
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1)
    }));
    var monthPicker = subject.find("DateComponentRangePicker.".concat(_DatePicker2.default.month));
    var expected = label;
    var actual = monthPicker.prop('label');
    expect(actual).to.equal(expected);
  });
  it('should set "yearAriaLabel" to year picker', function () {
    var label = 'custom year label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_DatePicker.DatePicker, {
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1),
      yearLabel: label
    }));
    var yearPicker = subject.find("DateComponentRangePicker.".concat(_DatePicker2.default.year));
    var expected = label;
    var actual = yearPicker.prop('label');
    expect(actual).to.equal(expected);
  });
});