import { beforeEach, describe, it } from '@ephox/bedrock-client'; import { Fun } from '@ephox/katamari'; import { TinyHooks, TinyUiActions } from '@ephox/wrap-mcagar'; import Editor from 'tinymce/core/api/Editor'; import { DataToHtmlCallback } from 'tinymce/plugins/media/core/DataToHtml'; import Plugin from 'tinymce/plugins/media/Plugin'; import * as Utils from '../module/test/Utils'; describe('browser.tinymce.plugins.media.core.SubmitTest', () => { const hook = TinyHooks.bddSetupLight({ plugins: [ 'media' ], toolbar: 'media', base_url: '/project/tinymce/js/tinymce' }, [ Plugin ]); const mediaUrlResolver = (data: { url: string }, resolve: (data: { html: string }) => void) => { setTimeout(() => { resolve({ html: '' + data.url + '' }); }, 500); }; const customEmbed = '
' + '
'; const pTestResolvedEmbedContentSubmit = async (editor: Editor, url: string, expected: string) => { await Utils.pOpenDialog(editor); await Utils.pSetFormItemNoEvent(editor, url); TinyUiActions.submitDialog(editor); await Utils.pAssertEditorContent(editor, expected); }; const pTestManualEmbedContentSubmit = async (editor: Editor, embed: string, expected: string) => { await Utils.pOpenDialog(editor); await Utils.pPasteTextareaValue(editor, embed); TinyUiActions.submitDialog(editor); await Utils.pAssertEditorContent(editor, expected); }; const pTestEmbedUnchangedAfterOpenCloseDialog = async (editor: Editor, expected: string) => { await Utils.pOpenDialog(editor); TinyUiActions.submitDialog(editor); await Utils.pAssertEditorContent(editor, expected); }; const pTestTemplateCallbackContentSubmit = async (editor: Editor, templateOption: string, templateCallback: DataToHtmlCallback, url: string, expected: string) => { editor.options.set(templateOption, templateCallback); await Utils.pOpenDialog(editor); await Utils.pPasteSourceValue(editor, url); TinyUiActions.submitDialog(editor); await Utils.pAssertEditorContent(editor, expected); editor.options.unset(templateOption); }; beforeEach(() => { hook.editor().setContent(''); }); it('TBA: Open dialog, set url, submit dialog and assert content', async () => { const editor = hook.editor(); editor.options.set('media_url_resolver', mediaUrlResolver); await pTestResolvedEmbedContentSubmit(editor, 'https://www.youtube.com/watch?v=IcgmSRJHu_8', '

https://www.youtube.com/watch?v=IcgmSRJHu_8

' ); }); it('TBA: Remove media_url_resolver setting and assert changed content', async () => { const editor = hook.editor(); editor.options.unset('media_url_resolver'); await pTestResolvedEmbedContentSubmit(editor, 'https://www.youtube.com/watch?v=IcgmSRJHu_8', '

' ); }); it('TBA: Open dialog, set embed content, submit dialog and assert content', async () => { const editor = hook.editor(); editor.options.set('media_url_resolver', mediaUrlResolver); await pTestManualEmbedContentSubmit(editor, customEmbed, customEmbed); editor.options.unset('media_url_resolver'); await pTestEmbedUnchangedAfterOpenCloseDialog(editor, customEmbed); }); it('TBA: Set audio_template_callback and embed content, submit dialog and assert content', async () => { // Audio should be any mp3 link to trigger callback const editor = hook.editor(); const audioTemplateCallback = Fun.constant(''); const expected = '

'; await pTestTemplateCallbackContentSubmit(editor, 'audio_template_callback', audioTemplateCallback, 'https://assets.mixkit.co/music/preview/mixkit-tech-house-vibes-130.mp3', expected); await pTestEmbedUnchangedAfterOpenCloseDialog(editor, expected); }); it('TBA: Set video_template_callback and embed content, submit dialog and assert content', async () => { // Video should be any mp4 link to trigger callback const editor = hook.editor(); const videoTemplateCallback = Fun.constant(''); const expected = '

'; await pTestTemplateCallbackContentSubmit(editor, 'video_template_callback', videoTemplateCallback, 'https://i.imgur.com/Tu4e5WX.mp4', expected); await pTestEmbedUnchangedAfterOpenCloseDialog(editor, expected); }); it('TINY-8684: Set iframe_template_callback and embed content, submit dialog and assert content', async () => { // Any youtube link triggers iframe callback const editor = hook.editor(); const iframeTemplateCallback = Fun.constant(''); const expected = '

'; await pTestTemplateCallbackContentSubmit(editor, 'iframe_template_callback', iframeTemplateCallback, 'https://www.youtube.com/embed/IcgmSRJHu_8', expected); await pTestEmbedUnchangedAfterOpenCloseDialog(editor, expected); }); });