8
0

msword.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import { mswordNormalizer as normalizer } from '../../src/normalizers/msword';
  6. import ContentNormalizer from '../../src/contentnormalizer';
  7. import { createDataTransfer } from '../_utils/utils';
  8. import DocumentFragment from '@ckeditor/ckeditor5-engine/src/view/documentfragment';
  9. // Functionality of the msword normalizer is tested with autogenerated normalization tests.
  10. describe( 'PasteFromOffice/normalizers/msword', () => {
  11. afterEach( () => {
  12. normalizer.setInputData( {} );
  13. } );
  14. it( 'should be instance of content normalizers', () => {
  15. expect( normalizer ).to.be.instanceOf( ContentNormalizer );
  16. } );
  17. it( 'should mark data as processed', () => {
  18. const data = {
  19. dataTransfer: createDataTransfer( {
  20. 'text/html': '<meta name=Generator content="Microsoft Word 15">'
  21. } )
  22. };
  23. normalizer.setInputData( data ).exec();
  24. expect( data.isTransformedWithPasteFromOffice ).to.be.true;
  25. } );
  26. it( 'should not mark non-word data as processed', () => {
  27. const data = {
  28. dataTransfer: createDataTransfer( { 'text/html': 'foo bar' } )
  29. };
  30. normalizer.setInputData( data ).exec();
  31. expect( data.isTransformedWithPasteFromOffice ).to.be.undefined;
  32. } );
  33. it( 'outputs view#documentFragment', () => {
  34. const data = {
  35. dataTransfer: createDataTransfer( {
  36. 'text/html': '<meta name=Generator content="Microsoft Word 15"><p>Foo bar</p>'
  37. } )
  38. };
  39. normalizer.setInputData( data ).exec();
  40. expect( data.content ).to.be.instanceOf( DocumentFragment );
  41. } );
  42. describe( 'activation trigger', () => {
  43. describe( 'correct markup', () => {
  44. [
  45. {
  46. 'text/html': '<meta name=Generator content="Microsoft Word 15">'
  47. },
  48. {
  49. 'text/html': '<html><head><meta name="Generator" content=Microsoft Word 15></head></html>'
  50. }
  51. ].forEach( ( data, index ) => {
  52. it( `should be active for markup #${ index }`, () => {
  53. expect( normalizer.isActive ).to.be.false;
  54. normalizer.setInputData( {
  55. dataTransfer: createDataTransfer( data )
  56. } );
  57. expect( normalizer.isActive ).to.be.true;
  58. } );
  59. } );
  60. } );
  61. describe( 'wrong markup', () => {
  62. [
  63. {
  64. 'text/html': '<meta name=Generator content="Other">'
  65. },
  66. {
  67. 'text/html': '<p id="docs-internal-guid-12345"></p>'
  68. }
  69. ].forEach( ( data, index ) => {
  70. it( `should be not active for wrong markup #${ index }`, () => {
  71. expect( normalizer.isActive ).to.be.false;
  72. normalizer.setInputData( {
  73. dataTransfer: createDataTransfer( data )
  74. } );
  75. expect( normalizer.isActive ).to.be.false;
  76. } );
  77. } );
  78. } );
  79. } );
  80. } );