unwrapdelta.js 1.7 KB

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