8
0

pastefromoffice.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  8. import PasteFromOffice from '../src/pastefromoffice';
  9. import { createDataTransfer } from './_utils/utils';
  10. describe( 'Paste from Office plugin', () => {
  11. let editor, normalizeSpy;
  12. testUtils.createSinonSandbox();
  13. beforeEach( () => {
  14. return VirtualTestEditor
  15. .create( {
  16. plugins: [ Clipboard, PasteFromOffice ]
  17. } )
  18. .then( newEditor => {
  19. editor = newEditor;
  20. normalizeSpy = testUtils.sinon.spy( editor.plugins.get( 'PasteFromOffice' ), '_normalizeWordInput' );
  21. } );
  22. } );
  23. it( 'runs normalizations if Word meta tag detected #1', () => {
  24. const dataTransfer = createDataTransfer( {
  25. 'text/html': '<meta name=Generator content="Microsoft Word 15">'
  26. } );
  27. editor.editing.view.document.fire( 'clipboardInput', { dataTransfer } );
  28. expect( normalizeSpy.calledOnce ).to.true;
  29. } );
  30. it( 'runs normalizations if Word meta tag detected #2', () => {
  31. const dataTransfer = createDataTransfer( {
  32. 'text/html': '<html><head><meta name="Generator" content=Microsoft Word 15></head></html>'
  33. } );
  34. editor.editing.view.document.fire( 'clipboardInput', { dataTransfer } );
  35. expect( normalizeSpy.calledOnce ).to.true;
  36. } );
  37. it( 'does not normalize the content without Word meta tag', () => {
  38. const dataTransfer = createDataTransfer( {
  39. 'text/html': '<meta name=Generator content="Other">'
  40. } );
  41. editor.editing.view.document.fire( 'clipboardInput', { dataTransfer } );
  42. expect( normalizeSpy.called ).to.false;
  43. } );
  44. } );