8
0

699.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals document */
  6. import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
  7. import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
  8. import buildViewConverter from '../../src/conversion/buildviewconverter';
  9. import buildModelConverter from '../../src/conversion/buildmodelconverter';
  10. import { getData as getModelData } from '../../src/dev-utils/model';
  11. import { getData as getViewData } from '../../src/dev-utils/view';
  12. describe( 'Bug ckeditor5-engine#699', () => {
  13. let element;
  14. beforeEach( () => {
  15. element = document.createElement( 'div' );
  16. document.body.appendChild( element );
  17. } );
  18. afterEach( () => {
  19. element.remove();
  20. } );
  21. it( 'the engine sets the initial selection on the first widget', () => {
  22. return ClassicTestEditor
  23. .create( element, { plugins: [ Paragraph, WidgetPlugin ] } )
  24. .then( editor => {
  25. editor.setData( '<widget></widget><p>foo</p>' );
  26. expect( getModelData( editor.document ) ).to.equal( '[<widget></widget>]<paragraph>foo</paragraph>' );
  27. expect( getViewData( editor.editing.view ) ).to.equal( '[<widget></widget>]<p>foo</p>' );
  28. return editor.destroy();
  29. } );
  30. } );
  31. } );
  32. function WidgetPlugin( editor ) {
  33. const schema = editor.document.schema;
  34. schema.registerItem( 'widget' );
  35. schema.allow( { name: 'widget', inside: '$root' } );
  36. schema.objects.add( 'widget' );
  37. buildModelConverter().for( editor.data.modelToView, editor.editing.modelToView )
  38. .fromElement( 'widget' )
  39. .toElement( 'widget' );
  40. buildViewConverter().for( editor.data.viewToModel )
  41. .fromElement( 'widget' )
  42. .toElement( 'widget' );
  43. }