8
0

699.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  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 { getData as getModelData } from '../../src/dev-utils/model';
  9. import { getData as getViewData } from '../../src/dev-utils/view';
  10. describe( 'Bug ckeditor5-engine#699', () => {
  11. let element;
  12. beforeEach( () => {
  13. element = document.createElement( 'div' );
  14. document.body.appendChild( element );
  15. } );
  16. afterEach( () => {
  17. element.remove();
  18. } );
  19. it( 'the engine sets the initial selection on the first widget', () => {
  20. return ClassicTestEditor
  21. .create( element, { plugins: [ Paragraph, WidgetPlugin ] } )
  22. .then( editor => {
  23. editor.setData( '<widget></widget><p>foo</p>' );
  24. expect( getModelData( editor.model ) ).to.equal( '[<widget></widget>]<paragraph>foo</paragraph>' );
  25. expect( getViewData( editor.editing.view ) ).to.equal( '[<widget></widget>]<p>foo</p>' );
  26. return editor.destroy();
  27. } );
  28. } );
  29. } );
  30. function WidgetPlugin( editor ) {
  31. const schema = editor.model.schema;
  32. schema.register( 'widget', {
  33. isObject: true
  34. } );
  35. schema.extend( 'widget', { allowIn: '$root' } );
  36. editor.conversion.for( 'downcast' ).elementToElement( {
  37. model: 'widget',
  38. view: 'widget'
  39. } );
  40. editor.conversion.for( 'upcast' ).elementToElement( {
  41. model: 'widget',
  42. view: 'widget'
  43. } );
  44. }