delta.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: document, delta */
  6. /* bender-include: ../../_tools/tools.js */
  7. 'use strict';
  8. const getIteratorCount = bender.tools.core.getIteratorCount;
  9. const modules = bender.amd.require(
  10. 'document/delta/delta' );
  11. describe( 'Delta', () => {
  12. let Delta;
  13. before( () => {
  14. Delta = modules[ 'document/delta/delta' ];
  15. } );
  16. describe( 'constructor', () => {
  17. it( 'should create an delta with empty properties', () => {
  18. const delta = new Delta();
  19. expect( delta ).to.have.property( 'transaction' ).that.is.null;
  20. expect( delta ).to.have.property( 'operations' ).that.a( 'array' ).and.have.length( 0 );
  21. } );
  22. } );
  23. describe( 'addOperation', () => {
  24. it( 'should add operation to the delta', () => {
  25. const delta = new Delta();
  26. const operation = {};
  27. delta.addOperation( operation );
  28. expect( delta.operations ).to.have.length( 1 );
  29. expect( delta.operations[ 0 ] ).to.equal( operation );
  30. } );
  31. it( 'should add delta property to the operation', () => {
  32. const delta = new Delta();
  33. const operation = {};
  34. delta.addOperation( operation );
  35. expect( operation.delta ).to.equal( delta );
  36. } );
  37. } );
  38. describe( 'iterator', () => {
  39. it( 'should iterate over delta operations', () => {
  40. const delta = new Delta();
  41. delta.addOperation( {} );
  42. delta.addOperation( {} );
  43. delta.addOperation( {} );
  44. const count = getIteratorCount( delta );
  45. expect( count ).to.equal( 3 );
  46. } );
  47. } );
  48. } );