weakinsertdelta.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. 'use strict';
  7. import Document from '/ckeditor5/core/treemodel/document.js';
  8. import Position from '/ckeditor5/core/treemodel/position.js';
  9. describe( 'Batch', () => {
  10. let doc, root, batch, chain, attrs;
  11. beforeEach( () => {
  12. doc = new Document();
  13. root = doc.createRoot( 'root' );
  14. root.insertChildren( 0, 'abc' );
  15. batch = doc.batch();
  16. attrs = [ [ 'bold', true ], [ 'foo', 'bar' ] ];
  17. doc.selection.setAttributesTo( attrs );
  18. chain = batch.weakInsert( new Position( root, [ 2 ] ), 'xyz' );
  19. } );
  20. describe( 'weakInsert', () => {
  21. it( 'should insert given nodes at given position', () => {
  22. expect( root.getChildCount() ).to.equal( 6 );
  23. expect( root.getChild( 2 ).character ).to.equal( 'x' );
  24. expect( root.getChild( 3 ).character ).to.equal( 'y' );
  25. expect( root.getChild( 4 ).character ).to.equal( 'z' );
  26. } );
  27. it( 'should set inserted nodes attributes to same as current selection attributes', () => {
  28. expect( Array.from( root.getChild( 2 )._attrs ) ).to.deep.equal( attrs );
  29. expect( Array.from( root.getChild( 3 )._attrs ) ).to.deep.equal( attrs );
  30. expect( Array.from( root.getChild( 4 )._attrs ) ).to.deep.equal( attrs );
  31. } );
  32. it( 'should be chainable', () => {
  33. expect( chain ).to.equal( batch );
  34. } );
  35. } );
  36. } );