pastefromoffice.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  6. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  7. import DocumentFragment from '@ckeditor/ckeditor5-engine/src/view/documentfragment';
  8. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  9. import PasteFromOffice from '../src/pastefromoffice';
  10. import { createDataTransfer } from './_utils/utils';
  11. describe( 'Paste from Office plugin', () => {
  12. let editor, content, normalizeSpy;
  13. testUtils.createSinonSandbox();
  14. before( () => {
  15. content = new DocumentFragment();
  16. } );
  17. beforeEach( () => {
  18. return VirtualTestEditor
  19. .create( {
  20. plugins: [ Clipboard, PasteFromOffice ]
  21. } )
  22. .then( newEditor => {
  23. editor = newEditor;
  24. normalizeSpy = testUtils.sinon.spy( editor.plugins.get( 'PasteFromOffice' ), '_normalizeWordInput' );
  25. } );
  26. } );
  27. it( 'runs normalizations if Word meta tag detected #1', () => {
  28. const dataTransfer = createDataTransfer( {
  29. 'text/html': '<meta name=Generator content="Microsoft Word 15">'
  30. } );
  31. editor.plugins.get( 'Clipboard' ).fire( 'inputTransformation', { content, dataTransfer } );
  32. expect( normalizeSpy.calledOnce ).to.true;
  33. } );
  34. it( 'runs normalizations if Word meta tag detected #2', () => {
  35. const dataTransfer = createDataTransfer( {
  36. 'text/html': '<html><head><meta name="Generator" content=Microsoft Word 15></head></html>'
  37. } );
  38. editor.plugins.get( 'Clipboard' ).fire( 'inputTransformation', { content, dataTransfer } );
  39. expect( normalizeSpy.calledOnce ).to.true;
  40. } );
  41. it( 'does not normalize the content without Word meta tag', () => {
  42. const dataTransfer = createDataTransfer( {
  43. 'text/html': '<meta name=Generator content="Other">'
  44. } );
  45. editor.plugins.get( 'Clipboard' ).fire( 'inputTransformation', { content, dataTransfer } );
  46. expect( normalizeSpy.called ).to.false;
  47. } );
  48. } );