8
0
فهرست منبع

Aligned tests to the new API.

Maciej Bukowski 8 سال پیش
والد
کامیت
27760e9984
2فایلهای تغییر یافته به همراه73 افزوده شده و 37 حذف شده
  1. 1 3
      packages/ckeditor5-clipboard/src/clipboard.js
  2. 72 34
      packages/ckeditor5-clipboard/tests/clipboard.js

+ 1 - 3
packages/ckeditor5-clipboard/src/clipboard.js

@@ -135,7 +135,7 @@ export default class Clipboard extends Plugin {
 				const dataController = this.editor.data;
 				const dataController = this.editor.data;
 
 
 				// Convert the pasted content to a model document fragment.
 				// Convert the pasted content to a model document fragment.
-				// Convertion is contextual, but in this case we need an "all allowed" context and for that
+				// Conversion is contextual, but in this case we need an "all allowed" context and for that
 				// we use the $clipboardHolder item.
 				// we use the $clipboardHolder item.
 				const modelFragment = dataController.toModel( data.content, '$clipboardHolder' );
 				const modelFragment = dataController.toModel( data.content, '$clipboardHolder' );
 
 
@@ -171,8 +171,6 @@ export default class Clipboard extends Plugin {
 			}
 			}
 		}, { priority: 'low' } );
 		}, { priority: 'low' } );
 	}
 	}
