| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- /**
- * @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 { googleDocsNormalizer as normalizer } from '../../src/normalizers/googledocs';
- import ContentNormalizer from '../../src/contentnormalizer';
- import { createDataTransfer } from '../_utils/utils';
- import DocumentFragment from '@ckeditor/ckeditor5-engine/src/view/documentfragment';
- import HtmlDataProcessor from '@ckeditor/ckeditor5-engine/src/dataprocessor/htmldataprocessor';
- // Functionality of the google docs normalizer is tested with autogenerated normalization tests.
- describe( 'PasteFromOffice/normalizers/googledocs', () => {
- const htmlDataProcessor = new HtmlDataProcessor();
- it( 'should be instance of content normalizers', () => {
- expect( normalizer ).to.be.instanceOf( ContentNormalizer );
- } );
- it( 'should mark data as processed', () => {
- const gDocs = '<p id="docs-internal-guid-12345678-1234-1234-1234-1234567890ab"></p>';
- const data = {
- dataTransfer: createDataTransfer( {
- 'text/html': gDocs
- } ),
- content: htmlDataProcessor.toView( gDocs )
- };
- normalizer.transform( data );
- expect( data.isTransformedWithPasteFromOffice ).to.be.true;
- } );
- it( 'should not mark non-google-docs data as processed', () => {
- const data = {
- dataTransfer: createDataTransfer( { 'text/html': 'foo bar' } )
- };
- normalizer.transform( data );
- expect( data.isTransformedWithPasteFromOffice ).to.be.undefined;
- } );
- it( 'outputs view#documentFragment', () => {
- const gDocs = '<p id="docs-internal-guid-12345678-1234-1234-1234-1234567890ab">Foo bar</p>';
- const data = {
- dataTransfer: createDataTransfer( {
- 'text/html': gDocs
- } ),
- content: htmlDataProcessor.toView( gDocs )
- };
- normalizer.transform( data );
- expect( data.isTransformedWithPasteFromOffice ).to.be.true;
- expect( data.content ).to.be.instanceOf( DocumentFragment );
- } );
- describe( 'activation trigger', () => {
- describe( 'correct markup', () => {
- [
- {
- 'text/html': '<meta charset="utf-8"><p id="docs-internal-guid-12345678-1234-1234-1234-1234567890ab">Foo bar</p>'
- },
- {
- // eslint-disable-next-line max-len
- 'text/html': '<meta charset="utf-8"><b style="font-weight:normal;" id="docs-internal-guid-30db46f5-7fff-15a1-e17c-1234567890ab"></b>'
- }
- ].forEach( ( html, index ) => {
- it( `should be active for markup #${ index }`, () => {
- const data = {
- dataTransfer: createDataTransfer( html ),
- content: htmlDataProcessor.toView( html[ 'text/html' ] )
- };
- expect( data.isTransformedWithPasteFromOffice ).to.be.undefined;
- normalizer.transform( data );
- expect( data.isTransformedWithPasteFromOffice ).to.be.true;
- } );
- } );
- } );
- describe( 'wrong markup', () => {
- [
- {
- 'text/html': '<p id="random_id">Hello world</p>'
- },
- {
- 'text/html': '<meta name=Generator content="Microsoft Word 15">'
- }
- ].forEach( ( html, index ) => {
- it( `should be not active for wrong markup #${ index }`, () => {
- const data = {
- dataTransfer: createDataTransfer( html ),
- content: htmlDataProcessor.toView( html[ 'text/html' ] )
- };
- expect( data.isTransformedWithPasteFromOffice ).to.be.undefined;
- normalizer.transform( data );
- expect( data.isTransformedWithPasteFromOffice ).to.be.undefined;
- } );
- } );
- } );
- } );
- } );
|