8
0

removedelta.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. /* bender-include: ../../_tools/tools.js */
  7. 'use strict';
  8. const modules = bender.amd.require(
  9. 'document/document',
  10. 'document/position' );
  11. describe( 'Transaction', () => {
  12. let Document, Position;
  13. let doc, root;
  14. before( () => {
  15. Document = modules[ 'document/document' ];
  16. Position = modules[ 'document/position' ];
  17. } );
  18. beforeEach( () => {
  19. doc = new Document();
  20. root = doc.createRoot( 'root' );
  21. root.insertChildren( 0, 'foobar' );
  22. } );
  23. describe( 'remove', () => {
  24. it( 'should remove one element', () => {
  25. const position = new Position( [ 1 ], root );
  26. doc.makeTransaction().remove( position );
  27. expect( root.getChildCount() ).to.equal( 5 );
  28. expect( root.getChild( 0 ).character ).to.equal( 'f' );
  29. expect( root.getChild( 1 ).character ).to.equal( 'o' );
  30. expect( root.getChild( 2 ).character ).to.equal( 'b' );
  31. expect( root.getChild( 3 ).character ).to.equal( 'a' );
  32. expect( root.getChild( 4 ).character ).to.equal( 'r' );
  33. } );
  34. it( 'should remove 3 elements', () => {
  35. const position = new Position( [ 1 ], root );
  36. doc.makeTransaction().remove( position, 3 );
  37. expect( root.getChildCount() ).to.equal( 3 );
  38. expect( root.getChild( 0 ).character ).to.equal( 'f' );
  39. expect( root.getChild( 1 ).character ).to.equal( 'a' );
  40. expect( root.getChild( 2 ).character ).to.equal( 'r' );
  41. } );
  42. } );
  43. } );