"use strict";

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

var _chai = require("chai");

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

var _globalHeader = _interopRequireDefault(require("../../global-header"));

var _favorites = _interopRequireDefault(require("../../global-header/favorites"));

var _help = _interopRequireDefault(require("../../global-header/help"));

var _notifications = _interopRequireDefault(require("../../global-header/notifications"));

var _profile = _interopRequireDefault(require("../../global-header/profile"));

var _search = _interopRequireDefault(require("../../global-header/search"));

var _setup = _interopRequireDefault(require("../../global-header/setup"));

var _task = _interopRequireDefault(require("../../global-header/task"));

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

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

describe('SLDSGlobalHeader', function () {
  describe('SLDSGlobalHeader index', function () {
    beforeEach((0, _enzymeHelpers.mountComponent)(_react.default.createElement(_iconSettings.default, {
      iconPath: "/assets/icons"
    }, _react.default.createElement(_globalHeader.default, null, _react.default.createElement(_profile.default, null), _react.default.createElement(_setup.default, null), _react.default.createElement(_favorites.default, null), _react.default.createElement(_task.default, null), _react.default.createElement(_notifications.default, null), _react.default.createElement(_search.default, {
      options: []
    }), _react.default.createElement(_help.default, null)))));
    afterEach(_enzymeHelpers.unmountComponent);
    it('arranges components correctly even if the developer put them out of order', function () {
      var order = ['div.slds-global-actions__favorites', 'button.slds-global-actions__task', 'button.slds-global-actions__help', 'button.slds-global-actions__setup', 'button.slds-global-actions__notifications', 'button.slds-global-actions__avatar'];
      this.wrapper.find('ul.slds-global-actions li.slds-global-actions__item').forEach(function (node, index) {
        (0, _chai.expect)(node.find(order[index]).length).to.eql(1);
      });
    });
  });
  describe('SLDSGlobalHeaderFavorites', function () {
    it('handles actionDisabled correctly', function () {
      (0, _enzymeHelpers.mountComponent)(_react.default.createElement(_iconSettings.default, {
        iconPath: "/assets/icons"
      }, _react.default.createElement(_globalHeader.default, null, _react.default.createElement(_favorites.default, {
        actionDisabled: true
      })))).call(this);
      var actionButtonSelector = 'button.slds-global-actions__favorites-action';
      (0, _chai.expect)(this.wrapper.find(actionButtonSelector).hasClass('slds-is-disabled')).to.eql(true);
      (0, _chai.expect)(this.wrapper.find("".concat(actionButtonSelector, "[disabled=true]")).length).to.eql(1);

      _enzymeHelpers.unmountComponent.call(this);
    });
    it('handles actionSelected correctly', function () {
      (0, _enzymeHelpers.mountComponent)(_react.default.createElement(_iconSettings.default, {
        iconPath: "/assets/icons"
      }, _react.default.createElement(_globalHeader.default, null, _react.default.createElement(_favorites.default, {
        actionSelected: true
      })))).call(this);
      var actionButtonSelector = 'button.slds-global-actions__favorites-action';
      (0, _chai.expect)(this.wrapper.find(actionButtonSelector).hasClass('slds-is-selected')).to.eql(true);
      (0, _chai.expect)(this.wrapper.find("".concat(actionButtonSelector, "[aria-pressed=true]")).length).to.eql(1);

      _enzymeHelpers.unmountComponent.call(this);
    });
    it('handles onToggleActionSelected correctly', function () {
      var args = {};
      (0, _enzymeHelpers.mountComponent)(_react.default.createElement(_iconSettings.default, {
        iconPath: "/assets/icons"
      }, _react.default.createElement(_globalHeader.default, null, _react.default.createElement(_favorites.default, {
        onToggleActionSelected: function onToggleActionSelected(event, data) {
          args.event = event;
          args.data = data;
        }
      })))).call(this);
      var actionButton = this.wrapper.find('button.slds-global-actions__favorites-action');
      actionButton.simulate('click');
      (0, _chai.expect)(_typeof(args.event)).to.eql('object');
      (0, _chai.expect)(_typeof(args.data)).to.eql('object');
      (0, _chai.expect)(_typeof(args.data.actionSelected)).to.eql('boolean');
      args = {};
      actionButton.simulate('keydown', {
        keyCode: 13
      });
      (0, _chai.expect)(_typeof(args.event)).to.eql('object');
      (0, _chai.expect)(_typeof(args.data)).to.eql('object');
      (0, _chai.expect)(_typeof(args.data.actionSelected)).to.eql('boolean');

      _enzymeHelpers.unmountComponent.call(this);
    });
  });
  describe('SLDSGlobalHeaderNotifications', function () {
    it('handles notificationCount correctly when no value provided', function () {
      (0, _enzymeHelpers.mountComponent)(_react.default.createElement(_iconSettings.default, {
        iconPath: "/assets/icons"
      }, _react.default.createElement(_globalHeader.default, null, _react.default.createElement(_notifications.default, null)))).call(this);
      (0, _chai.expect)(this.wrapper.find('.slds-notification-badge').text()).to.eql('');

      _enzymeHelpers.unmountComponent.call(this);
    });
    it('handles notificationCount correctly when a value is provided', function () {
      (0, _enzymeHelpers.mountComponent)(_react.default.createElement(_iconSettings.default, {
        iconPath: "/assets/icons"
      }, _react.default.createElement(_globalHeader.default, null, _react.default.createElement(_notifications.default, {
        notificationCount: 5
      })))).call(this);
      (0, _chai.expect)(this.wrapper.find('.slds-notification-badge').text()).to.eql('5');

      _enzymeHelpers.unmountComponent.call(this);
    });
  });
});