"use strict";

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

var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));

var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));

var _find = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/find"));

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

var _reactHooks = require("@testing-library/react-hooks");

var _enzyme = require("enzyme");

var _multiSelect2 = require("../multiSelect");

var _pipeline = require("../../pipeline");

var __rest = void 0 && (void 0).__rest || function (s, e) {
  var t = {};

  for (var p in s) {
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  }

  if (s != null && typeof _getOwnPropertySymbols.default === "function") for (var i = 0, p = (0, _getOwnPropertySymbols.default)(s); i < p.length; i++) {
    if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  }
  return t;
};

var NAME = 'multiSelect';

var MockCheckbox = function MockCheckbox(_a) {
  var indeterminate = _a.indeterminate,
      props = __rest(_a, ["indeterminate"]);

  return /*#__PURE__*/_react.default.createElement("input", (0, _extends2.default)({
    type: 'checkbox',
    className: 'checkbox'
  }, props));
};

var ROWS = [{
  id: '1'
}];
var INPUT_DATA = {
  columns: [],
  dataSource: ROWS
};
describe("".concat(NAME), function () {
  it('not set Checkbox', function () {
    var _renderHook = (0, _reactHooks.renderHook)(function () {
      return (0, _pipeline.useTablePipeline)();
    }),
        result = _renderHook.result;

    var _multiSelect = function _multiSelect() {
      return (0, _multiSelect2.multiSelect)()(result.current);
    };

    expect(_multiSelect).toThrowError(/Checkbox/);
  });
  it('set require props,test checkboxColumn render, cell change and select all event', function () {
    var _renderHook2 = (0, _reactHooks.renderHook)(function () {
      return (0, _pipeline.useTablePipeline)({
        components: {
          Checkbox: MockCheckbox
        }
      }).input(INPUT_DATA).primaryKey('id');
    }),
        result = _renderHook2.result;

    (0, _multiSelect2.multiSelect)({
      stopClickEventPropagation: true // 阻止冒泡

    })(result.current);
    expect(result.current.getColumns().length).toBeGreaterThan(0);
    var checkboxColumn = result.current.getColumns()[0];
    var wrapper = (0, _enzyme.mount)(checkboxColumn.render({}, {
      id: '1'
    }, 0)); // 测试复选框行点击onChange

    (0, _reactHooks.act)(function () {
      (0, _find.default)(wrapper).call(wrapper, MockCheckbox).at(0).simulate('change', {
        target: {},
        nativeEvent: {
          stopPropagation: jest.fn()
        }
      });
    });
    expect(result.current.getStateAtKey('multiSelect')).toMatchObject({
      "lastKey": "1",
      "value": ["1"]
    });
    var titleWrapper = (0, _enzyme.mount)(checkboxColumn.title); // 测试选择列表头全选

    (0, _reactHooks.act)(function () {
      (0, _find.default)(titleWrapper).call(titleWrapper, MockCheckbox).at(0).simulate('change');
    });
  });
  it('set clickArea=cell, test getCellProps and cell click', function () {
    var _renderHook3 = (0, _reactHooks.renderHook)(function () {
      return (0, _pipeline.useTablePipeline)({
        components: {
          Checkbox: MockCheckbox
        }
      }).input(INPUT_DATA).primaryKey('id');
    }),
        result = _renderHook3.result;

    (0, _multiSelect2.multiSelect)({
      clickArea: 'cell'
    })(result.current);
    var checkboxColumn = result.current.getColumns()[0]; // 测试getCellProps

    var cellProps = checkboxColumn.getCellProps('', ROWS[0], 0);

    if (typeof cellProps.onClick === 'function') {
      (0, _reactHooks.act)(function () {
        var mockEvent = {};
        cellProps.onClick(mockEvent);
      });
      expect(result.current.getStateAtKey('multiSelect')).toMatchObject({
        "lastKey": "1",
        "value": ["1"]
      });
    }
  });
  it('set clickArea=row, test appendRowPropsGetter fn', function () {
    var _renderHook4 = (0, _reactHooks.renderHook)(function () {
      return (0, _pipeline.useTablePipeline)({
        components: {
          Checkbox: MockCheckbox
        }
      }).input(INPUT_DATA).primaryKey('id');
    }),
        result = _renderHook4.result;

    var pipeline = (0, _multiSelect2.multiSelect)({
      lastKey: '1',
      clickArea: 'row'
    })(result.current); // 调用 appendRowPropsGetter 设置的函数

    var props = pipeline.getProps();
    var rowProps = props.getRowProps(ROWS[0], 0);

    if (rowProps.onClick) {
      (0, _reactHooks.act)(function () {
        var mockEvent = {
          shiftKey: true
        };
        rowProps.onClick(mockEvent);
      });
      expect(result.current.getStateAtKey('multiSelect')).toMatchObject({
        "lastKey": "1",
        "value": ["1"]
      });
    }
  });
});