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('mergeCells command', () => { it('should merge cells included spanning cell', () => { setCellSelection(37, 131); // select [1, 0] cell(mergedCell1-1 text) to [3, 2](cell3-1 text) editor.exec('mergeCells'); const expected = oneLineTrim`

mergedHead1

mergedHead2

mergedCell1-1

cell1-2

mergedCell2-1

mergedCell2-2

cell2-3

cell3-1

mergedCell1-3

cell4-1

cell4

cell4-3

cell5-1

cell5-2

cell5-3

`; assertWYSIWYGHTML(editor, expected); }); it('should merge cells(normal cells)', () => { setCellSelection(54, 131); // select [1, 2] cell(cell1-2 text) to [3, 2](cell3-1 text) editor.exec('mergeCells'); const expected = oneLineTrim`

mergedHead1

mergedHead2

mergedCell1-1

cell1-2

cell2-3

cell3-1

mergedCell1-3

mergedCell2-1

mergedCell2-2

cell4-1

cell4

cell4-3

cell5-1

cell5-2

cell5-3

`; assertWYSIWYGHTML(editor, expected); }); it('should not merge cells in case of selecting all cells', () => { setCellSelection(37, 65); // select all body cells editor.exec('mergeCells'); 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 not merge cells in case of selecting head cells', () => { setCellSelection(1, 37); // select [0, 0](mergedHead1 text) cellto [1, 0](mergedCell1-1 text) editor.exec('mergeCells'); 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); }); });