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

mockResizeObserver();

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

describe('<DeleteColumnCommand/>', () => {
  it('j=0处删除', () => {
    const wrapper = mount(<Story env="test" />);

    let cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultIds).toEqual([...[11, 13], ...[21]]);
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

    wrapper
      .find('#deleteColumnAt0')
      .at(0)
      .simulate('click');

    cellInfo = getCellsInfo(wrapper);
    // 因为id是动态生成的, 所以无法判断了, 直接使用equals
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

    wrapper
      .find('#undo')
      .at(0)
      .simulate('click');
    cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultIds).toEqual([...[11, 13], ...[21]]);
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

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

describe('<DeleteColumnCommand/>', () => {
  it('j=1处删除', () => {
    const wrapper = mount(<Story env="test" />);

    let cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultIds).toEqual([...[11, 13], ...[21]]);
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

    wrapper
      .find('#deleteColumnAt1')
      .at(0)
      .simulate('click');

    cellInfo = getCellsInfo(wrapper);
    // 因为id是动态生成的, 所以无法判断了, 直接使用equals
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

    wrapper
      .find('#undo')
      .at(0)
      .simulate('click');
    cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultIds).toEqual([...[11, 13], ...[21]]);
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

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

describe('<DeleteColumnCommand/>', () => {
  it('j=2处删除', () => {
    const wrapper = mount(<Story env="test" />);

    let cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultIds).toEqual([...[11, 13], ...[21]]);
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

    wrapper
      .find('#deleteColumnAt2')
      .at(0)
      .simulate('click');

    cellInfo = getCellsInfo(wrapper);
    // 因为id是动态生成的, 所以无法判断了, 直接使用equals
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

    wrapper
      .find('#undo')
      .at(0)
      .simulate('click');
    cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultIds).toEqual([...[11, 13], ...[21]]);
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

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

describe('<DeleteColumnCommand/>', () => {
  it('j=3处删除', () => {
    const wrapper = mount(<Story env="test" />);

    let cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultIds).toEqual([...[11, 13], ...[21]]);
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

    wrapper
      .find('#deleteColumnAt3')
      .at(0)
      .simulate('click');

    cellInfo = getCellsInfo(wrapper);
    // 因为id是动态生成的, 所以无法判断了, 直接使用equals
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

    wrapper
      .find('#undo')
      .at(0)
      .simulate('click');
    cellInfo = getCellsInfo(wrapper);
    expect(cellInfo.resultIds).toEqual([...[11, 13], ...[21]]);
    expect(cellInfo.resultValues).toEqual([...[1, 1], ...[1]]);

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