"use strict";

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

var _enzyme = require("enzyme");

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

var _TimePicker = require("../TimePicker");

var _TimePicker2 = _interopRequireDefault(require("../TimePicker.less"));

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

describe('TimePicker', function () {
  // Suite-wide setup
  it('should not generate a label when value is undefined', function () {
    var subject = (0, _enzyme.mount)(_react.default.createElement(_TimePicker.TimePicker, {
      title: "Time"
    }));
    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(_TimePicker.TimePicker, {
      onChange: handleChange,
      open: true,
      title: "Time",
      value: new Date(2000, 6, 15, 3, 30)
    }));
    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(_TimePicker.TimePickerBase, {
      hour: 1,
      meridiem: 0,
      meridiems: ['am', 'pm'],
      minute: 1,
      noLabels: true,
      open: true,
      order: ['h', 'm'],
      title: "Time"
    }));
    var expected = 2;
    var actual = subject.find(".".concat(_TimePicker2.default.timeComponents)).children().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(_TimePicker.TimePickerBase, {
      hour: 1,
      meridiem: 0,
      meridiems: ['am', 'pm'],
      minute: 1,
      open: true,
      order: ['h', 'm'],
      title: "Time"
    }));
    var expected = ['hour', 'minute'];
    var actual = subject.find(".".concat(_TimePicker2.default.timeComponents)).children().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(_TimePicker.TimePicker, {
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1, 12, 30)
    }));
    var minutePicker = subject.find(".".concat(_TimePicker2.default.minutesComponents)).at(0);
    var expected = 30;
    var actual = minutePicker.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(_TimePicker.TimePicker, {
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1, 12, 30)
    }));
    subject.setProps({
      value: new Date(2000, 0, 1, 12, 45)
    });
    var minutePicker = subject.find(".".concat(_TimePicker2.default.minutesComponents)).at(0);
    var expected = 45;
    var actual = minutePicker.prop('value');
    expect(actual).to.equal(expected);
  });
  it('should set "hourAriaLabel" to hour picker', function () {
    var label = 'custom hour aria-label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_TimePicker.TimePicker, {
      hourAriaLabel: label,
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1, 12, 30)
    }));
    var hourPicker = subject.find(".".concat(_TimePicker2.default.hourComponents)).at(0);
    var expected = label;
    var actual = hourPicker.prop('aria-label');
    expect(actual).to.equal(expected);
  });
  it('should set "meridiemAriaLabel" to meridiem picker', function () {
    var label = 'custom meridiem aria-label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_TimePicker.TimePicker, {
      meridiemAriaLabel: label,
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1, 12, 30)
    }));
    var meridiemPicker = subject.find(".".concat(_TimePicker2.default.meridiemComponent)).at(0);
    var expected = label;
    var actual = meridiemPicker.prop('aria-label');
    expect(actual).to.equal(expected);
  });
  it('should set "minuteAriaLabel" to minute picker', function () {
    var label = 'custom minute aria-label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_TimePicker.TimePicker, {
      minuteAriaLabel: label,
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1, 12, 30)
    }));
    var minutePicker = subject.find(".".concat(_TimePicker2.default.minutesComponents)).at(0);
    var expected = label;
    var actual = minutePicker.prop('aria-label');
    expect(actual).to.equal(expected);
  });
  it('should set "hourLabel" to hour picker', function () {
    var label = 'custom hour label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_TimePicker.TimePicker, {
      hourLabel: label,
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1, 12, 30)
    }));
    var hourPicker = subject.find(".".concat(_TimePicker2.default.hourComponents)).at(0);
    var expected = label;
    var actual = hourPicker.prop('label');
    expect(actual).to.equal(expected);
  });
  it('should set "meridiemLabel" to meridiem picker', function () {
    var label = 'custom meridiem label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_TimePicker.TimePicker, {
      meridiemLabel: label,
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1, 12, 30)
    }));
    var meridiemPicker = subject.find(".".concat(_TimePicker2.default.meridiemComponent)).at(0);
    var expected = label;
    var actual = meridiemPicker.prop('label');
    expect(actual).to.equal(expected);
  });
  it('should set "minuteLabel" to minute picker', function () {
    var label = 'custom minute label';
    var subject = (0, _enzyme.mount)(_react.default.createElement(_TimePicker.TimePicker, {
      minuteLabel: label,
      open: true,
      title: "Date",
      value: new Date(2000, 0, 1, 12, 30)
    }));
    var minutePicker = subject.find(".".concat(_TimePicker2.default.minutesComponents)).at(0);
    var expected = label;
    var actual = minutePicker.prop('label');
    expect(actual).to.equal(expected);
  });
});