import { Assertions, GeneralSteps, Pipeline, Step, Waiter } from '@ephox/agar'; import { UnitTest } from '@ephox/bedrock'; import { Arr } from '@ephox/katamari'; import { LegacyUnit, TinyLoader } from '@ephox/mcagar'; import Plugin from 'tinymce/plugins/fullpage/Plugin'; import Theme from 'tinymce/themes/modern/Theme'; UnitTest.asynctest('browser.tinymce.plugins.fullpage.FullPagePluginTest', function () { const success = arguments[arguments.length - 2]; const failure = arguments[arguments.length - 1]; const suite = LegacyUnit.createSuite(); Plugin(); Theme(); const teardown = function (editor) { editor.getBody().rtl = ''; }; suite.test('Keep header/footer intact', function (editor) { const normalizeHTML = function (html) { return html.replace(/\s/g, ''); }; editor.setContent('

Test

'); LegacyUnit.equal(normalizeHTML(editor.getContent()), '

Test

', 'Invalid HTML content is still editable.'); editor.setContent('

Test

'); LegacyUnit.equal(normalizeHTML(editor.getContent()), '

Test

', 'Header/footer is intact.'); }); suite.test('Default header/footer', function (editor) { editor.setContent('

Test

'); LegacyUnit.equal( editor.getContent(), '\n\n\n\n\n

Test

\n\n', 'Invalid HTML content is still editable.' ); }); suite.test('Parse body attributes', function (editor) { editor.setContent('

Test

'); LegacyUnit.equal(editor.getBody().style.color, '', 'No color on body.'); LegacyUnit.equal(editor.getBody().dir, '', 'No dir on body.'); LegacyUnit.equal(editor.dom.getStyle(editor.getBody().firstChild, 'display', true), 'block', 'No styles added to iframe document'); editor.setContent('

Test

'); LegacyUnit.equal(editor.getBody().style.color.length > 0, true, 'Color added to body'); editor.setContent('

Test

'); LegacyUnit.equal(editor.getBody().dir, 'rtl', 'Dir added to body'); editor.setContent('

Test

'); LegacyUnit.equal(editor.getBody().style.color, '', 'No color on body.'); LegacyUnit.equal(editor.getBody().dir, '', 'No dir on body.'); LegacyUnit.equal(editor.dom.getStyle(editor.getBody().firstChild, 'display', true), 'block', 'No styles added to iframe document'); }); suite.test('fullpage_hide_in_source_view: false', function (editor) { editor.settings.fullpage_hide_in_source_view = false; editor.setContent('

1

'); LegacyUnit.equal(editor.getContent({ source_view: true }), '\n

1

\n'); }); suite.test('fullpage_hide_in_source_view: false', function (editor) { editor.settings.fullpage_hide_in_source_view = true; editor.setContent('

1

'); LegacyUnit.equal(editor.getContent({ source_view: true }), '

1

'); }); suite.test('link elements', function (editor) { editor.setContent('

c

'); LegacyUnit.equal( editor.getContent(), '\n

c

\n' ); }); suite.test('add/remove stylesheets', function (editor) { const hasLink = function hasink(href) { const links = editor.getDoc().getElementsByTagName('link'); for (let i = 0; i < links.length; i++) { if (links[i].href.indexOf('/' + href) !== -1) { return true; } } return false; }; editor.setContent('

c

'); LegacyUnit.equal(hasLink('a.css'), true); LegacyUnit.equal(hasLink('b.css'), false); LegacyUnit.equal(hasLink('c.css'), false); editor.setContent( '

c

' ); LegacyUnit.equal(hasLink('a.css'), true); LegacyUnit.equal(hasLink('b.css'), true); LegacyUnit.equal(hasLink('c.css'), false); editor.setContent( '' + '' + '' + '' + '' + '

c

' ); LegacyUnit.equal(hasLink('a.css'), true); LegacyUnit.equal(hasLink('b.css'), true); LegacyUnit.equal(hasLink('c.css'), true); editor.setContent('

c

'); LegacyUnit.equal(hasLink('a.css'), true); LegacyUnit.equal(hasLink('b.css'), false); LegacyUnit.equal(hasLink('c.css'), false); editor.setContent('

c

'); LegacyUnit.equal(hasLink('a.css'), false); LegacyUnit.equal(hasLink('b.css'), false); LegacyUnit.equal(hasLink('c.css'), false); }); const sParseStyles = function (editor) { return GeneralSteps.sequence([ Step.sync(function () { editor.setContent('

Test

'); }), Waiter.sTryUntil( 'Expected styles where not added', Step.sync(function () { Assertions.assertEq('Styles added to iframe document', 'right', editor.dom.getStyle(editor.getBody().firstChild, 'text-align', true)); } ), 10, 3000) ]); }; const sProtectConditionalCommentsInHeadFoot = function (editor) { return GeneralSteps.sequence([ Step.sync(function () { editor.setContent([ '', '', '', '', '', '

text

', '', '' ].join('\n')); }), Step.sync(function () { const expectedContent = [ '', '', '', '', '', '

text

', '', '' ].join('\n'); Assertions.assertHtml('Styles added to iframe document', expectedContent, editor.getContent()); }) ]); }; TinyLoader.setup(function (editor, onSuccess, onFailure) { Pipeline.async({}, Arr.flatten([ [ sParseStyles(editor), sProtectConditionalCommentsInHeadFoot(editor) ], suite.toSteps(editor) ]), onSuccess, onFailure); teardown(editor); }, { plugins: 'fullpage', indent: false, skin_url: '/project/js/tinymce/skins/lightgray', protect: [ //g ] }, success, failure); });