"use strict";

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

var _enzyme = require("enzyme");

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

var _Panels = require("../Panels");

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

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

describe('Panels Specs', function () {
  it('should render application close button when \'noCloseButton\' is not specified', function () {
    var panels = (0, _enzyme.mount)(_react.default.createElement(_Panels.Panels, null));
    var applicationCloseButton = panels.find('IconButton');
    var expected = 1;
    var actual = applicationCloseButton.length;
    expect(actual).to.equal(expected);
  });
  it('should not render application close button when \'noCloseButton\' is set to true', function () {
    var panels = (0, _enzyme.mount)(_react.default.createElement(_Panels.Panels, {
      noCloseButton: true
    }));
    var applicationCloseButton = panels.find('IconButton');
    var expected = 0;
    var actual = applicationCloseButton.length;
    expect(actual).to.equal(expected);
  });
  it('should call onApplicationClose when application close button is clicked', function () {
    var handleAppClose = _sinon.default.spy();

    var subject = (0, _enzyme.mount)(_react.default.createElement(_Panels.Panels, {
      onApplicationClose: handleAppClose
    }));
    tap(subject.find('IconButton'));
    var expected = true;
    var actual = handleAppClose.calledOnce;
    expect(expected).to.equal(actual);
  });
  it('should set application close button "aria-label" to closeButtonAriaLabel', function () {
    var label = 'custom close button label';
    var panels = (0, _enzyme.mount)(_react.default.createElement(_Panels.Panels, {
      closeButtonAriaLabel: label
    }));
    var expected = label;
    var actual = panels.find('IconButton').prop('aria-label');
    expect(actual).to.equal(expected);
  });
  describe('computed', function () {
    describe('childProps', function () {
      it('should not add aria-owns when noCloseButton is true', function () {
        var id = 'id';
        var childProps = {};
        var props = {
          childProps: childProps,
          noCloseButton: true,
          id: id
        };
        var expected = childProps;

        var actual = _Panels.PanelsBase.computed.childProps(props);

        expect(actual).to.equal(expected);
      });
      it('should not add aria-owns when id is not set', function () {
        var childProps = {};
        var props = {
          childProps: childProps,
          noCloseButton: false
        };
        var expected = childProps;

        var actual = _Panels.PanelsBase.computed.childProps(props);

        expect(actual).to.equal(expected);
      });
      it('should add aria-owns', function () {
        var id = 'id';
        var childProps = {};
        var props = {
          childProps: childProps,
          noCloseButton: false,
          id: id
        };
        var expected = "".concat(id, "_close");

        var actual = _Panels.PanelsBase.computed.childProps(props)['aria-owns'];

        expect(actual).to.equal(expected);
      });
      it('should append aria-owns', function () {
        var id = 'id';
        var ariaOwns = ':allthethings:';
        var childProps = {
          'aria-owns': ariaOwns
        };
        var props = {
          childProps: childProps,
          noCloseButton: false,
          id: id
        };
        var expected = "".concat(ariaOwns, " ").concat(id, "_close");

        var actual = _Panels.PanelsBase.computed.childProps(props)['aria-owns'];

        expect(actual).to.equal(expected);
      });
    });
  });
});