unwrapdelta.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: treemodel, delta */
  6. 'use strict';
  7. import Document from '/ckeditor5/core/treemodel/document.js';
  8. import Element from '/ckeditor5/core/treemodel/element.js';
  9. import CKEditorError from '/ckeditor5/core/ckeditorerror.js';
  10. describe( 'Batch', () => {
  11. let doc, root, p;
  12. beforeEach( () => {
  13. doc = new Document();
  14. root = doc.createRoot( 'root' );
  15. p = new Element( 'p', [], 'xyz' );
  16. root.insertChildren( 0, [ 'a', p, 'b' ] );
  17. } );
  18. describe( 'unwrap', () => {
  19. it( 'should unwrap given element', () => {
  20. doc.batch().unwrap( p );
  21. expect( root.getChildCount() ).to.equal( 5 );
  22. expect( root.getChild( 0 ).character ).to.equal( 'a' );
  23. expect( root.getChild( 1 ).character ).to.equal( 'x' );
  24. expect( root.getChild( 2 ).character ).to.equal( 'y' );
  25. expect( root.getChild( 3 ).character ).to.equal( 'z' );
  26. expect( root.getChild( 4 ).character ).to.equal( 'b' );
  27. } );
  28. it( 'should throw if element to unwrap has no parent', () => {
  29. let element = new Element( 'p' );
  30. expect( () => {
  31. doc.batch().unwrap( element );
  32. } ).to.throw( CKEditorError, /^batch-unwrap-element-no-parent/ );
  33. } );
  34. it( 'should be chainable', () => {
  35. const batch = doc.batch();
  36. const chain = batch.unwrap( p );
  37. expect( chain ).to.equal( batch );
  38. } );
  39. } );
  40. } );