import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
import { rowGrouping } from '../rowGrouping';
import { useTablePipeline } from '../../pipeline';
import { mount } from 'enzyme';
import { renderHook } from '@testing-library/react-hooks';
var dataSource = [{
  id: 'alibaba',
  groupTitle: '阿里巴巴网络技术有限公司',
  children: [{
    id: '1-1',
    title: '二级标题',
    dept: '消费者事业部-淘宝-UED',
    dest: '云南大理',
    guide: 'Douglas Lee'
  }, {
    id: '1-2',
    title: '二级标题',
    dept: '消费者事业部-淘宝-UED',
    dest: '云南大理',
    guide: 'Douglas Lee'
  }]
}, {
  id: 'antfin',
  groupTitle: '蚂蚁金服有限公司',
  children: [{
    id: '2-1',
    title: '二级标题',
    dept: '消费者事业部-淘宝-UED',
    dest: '云南大理',
    guide: 'Douglas Lee'
  }, {
    id: '2-2',
    title: '二级标题',
    dept: '消费者事业部-淘宝-UED',
    dest: '云南大理',
    guide: 'Douglas Lee'
  }]
}, {
  id: 'other',
  groupTitle: 'group without children'
}];
var columns = [{
  code: 'title',
  name: '标题',
  width: 200
}, {
  code: 'dept',
  name: '部门名称',
  width: 180
}, {
  code: 'dest',
  name: '团建目的地',
  width: 160
}, {
  code: 'guide',
  name: '当地导游',
  width: 160
}];
describe('rowGrouping 单元测试', function () {
  var opts = {
    defaultOpenAll: true,
    onChangeOpenKeys: jest.fn()
  };
  var newPipeline = null;
  beforeEach(function () {
    var _renderHook = renderHook(function () {
      return useTablePipeline({
        primaryKey: 'id'
      }).input({
        dataSource: dataSource,
        columns: columns
      });
    }),
        result = _renderHook.result;

    var tablePipeline = result.current;
    newPipeline = rowGrouping(opts)(tablePipeline);
  });
  afterEach(function () {
    newPipeline = null;
    opts.onChangeOpenKeys.mockClear();
  });
  it('初始化', function () {
    expect(newPipeline.getDataSource().length).toBe(7);
  });
  it('getCellProps', function () {
    var col = newPipeline.getColumns();
    var cellProps = col[0].getCellProps('阿里巴巴网络技术有限公司', newPipeline.getDataSource()[0], 0);
    expect(cellProps.style).toEqual({
      cursor: 'pointer'
    });
    cellProps.onClick();
    expect(opts.onChangeOpenKeys).toBeCalled(); // 不是分组行没有cellProps

    var cellProps1 = col[0].getCellProps('阿里巴巴网络技术有限公司', newPipeline.getDataSource()[1], 1);
    expect(cellProps1).toBe(undefined);
  });
  it('getSpanRect', function () {
    var col = newPipeline.getColumns();
    var spanRect = col[0].getSpanRect('阿里巴巴网络技术有限公司', newPipeline.getDataSource()[0], 0);
    expect(spanRect).toEqual({
      top: 0,
      bottom: 1,
      left: 0,
      right: 5
    });
  });
  it('单元格渲染', function () {
    var col = newPipeline.getColumns();
    var wrapper = mount(col[0].render('1', newPipeline.getDataSource()[0], 0));
    expect(_findInstanceProperty(wrapper).call(wrapper, '.expansion-cell').length).toBe(2);
    var wrapper1 = mount(col[0].render('1', newPipeline.getDataSource()[1], 1));
    expect(_findInstanceProperty(wrapper1).call(wrapper1, '.expansion-cell').length).toBe(0);
  });
  it('appendRowPropsGetter', function () {
    var props = newPipeline.getProps();
    var rowProps = props.getRowProps(newPipeline.getDataSource()[0], 0);
    expect(rowProps.className).toBe('alternative');
  });
});