import _extends from "@babel/runtime-corejs3/helpers/extends";
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";

var __rest = this && this.__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 _Object$getOwnPropertySymbols === "function") for (var i = 0, p = _Object$getOwnPropertySymbols(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;
};

import React from 'react';
import { renderHook, act } from '@testing-library/react-hooks';
import { mount } from 'enzyme';
import { multiSelect } from '../multiSelect';
import { useTablePipeline } from '../../pipeline';
var NAME = 'multiSelect';

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

  return /*#__PURE__*/React.createElement("input", _extends({
    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 = renderHook(function () {
      return useTablePipeline();
    }),
        result = _renderHook.result;

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

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

    multiSelect({
      stopClickEventPropagation: true // 阻止冒泡

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

    act(function () {
      _findInstanceProperty(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 = mount(checkboxColumn.title); // 测试选择列表头全选

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

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

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

    if (typeof cellProps.onClick === 'function') {
      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 = renderHook(function () {
      return useTablePipeline({
        components: {
          Checkbox: MockCheckbox
        }
      }).input(INPUT_DATA).primaryKey('id');
    }),
        result = _renderHook4.result;

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

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

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