8
0
Просмотр исходного кода

Add test for google docs normalizer.

Mateusz Samsel 6 лет назад
Родитель
Сommit
66b6912e5c
1 измененных файлов с 107 добавлено и 0 удалено
  1. 107 0
      packages/ckeditor5-paste-from-office/tests/normalizers/googledocs.js

+ 107 - 0
packages/ckeditor5-paste-from-office/tests/normalizers/googledocs.js

@@ -0,0 +1,107 @@
+/**
+ * @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();
+
+	afterEach( () => {
+		normalizer.setInputData( {} );
+	} );
+
+	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.setInputData( data ).exec();
+
+		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.setInputData( data ).exec();
+
+		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.setInputData( data ).exec();
+
+		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( ( data, index ) => {
+				it( `should be active for markup #${ index }`, () => {
+					expect( normalizer.isActive ).to.be.false;
+
+					normalizer.setInputData( {
+						dataTransfer: createDataTransfer( data )
+					} );
+
+					expect( normalizer.isActive ).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( ( data, index ) => {
+				it( `should be not active for wrong markup #${ index }`, () => {
+					expect( normalizer.isActive ).to.be.false;
+
+					normalizer.setInputData( {
+						dataTransfer: createDataTransfer( data )
+					} );
+
+					expect( normalizer.isActive ).to.be.false;
+				} );
+			} );
+		} );
+	} );
+} );