import * as React from 'react';
import { configure, mount, ReactWrapper } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import Story from './Story';
import SpreadSheet from '../../../SpreadSheetProvider';
import { getCellsInfo } from '../helper';
import { sliceBy, mockResizeObserver } from 'valor-app-utils';

mockResizeObserver();

configure({ adapter: new Adapter() });

describe('<MergeCellCommand/>', () => {
  it('选择第一个大合并单元格, 点合并后, 实际为拆分', () => {
    const wrapper = mount(<Story env="test" />);
    const sheetWrapper = wrapper.find(SpreadSheet).at(0);

    let cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultIds).toEqual([...[11], ...[], ...[31, 32, 33]]);
    expect(cellInfo.resultValues).toEqual([...[1], ...[], ...[2, 1, 1]]);

    // 选择第一个单元格
    const spreadSheetInstance = sheetWrapper.instance() as any;
    spreadSheetInstance.runtime.fsmService.send('MOUSE.DOWN', { selectedCell: 11 });
    wrapper
      .find('#mergeCell')
      .at(0)
      .simulate('click');
    cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultValues).toEqual([...[1, 0, 0], ...[0, 0, 0], ...[2, 1, 1]]);

    // 由于无法选择自动选择多个单元格, 所以别的只好手测
    wrapper
      .find('#undo')
      .at(0)
      .simulate('click');
    cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultIds).toEqual([...[11], ...[], ...[31, 32, 33]]);
    expect(cellInfo.resultValues).toEqual([...[1], ...[], ...[2, 1, 1]]);

    wrapper
      .find('#redo')
      .at(0)
      .simulate('click');
    cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultValues).toEqual([...[1, 0, 0], ...[0, 0, 0], ...[2, 1, 1]]);
  });
});
