weakinsertdelta.js 1.5 KB

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