8
0

linkengine.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import LinkEngine from '/ckeditor5/link/linkengine.js';
  6. import LinkCommand from '/ckeditor5/link/linkcommand.js';
  7. import UnlinkCommand from '/ckeditor5/link/unlinkcommand.js';
  8. import VirtualTestEditor from '/tests/core/_utils/virtualtesteditor.js';
  9. import { getData as getModelData, setData as setModelData } from '/tests/engine/_utils/model.js';
  10. import { getData as getViewData } from '/tests/engine/_utils/view.js';
  11. describe( 'LinkEngine', () => {
  12. let editor, doc;
  13. beforeEach( () => {
  14. return VirtualTestEditor.create( {
  15. features: [ LinkEngine ]
  16. } )
  17. .then( newEditor => {
  18. editor = newEditor;
  19. doc = editor.document;
  20. doc.schema.allow( { name: '$text', inside: '$root' } );
  21. } );
  22. } );
  23. it( 'should be loaded', () => {
  24. expect( editor.plugins.get( LinkEngine ) ).to.be.instanceOf( LinkEngine );
  25. } );
  26. it( 'should set proper schema rules', () => {
  27. expect( doc.schema.check( { name: '$inline', attributes: [ 'link' ] } ) ).to.be.true;
  28. } );
  29. describe( 'command', () => {
  30. it( 'should register link command', () => {
  31. expect( editor.commands.has( 'link' ) ).to.be.true;
  32. const command = editor.commands.get( 'link' );
  33. expect( command ).to.be.instanceOf( LinkCommand );
  34. } );
  35. it( 'should register unlink command', () => {
  36. expect( editor.commands.has( 'unlink' ) ).to.be.true;
  37. const command = editor.commands.get( 'unlink' );
  38. expect( command ).to.be.instanceOf( UnlinkCommand );
  39. } );
  40. } );
  41. describe( 'data pipeline conversions', () => {
  42. it( 'should convert `<a href="url">` to `link="url"` attribute', () => {
  43. editor.setData( '<a href="url">foo</a>bar' );
  44. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text link="url">foo</$text>bar' );
  45. expect( editor.getData() ).to.equal( '<a href="url">foo</a>bar' );
  46. } );
  47. } );
  48. describe( 'editing pipeline conversion', () => {
  49. it( 'should convert attribute', () => {
  50. setModelData( doc, '<$text link="url">foo</$text>bar' );
  51. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<a href="url">foo</a>bar' );
  52. } );
  53. } );
  54. } );