batch.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import Batch from '../../src/model/batch';
  6. import Operation from '../../src/model/operation/operation';
  7. describe( 'Batch', () => {
  8. describe( 'type', () => {
  9. it( 'should default to "default"', () => {
  10. const batch = new Batch();
  11. expect( batch.type ).to.equal( 'default' );
  12. } );
  13. it( 'should be set to the value set in constructor', () => {
  14. const batch = new Batch( 'transparent' );
  15. expect( batch.type ).to.equal( 'transparent' );
  16. } );
  17. } );
  18. describe( 'addOperation()', () => {
  19. it( 'should add operation to the batch', () => {
  20. const batch = new Batch();
  21. const op = new Operation( 0 );
  22. batch.addOperation( op );
  23. expect( batch.operations.length ).to.equal( 1 );
  24. expect( batch.operations[ 0 ] ).to.equal( op );
  25. } );
  26. } );
  27. describe( 'baseVersion', () => {
  28. it( 'should return base version of the first operation from the batch', () => {
  29. const batch = new Batch();
  30. const operation = new Operation( 2 );
  31. batch.addOperation( operation );
  32. expect( batch.baseVersion ).to.equal( 2 );
  33. } );
  34. it( 'should return null if there are no operations in batch', () => {
  35. const batch = new Batch();
  36. expect( batch.baseVersion ).to.be.null;
  37. } );
  38. it( 'should return null if all operations in batch have base version set to null', () => {
  39. const batch = new Batch();
  40. const opA = new Operation( null );
  41. const opB = new Operation( null );
  42. batch.addOperation( opA );
  43. batch.addOperation( opB );
  44. expect( batch.baseVersion ).to.equal( null );
  45. } );
  46. } );
  47. } );