mention-integration.js 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global document */
  6. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  7. import { getData as getViewData } from '@ckeditor/ckeditor5-engine/src/dev-utils/view';
  8. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  9. import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting';
  10. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  11. import MentionEditing from '../src/mentionediting';
  12. describe( 'MentionEditing - integration', () => {
  13. let div, editor, model, doc;
  14. testUtils.createSinonSandbox();
  15. beforeEach( () => {
  16. div = document.createElement( 'div' );
  17. document.body.appendChild( div );
  18. return ClassicTestEditor.create( div, { plugins: [ Paragraph, MentionEditing, UndoEditing ] } )
  19. .then( newEditor => {
  20. editor = newEditor;
  21. model = editor.model;
  22. doc = model.document;
  23. } );
  24. } );
  25. afterEach( () => {
  26. div.remove();
  27. return editor.destroy();
  28. } );
  29. describe( 'undo', () => {
  30. // Failing test. See ckeditor/ckeditor5#1645.
  31. it( 'should restore removed mention on adding a text inside mention', () => {
  32. editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
  33. expect( editor.getData() ).to.equal( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
  34. model.change( writer => {
  35. const paragraph = doc.getRoot().getChild( 0 );
  36. writer.setSelection( paragraph, 6 );
  37. writer.insertText( 'a', doc.selection.getAttributes(), writer.createPositionAt( paragraph, 6 ) );
  38. } );
  39. expect( editor.getData() ).to.equal( '<p>foo @Jaohn bar</p>' );
  40. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p>foo @Jaohn bar</p>' );
  41. editor.execute( 'undo' );
  42. expect( editor.getData() ).to.equal( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
  43. expect( getViewData( editor.editing.view ) )
  44. .to.equal( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
  45. } );
  46. // Failing test. See ckeditor/ckeditor5#1645.
  47. it( 'should restore removed mention on removing a text inside mention', () => {
  48. editor.setData( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
  49. expect( editor.getData() ).to.equal( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
  50. model.change( writer => {
  51. const paragraph = doc.getRoot().getChild( 0 );
  52. writer.setSelection( paragraph, 7 );
  53. model.modifySelection( doc.selection, { direction: 'backward', unit: 'codepoint' } );
  54. model.deleteContent( doc.selection );
  55. } );
  56. expect( editor.getData() ).to.equal( '<p>foo @Jhn bar</p>' );
  57. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<p>foo @Jhn bar</p>' );
  58. editor.execute( 'undo' );
  59. expect( editor.getData() ).to.equal( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
  60. expect( getViewData( editor.editing.view ) )
  61. .to.equal( '<p>foo <span class="mention" data-mention="John">@John</span> bar</p>' );
  62. } );
  63. } );
  64. } );