Преглед изворни кода

Add tests for clipboard output for mention editing.

Maciej Gołaszewski пре 6 година
родитељ
комит
de00e5d660
1 измењених фајлова са 43 додато и 4 уклоњено
  1. 43 4
      packages/ckeditor5-mention/tests/mentionediting.js

+ 43 - 4
packages/ckeditor5-mention/tests/mentionediting.js

@@ -6,7 +6,8 @@
 import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
 import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
 import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
-import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
+import { stringify as stringifyView, getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
+import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
 import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
 
 import MentionEditing from '../src/mentionediting';
@@ -57,7 +58,7 @@ describe( 'MentionEditing', () => {
 			} );
 	} );
 
-	describe( 'conversion', () => {
+	describe.only( 'conversion', () => {
 		beforeEach( () => {
 			return createTestEditor()
 				.then( newEditor => {
@@ -122,7 +123,7 @@ describe( 'MentionEditing', () => {
 			}
 		} );
 
-		it( 'should not convert partial mentions', () => {
+		it( 'should upcast partial mention', () => {
 			editor.setData( '<p><span class="mention" data-mention="@John">@Jo</span></p>' );
 
 			const textNode = doc.getRoot().getChild( 0 ).getChild( 0 );
@@ -139,6 +140,30 @@ describe( 'MentionEditing', () => {
 			expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
 		} );
 
+		it( 'should not downcast partial mention', done => {
+			editor.setData( '<p>Hello <span class="mention" data-mention="@John">@John</span></p>' );
+
+			model.change( writer => {
+				const start = writer.createPositionAt( doc.getRoot().getChild( 0 ), 0 );
+				const end = writer.createPositionAt( doc.getRoot().getChild( 0 ), 9 );
+				writer.setSelection( writer.createRange( start, end ) );
+			} );
+
+			const dataTransferMock = createDataTransfer();
+			const preventDefaultSpy = sinon.spy();
+
+			editor.editing.view.document.on( 'clipboardOutput', ( evt, data ) => {
+				expect( stringifyView( data.content ) ).to.equal( 'Hello @Jo' );
+
+				done();
+			} );
+
+			editor.editing.view.document.fire( 'copy', {
+				dataTransfer: dataTransferMock,
+				preventDefault: preventDefaultSpy
+			} );
+		} );
+
 		it( 'should not convert empty mentions', () => {
 			editor.setData( '<p>foo<span class="mention" data-mention="@John"></span></p>' );
 
@@ -526,8 +551,22 @@ describe( 'MentionEditing', () => {
 	function createTestEditor( mentionConfig ) {
 		return VirtualTestEditor
 			.create( {
-				plugins: [ Paragraph, MentionEditing ],
+				plugins: [ Paragraph, MentionEditing, Clipboard ],
 				mention: mentionConfig
 			} );
 	}
+
+	function createDataTransfer() {
+		const store = new Map();
+
+		return {
+			setData( type, data ) {
+				store.set( type, data );
+			},
+
+			getData( type ) {
+				return store.get( type );
+			}
+		};
+	}
 } );