|
@@ -6,7 +6,8 @@
|
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
|
|
|
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
|
|
|
import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
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 Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
|
|
|
|
|
|
|
|
import MentionEditing from '../src/mentionediting';
|
|
import MentionEditing from '../src/mentionediting';
|
|
@@ -57,7 +58,7 @@ describe( 'MentionEditing', () => {
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- describe( 'conversion', () => {
|
|
|
|
|
|
|
+ describe.only( 'conversion', () => {
|
|
|
beforeEach( () => {
|
|
beforeEach( () => {
|
|
|
return createTestEditor()
|
|
return createTestEditor()
|
|
|
.then( newEditor => {
|
|
.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>' );
|
|
editor.setData( '<p><span class="mention" data-mention="@John">@Jo</span></p>' );
|
|
|
|
|
|
|
|
const textNode = doc.getRoot().getChild( 0 ).getChild( 0 );
|
|
const textNode = doc.getRoot().getChild( 0 ).getChild( 0 );
|
|
@@ -139,6 +140,30 @@ describe( 'MentionEditing', () => {
|
|
|
expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( expectedView );
|
|
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', () => {
|
|
it( 'should not convert empty mentions', () => {
|
|
|
editor.setData( '<p>foo<span class="mention" data-mention="@John"></span></p>' );
|
|
editor.setData( '<p>foo<span class="mention" data-mention="@John"></span></p>' );
|
|
|
|
|
|
|
@@ -526,8 +551,22 @@ describe( 'MentionEditing', () => {
|
|
|
function createTestEditor( mentionConfig ) {
|
|
function createTestEditor( mentionConfig ) {
|
|
|
return VirtualTestEditor
|
|
return VirtualTestEditor
|
|
|
.create( {
|
|
.create( {
|
|
|
- plugins: [ Paragraph, MentionEditing ],
|
|
|
|
|
|
|
+ plugins: [ Paragraph, MentionEditing, Clipboard ],
|
|
|
mention: mentionConfig
|
|
mention: mentionConfig
|
|
|
} );
|
|
} );
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ function createDataTransfer() {
|
|
|
|
|
+ const store = new Map();
|
|
|
|
|
+
|
|
|
|
|
+ return {
|
|
|
|
|
+ setData( type, data ) {
|
|
|
|
|
+ store.set( type, data );
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
|
|
+ getData( type ) {
|
|
|
|
|
+ return store.get( type );
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
} );
|
|
} );
|