8
0

linkengine.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. expect( command ).to.have.property( 'attributeKey', 'link' );
  34. } );
  35. } );
  36. describe( 'data pipeline conversions', () => {
  37. it( 'should convert `<a href="url">` to `bold="url"` attribute', () => {
  38. editor.setData( '<a href="url">foo</a>bar' );
  39. expect( getModelData( doc, { withoutSelection: true } ) ).to.equal( '<$text link="url">foo</$text>bar' );
  40. expect( editor.getData() ).to.equal( '<a href="url">foo</a>bar' );
  41. } );
  42. } );
  43. describe( 'editing pipeline conversion', () => {
  44. it( 'should convert attribute', () => {
  45. setModelData( doc, '<$text link="url">foo</$text>bar' );
  46. expect( getViewData( editor.editing.view, { withoutSelection: true } ) ).to.equal( '<a href="url">foo</a>bar' );
  47. } );
  48. } );
  49. } );