import { oneLineTrim } from 'common-tags'; import Editor from '@toast-ui/editor'; import { assertWYSIWYGHTML, createEditor } from './helper/utils'; import type { EditorView } from 'prosemirror-view'; import CellSelection from './helper/cellSelection'; let container: HTMLElement, editor: Editor; beforeEach(() => { const editorInfo = createEditor(); container = editorInfo.container; editor = editorInfo.editor; }); afterEach(() => { editor.destroy(); document.body.removeChild(container); }); function setCellSelection(startPos: number, endPos: number) { // @ts-ignore const wwView: EditorView = editor.wwEditor.view; const { tr } = wwView.state; wwView.dispatch!( tr.setSelection(new CellSelection(tr.doc.resolve(startPos), tr.doc.resolve(endPos))) ); } describe('splitCells command', () => { it('should split cells included spanning cell', () => { setCellSelection(37, 131); // select [1, 0] cell(mergedCell1-1 text) to [3, 2](cell3-1 text) editor.exec('splitCells'); const expected = oneLineTrim`

mergedHead1

mergedHead2

mergedCell1-1


cell1-2

mergedCell1-3

mergedCell2-1

mergedCell2-2

cell2-3



cell3-1

cell4-1

cell4

cell4-3

cell5-1

cell5-2

cell5-3

`; assertWYSIWYGHTML(editor, expected); }); it('should split cell(single spanning cell)', () => { editor.setSelection(66, 66); // select [1, 3] cell(mergedCell1-3 text) editor.exec('splitCells'); const expected = oneLineTrim`

mergedHead1

mergedHead2

mergedCell1-1

cell1-2

mergedCell1-3


mergedCell2-1

mergedCell2-2

cell2-3



cell3-1



cell4-1

cell4

cell4-3



cell5-1

cell5-2

cell5-3



`; assertWYSIWYGHTML(editor, expected); }); it('should split cells in case that all cells are spanning on the row', () => { setCellSelection(118, 131); // select [2, 2] cell(cell2-3 text) to [3, 2](cell3-1 text) editor.exec('mergeCells'); editor.exec('splitCells'); const expected = oneLineTrim`

mergedHead1

mergedHead2

mergedCell1-1

cell1-2

mergedCell1-3

mergedCell2-1

mergedCell2-2

cell2-3

cell3-1


cell4-1

cell4

cell4-3

cell5-1

cell5-2

cell5-3

`; assertWYSIWYGHTML(editor, expected); }); });