8
0

delta.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. /* bender-include: ../../_tools/tools.js */
  7. 'use strict';
  8. const getIteratorCount = bender.tools.core.getIteratorCount;
  9. const modules = bender.amd.require(
  10. 'core/treemodel/delta/delta'
  11. );
  12. describe( 'Delta', () => {
  13. let Delta;
  14. before( () => {
  15. Delta = modules[ 'core/treemodel/delta/delta' ];
  16. } );
  17. describe( 'constructor', () => {
  18. it( 'should create an delta with empty properties', () => {
  19. const delta = new Delta();
  20. expect( delta ).to.have.property( 'batch' ).that.is.null;
  21. expect( delta ).to.have.property( 'operations' ).that.a( 'array' ).and.have.length( 0 );
  22. } );
  23. } );
  24. describe( 'addOperation', () => {
  25. it( 'should add operation to the delta', () => {
  26. const delta = new Delta();
  27. const operation = {};
  28. delta.addOperation( operation );
  29. expect( delta.operations ).to.have.length( 1 );
  30. expect( delta.operations[ 0 ] ).to.equal( operation );
  31. } );
  32. it( 'should add delta property to the operation', () => {
  33. const delta = new Delta();
  34. const operation = {};
  35. delta.addOperation( operation );
  36. expect( operation.delta ).to.equal( delta );
  37. } );
  38. } );
  39. describe( 'iterator', () => {
  40. it( 'should iterate over delta operations', () => {
  41. const delta = new Delta();
  42. delta.addOperation( {} );
  43. delta.addOperation( {} );
  44. delta.addOperation( {} );
  45. const count = getIteratorCount( delta.operations );
  46. expect( count ).to.equal( 3 );
  47. } );
  48. } );
  49. } );