699.js 1.7 KB

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