// jshint esversion: 6
'use strict';

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

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

var _lodash = _interopRequireDefault(require("lodash"));

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

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

var _Pagination = require("./Pagination");

// TODO: export default
var createFakeStore = function createFakeStore(page, pageSize, itemsCount) {
  if (itemsCount === void 0) {
    itemsCount = 100;
  }

  var store = new _Store.default({
    fields: [{
      id: 'test',
      type: 'number',
      isPrimaryKey: true
    }]
  });

  var items = _lodash.default.range(itemsCount).map(function (v) {
    return {
      test: v
    };
  });

  store.setItems(items);
  store.setInitialPagination(page, pageSize);
  return store;
};

var component = function component(props) {
  return (0, _enzyme.mount)(_react.default.createElement(_Pagination.Pagination, props));
};

describe.skip('Pagination', function () {
  it('next click moves forward', function () {
    var wrapper = component({
      store: createFakeStore(2, 12)
    });
    wrapper.findByTestAutomation('p1').hostNodes().simulate('click');
    wrapper.findByTestAutomation('next').hostNodes().simulate('click');
    expect(wrapper.findByTestAutomation('p2').hostNodes()).to.have.className('active');
  });
  it('prev click moves backward', function () {
    var wrapper = component({
      store: createFakeStore(2, 12)
    });
    wrapper.findByTestAutomation('prev').hostNodes().simulate('click');
    expect(wrapper.findByTestAutomation('p1').hostNodes()).to.have.className('active');
  });
  it('disabled prev/next controls in case of first and last page', function () {
    var wrapper = component({
      store: createFakeStore(2, 12),
      availablePageSizes: [12, 20]
    });
    wrapper.findByTestAutomation('p1').hostNodes().simulate('click');
    expect(wrapper.findByTestAutomation('prev').hostNodes()).to.be.disabled();
    wrapper.findByTestAutomation('p9').hostNodes().simulate('click');
    expect(wrapper.findByTestAutomation('next').hostNodes()).to.be.disabled();
  });
  it('onPageChange callback', function () {
    var onPageChange = sinon.spy();
    var wrapper = component({
      store: createFakeStore(2, 10),
      onPageChange: onPageChange
    });
    wrapper.findByTestAutomation('p1').hostNodes().simulate('click');
    expect(onPageChange.lastCall).calledWithExactly(0);
  });
  it('page size selector is shown by default', function () {
    var wrapper = component({
      store: createFakeStore(2, 12),
      availablePageSizes: [12, 20]
    });
    wrapper.prop('availablePageSizes').forEach(function (pageSize, index) {
      expect(wrapper.findByTestAutomation("pageSizeSelector.size" + index)).to.have.text(pageSize);
    });
  });
  it("page size selector isn't show if showPageSizeSelector = false", function () {
    var wrapper = component({
      store: createFakeStore(2, 10),
      showPageSizeSelector: false
    });
    expect(wrapper.findByTestAutomation('pageSizeSelector').length).to.be.eql(0);
  });
  it('resets page selection to the first page when pageSize has been changed', function () {
    var wrapper = component({
      store: createFakeStore(2, 10, 30),
      availablePageSizes: [5, 10]
    });
    expect(wrapper.findByTestAutomation('p3').hostNodes()).to.have.className('active');
    wrapper.findByTestAutomation('pageSizeSelector.select').hostNodes().simulate('change', {
      target: {
        value: '5'
      }
    });
    expect(wrapper.findByTestAutomation('p1').hostNodes()).to.have.className('active');
  });
  it('gap between head and floating frame of pagination', function () {
    var wrapper = component({
      store: createFakeStore(5, 10)
    });
    expect(wrapper.find('.gap-left').hostNodes()).to.be.disabled();
  });
  it('gap between floating frame and tail of pagination', function () {
    var wrapper = component({
      store: createFakeStore(4, 10)
    });
    expect(wrapper.find('.gap-right').hostNodes()).to.be.disabled();
  });
});