"use strict";

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

var _chai = _interopRequireWildcard(require("chai"));

var _chaiEnzyme = _interopRequireDefault(require("chai-enzyme"));

var _enzymeHelpers = require("../../../tests/enzyme-helpers");

var _illustration = _interopRequireDefault(require("../../illustration"));

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

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

_chai.default.use((0, _chaiEnzyme.default)());

var DemoIllustration =
/*#__PURE__*/
function (_React$Component) {
  _inherits(DemoIllustration, _React$Component);

  function DemoIllustration() {
    _classCallCheck(this, DemoIllustration);

    return _possibleConstructorReturn(this, _getPrototypeOf(DemoIllustration).apply(this, arguments));
  }

  _createClass(DemoIllustration, [{
    key: "render",
    value: function render() {
      return _react.default.createElement(_illustration.default, this.props);
    }
  }]);

  return DemoIllustration;
}(_react.default.Component);

_defineProperty(DemoIllustration, "displayName", 'DemoIllustration');

describe('SLDSIllustration: ', function describeFunction() {
  describe('Image with heading and message render', function describeFunction2() {
    var svg;
    var heading;
    var messageBody;
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(DemoIllustration, {
      className: "custom-illustration",
      internalIllustration: true,
      heading: "Lorem ipsum dolor",
      messageBody: "Lorem ipsum dolor sit amet, consectetur",
      name: "No Access",
      path: "/assets/images/illustrations/empty-state-no-access.svg#no-access",
      size: "small",
      style: {
        backgroundColor: 'rgb(218, 165, 32)'
      }
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('renders container class', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-illustration');
      (0, _chai.expect)(this.wrapper).to.have.className('custom-illustration');
    });
    it('renders illustration size class', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-illustration_small');
    });
    it('sets svg aria-hidden to true', function () {
      svg = this.wrapper.find('svg');
      (0, _chai.expect)(svg).to.have.attr('aria-hidden', 'true');
    });
    it('renders illustration svg class', function () {
      svg = this.wrapper.find('svg');
      (0, _chai.expect)(svg.hasClass('slds-illustration__svg')).to.be.true; // chai-enzyme is buggy with an svg
    });
    it('renders svg name attribute', function () {
      svg = this.wrapper.find('svg'); // also tests that all '_' and ' ' are replaced with '-'

      (0, _chai.expect)(svg).to.have.attr('name', 'no-access');
    });
    it('renders svg custom background color', function () {
      svg = this.wrapper.find('svg');
      (0, _chai.expect)(svg).to.have.style('backgroundColor', 'rgb(218, 165, 32)');
    });
    it('renders heading', function () {
      heading = this.wrapper.find('.slds-text-heading_medium');
      (0, _chai.expect)(heading.text()).to.equal('Lorem ipsum dolor');
    });
    it('renders message body', function () {
      messageBody = this.wrapper.find('.slds-text-body_regular');
      (0, _chai.expect)(messageBody.text()).to.equal('Lorem ipsum dolor sit amet, consectetur');
    });
  });
  describe('Heading and message render', function describeFunction2() {
    var svg;
    var heading;
    var messageBody;
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(DemoIllustration, {
      internalIllustration: true,
      heading: "Lorem ipsum dolor",
      messageBody: "Lorem ipsum dolor sit amet, consectetur"
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('does not render svg', function () {
      svg = this.wrapper.find('svg');
      (0, _chai.expect)(svg).not.to.be.present();
    });
    it('renders heading', function () {
      heading = this.wrapper.find('.slds-text-heading_medium');
      (0, _chai.expect)(heading.text()).to.equal('Lorem ipsum dolor');
    });
    it('renders message body', function () {
      messageBody = this.wrapper.find('.slds-text-body_regular');
      (0, _chai.expect)(messageBody.text()).to.equal('Lorem ipsum dolor sit amet, consectetur');
    });
  });
  describe('Heading only renders', function describeFunction2() {
    var svg;
    var heading;
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(DemoIllustration, {
      internalIllustration: true,
      heading: "Lorem ipsum dolor"
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('does not render svg', function () {
      svg = this.wrapper.find('svg');
      (0, _chai.expect)(svg).not.to.be.present();
    });
    it('renders heading', function () {
      heading = this.wrapper.find('.slds-text-heading_medium');
      (0, _chai.expect)(heading.text()).to.equal('Lorem ipsum dolor');
    });
    it('does not render message body', function () {
      (0, _chai.expect)(this.wrapper.find('.slds-text-body_regular')).not.to.be.present();
    });
  });
  describe('Message only renders', function () {
    var svg;
    var heading;
    var messageBody;
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(DemoIllustration, {
      internalIllustration: true,
      messageBody: "Lorem ipsum dolor sit amet, consectetur"
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('does not render svg', function () {
      svg = this.wrapper.find('svg');
      (0, _chai.expect)(svg).not.to.be.present();
    });
    it('does not render heading', function () {
      heading = this.wrapper.find('.slds-text-heading_medium');
      (0, _chai.expect)(heading).not.to.be.present();
    });
    it('renders message body', function () {
      messageBody = this.wrapper.find('.slds-text-body_regular');
      (0, _chai.expect)(messageBody.text()).to.equal('Lorem ipsum dolor sit amet, consectetur');
    });
  });
});