|
|
@@ -51,97 +51,119 @@ describe( 'MentionEditing', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'should convert <span class="mention" data-mention="John"> to mention attribute', () => {
|
|
|
- editor.setData( '<p>foo <span class="mention" data-mention="John">John</span> bar</p>' );
|
|
|
+ editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
|
|
|
|
|
|
expect( getModelData( model, { withoutSelection: true } ) )
|
|
|
- .to.equal( '<paragraph>foo <$text mention="John">John</$text> bar</paragraph>' );
|
|
|
+ .to.equal( '<paragraph>foo <$text mention="{"name":"John"}">@John</$text> bar</paragraph>' );
|
|
|
|
|
|
- expect( editor.getData() ).to.equal( '<p>foo <span class="mention" data-mention="John">John</span> bar</p>' );
|
|
|
+ const textNode = doc.getRoot().getChild( 0 ).getChild( 1 );
|
|
|
+
|
|
|
+ expect( textNode ).to.not.be.null;
|
|
|
+ expect( textNode.hasAttribute( 'mention' ) ).to.be.true;
|
|
|
+ expect( textNode.getAttribute( 'mention' ) ).to.deep.equal( { name: 'John' } );
|
|
|
+
|
|
|
+ expect( editor.getData() ).to.equal( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should remove mention on adding a text inside mention', () => {
|
|
|
- editor.setData( '<p>foo <span class="mention" data-mention="John">John</span> bar</p>' );
|
|
|
+ editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
|
|
|
|
|
|
model.change( writer => {
|
|
|
const paragraph = doc.getRoot().getChild( 0 );
|
|
|
|
|
|
- writer.setSelection( paragraph, 5 );
|
|
|
+ writer.setSelection( paragraph, 6 );
|
|
|
|
|
|
writer.insertText( 'a', doc.selection.getAttributes(), writer.createPositionAt( paragraph, 6 ) );
|
|
|
} );
|
|
|
|
|
|
- expect( editor.getData() ).to.equal( '<p>foo Joahn bar</p>' );
|
|
|
+ expect( editor.getData() ).to.equal( '<p>foo @Jaohn bar</p>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should remove mention on removing a text inside mention', () => {
|
|
|
- editor.setData( '<p>foo <span class="mention" data-mention="John">John</span> bar</p>' );
|
|
|
+ editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- const paragraph = doc.getRoot().getChild( 0 );
|
|
|
+ const paragraph = doc.getRoot().getChild( 0 );
|
|
|
|
|
|
- writer.setSelection( paragraph, 5 );
|
|
|
+ model.change( writer => {
|
|
|
+ writer.setSelection( paragraph, 6 );
|
|
|
+ } );
|
|
|
|
|
|
- writer.remove( writer.createRange( writer.createPositionAt( paragraph, 5 ), writer.createPositionAt( paragraph, 6 ) ) );
|
|
|
+ model.enqueueChange( () => {
|
|
|
+ model.modifySelection( doc.selection, { direction: 'backward', unit: 'codepoint' } );
|
|
|
+ model.deleteContent( doc.selection );
|
|
|
} );
|
|
|
|
|
|
- expect( editor.getData() ).to.equal( '<p>foo Jhn bar</p>' );
|
|
|
+ expect( editor.getData() ).to.equal( '<p>foo @ohn bar</p>' );
|
|
|
} );
|
|
|
|
|
|
it( 'should remove mention on removing a text at the and of a mention', () => {
|
|
|
- editor.setData( '<p>foo <span class="mention" data-mention="John">John</span> bar</p>' );
|
|
|
+ editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
|
|
|
|
|
|
const paragraph = doc.getRoot().getChild( 0 );
|
|
|
|
|
|
// Set selection at the end of a John.
|
|
|
model.change( writer => {
|
|
|
- writer.setSelection( paragraph, 8 );
|
|
|
+ writer.setSelection( paragraph, 9 );
|
|
|
} );
|
|
|
|
|
|
- model.change( writer => {
|
|
|
- writer.remove( writer.createRange( writer.createPositionAt( paragraph, 7 ), writer.createPositionAt( paragraph, 8 ) ) );
|
|
|
+ model.enqueueChange( () => {
|
|
|
+ model.modifySelection( doc.selection, { direction: 'backward', unit: 'codepoint' } );
|
|
|
+ model.deleteContent( doc.selection );
|
|
|
} );
|
|
|
|
|
|
- expect( editor.getData() ).to.equal( '<p>foo Joh bar</p>' );
|
|
|
+ expect( editor.getData() ).to.equal( '<p>foo @Joh bar</p>' );
|
|
|
} );
|
|
|
|
|
|
- it( 'should work on insert text to an empty node', () => {
|
|
|
- editor.setData( '<p></p>' );
|
|
|
+ it( 'should not remove mention on removing a text just after a mention', () => {
|
|
|
+ editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
|
|
|
|
|
|
+ const paragraph = doc.getRoot().getChild( 0 );
|
|
|
+
|
|
|
+ // Set selection before bar.
|
|
|
model.change( writer => {
|
|
|
- const paragraph = doc.getRoot().getChild( 0 );
|
|
|
+ writer.setSelection( paragraph, 10 );
|
|
|
+ } );
|
|
|
|
|
|
- writer.insertText( 'foo', paragraph, 0 );
|
|
|
+ model.enqueueChange( () => {
|
|
|
+ model.modifySelection( doc.selection, { direction: 'backward', unit: 'codepoint' } );
|
|
|
+ model.deleteContent( doc.selection );
|
|
|
} );
|
|
|
|
|
|
- expect( editor.getData() ).to.equal( '<p>foo</p>' );
|
|
|
+ expect( editor.getData() ).to.equal( '<p>foo <span class="mention" data-mention="John">@John</span>bar</p>' );
|
|
|
} );
|
|
|
+ } );
|
|
|
|
|
|
+ describe( 'typing integration', () => {
|
|
|
it( 'should remove mention attribute from a selection if selection is on right side of a mention', () => {
|
|
|
- editor.setData( '<p>foo <span class="mention" data-mention="John">John</span>bar</p>' );
|
|
|
+ editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span>bar</p>' );
|
|
|
|
|
|
model.change( writer => {
|
|
|
const paragraph = doc.getRoot().getChild( 0 );
|
|
|
|
|
|
- writer.setSelection( paragraph, 8 );
|
|
|
+ writer.setSelection( paragraph, 9 );
|
|
|
} );
|
|
|
|
|
|
expect( Array.from( doc.selection.getAttributes() ) ).to.deep.equal( [] );
|
|
|
} );
|
|
|
|
|
|
it( 'should allow to type after a mention', () => {
|
|
|
- editor.setData( '<p>foo <span class="mention" data-mention="John">John</span>bar</p>' );
|
|
|
+ editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span>bar</p>' );
|
|
|
|
|
|
model.change( writer => {
|
|
|
const paragraph = doc.getRoot().getChild( 0 );
|
|
|
|
|
|
- writer.setSelection( paragraph, 8 );
|
|
|
+ writer.setSelection( paragraph, 9 );
|
|
|
|
|
|
- writer.insertText( ' ', paragraph, 8 );
|
|
|
+ writer.insertText( ' ', paragraph, 9 );
|
|
|
} );
|
|
|
|
|
|
- expect( editor.getData() ).to.equal( '<p>foo <span class="mention" data-mention="John">John</span> bar</p>' );
|
|
|
+ expect( editor.getData() ).to.equal( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
|
|
|
} );
|
|
|
} );
|
|
|
+
|
|
|
+ describe( 'postFixer', () => {
|
|
|
+ it( 'should..', () => {} );
|
|
|
+ } );
|
|
|
} );
|
|
|
|
|
|
function createTestEditor( mentionConfig ) {
|