import { ApproxStructure } from '@ephox/agar'; import { describe, it } from '@ephox/bedrock-client'; import { TinyAssertions, TinyHooks, TinySelections } from '@ephox/wrap-mcagar'; import { assert } from 'chai'; import Editor from 'tinymce/core/api/Editor'; import * as BlockRangeDelete from 'tinymce/core/delete/BlockRangeDelete'; describe('browser.tinymce.core.delete.BlockRangeDeleteTest', () => { const hook = TinyHooks.bddSetupLight({ base_url: '/project/tinymce/js/tinymce', indent: false }, [], true); const doDelete = (editor: Editor) => { const returnVal = BlockRangeDelete.backspaceDelete(editor, true); returnVal.each((apply) => apply()); assert.isTrue(returnVal.isSome(), 'Should return true since the operation should have done something'); }; const noopDelete = (editor: Editor) => { const returnVal = BlockRangeDelete.backspaceDelete(editor, true); assert.isFalse(returnVal.isSome(), 'Should return false since the operation is a noop'); }; const doBackspace = (editor: Editor) => { const returnVal = BlockRangeDelete.backspaceDelete(editor, false); returnVal.each((apply) => apply()); assert.isTrue(returnVal.isSome(), 'Should return true since the operation should have done something'); }; const noopBackspace = (editor: Editor) => { const returnVal = BlockRangeDelete.backspaceDelete(editor, false); assert.isFalse(returnVal.isSome(), 'Should return false since the operation is a noop'); }; it('Backspace on collapsed range should be a noop', () => { const editor = hook.editor(); editor.setContent('

a

'); TinySelections.setCursor(editor, [ 0, 0 ], 1); noopBackspace(editor); TinyAssertions.assertContent(editor, '

a

'); TinyAssertions.assertSelection(editor, [ 0, 0 ], 1, [ 0, 0 ], 1); }); it('Delete on collapsed range should be a noop', () => { const editor = hook.editor(); editor.setContent('

a

'); TinySelections.setCursor(editor, [ 0, 0 ], 1); noopDelete(editor); TinyAssertions.assertContent(editor, '

a

'); TinyAssertions.assertSelection(editor, [ 0, 0 ], 1, [ 0, 0 ], 1); }); it('Backspace on range between simple blocks should merge', () => { const editor = hook.editor(); editor.setContent('

a

b

'); TinySelections.setSelection(editor, [ 0, 0 ], 1, [ 1, 0 ], 0); doBackspace(editor); TinyAssertions.assertContent(editor, '

ab

'); TinyAssertions.assertSelection(editor, [ 0, 0 ], 1, [ 0, 0 ], 1); }); it('Delete on range between simple blocks should merge', () => { const editor = hook.editor(); editor.setContent('

a

b

'); TinySelections.setSelection(editor, [ 0, 0 ], 1, [ 1, 0 ], 0); doDelete(editor); TinyAssertions.assertContent(editor, '

ab

'); TinyAssertions.assertSelection(editor, [ 0, 0 ], 1, [ 0, 0 ], 1); }); it('Backspace from red span to h1 should merge', () => { const editor = hook.editor(); editor.setContent('

ab

cd

'); TinySelections.setSelection(editor, [ 0, 0 ], 1, [ 1, 0, 0 ], 1); doBackspace(editor); TinyAssertions.assertContent(editor, '

ad

'); TinyAssertions.assertSelection(editor, [ 0, 0 ], 1, [ 0, 0 ], 1); }); it('Delete from red span to h1 should merge', () => { const editor = hook.editor(); editor.setContent('

ab

cd

'); TinySelections.setSelection(editor, [ 0, 0, 0 ], 1, [ 1, 0 ], 1); doDelete(editor); TinyAssertions.assertContent(editor, '

ad

'); TinyAssertions.assertSelection(editor, [ 0, 0, 0 ], 1, [ 0, 0, 0 ], 1); }); it('Delete from li to li should merge', () => { const editor = hook.editor(); editor.setContent(''); TinySelections.setSelection(editor, [ 0, 0, 0 ], 1, [ 0, 1, 0 ], 1); doDelete(editor); TinyAssertions.assertContent(editor, ''); TinyAssertions.assertSelection(editor, [ 0, 0, 0 ], 1, [ 0, 0, 0 ], 1); }); it('Delete from nested li to li should merge', () => { const editor = hook.editor(); editor.setContent(''); TinySelections.setSelection(editor, [ 0, 0, 0 ], 1, [ 0, 0, 1, 0, 0 ], 1); doDelete(editor); TinyAssertions.assertContent(editor, ''); TinyAssertions.assertSelection(editor, [ 0, 0, 0 ], 1, [ 0, 0, 0 ], 1); }); it('Delete from li to nested li should merge', () => { const editor = hook.editor(); editor.setContent(''); TinySelections.setSelection(editor, [ 0, 0, 1, 0, 0 ], 1, [ 0, 1, 0 ], 1); doDelete(editor); TinyAssertions.assertContent(editor, ''); TinyAssertions.assertSelection(editor, [ 0, 0, 1, 0, 0 ], 1, [ 0, 0, 1, 0, 0 ], 1); }); it('Delete from deep nested li to li should merge', () => { const editor = hook.editor(); editor.setContent('