mention.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  6. import global from '@ckeditor/ckeditor5-utils/src/dom/global';
  7. import Element from '@ckeditor/ckeditor5-engine/src/view/element';
  8. import Text from '@ckeditor/ckeditor5-engine/src/view/text';
  9. import Mention from '../src/mention';
  10. import MentionEditing from '../src/mentionediting';
  11. import MentionUI from '../src/mentionui';
  12. describe( 'Mention', () => {
  13. let editorElement, editor;
  14. beforeEach( () => {
  15. editorElement = global.document.createElement( 'div' );
  16. global.document.body.appendChild( editorElement );
  17. return ClassicTestEditor
  18. .create( editorElement, {
  19. plugins: [ Mention ]
  20. } )
  21. .then( newEditor => {
  22. editor = newEditor;
  23. } );
  24. } );
  25. afterEach( () => {
  26. editorElement.remove();
  27. return editor.destroy();
  28. } );
  29. it( 'should be loaded', () => {
  30. expect( editor.plugins.get( Mention ) ).to.instanceOf( Mention );
  31. } );
  32. it( 'has proper name', () => {
  33. expect( Mention.pluginName ).to.equal( 'Mention' );
  34. } );
  35. it( 'should load MentionEditing plugin', () => {
  36. expect( editor.plugins.get( MentionEditing ) ).to.instanceOf( MentionEditing );
  37. } );
  38. it( 'should load MentionUI plugin', () => {
  39. expect( editor.plugins.get( MentionUI ) ).to.instanceOf( MentionUI );
  40. } );
  41. describe( 'toMentionAttribute()', () => {
  42. it( 'should create mention attribute with default properties', () => {
  43. const text = new Text( 'John Doe' );
  44. const viewElement = new Element( 'span', {
  45. 'data-mention': '@John'
  46. }, text );
  47. const mentionAttribute = editor.plugins.get( 'Mention' ).toMentionAttribute( viewElement );
  48. expect( mentionAttribute ).to.have.property( 'id', '@John' );
  49. expect( mentionAttribute ).to.have.property( '_uid' );
  50. expect( mentionAttribute ).to.have.property( '_text', 'John Doe' );
  51. } );
  52. it( 'should create mention attribute with provided attributes', () => {
  53. const text = new Text( 'John Doe' );
  54. const viewElement = new Element( 'span', {
  55. 'data-mention': '@John'
  56. }, text );
  57. const mentionAttribute = editor.plugins.get( 'Mention' ).toMentionAttribute( viewElement, { foo: 'bar' } );
  58. expect( mentionAttribute ).to.have.property( 'id', '@John' );
  59. expect( mentionAttribute ).to.have.property( 'foo', 'bar' );
  60. expect( mentionAttribute ).to.have.property( '_uid' );
  61. expect( mentionAttribute ).to.have.property( '_text', 'John Doe' );
  62. } );
  63. it( 'should return undefined if Element has no text node', () => {
  64. const viewElement = new Element( 'span', {
  65. 'data-mention': '@John'
  66. } );
  67. const mentionAttribute = editor.plugins.get( 'Mention' ).toMentionAttribute( viewElement );
  68. expect( mentionAttribute ).to.be.undefined;
  69. } );
  70. } );
  71. } );