8
0

pastefromword.js 1.8 KB

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