"use strict";

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

var _enzyme = require("enzyme");

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

var _ExpandablePicker = _interopRequireWildcard(require("../ExpandablePicker"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

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

var tap = function tap(node) {
  node.simulate('mousedown');
  node.simulate('mouseup');
};

describe('ExpandablePicker Specs', function () {
  it('should close onChange', function () {
    var expandablePicker = (0, _enzyme.mount)(_react.default.createElement(_ExpandablePicker.default, {
      defaultOpen: true,
      title: "Options"
    }, ['Option one', 'Option two', 'Option three']));
    var checkButton = expandablePicker.find('IconButton').last();
    tap(checkButton);
    var expected = false;
    var actual = expandablePicker.find('ExpandableItem').props().open;
    expect(actual).to.equal(expected);
  });
  it('should include value in onChange when value is specified', function () {
    var value = 2;

    var handleChange = _sinon.default.spy();

    var expandablePicker = (0, _enzyme.mount)(_react.default.createElement(_ExpandablePicker.default, {
      onChange: handleChange,
      open: true,
      title: "Options",
      value: value
    }, ['Option one', 'Option two', 'Option three']));
    var checkButton = expandablePicker.find('IconButton').last();
    tap(checkButton);
    var expected = value;
    var actual = handleChange.firstCall.args[0].value;
    expect(actual).to.equal(expected);
  });
  it('should include default value in onChange when value is not specified', function () {
    var value = 0;

    var handleChange = _sinon.default.spy();

    var expandablePicker = (0, _enzyme.mount)(_react.default.createElement(_ExpandablePicker.ExpandablePickerBase, {
      onChange: handleChange,
      open: true,
      title: "Options"
    }, ['Option one', 'Option two', 'Option three']));
    var checkButton = expandablePicker.find('IconButton').last();
    tap(checkButton);
    var expected = value;
    var actual = handleChange.firstCall.args[0].value;
    expect(actual).to.equal(expected);
  });
  it('should set "checkButtonAriaLabel" to check button', function () {
    var label = 'custom check button aria-label';
    var expandablePicker = (0, _enzyme.mount)(_react.default.createElement(_ExpandablePicker.ExpandablePickerBase, {
      checkButtonAriaLabel: label,
      open: true,
      title: "Options"
    }, ['Option one', 'Option two', 'Option three']));
    var checkButton = expandablePicker.find('IconButton').at(2);
    var expected = label;
    var actual = checkButton.prop('aria-label');
    expect(actual).to.equal(expected);
  });
  it('should set "decrementAriaLabel" to previous button', function () {
    var label = 'custom previous button aria-label';
    var expandablePicker = (0, _enzyme.mount)(_react.default.createElement(_ExpandablePicker.ExpandablePickerBase, {
      decrementAriaLabel: label,
      open: true,
      title: "Options"
    }, ['Option one', 'Option two', 'Option three']));
    var checkButton = expandablePicker.find('IconButton').at(1);
    var expected = label;
    var actual = checkButton.prop('aria-label');
    expect(actual).to.equal(expected);
  });
  it('should set "incrementAriaLabel" to next button', function () {
    var label = 'custom next button aria-label';
    var expandablePicker = (0, _enzyme.mount)(_react.default.createElement(_ExpandablePicker.ExpandablePickerBase, {
      incrementAriaLabel: label,
      open: true,
      title: "Options"
    }, ['Option one', 'Option two', 'Option three']));
    var checkButton = expandablePicker.find('IconButton').at(0);
    var expected = label;
    var actual = checkButton.prop('aria-label');
    expect(actual).to.equal(expected);
  });
  it('should set "pickerAriaLabel" to joined picker', function () {
    var label = 'custom joined picker aria-label';
    var expandablePicker = (0, _enzyme.mount)(_react.default.createElement(_ExpandablePicker.ExpandablePickerBase, {
      joined: true,
      open: true,
      pickerAriaLabel: label,
      title: "Options"
    }, ['Option one', 'Option two', 'Option three']));
    var joinedPicker = expandablePicker.find('Picker').at(1);
    var expected = label;
    var actual = joinedPicker.prop('aria-label');
    expect(actual).to.equal(expected);
  });
});