removedelta.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: document, delta */
  6. 'use strict';
  7. const modules = bender.amd.require(
  8. 'document/document',
  9. 'document/position' );
  10. describe( 'Transaction', () => {
  11. let Document, Position;
  12. let doc, root;
  13. before( () => {
  14. Document = modules[ 'document/document' ];
  15. Position = modules[ 'document/position' ];
  16. } );
  17. beforeEach( () => {
  18. doc = new Document();
  19. root = doc.createRoot( 'root' );
  20. root.insertChildren( 0, 'foobar' );
  21. } );
  22. describe( 'remove', () => {
  23. it( 'should remove one element', () => {
  24. const position = new Position( [ 1 ], root );
  25. doc.createTransaction().remove( position );
  26. expect( root.getChildCount() ).to.equal( 5 );
  27. expect( root.getChild( 0 ).character ).to.equal( 'f' );
  28. expect( root.getChild( 1 ).character ).to.equal( 'o' );
  29. expect( root.getChild( 2 ).character ).to.equal( 'b' );
  30. expect( root.getChild( 3 ).character ).to.equal( 'a' );
  31. expect( root.getChild( 4 ).character ).to.equal( 'r' );
  32. } );
  33. it( 'should remove 3 elements', () => {
  34. const position = new Position( [ 1 ], root );
  35. doc.createTransaction().remove( position, 3 );
  36. expect( root.getChildCount() ).to.equal( 3 );
  37. expect( root.getChild( 0 ).character ).to.equal( 'f' );
  38. expect( root.getChild( 1 ).character ).to.equal( 'a' );
  39. expect( root.getChild( 2 ).character ).to.equal( 'r' );
  40. } );
  41. } );
  42. } );