"use strict";

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _createReactClass = require("create-react-class");

var _createReactClass2 = _interopRequireDefault(_createReactClass);

var _propTypes = require("prop-types");

var _propTypes2 = _interopRequireDefault(_propTypes);

var _chai = require("chai");

var _chai2 = _interopRequireDefault(_chai);

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

var _chaiEnzyme2 = _interopRequireDefault(_chaiEnzyme);

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

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

var _illustration2 = _interopRequireDefault(_illustration);

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

/* eslint-env mocha */

/* global sinon */

/* eslint-disable prefer-arrow-callback */

/* eslint-disable no-unused-expressions */
// `this.wrapper` and `this.dom` is set in the helpers file
_chai2.default.use((0, _chaiEnzyme2.default)());

var DemoIllustration = (0, _createReactClass2.default)({
  displayName: 'DemoIllustration',
  render: function render() {
    return _react2.default.createElement(_illustration2.default, this.props);
  }
});
describe('SLDSIllustration: ', function () {
  describe('Image with heading and message render', function () {
    var svg;
    var heading;
    var messageBody;
    beforeEach((0, _enzymeHelpers.mountComponent)(_react2.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 () {
    var svg;
    var heading;
    var messageBody;
    beforeEach((0, _enzymeHelpers.mountComponent)(_react2.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 () {
    var svg;
    var heading;
    var messageBody;
    beforeEach((0, _enzymeHelpers.mountComponent)(_react2.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)(_react2.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');
    });
  });
});