"use strict";

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

var _enzyme = _interopRequireWildcard(require("enzyme"));

var _ = _interopRequireDefault(require("../"));

var _enzymeAdapterReact = _interopRequireDefault(require("enzyme-adapter-react-16"));

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

_enzyme.default.configure({
  adapter: new _enzymeAdapterReact.default()
});

describe('DialogLayout', function () {
  test('should render', function () {
    var onClickCalled = false;

    var onClickFake = function onClickFake() {
      onClickCalled = true;
    };

    var component = (0, _enzyme.mount)(_react.default.createElement(_.default, {
      title: "titleFromTest",
      cancelButtonText: "testCancelButtonText",
      submitButtonText: "testSubmitButtonText",
      logo: _react.default.createElement("div", {
        id: "test-logo"
      }, "I am a logo"),
      onCancel: onClickFake
    }, _react.default.createElement("div", {
      id: "test-children"
    }, "I am a child")));
    expect('titleFromTest').toEqual(component.find('.vs-dialog-layout-title').prop('children'));
    expect('testCancelButtonText').toEqual(component.find('#vs-dialog-layout-cancel button').prop('children'));
    expect('testSubmitButtonText').toEqual(component.find('#vs-dialog-layout-submit button').prop('children'));
    expect('I am a child').toEqual(component.find('#test-children').prop('children'));
    expect('I am a logo').toEqual(component.find('#test-logo').prop('children'));
    expect(component.find('#vs-dialog-layout-submit').find('button').prop('disabled')).toEqual(false);
  });
  test('should render submit as disabled button when disableSubmit is true', function () {
    var component = (0, _enzyme.shallow)(_react.default.createElement(_.default, {
      disableSubmit: true
    }));
    var submitButton = component.find('#vs-dialog-layout-submit');
    expect(submitButton.prop('disabled')).toEqual(true);
  });
  test('should call cancel handler when cancel button is clicked', function () {
    var onCancel = false;

    var onClickFake = function onClickFake() {
      onCancel = true;
    };

    var component = (0, _enzyme.shallow)(_react.default.createElement(_.default, {
      onCancel: onClickFake
    }));
    var cancelButton = component.find('#vs-dialog-layout-cancel');
    cancelButton.simulate('click');
    expect(onCancel).toEqual(true);
  });
  test('should call cancel handler when cancel logo is clicked', function () {
    var onCancelCalled = false;

    var onClickFake = function onClickFake() {
      onCancelCalled = true;
    };

    var component = (0, _enzyme.shallow)(_react.default.createElement(_.default, {
      onCancel: onClickFake
    }));
    var closeIcon = component.find('.vs-dialog-layout-icon-close');
    closeIcon.simulate('click');
    expect(onCancelCalled).toEqual(true);
  });
  test('should call submit handler when submit button is clicked', function () {
    var onSubmitCalled = false;

    var onClickFake = function onClickFake() {
      onSubmitCalled = true;
    };

    var component = (0, _enzyme.shallow)(_react.default.createElement(_.default, {
      onSubmit: onClickFake
    }));
    var submitButton = component.find('#vs-dialog-layout-submit');
    submitButton.simulate('click');
    expect(onSubmitCalled).toEqual(true);
  });
  test('should show spinner on isSubmitting', function () {
    var submitButtonText = "test submit text";
    var component = (0, _enzyme.mount)(_react.default.createElement(_.default, {
      showSubmitButtonSpinner: true,
      submitButtonText: submitButtonText
    }));
    var submitButton = component.find('#vs-dialog-layout-submit');
    expect(submitButton.find("Spinner").length).toEqual(1);
    expect(submitButton.at(0).text()).toEqual(" " + submitButtonText);
  });
});