// 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 _enzyme = require("../../build/enzyme");

var _TiledGrid2 = require("./TiledGrid");

var items = function items(count) {
  return Array(count).fill('item');
};

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

  function MyTiledGrid(props, context) {
    return _TiledGrid.call(this, props, context) || this;
  }

  var _proto = MyTiledGrid.prototype;

  _proto.renderItem = function renderItem(item, index) {
    return _react.default.createElement("div", {
      key: index,
      className: 'cell cell' + index
    }, 'item' + index);
  };

  _proto.renderItemDetails = function renderItemDetails(item) {
    return _react.default.createElement("span", null);
  };

  return MyTiledGrid;
}(_TiledGrid2.TiledGrid);

describe('TiledGrid', function () {
  it('throws RangeError for incorrect col count', function () {
    var props = {
      cols: 5,
      items: items(10)
    };
    var instance = (0, _enzyme.mount)(_react.default.createElement(MyTiledGrid, props)).instance();
    expect(instance.getColSize.bind(instance)).toThrow(RangeError, /Invalid cols parameter/);
  });
  it('returns active row index (based on current item index and col count)', function () {
    var props = {
      cols: 2,
      items: items(10),
      currentItemIndex: 2
    };
    var instance = (0, _enzyme.mount)(_react.default.createElement(MyTiledGrid, props)).instance();
    expect(instance.getActiveRow()).toBe(2);
  });
  it('returns row count (based on item count and col count)', function () {
    var props = {
      cols: 2,
      items: items(10)
    };
    var instance = (0, _enzyme.mount)(_react.default.createElement(MyTiledGrid, props)).instance();
    expect(instance.getRowNumbers()).toBe(5);
  });
  describe('renders', function () {
    it('X*Y grid', function () {
      var props = {
        cols: 2,
        items: items(3)
      };
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(MyTiledGrid, props));
      expect(wrapper.find('.row').length).toBe(2);
      expect(wrapper.find('.cell').length).toBe(3);
    });
    it('active row', function () {
      var props = {
        cols: 2,
        items: items(5),
        currentItemIndex: 3
      };
      var wrapper = (0, _enzyme.mount)(_react.default.createElement(MyTiledGrid, props));
      expect(wrapper.find('.active').hostNodes().length).toBe(1);
      expect(wrapper.find('.row').hostNodes().at(2).hasClass('active')).toBe(true);
    });
  });
});