/** * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ import PasteFromOffice from '../src/pastefromoffice'; import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard'; import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor'; import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor'; import { createDataTransfer } from './_utils/utils'; import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils'; describe( 'PasteFromOffice', () => { let editor, pasteFromOffice, clipboard; testUtils.createSinonSandbox(); beforeEach( () => { return VirtualTestEditor.create( { plugins: [ PasteFromOffice ] } ) .then( _editor => { editor = _editor; pasteFromOffice = editor.plugins.get( 'PasteFromOffice' ); clipboard = editor.plugins.get( 'Clipboard' ); } ); } ); it( 'should be loaded', () => { expect( pasteFromOffice ).to.be.instanceOf( PasteFromOffice ); } ); it( 'has proper name', () => { expect( PasteFromOffice.pluginName ).to.equal( 'PasteFromOffice' ); } ); it( 'should load Clipboard plugin', () => { expect( editor.plugins.get( Clipboard ) ).to.be.instanceOf( Clipboard ); } ); describe( 'isTransformedWithPasteFromOffice - flag', () => { const htmlDataProcessor = new HtmlDataProcessor(); describe( 'data which should be processed', () => { [ { 'text/html': '
' }, { 'text/html': '' }, { 'text/html': '' } ].forEach( ( inputData, index ) => { it( `should mark data as transformed with paste from office - data set: #${ index }`, () => { const data = { content: htmlDataProcessor.toView( inputData[ 'text/html' ] ), dataTransfer: createDataTransfer( inputData ) }; clipboard.fire( 'inputTransformation', data ); expect( data.isTransformedWithPasteFromOffice ).to.be.true; } ); } ); } ); describe( 'not recognized data', () => { [ { 'text/html': 'Hello world
' }, { 'text/html': '' } ].forEach( ( inputData, index ) => { it( `should not modify data set: #${ index }`, () => { const data = { content: htmlDataProcessor.toView( inputData[ 'text/html' ] ), dataTransfer: createDataTransfer( inputData ) }; clipboard.fire( 'inputTransformation', data ); expect( data.isTransformedWithPasteFromOffice ).to.be.undefined; } ); } ); } ); describe( 'already processed data', () => { [ { 'text/html': 'Hello world
' }, { 'text/html': 'Hello world