// jshint esversion: 6
'use strict';

import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import React from 'react';
import { mount } from '../../build/enzyme';
import { TiledGrid } from './TiledGrid';

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

var MyTiledGrid =
/*#__PURE__*/
function (_TiledGrid) {
  _inheritsLoose(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.createElement("div", {
      key: index,
      className: 'cell cell' + index
    }, 'item' + index);
  };

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

  return MyTiledGrid;
}(TiledGrid);

describe('TiledGrid', function () {
  it('throws RangeError for incorrect col count', function () {
    var props = {
      cols: 5,
      items: items(10)
    };
    var instance = mount(React.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 = mount(React.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 = mount(React.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 = mount(React.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 = mount(React.createElement(MyTiledGrid, props));
      expect(wrapper.find('.active').hostNodes().length).toBe(1);
      expect(wrapper.find('.row').hostNodes().at(2).hasClass('active')).toBe(true);
    });
  });
});