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

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

describe('PushRowCommand', () => {
  it('行2升级', () => {
    const wrapper = mount(<Story env="test" />);

    // 选中第2行第1个单元格
    selectCell(wrapper, 2);
    wrapper
      .find('#moveLeftRow2')
      .at(0)
      .simulate('click');
    let cellInfo = getCellsInfo(wrapper, false);
    expect(cellInfo.resultValues).toEqual(['一', '二', '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', '三']);
  });
});

describe('PushRowCommand', () => {
  it('行2降级', () => {
    const wrapper = mount(<Story env="test" />);

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

describe('PushRowCommand', () => {
  it('行4升级', () => {
    const wrapper = mount(<Story env="test" />);

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

    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', '2']);
  });
});
