"use strict";

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

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

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

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

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

var _icon = _interopRequireDefault(require("../../icon"));

var _iconSettings = _interopRequireDefault(require("../../icon-settings"));

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 DemoIcon =
/*#__PURE__*/
function (_React$Component) {
  _inherits(DemoIcon, _React$Component);

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

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

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

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

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

describe('SLDSIcon: ', function describeFunction() {
  describe('Standard Icon Props Render', function () {
    var svg;
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_iconSettings.default, {
      iconPath: "/assets/icons"
    }, _react.default.createElement(DemoIcon, {
      assistiveText: {
        label: 'Log a Call'
      },
      category: "standard",
      name: "log_a_call",
      style: {
        backgroundColor: 'rgb(218, 165, 32)'
      },
      size: "large"
    }))));
    afterEach(_enzymeHelpers.unmountComponent);
    it('renders container class', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-icon_container');
    });
    it('renders assistive text', function () {
      (0, _chai.expect)(this.wrapper.find('.slds-assistive-text')).to.have.text('Log a Call');
    });
    it('renders icon name class on svg', function () {
      // also tests that all '_' are replaced with '-'
      (0, _chai.expect)(this.wrapper).to.have.className('slds-icon-standard-log-a-call');
    });
    it('renders custom background color', function () {
      svg = this.wrapper.find('svg');
      (0, _chai.expect)(svg).to.have.style('backgroundColor', 'rgb(218, 165, 32)');
    });
    it('renders icon size class', function () {
      svg = this.wrapper.find('svg');
      (0, _chai.expect)(svg.hasClass('slds-icon_large')).to.be.true;
    });
  });
  describe('Custom Icon Props Render', function describeFunction2() {
    var svg;
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_iconSettings.default, {
      iconPath: "/assets/icons"
    }, _react.default.createElement(DemoIcon, {
      assistiveText: {
        label: 'Heart'
      },
      category: "custom",
      name: "custom1",
      size: "small"
    }))));
    afterEach(_enzymeHelpers.unmountComponent);
    it('renders container class', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-icon_container');
    });
    it('renders assistive text', function () {
      (0, _chai.expect)(this.wrapper.find('.slds-assistive-text')).to.have.text('Heart');
    });
    it('renders icon name class on svg', function () {
      // also tests that all '_' are replaced with '-'
      (0, _chai.expect)(this.wrapper).to.have.className('slds-icon-custom-custom1');
    });
    it('renders icon size class', function () {
      svg = this.wrapper.find('svg');
      (0, _chai.expect)(svg.hasClass('slds-icon_small')).to.be.true;
    });
  });
  describe('Action Icon Props Render', function describeFunction() {
    var svg;
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_iconSettings.default, {
      iconPath: "/assets/icons"
    }, _react.default.createElement(DemoIcon, {
      assistiveText: {
        label: 'Announcements'
      },
      category: "action",
      name: "announcement",
      size: "large",
      title: "custom title",
      className: "slds-m-around_x-small"
    }))));
    afterEach(_enzymeHelpers.unmountComponent);
    it('renders container class', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-icon_container');
    });
    it('renders assistive text', function () {
      (0, _chai.expect)(this.wrapper.find('.slds-assistive-text')).to.have.text('Announcements');
    });
    it('renders round container', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-icon_container_circle');
    });
    it('renders icon name class on svg', function () {
      // also tests that all '_' are replaced with '-'
      (0, _chai.expect)(this.wrapper).to.have.className('slds-icon-action-announcement');
    });
    it('renders icon size class', function () {
      svg = this.wrapper.find('svg');
      (0, _chai.expect)(svg.hasClass('slds-icon_large')).to.be.true;
    });
    it('renders title', function () {
      (0, _chai.expect)(this.wrapper.find('[title="custom title"]')).to.exist;
    });
  });
  describe('Utility Icon Props Render', function describeFunction() {
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_iconSettings.default, {
      iconPath: "/assets/icons"
    }, _react.default.createElement(DemoIcon, {
      category: "utility",
      name: "open_folder",
      size: "medium"
    }))));
    afterEach(_enzymeHelpers.unmountComponent);
    it('does NOT render container class', function () {
      (0, _chai.expect)(this.wrapper.hasClass('slds-icon_container')).to.be.false;
    });
    it('medium size does not render size class', function () {
      // also tests that all '_' are replaced with '-'
      (0, _chai.expect)(this.wrapper.hasClass('slds-icon_medium')).to.be.false;
    });
    it('utility icons do not render name class on svg', function () {
      // also tests that all '_' are replaced with '-'
      (0, _chai.expect)(this.wrapper.hasClass('slds-icon-text-default')).to.be.false;
    });
  });
  describe('Icon with external path renders', function describeFunction() {
    var use;
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_iconSettings.default, {
      iconPath: "/assets/icons"
    }, _react.default.createElement(DemoIcon, {
      assistiveText: {
        label: 'New stuff!'
      },
      inverse: true,
      path: "/assets/icons/utility-sprite/svg/symbols.svg#announcement",
      size: "medium"
    }))));
    afterEach(_enzymeHelpers.unmountComponent);
    it('does NOT render slds-icon-standard class', function () {
      (0, _chai.expect)(this.wrapper.hasClass('slds-icon-standard-')).to.be.false;
    });
    it('path prop is passed to svg', function () {
      (0, _chai.expect)(this.wrapper.find('use')).to.have.attr('xlink:href', '/assets/icons/utility-sprite/svg/symbols.svg#announcement');
    });
  });
});