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 { mockResizeObserver } from 'valor-app-utils';
import { getCellsInfo, selectCell } from '../helper';
import { ID } from '../../../index.data';

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

describe('PushRowCommand', () => {
  it('行1上移(无效)', () => {
    const wrapper = mount(<Story env="test" />);

    // 选中第2行第1个单元格
    selectCell(wrapper, 1);
    wrapper
      .find('#moveUpRow1')
      .at(0)
      .simulate('click');
    let cellInfo = getCellsInfo(wrapper, false);
    expect(cellInfo.resultValues).toEqual(['一', '1', '1.1', '二']);

    wrapper
      .find('#undo')
      .at(0)
      .simulate('click');
    cellInfo = getCellsInfo(wrapper, false);
    expect(cellInfo.resultValues).toEqual(['一', '1', '1.1', '二']);

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

  it('行1下移', () => {
    const wrapper = mount(<Story env="test" />);

    // 选中第2行第1个单元格
    selectCell(wrapper, 1);
    wrapper
      .find('#moveDownRow1')
      .at(0)
      .simulate('click');
    let cellInfo = getCellsInfo(wrapper, false);
    expect(cellInfo.resultValues).toEqual(['一', '二', '1', '1.1']);

    wrapper
      .find('#undo')
      .at(0)
      .simulate('click');
    cellInfo = getCellsInfo(wrapper, false);
    expect(cellInfo.resultValues).toEqual(['一', '1', '1.1', '二']);

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

  it('行4下移(无效)', () => {
    const wrapper = mount(<Story env="test" />);

    // 选中第2行第1个单元格
    selectCell(wrapper, 4);
    wrapper
      .find('#moveDownRow4')
      .at(0)
      .simulate('click');
    let cellInfo = getCellsInfo(wrapper, false);
    expect(cellInfo.resultValues).toEqual(['一', '1', '1.1', '二']);

    wrapper
      .find('#undo')
      .at(0)
      .simulate('click');
    cellInfo = getCellsInfo(wrapper, false);
    expect(cellInfo.resultValues).toEqual(['一', '1', '1.1', '二']);

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