import { Assertions, Chain, FocusTools, GeneralSteps, Keys, Mouse, Step, Pipeline, UiControls, UiFinder, Waiter, ApproxStructure } from '@ephox/agar'; import { UnitTest } from '@ephox/bedrock'; import { TinyActions, TinyApis, TinyDom, TinyLoader } from '@ephox/mcagar'; import ContextMenuPlugin from 'tinymce/plugins/contextmenu/Plugin'; import ImagePlugin from 'tinymce/plugins/image/Plugin'; import LinkPlugin from 'tinymce/plugins/link/Plugin'; import PastePlugin from 'tinymce/plugins/paste/Plugin'; import TablePlugin from 'tinymce/plugins/table/Plugin'; import TextPatternPlugin from 'tinymce/plugins/textpattern/Plugin'; import InliteTheme from 'tinymce/themes/inlite/Theme'; import Toolbar from '../module/test/Toolbar'; import { SelectorFind, Element } from '@ephox/sugar'; const sAssertTableStructure = (editor, structure) => Step.sync(() => { const table = SelectorFind.descendant(Element.fromDom(editor.getBody()), 'table').getOrDie('Should exist a table'); Assertions.assertStructure('Should be a table the expected structure', structure, table); }); UnitTest.asynctest('browser.core.ThemeTest', function () { const success = arguments[arguments.length - 2]; const failure = arguments[arguments.length - 1]; const dialogRoot = TinyDom.fromDom(document.body); InliteTheme(); ImagePlugin(); TablePlugin(); LinkPlugin(); PastePlugin(); ContextMenuPlugin(); TextPatternPlugin(); const sClickFocusedButton = function (selector) { return GeneralSteps.sequence([ Waiter.sTryUntil( 'Focus was not moved to the expected element', FocusTools.sIsOnSelector('Is not on the right element', TinyDom.fromDom(document), selector), 10, 1000 ), Chain.asStep(TinyDom.fromDom(document), [ FocusTools.cGetFocused, Mouse.cTrueClick ]) ]); }; const sBoldTests = function (tinyApis) { return GeneralSteps.sequence([ tinyApis.sSetContent('
a
'), tinyApis.sSetSelection([0, 0], 0, [0, 0], 1), Toolbar.sClickButton('Bold'), tinyApis.sAssertContent('a
') ]); }; const sH2Tests = function (tinyApis) { return GeneralSteps.sequence([ tinyApis.sSetContent('a
'), tinyApis.sSetSelection([0, 0], 0, [0, 0], 1), Toolbar.sClickButton('Heading 2'), tinyApis.sAssertContent('a
', [0, 0], 0, [0, 0], 1, 'www.site.com', ''), sLinkWithConfirmCancelTest('a
', [0, 0], 0, [0, 0], 1, 'www.site.com', ''), sLinkTest('a
', [0, 0], 0, [0, 0], 1, '#1', ''), sLinkTest('', [0, 0, 0], 0, [0, 0, 0], 1, '#2', ''), sLinkTest('', [0, 0, 0], 0, [0, 0, 0], 1, '', 'a
'), sUnlinkTest('', [0, 0, 0], 0, [0, 0, 0], 1, 'a
') ]); }; const sInsertTableTests = function (editor, tinyApis) { return GeneralSteps.sequence([ tinyApis.sSetContent('b
'), tinyApis.sSetCursor([0], 0), Toolbar.sClickButton('Insert table'), sAssertTableStructure(editor, ApproxStructure.fromHtml([ 'a
'), tinyApis.sSetSelection([0, 0], 0, [0, 0], 1), Toolbar.sWaitForToolbar(), tinyActions.sContentKeydown(121, { alt: true }), sClickFocusedButton('*[aria-label="Bold"]'), tinyApis.sAssertContent('a
') ]); }; TinyLoader.setup(function (editor, onSuccess, onFailure) { const tinyApis = TinyApis(editor), tinyActions = TinyActions(editor); Pipeline.async({}, [ tinyApis.sFocus, sBoldTests(tinyApis), sH2Tests(tinyApis), sLinkTests(tinyApis, tinyActions), sInsertTableTests(editor, tinyApis), sAriaTests(tinyApis, tinyActions) ], onSuccess, onFailure); }, { theme: 'inlite', plugins: 'image table link paste contextmenu textpattern', insert_toolbar: 'quickimage media quicktable', selection_toolbar: 'bold italic | quicklink h1 h2 blockquote', inline: true, skin_url: '/project/js/tinymce/skins/lightgray' }, success, failure); });