weakinsertdelta.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. 'use strict';
  7. const modules = bender.amd.require(
  8. 'treemodel/document',
  9. 'treemodel/attribute',
  10. 'treemodel/position'
  11. );
  12. describe( 'Batch', () => {
  13. let Document, Attribute, Position;
  14. before( () => {
  15. Document = modules[ 'treemodel/document' ];
  16. Attribute = modules[ 'treemodel/attribute' ];
  17. Position = modules[ 'treemodel/position' ];
  18. } );
  19. let doc, root, batch, chain, attrs;
  20. beforeEach( () => {
  21. doc = new Document();
  22. root = doc.createRoot( 'root' );
  23. root.insertChildren( 0, 'abc' );
  24. batch = doc.batch();
  25. attrs = [
  26. new Attribute( 'bold', true ),
  27. new Attribute( 'foo', 'bar' )
  28. ];
  29. doc.selection.setAttrsTo( attrs );
  30. chain = batch.weakInsert( new Position( root, [ 2 ] ), 'xyz' );
  31. } );
  32. describe( 'insert', () => {
  33. it( 'should insert given nodes at given position', () => {
  34. expect( root.getChildCount() ).to.equal( 6 );
  35. expect( root.getChild( 2 ).character ).to.equal( 'x' );
  36. expect( root.getChild( 3 ).character ).to.equal( 'y' );
  37. expect( root.getChild( 4 ).character ).to.equal( 'z' );
  38. } );
  39. it( 'should set inserted nodes attributes to same as current selection attributes', () => {
  40. expect( Array.from( root.getChild( 2 ).getAttrs() ) ).to.deep.equal( attrs );
  41. expect( Array.from( root.getChild( 3 ).getAttrs() ) ).to.deep.equal( attrs );
  42. expect( Array.from( root.getChild( 4 ).getAttrs() ) ).to.deep.equal( attrs );
  43. } );
  44. it( 'should be chainable', () => {
  45. expect( chain ).to.equal( batch );
  46. } );
  47. } );
  48. } );