|
|
@@ -7,6 +7,7 @@ import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
|
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
|
import DocumentFragment from '@ckeditor/ckeditor5-engine/src/view/documentfragment';
|
|
|
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
|
+import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
|
|
|
|
|
|
import PasteFromOffice from '../src/pastefromoffice';
|
|
|
import { createDataTransfer } from './_utils/utils';
|
|
|
@@ -32,6 +33,10 @@ describe( 'Paste from Office plugin', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
+ afterEach( () => {
|
|
|
+ editor.destroy();
|
|
|
+ } );
|
|
|
+
|
|
|
it( 'runs normalizations if Word meta tag detected #1', () => {
|
|
|
const dataTransfer = createDataTransfer( {
|
|
|
'text/html': '<meta name=Generator content="Microsoft Word 15">'
|
|
|
@@ -88,4 +93,69 @@ describe( 'Paste from Office plugin', () => {
|
|
|
expect( normalizeSpy.calledOnce ).to.true;
|
|
|
} );
|
|
|
} );
|
|
|
+
|
|
|
+ describe( '_normalizeGoogleDocsInput()', () => {
|
|
|
+ before( () => {
|
|
|
+ content = new DocumentFragment();
|
|
|
+ } );
|
|
|
+
|
|
|
+ beforeEach( () => {
|
|
|
+ return VirtualTestEditor
|
|
|
+ .create( {
|
|
|
+ plugins: [ Clipboard, PasteFromOffice ]
|
|
|
+ } )
|
|
|
+ .then( newEditor => {
|
|
|
+ editor = newEditor;
|
|
|
+ normalizeSpy = testUtils.sinon.spy( PasteFromOffice, '_normalizeGoogleDocsInput' );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ afterEach( () => {
|
|
|
+ editor.destroy();
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'runs normalizations if Google docs meta tag detected #1', () => {
|
|
|
+ const fakeClipboardData = '<meta charset=\'utf-8\'><meta charset="utf-8"><b style="font-weight:normal;"' +
|
|
|
+ ' id="docs-internal-guid-45309eee-7fff-33a3-6dbd-a7e55da535b5"></b>';
|
|
|
+ const dataTransfer = createDataTransfer( {
|
|
|
+ 'text/html': fakeClipboardData
|
|
|
+ } );
|
|
|
+ const htmlDataProcessor = new HtmlDataProcessor();
|
|
|
+ const content = htmlDataProcessor.toView( fakeClipboardData );
|
|
|
+
|
|
|
+ editor.plugins.get( 'Clipboard' ).fire( 'inputTransformation', { content, dataTransfer } );
|
|
|
+
|
|
|
+ expect( normalizeSpy.calledOnce ).to.true;
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+
|
|
|
+ describe( '_getInputType()', () => {
|
|
|
+ [
|
|
|
+ {
|
|
|
+ input: '<html><head><meta name="Generator" content=Microsoft Word 15></head></html>',
|
|
|
+ output: 'msword'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ input: '<meta name=Generator content="Microsoft Word 15"></meta>',
|
|
|
+ output: 'msword'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ input: '<meta name=Generator content="Other"></meta>',
|
|
|
+ output: null
|
|
|
+ },
|
|
|
+ {
|
|
|
+ input: '<meta charset=\'utf-8\'><meta charset="utf-8"><b style="font-weight:normal;"' +
|
|
|
+ ' id="docs-internal-guid-45309eee-7fff-33a3-6dbd-a7e55da535b5"></b>',
|
|
|
+ output: 'gdocs'
|
|
|
+ }
|
|
|
+ ].forEach( ( value, index ) => {
|
|
|
+ it( `should return proper input type for test case: #${ index }.`, () => {
|
|
|
+ if ( value.output ) {
|
|
|
+ expect( PasteFromOffice._getInputType( value.input ) ).to.equal( value.output );
|
|
|
+ } else {
|
|
|
+ expect( PasteFromOffice._getInputType( value.input ) ).to.be.null;
|
|
|
+ }
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
} );
|