// jshint esversion: 6
'use strict';

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

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

var _List2 = require("./List");

var _Store = _interopRequireDefault(require("../../../data/Store"));

var _enzyme = require("../../../../build/enzyme");

var MyList =
/*#__PURE__*/
function (_List) {
  (0, _inheritsLoose2.default)(MyList, _List);

  function MyList() {
    return _List.apply(this, arguments) || this;
  }

  var _proto = MyList.prototype;

  _proto.renderItem = function renderItem(item, index) {
    return _react.default.createElement("span", {
      key: index
    }, item.value);
  };

  _proto.render = function render() {
    var r = _List.prototype.render.call(this);

    return _react.default.createElement("div", null, r);
  };

  return MyList;
}(_List2.List);

var storeFields = [{
  id: 'id',
  type: 'number'
}, {
  id: 'value',
  type: 'string'
}];
var storeItems = [{
  id: 1,
  value: 'Alpha'
}, {
  id: 2,
  value: 'Bravo'
}, {
  id: 3,
  value: 'Charlie'
}];
describe('List', function () {
  it('renders list of items', function () {
    var store = new _Store.default({
      fields: storeFields
    });
    store.setItems(storeItems);
    var props = {
      store: store
    };
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(MyList, props));
    var actualTexts = wrapper.find('span').map(function (item) {
      return item.text();
    });
    var expectedText = storeItems.map(function (item) {
      return item.value;
    });
    expect(actualTexts).toEqual(expectedText);
  });
  it('renders empty message', function () {
    var store = new _Store.default({
      fields: storeFields
    });
    store.setItems([]);
    var props = {
      noResultsText: 'no results',
      store: store
    };
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(MyList, props));
    var actualText = wrapper.text();
    var expectedText = props.noResultsText;
    expect(actualText).toBe(expectedText);
  });
});