"use strict";

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

var _chai = require("chai");

var _pill = _interopRequireDefault(require("../../pill"));

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

var _avatar = _interopRequireDefault(require("../..//avatar"));

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

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

/* eslint-disable react/no-find-dom-node */
describe('SLDSPill', function () {
  var LABEL = 'Pill Label';
  var LABEL_TITLE = 'Full pill label verbiage mirrored here';
  describe('Linked', function () {
    var onClick = sinon.stub();
    var onRemove = sinon.stub();
    var onFocus = sinon.stub();
    var onBlur = sinon.stub();
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_pill.default, {
      tabIndex: "0",
      labels: {
        label: LABEL,
        title: LABEL_TITLE,
        removeTitle: 'Remove'
      },
      assistiveText: {
        remove: 'Remove assistive text'
      },
      className: "extra-class",
      onClick: onClick,
      onRemove: onRemove,
      onFocus: onFocus,
      onBlur: onBlur
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('has correct style and attributes', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-pill');
      (0, _chai.expect)(this.wrapper).to.have.className('slds-pill_link');
      (0, _chai.expect)(this.wrapper).to.have.className('extra-class');
      (0, _chai.expect)(this.wrapper.find('.slds-pill[role="button"]')).to.be.present();
    });
    it('renders label as a link', function () {
      var anchor = this.wrapper.find('.slds-pill__action');
      (0, _chai.expect)(anchor.exists()).to.be.true;
      (0, _chai.expect)(anchor.prop('title')).to.equal(LABEL_TITLE);
      var label = this.wrapper.find('.slds-pill__label');
      (0, _chai.expect)(label.text()).to.equal(LABEL);
    });
    it('renders remove button', function () {
      var removeButton = this.wrapper.find('.slds-pill__remove');
      (0, _chai.expect)(removeButton.exists()).to.be.true;
    });
    it('renders assistive text in remove button', function () {
      var removeButton = this.wrapper.find('.slds-pill__remove');
      (0, _chai.expect)(removeButton.exists()).to.be.true;
      var assistiveText = removeButton.find('.slds-assistive-text');
      (0, _chai.expect)(assistiveText.exists()).to.be.true;
      (0, _chai.expect)(assistiveText.text()).to.equal('Remove assistive text');
    });
    it('focuses and blurs', function () {
      this.wrapper.simulate('focus');
      (0, _chai.expect)(this.wrapper).to.containMatchingElement(document.activeElement);
      (0, _chai.expect)(onFocus.calledOnce).to.be.true;
      this.wrapper.simulate('blur');
      (0, _chai.expect)(document.activeElement).to.equal(document.querySelector('body'));
      (0, _chai.expect)(onBlur.calledOnce).to.be.true;
    });
    it('reponds to link clicks', function () {
      var pillLink = this.wrapper.find('.slds-pill__action');
      (0, _chai.expect)(pillLink).to.exist;
      pillLink.simulate('click');
      (0, _chai.expect)(onClick.calledOnce).to.be.true;
    });
    it('responds to remove clicks', function () {
      var removeButton = this.wrapper.find('.slds-pill__remove');
      (0, _chai.expect)(removeButton).to.exist;
      removeButton.simulate('click');
      (0, _chai.expect)(onRemove.calledOnce).to.be.true;
    });
  });
  describe('Linked With Href', function () {
    var HREF = 'https://www.salesforce.com';
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_pill.default, {
      labels: {
        label: LABEL
      },
      href: HREF
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('uses href', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-pill_link');
      var anchor = this.wrapper.find('.slds-pill__action');
      (0, _chai.expect)(anchor).to.exist;
      (0, _chai.expect)(anchor).to.have.prop('href', HREF);
    });
  });
  describe('Link style on', function () {
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_pill.default, {
      labels: {
        label: LABEL
      }
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('forces link style', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-pill_link');
      var anchor = this.wrapper.find('.slds-pill__action');
      (0, _chai.expect)(anchor).to.exist;
    });
  });
  describe('Bare Linked With Role', function () {
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_pill.default, {
      labels: {
        label: LABEL
      },
      bare: true
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('has correct style and attributes', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-pill');
      (0, _chai.expect)(this.wrapper).to.have.className('slds-pill_bare');
      (0, _chai.expect)(this.wrapper.find('.slds-pill[role="button"]').exists()).to.be.true;
    });
  });
  describe('Linked With Error', function () {
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_pill.default, {
      labels: {
        label: LABEL
      },
      hasError: true
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('has correct style and attributes', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-has-error');
    });
  });
  describe('Linked With Icon', function () {
    var onClick = sinon.stub();
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_pill.default, {
      labels: {
        label: LABEL
      },
      onClick: onClick,
      icon: _react.default.createElement(_icon.default, {
        title: "Account",
        category: "standard",
        name: "account"
      })
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('renders icon to the left from label', function () {
      var icon = this.wrapper.find(_icon.default);
      (0, _chai.expect)(icon.exists()).to.be.true;
      (0, _chai.expect)(icon.prop('title')).to.equal('Account');
      (0, _chai.expect)(icon.prop('category')).to.equal('standard');
      (0, _chai.expect)(icon.prop('name')).to.equal('account');
    });
  });
  describe('Linked With Avatar', function () {
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_pill.default, {
      labels: {
        label: LABEL
      },
      avatar: _react.default.createElement(_avatar.default, {
        variant: "user",
        title: "User avatar",
        imgSrc: "https://lightningdesignsystem.com/assets/images/avatar2.jpg"
      })
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('renders icon to the left from label', function () {
      var avatar = this.wrapper.find(_avatar.default);
      (0, _chai.expect)(avatar.exists()).to.be.true;
      (0, _chai.expect)(avatar.prop('title')).to.equal('User avatar');
      (0, _chai.expect)(avatar.prop('variant')).to.equal('user');
      (0, _chai.expect)(avatar.prop('imgSrc')).to.equal('https://lightningdesignsystem.com/assets/images/avatar2.jpg');
    });
  });
  describe('Option', function () {
    var onRemove = sinon.stub();
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_pill.default, {
      labels: {
        label: LABEL,
        title: LABEL_TITLE,
        removeTitle: 'Remove'
      },
      variant: "option",
      onRemove: onRemove
    })));
    afterEach(_enzymeHelpers.unmountComponent);
    it('has correct style', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-pill');
      (0, _chai.expect)(this.wrapper).to.not.have.className('slds-pill_link');
      var anchor = this.wrapper.find('.slds-pill__action');
      (0, _chai.expect)(anchor).to.not.exist;
    });
  });
  describe('Linked Custom', function () {
    var onClick = sinon.stub();
    var onRemove = sinon.stub();
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_pill.default, {
      onClick: onClick,
      onRemove: onRemove
    }, _react.default.createElement("div", {
      className: "abc"
    }, "this is a custom label"))));
    afterEach(_enzymeHelpers.unmountComponent);
    it('has correct style', function () {
      (0, _chai.expect)(this.wrapper).to.have.className('slds-pill');
      (0, _chai.expect)(this.wrapper).to.have.className('slds-pill_link');
      var child = this.wrapper.find('.abc');
      (0, _chai.expect)(child.exists()).to.be.true;
      (0, _chai.expect)(child.text()).to.equal('this is a custom label');
    });
    it('renders remove button', function () {
      var removeButton = this.wrapper.find('.slds-pill__remove');
      (0, _chai.expect)(removeButton.exists()).to.be.true;
    });
    it('reponds to link clicks', function () {
      var pillLink = this.wrapper.find('.slds-pill');
      (0, _chai.expect)(pillLink).to.exist;
      pillLink.simulate('click');
      (0, _chai.expect)(onClick.calledOnce).to.be.true;
    });
    it('responds to remove clicks', function () {
      var removeButton = this.wrapper.find('.slds-pill__remove');
      (0, _chai.expect)(removeButton).to.exist;
      removeButton.simulate('click');
      (0, _chai.expect)(onRemove.calledOnce).to.be.true;
    });
  });
});