-
-
 }
 }
 
 
 /**
 /**

+ 72 - 34
packages/ckeditor5-clipboard/tests/clipboard.js

@@ -20,7 +20,7 @@ import ViewDocumentFragment from '@ckeditor/ckeditor5-engine/src/view/documentfr
 import ViewText from '@ckeditor/ckeditor5-engine/src/view/text';
 import ViewText from '@ckeditor/ckeditor5-engine/src/view/text';
 
 
 describe( 'Clipboard feature', () => {
 describe( 'Clipboard feature', () => {
-	let editor, editingView;
+	let editor, editingView, clipboardPlugin;
 
 
 	beforeEach( () => {
 	beforeEach( () => {
 		return VirtualTestEditor.create( {
 		return VirtualTestEditor.create( {
@@ -29,6 +29,7 @@ describe( 'Clipboard feature', () => {
 			.then( ( newEditor ) => {
 			.then( ( newEditor ) => {
 				editor = newEditor;
 				editor = newEditor;
 				editingView = editor.editing.view;
 				editingView = editor.editing.view;
+				clipboardPlugin = editor.plugins.get( 'clipboard' );
 			} );
 			} );
 	} );
 	} );
 
 
@@ -39,60 +40,97 @@ describe( 'Clipboard feature', () => {
 	} );
 	} );
 
 
 	describe( 'clipboard paste pipeline', () => {
 	describe( 'clipboard paste pipeline', () => {
-		it( 'takes HTML data from the dataTransfer', ( done ) => {
-			const dataTransferMock = createDataTransfer( { 'text/html': '<p>x</p>', 'text/plain': 'y' } );
-			const preventDefaultSpy = sinon.spy();
-
-			editingView.on( 'clipboardInput', ( evt, data ) => {
-				expect( preventDefaultSpy.calledOnce ).to.be.true;
+		describe( 'takes HTML data from the dataTransfer', () => {
+			it( 'and fires the input event on the editingView', ( done ) => {
+				const dataTransferMock = createDataTransfer( { 'text/html': '<p>x</p>', 'text/plain': 'y' } );
+				const preventDefaultSpy = sinon.spy();
+
+				editingView.on( 'input', ( evt, data ) => {
+					expect( preventDefaultSpy.calledOnce ).to.be.true;
+					expect( data.dataTransfer ).to.equal( dataTransferMock );
+
+					done();
+				} );
+
+				editingView.fire( 'paste', {
+					dataTransfer: dataTransferMock,
+					preventDefault: preventDefaultSpy
+				} );
+			} );
 
 
-				expect( data.dataTransfer ).to.equal( dataTransferMock );
+			it( 'and fires the inputTransformation event on the clipboardPlugin', ( done ) => {
+				const dataTransferMock = createDataTransfer( { 'text/html': '<p>x</p>', 'text/plain': 'y' } );
+				const preventDefaultSpy = sinon.spy();
 
 
-				expect( data.content ).is.instanceOf( ViewDocumentFragment );
-				expect( stringifyView( data.content ) ).to.equal( '<p>x</p>' );
+				clipboardPlugin.on( 'inputTransformation', ( evt, data ) => {
+					expect( data.content ).is.instanceOf( ViewDocumentFragment );
+					expect( stringifyView( data.content ) ).to.equal( '<p>x</p>' );
 
 
-				done();
-			} );
+					done();
+				} );
 
 
-			editingView.fire( 'paste', {
-				dataTransfer: dataTransferMock,
-				preventDefault: preventDefaultSpy
+				editingView.fire( 'paste', {
+					dataTransfer: dataTransferMock,
+					preventDefault: preventDefaultSpy
+				} );
 			} );
 			} );
 		} );
 		} );
 
 
-		it( 'takes plain text data from the dataTransfer if there is no HTML', ( done ) => {
-			const dataTransferMock = createDataTransfer( { 'text/plain': 'x\n\ny  z' } );
-			const preventDefaultSpy = sinon.spy();
+		describe( 'takes plain text data from the dataTransfer if there is no HTML', () => {
+			it( 'and fires the input event on the editingView', ( done ) => {
+				const dataTransferMock = createDataTransfer( { 'text/plain': 'x\n\ny  z' } );
+				const preventDefaultSpy = sinon.spy();
 
 
-			editingView.on( 'clipboardInput', ( evt, data ) => {
-				expect( preventDefaultSpy.calledOnce ).to.be.true;
+				editingView.on( 'input', ( evt, data ) => {
+					expect( preventDefaultSpy.calledOnce ).to.be.true;
+					expect( data.dataTransfer ).to.equal( dataTransferMock );
 
 
-				expect( data.dataTransfer ).to.equal( dataTransferMock );
-
-				expect( data.content ).is.instanceOf( ViewDocumentFragment );
-				expect( stringifyView( data.content ) ).to.equal( '<p>x</p><p>y  z</p>' );
+					done();
+				} );
 
 
-				done();
+				editingView.fire( 'paste', {
+					dataTransfer: dataTransferMock,
+					preventDefault: preventDefaultSpy
+				} );
 			} );
 			} );
 
 
-			editingView.fire( 'paste', {
-				dataTransfer: dataTransferMock,
-				preventDefault: preventDefaultSpy
+			it( 'and fires the inputTransformation event on the clipboardPlugin', ( done ) => {
+				const dataTransferMock = createDataTransfer( { 'text/plain': 'x\n\ny  z' } );
+				const preventDefaultSpy = sinon.spy();
+
+				clipboardPlugin.on( 'inputTransformation', ( evt, data ) => {
+					expect( data.content ).is.instanceOf( ViewDocumentFragment );
+					expect( stringifyView( data.content ) ).to.equal( '<p>x</p><p>y  z</p>' );
+
+					done();
+				} );
+
+				editingView.fire( 'paste', {
+					dataTransfer: dataTransferMock,
+					preventDefault: preventDefaultSpy
+				} );
 			} );
 			} );
 		} );
 		} );
 
 
-		it( 'fires clipboardInput event with empty data if there is no HTML nor plain text', ( done ) => {
+		it( 'fires events with empty data if there is no HTML nor plain text', ( done ) => {
 			const dataTransferMock = createDataTransfer( {} );
 			const dataTransferMock = createDataTransfer( {} );
 			const preventDefaultSpy = sinon.spy();
 			const preventDefaultSpy = sinon.spy();
+			const editorViewCalled = sinon.spy();
 
 
-			editingView.on( 'clipboardInput', ( evt, data ) => {
+			editingView.on( 'input', ( evt, data ) => {
 				expect( preventDefaultSpy.calledOnce ).to.be.true;
 				expect( preventDefaultSpy.calledOnce ).to.be.true;
 
 
 				expect( data.dataTransfer ).to.equal( dataTransferMock );
 				expect( data.dataTransfer ).to.equal( dataTransferMock );
 
 
+				editorViewCalled();
+			} );
+
+			clipboardPlugin.on( 'inputTransformation', ( evt, data ) => {
 				expect( data.content ).is.instanceOf( ViewDocumentFragment );
 				expect( data.content ).is.instanceOf( ViewDocumentFragment );
 				expect( stringifyView( data.content ) ).to.equal( '' );
 				expect( stringifyView( data.content ) ).to.equal( '' );
 
 
+				expect( editorViewCalled.calledOnce ).to.be.true;
+
 				done();
 				done();
 			} );
 			} );
 
 
@@ -110,7 +148,7 @@ describe( 'Clipboard feature', () => {
 				evt.stop();
 				evt.stop();
 			} );
 			} );
 
 
-			editingView.on( 'clipboardInput', spy );
+			editingView.on( 'input', spy );
 
 
 			editingView.fire( 'paste', {
 			editingView.fire( 'paste', {
 				dataTransfer: dataTransferMock,
 				dataTransfer: dataTransferMock,
@@ -152,7 +190,7 @@ describe( 'Clipboard feature', () => {
 			const dataTransferMock = createDataTransfer( { 'text/plain': '' } );
 			const dataTransferMock = createDataTransfer( { 'text/plain': '' } );
 			const spy = sinon.stub( editor.data, 'insertContent' );
 			const spy = sinon.stub( editor.data, 'insertContent' );
 
 
-			editingView.fire( 'clipboardInput', {
+			editingView.fire( 'input', {
 				dataTransfer: dataTransferMock,
 				dataTransfer: dataTransferMock,
 				content: new ViewDocumentFragment()
 				content: new ViewDocumentFragment()
 			} );
 			} );
@@ -160,11 +198,11 @@ describe( 'Clipboard feature', () => {
 			expect( spy.callCount ).to.equal( 0 );
 			expect( spy.callCount ).to.equal( 0 );
 		} );
 		} );
 
 
-		it( 'uses low priority observer for the clipboardInput event', () => {
+		it( 'uses low priority observer for the input event', () => {
 			const dataTransferMock = createDataTransfer( { 'text/html': 'x' } );
 			const dataTransferMock = createDataTransfer( { 'text/html': 'x' } );
 			const spy = sinon.stub( editor.data, 'insertContent' );
 			const spy = sinon.stub( editor.data, 'insertContent' );
 
 
-			editingView.on( 'clipboardInput', ( evt ) => {
+			editingView.on( 'input', ( evt ) => {
 				evt.stop();
 				evt.stop();
 			} );
 			} );