699.js 1.6 KB

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