"use strict";

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

var _enzyme = require("enzyme");

var _styledComponents = require("../styled-components.js");

var _optionProfile = _interopRequireDefault(require("../option-profile.js"));

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

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

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

var mockItem = {
  title: 'David Smith',
  subtitle: 'Senior Engineering Manager',
  body: 'Uber Everything',
  imgUrl: 'imgUrl'
};

function getSharedProps() {
  return {
    item: mockItem,
    getProfileItemLabels: function getProfileItemLabels(_ref) {
      var title = _ref.title,
          subtitle = _ref.subtitle,
          body = _ref.body;
      return {
        title: title,
        subtitle: subtitle,
        body: body
      };
    },
    getProfileItemImg: function getProfileItemImg(item) {
      return item.imgUrl;
    },
    getProfileItemImgText: function getProfileItemImgText(item) {
      return item.title;
    }
  };
}

describe('Option Profile Stateless Component', function () {
  test('basic renders', function () {
    var component = (0, _enzyme.mount)(_react.default.createElement(_optionProfile.default, getSharedProps()));
    expect(component.find(_styledComponents.ListItemProfile)).toExist();
    expect(component.find(_styledComponents.ProfileTitle).first().text()).toEqual(mockItem.title);
    expect(component.find(_styledComponents.ProfileSubtitle).first().text()).toEqual(mockItem.subtitle);
    expect(component.find(_styledComponents.ProfileBody).first().text()).toEqual(mockItem.body);
    expect(component.find(_styledComponents.ProfileImg).first().prop('src')).toEqual(mockItem.imgUrl);
  });
  test('renders with custom image component', function () {
    function MockComponent() {
      return _react.default.createElement("div", null);
    }

    var props = _objectSpread({}, getSharedProps(), {
      getProfileItemImg: function getProfileItemImg(item) {
        return MockComponent;
      }
    });

    var component = (0, _enzyme.mount)(_react.default.createElement(_optionProfile.default, props));
    expect(component.find(MockComponent)).toExist();
  });
  test('renders with components overrides', function () {
    function MockComponent() {
      return _react.default.createElement("div", null);
    }

    var props = _objectSpread({}, getSharedProps(), {
      overrides: {
        ListItemProfile: {
          component: MockComponent,
          props: {
            custom: 'prop'
          }
        }
      }
    });

    var component = (0, _enzyme.mount)(_react.default.createElement(_optionProfile.default, props));
    expect(component.find(_styledComponents.ListItemProfile)).not.toExist();
    expect(component.find(MockComponent)).toExist();
    expect(component.find(MockComponent).prop('custom')).toEqual('prop');
  });
});