8
0

engine.js 1.6 KB

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