import { Cursors, Mouse } from '@ephox/agar'; import { describe, it } from '@ephox/bedrock-client'; import { SugarElement } from '@ephox/sugar'; import { TinyAssertions, TinyHooks, TinySelections } from '@ephox/wrap-mcagar'; import { assert } from 'chai'; import DOMUtils from 'tinymce/core/api/dom/DOMUtils'; import Editor from 'tinymce/core/api/Editor'; import { findClosestBlockRange } from 'tinymce/core/selection/MultiClickSelection'; import * as ViewBlock from '../../module/test/ViewBlock'; describe('browser.tinymce.core.selection.MultiClickSelectionTest', () => { describe('findClosestBlockRange test', () => { const DOM = DOMUtils.DOM; const viewBlock = ViewBlock.bddSetup(); const getRoot = viewBlock.get; const setupHtml = viewBlock.update; const toDomRange = (path: Cursors.CursorPath): Range => { const root = SugarElement.fromDom(getRoot()); const range = Cursors.calculate(root, path); const domRng = DOM.createRng(); domRng.setStart(range.start.dom, range.soffset); domRng.setEnd(range.finish.dom, range.foffset); return domRng; }; const assertRange = (expected: Range, actual: Range) => { assert.strictEqual(actual.startContainer, expected.startContainer, 'startContainers should be equal'); assert.strictEqual(actual.startOffset, expected.startOffset, 'startOffset should be equal'); assert.strictEqual(actual.endContainer, expected.endContainer, 'endContainer should be equal'); assert.strictEqual(actual.endOffset, expected.endOffset, 'endOffset should be equal'); }; const testFindClosestBlockRange = (startRngPath: Cursors.CursorPath, expectedRngPath: Cursors.CursorPath) => assertRange(toDomRange(expectedRngPath), findClosestBlockRange(toDomRange(startRngPath), getRoot())); it('TINY-8215: Should return the range with the whole text content of the block', () => { setupHtml('
aaa bIb ccc
'); testFindClosestBlockRange({ startPath: [ 0, 0 ], soffset: 4, finishPath: [ 0, 0 ], foffset: 7 }, { startPath: [ 0, 0 ], soffset: 0, finishPath: [ 0, 0 ], foffset: 11 }); }); it('TINY-8215: Should return the range expanded from the block start to the next closestaaa bIb ccc
ddd
aaa
bbb cIc ddd
aaa
bbb cIc ddd
eee
aaa bbb ccc
ddd
aaa bIb
'); testFindClosestBlockRange({ startPath: [ 0, 1 ], soffset: 1, finishPath: [ 0, 1 ], foffset: 4 }, { startPath: [ 0 ], soffset: 0, finishPath: [ 0, 1 ], foffset: 4 }); }); it('TINY-8215: Should set end of the range right after cef element if the last caret candidate is within it', () => { setupHtml('aIa bbb
ccc
aaabbb cIc dddeee
'); testFindClosestBlockRange({ startPath: [ 0, 1, 0 ], soffset: 4, finishPath: [ 0, 1, 0 ], foffset: 7 }, { startPath: [ 0, 1, 0 ], soffset: 0, finishPath: [ 0, 1, 0 ], foffset: 11 }); }); it('TINY-8215: Should include nested cef element to range scoped with cet element', () => { setupHtml('aaabbb ccc dddeee
'); testFindClosestBlockRange({ startPath: [ 0 ], soffset: 1, finishPath: [ 0 ], foffset: 2 }, { startPath: [ 0, 0 ], soffset: 0, finishPath: [ 0, 2 ], foffset: 3 }); }); }); describe('fake multi click browser test', () => { const hook = TinyHooks.bddSetupLightabc
'); const target = editor.dom.select('p')[0]; TinySelections.setSelection(editor, [ 0 ], 0, [ 0 ], 1); fakeMultiClick( clickCount, target); TinyAssertions.assertSelection(editor, [ 0, 0 ], 0, [ 0, 0 ], 3); }); it(`Normalize selection start in text node end after paragraph with ${clickCount} clicks`, () => { const editor = hook.editor(); editor.setContent('abc
'); const target = editor.dom.select('p')[0]; TinySelections.setSelection(editor, [ 0, 0 ], 0, [], 1); fakeMultiClick( clickCount, target); TinyAssertions.assertSelection(editor, [ 0, 0 ], 0, [ 0, 0 ], 3); }); } it('TINY-8215: Should select the content afteraaa
cIc ddd
aaa bbb
ccc