699.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
  11. describe( 'Bug ckeditor5-engine#699', () => {
  12. let element;
  13. beforeEach( () => {
  14. element = document.createElement( 'div' );
  15. document.body.appendChild( element );
  16. } );
  17. afterEach( () => {
  18. element.remove();
  19. } );
  20. it( 'the engine sets the initial selection on the first widget', () => {
  21. return ClassicTestEditor
  22. .create( element, { plugins: [ Paragraph, WidgetPlugin ] } )
  23. .then( editor => {
  24. editor.setData( '<widget></widget><p>foo</p>' );
  25. expect( getData( editor.document ) ).to.equal( '[<widget></widget>]<paragraph>foo</paragraph>' );
  26. return editor.destroy();
  27. } );
  28. } );
  29. } );
  30. function WidgetPlugin( editor ) {
  31. const schema = editor.document.schema;
  32. schema.registerItem( 'widget' );
  33. schema.allow( { name: 'widget', inside: '$root' } );
  34. schema.objects.add( 'widget' );
  35. buildModelConverter().for( editor.data.modelToView, editor.editing.modelToView )
  36. .fromElement( 'widget' )
  37. .toElement( 'widget' );
  38. buildViewConverter().for( editor.data.viewToModel )
  39. .fromElement( 'widget' )
  40. .toElement( 'widget' );
  41. }