mentionediting.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import VirtualTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/virtualtesteditor';
  6. import MentionEditing from '../src/mentionediting';
  7. import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
  8. import { getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  9. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  10. describe( 'MentionEditing', () => {
  11. testUtils.createSinonSandbox();
  12. it( 'should be named', () => {
  13. expect( MentionEditing.pluginName ).to.equal( 'MentionEditing' );
  14. } );
  15. describe( 'init()', () => {
  16. let editor, model;
  17. it( 'should be loaded', () => {
  18. return createTestEditor()
  19. .then( newEditor => {
  20. expect( newEditor.plugins.get( MentionEditing ) ).to.be.instanceOf( MentionEditing );
  21. } );
  22. } );
  23. it( 'should set proper schema rules', () => {
  24. return createTestEditor()
  25. .then( newEditor => {
  26. model = newEditor.model;
  27. expect( model.schema.checkAttribute( [ '$root', '$text' ], 'mention' ) ).to.be.true;
  28. expect( model.schema.checkAttribute( [ '$block', '$text' ], 'mention' ) ).to.be.true;
  29. expect( model.schema.checkAttribute( [ '$clipboardHolder', '$text' ], 'mention' ) ).to.be.true;
  30. expect( model.schema.checkAttribute( [ '$block' ], 'mention' ) ).to.be.false;
  31. } );
  32. } );
  33. describe( 'conversion in the data pipeline', () => {
  34. beforeEach( () => {
  35. return createTestEditor()
  36. .then( newEditor => {
  37. editor = newEditor;
  38. model = editor.model;
  39. } );
  40. } );
  41. it( 'should convert <span class="mention" data-mention="John"> to mention attribute', () => {
  42. editor.setData( '<p>foo <span class="mention" data-mention="John">John</span> bar</p>' );
  43. expect( getModelData( model, { withoutSelection: true } ) )
  44. .to.equal( '<paragraph>foo <$text mention="John">John</$text> bar</paragraph>' );
  45. expect( editor.getData() ).to.equal( '<p>foo <span class="mention" data-mention="John">John</span> bar</p>' );
  46. } );
  47. } );
  48. } );
  49. function createTestEditor( mentionConfig ) {
  50. return VirtualTestEditor
  51. .create( {
  52. plugins: [ Paragraph, MentionEditing ],
  53. mention: mentionConfig
  54. } );
  55. }
  56. } );