import { defaultStoreState, initStoreState, validate } from './helper'; import { IStoreState } from '../index.data'; import { Props } from './index.data'; import { dissoc } from 'valor-app-utils'; import { getRowWithCells_subtree } from '../commands/helper'; describe('validate', () => { it('columns与rows.item长度不匹配', () => { const props = { columns: [{ width: 10 }], rows: [{ id: 1, cells: [{ id: 1, rowspan: 2, colspan: 2 }, null] }], }; expect(() => validate(props)).toThrow(); }); it('rows.item的长度应全部相等', () => { const props = { columns: [{ width: 10 }, { width: 0 }], rows: [ { id: 1, cells: [{ id: 1, rowspan: 2, colspan: 2 }, null] }, { id: 1, cells: [{ id: 1, rowspan: 2, colspan: 2 }] }, ], }; expect(() => validate(props)).toThrow(); }); }); describe('initStore', () => { const props = { usage: 'editor', columns: [{ width: 10 }, { width: 10 }], rows: [ { id: 1, level: 1, cells: [{ id: 1, rowspan: 2, colspan: 2 }, null] }, { id: 2, level: 1, cells: [null, null] }, { id: 3, level: 2, cells: [{ id: 3, colspan: 2 }, null], }, // 注意这一行与上面的span对不上, 仅供测试 { id: 4, level: 1, cells: [null, { id: 4 }] }, ], }; const expected: IStoreState = { ...defaultStoreState, rows: [ { id: 1, level: 1, i: 0, cellIds: [1, null] }, { id: 2, level: 1, i: 1, cellIds: [null, null] }, { id: 3, level: 2, i: 2, cellIds: [3, null], }, { id: 4, level: 1, i: 3, cellIds: [null, 4], }, ], columns: [{ id: 0, width: 10, j: 0 }, { id: 1, width: 10, j: 1 }], cells: { 1: { id: 1, rowspan: 2, colspan: 2, rowId: 1, i: 0, j: 0 }, 3: { id: 3, colspan: 2, rowId: 3, i: 2, j: 0 }, 4: { id: 4, rowId: 4, i: 3, j: 1 }, }, rowDimensions: { 1: { height: 30, offsetHeight: 30, top: 0, offsetTop: 0 }, 2: { height: 30, offsetHeight: 30, top: 30, offsetTop: 30 }, 3: { height: 30, offsetHeight: 30, top: 60, offsetTop: 60 }, 4: { height: 30, offsetHeight: 30, top: 90, offsetTop: 90 }, }, colDimensions: { 0: { left: 0, offsetLeft: 0, offsetWidth: 10, width: 10 }, 1: { left: 10, offsetLeft: 10, offsetWidth: 10, width: 10 }, }, }; const { cells, treeContext, ...rest } = initStoreState(props); it('default', () => { expect({ ...rest, cells: dissoc(cells, 'value') }).toEqual(dissoc(expected, 'treeContext')); }); });