linkengine.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 VirtualTestEditor from '/tests/core/_utils/virtualtesteditor.js';
  8. import { getData as getModelData, setData as setModelData } from '/tests/engine/_utils/model.js';
  9. import { getData as getViewData } from '/tests/engine/_utils/view.js';
  10. describe( 'LinkEngine', () => {
  11. let editor, doc;
  12. beforeEach( () => {
  13. return VirtualTestEditor.create( {
  14. features: [ LinkEngine ]
  15. } )
  16. .then( newEditor => {
  17. editor = newEditor;
  18. doc = editor.document;
  19. doc.schema.allow( { name: '$text', inside: '$root' } );
  20. } );
  21. } );
  22. it( 'should be loaded', () => {
  23. expect( editor.plugins.get( LinkEngine ) ).to.be.instanceOf( LinkEngine );
  24. } );
  25. it( 'should set proper schema rules', () => {
  26. expect( doc.schema.check( { name: '$inline', attributes: [ 'link' ] } ) ).to.be.true;
  27. } );
  28. describe( 'command', () => {
  29. it( 'should register link command', () => {
  30. expect( editor.commands.has( 'link' ) ).to.be.true;
  31. const command = editor.commands.get( 'link' );
  32. expect( command ).to.be.instanceOf( LinkCommand );
  33. } );
  34. } );
  35. describe( 'data pipeline conversions', () => {
  36. it( 'should convert `<a href="url">` to `link="url"` attribute', () => {
  37. editor.setData( '<a href="url">foo</a>bar' );
  38. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text link="url">foo</$text>bar' );
  39. expect( editor.getData() ).to.equal( '<a href="url">foo</a>bar' );
  40. } );
  41. } );
  42. describe( 'editing pipeline conversion', () => {
  43. it( 'should convert attribute', () => {
  44. setModelData( doc, '<$text link="url">foo</$text>bar' );
  45. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<a href="url">foo</a>bar' );
  46. } );
  47. } );
  48. } );