import { afterEach, beforeEach, context, describe, it } from '@ephox/bedrock-client'; import { TinyAssertions, TinyContentActions, TinyHooks, TinySelections } from '@ephox/wrap-mcagar'; import Editor from 'tinymce/core/api/Editor'; describe('browser.tinymce.selection.NoneditableRootElementSelectionTest', () => { const hook = TinyHooks.bddSetupLight({ indent: false, base_url: '/project/tinymce/js/tinymce' }, []); beforeEach(() => { const editor = hook.editor(); editor.getBody().contentEditable = 'false'; }); afterEach(() => { const editor = hook.editor(); editor.getBody().contentEditable = 'true'; }); const assertElementSelection = (editor: Editor, expected: number) => { TinyAssertions.assertContentPresence(editor, { '[data-mce-selected]': expected }); }; context('Clicking elements', () => { const testClickElement = (testCase: { input: string; selector: string; expected: number }) => () => { const editor = hook.editor(); editor.setContent(testCase.input); TinyContentActions.trueClickOn(editor, testCase.selector); assertElementSelection(editor, testCase.expected); }; it('TINY-9473: Clicking on a image inside a noneditable root should not select it', testClickElement({ input: '

', selector: 'img', expected: 0 })); it('TINY-9473: Clicking on a hr inside a noneditable root should not select it', testClickElement({ input: '
', selector: 'hr', expected: 0 })); it('TINY-9473: Clicking on a cef inside a noneditable root should not select it', testClickElement({ input: '
noneditable
', selector: 'div', expected: 0 })); it('TINY-9473: Clicking on a cef inside a editable element inside a noneditable root should select it', testClickElement({ input: '
editable
', selector: 'div[contenteditable="false"]', expected: 1 })); }); context('Selecting elements using selection apis', () => { const testSelectElement = (testCase: { input: string; selector: string; expected: number }) => () => { const editor = hook.editor(); editor.setContent(testCase.input); TinySelections.select(editor, testCase.selector, []); editor.nodeChanged(); // Workaround for the async nature of selectionchange assertElementSelection(editor, testCase.expected); }; it('TINY-9473: Selecting a image inside a noneditable root should not select it', testSelectElement({ input: '

', selector: 'img', expected: 0 })); it('TINY-9473: Selecting a hr inside a noneditable root should not select it', testSelectElement({ input: '
', selector: 'hr', expected: 0 })); it('TINY-9473: Selecting a cef inside a noneditable root should not select it', testSelectElement({ input: '
', selector: 'div', expected: 0 })); it('TINY-9473: Selecting a cef inside a editable element inside a noneditable root should select it', testSelectElement({ input: '
editable
', selector: 'div[contenteditable="false"]', expected: 1 })); it('TINY-9473: Selecting a element inside a table inside a noneditable root should not select it', testSelectElement({ input: '
table
', selector: 'em', expected: 0 })); }); });