8
0

delta.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 coreTestUtils from '/tests/core/_utils/utils.js';
  8. import Delta from '/ckeditor5/core/treemodel/delta/delta.js';
  9. const getIteratorCount = coreTestUtils.getIteratorCount;
  10. describe( 'Delta', () => {
  11. describe( 'constructor', () => {
  12. it( 'should create an delta with empty properties', () => {
  13. const delta = new Delta();
  14. expect( delta ).to.have.property( 'batch' ).that.is.null;
  15. expect( delta ).to.have.property( 'operations' ).that.a( 'array' ).and.have.length( 0 );
  16. } );
  17. } );
  18. describe( 'addOperation', () => {
  19. it( 'should add operation to the delta', () => {
  20. const delta = new Delta();
  21. const operation = {};
  22. delta.addOperation( operation );
  23. expect( delta.operations ).to.have.length( 1 );
  24. expect( delta.operations[ 0 ] ).to.equal( operation );
  25. } );
  26. it( 'should add delta property to the operation', () => {
  27. const delta = new Delta();
  28. const operation = {};
  29. delta.addOperation( operation );
  30. expect( operation.delta ).to.equal( delta );
  31. } );
  32. } );
  33. describe( 'iterator', () => {
  34. it( 'should iterate over delta operations', () => {
  35. const delta = new Delta();
  36. delta.addOperation( {} );
  37. delta.addOperation( {} );
  38. delta.addOperation( {} );
  39. const count = getIteratorCount( delta.operations );
  40. expect( count ).to.equal( 3 );
  41. } );
  42. } );
  43. } );