import { afterEach, describe, it } from '@ephox/bedrock-client';
import { TinyHooks } from '@ephox/wrap-mcagar';
import { assert } from 'chai';
import Editor from 'tinymce/core/api/Editor';
import Env from 'tinymce/core/api/Env';
import Plugin from 'tinymce/plugins/template/Plugin';
import { getPreviewContent } from 'tinymce/plugins/template/ui/Dialog';
import { Settings } from '../module/Settings';
const metaKey = Env.os.isMacOS() || Env.os.isiOS() ? 'e.metaKey' : 'e.ctrlKey && !e.altKey';
const host = document.location.host;
const noCorsNoStyle = '
' +
`` +
`` +
`` +
' ' +
'';
const corsNoStyle = '' +
`` +
`` +
`` +
' ';
const noCorsStyle = '' +
`` +
`` +
`` +
'' +
' ' +
'';
const corsStyle = '' +
`` +
`` +
`` +
'' +
' ' +
'';
const corsStyleAndContent = '' +
`` +
`` +
`` +
'' +
' ' +
'' +
'Custom content which was provided
';
describe('browser.tinymce.plugins.template.Dialog.getPreviewContent', () => {
const hook = TinyHooks.bddSetupLight({
plugins: 'template',
base_url: '/project/tinymce/js/tinymce'
}, [ Plugin ]);
const checkPreview = (expected: string, html: string = '') => {
const editor = hook.editor();
assert.equal(expected, getPreviewContent(editor, html));
};
const { addSettings, cleanupSettings } = Settings(hook);
afterEach(() => {
cleanupSettings();
});
it('TINY-6115: Dialog.getPreviewContent: No CORS or content style, no previous HTML', () => {
checkPreview(noCorsNoStyle);
});
it('TINY-6115: Dialog.getPreviewContent: CORS but no content style, no previous HTML', () => {
addSettings({ content_css_cors: true });
checkPreview(corsNoStyle);
});
it('TINY-6115: Dialog.getPreviewcontent: No CORS but content style, no previous HTML', () => {
addSettings({ content_style: 'This is the style inserted into the document' });
checkPreview(noCorsStyle);
});
it('TINY-6115: Dialog.getPreviewContent: No CORS but content style, no previous HTML', () => {
addSettings({
content_css_cors: true,
content_style: 'This is the style inserted into the document'
});
checkPreview(corsStyle);
});
it('TINY-6115: Dialog.getPreviewContent: with provided content', () => {
addSettings({
content_css_cors: true,
content_style: 'This is the style inserted into the document'
});
checkPreview(corsStyleAndContent, 'Custom content which was provided');
});
it('TINY-6115: Dialog.getPreviewContent: with provided html', () => {
addSettings({
content_css_cors: true,
content_style: 'This is the style inserted into the document'
});
checkPreview('Custom content here', 'Custom content here');
});
});