8
0

unwrapdelta.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. /* bender-include: ../../_tools/tools.js */
  7. 'use strict';
  8. const modules = bender.amd.require(
  9. 'core/treemodel/document',
  10. 'core/treemodel/position',
  11. 'core/treemodel/element',
  12. 'core/ckeditorerror'
  13. );
  14. describe( 'Batch', () => {
  15. let Document, Position, Element, CKEditorError;
  16. let doc, root, p;
  17. before( () => {
  18. Document = modules[ 'core/treemodel/document' ];
  19. Position = modules[ 'core/treemodel/position' ];
  20. Element = modules[ 'core/treemodel/element' ];
  21. CKEditorError = modules[ 'core/ckeditorerror' ];
  22. } );
  23. beforeEach( () => {
  24. doc = new Document();
  25. root = doc.createRoot( 'root' );
  26. p = new Element( 'p', [], 'xyz' );
  27. root.insertChildren( 0, [ 'a', p, 'b' ] );
  28. } );
  29. describe( 'unwrap', () => {
  30. it( 'should unwrap given element', () => {
  31. doc.batch().unwrap( p );
  32. expect( root.getChildCount() ).to.equal( 5 );
  33. expect( root.getChild( 0 ).character ).to.equal( 'a' );
  34. expect( root.getChild( 1 ).character ).to.equal( 'x' );
  35. expect( root.getChild( 2 ).character ).to.equal( 'y' );
  36. expect( root.getChild( 3 ).character ).to.equal( 'z' );
  37. expect( root.getChild( 4 ).character ).to.equal( 'b' );
  38. } );
  39. it( 'should throw if element to unwrap has no parent', () => {
  40. let element = new Element( 'p' );
  41. expect( () => {
  42. doc.batch().unwrap( element );
  43. } ).to.throw( CKEditorError, /^batch-unwrap-element-no-parent/ );
  44. } );
  45. it( 'should be chainable', () => {
  46. const batch = doc.batch();
  47. const chain = batch.unwrap( p );
  48. expect( chain ).to.equal( batch );
  49. } );
  50. } );
  51. } );