8
0

batch.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @license Copyright (c) 2003-2019, 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. describe( 'is()', () => {
  48. let batch;
  49. beforeEach( () => {
  50. batch = new Batch();
  51. } );
  52. it( 'should return true for "batch"', () => {
  53. expect( batch.is( 'batch' ) ).to.be.true;
  54. expect( batch.is( 'model:batch' ) ).to.be.true;
  55. } );
  56. it( 'should return false for incorrect values', () => {
  57. expect( batch.is( 'model' ) ).to.be.false;
  58. expect( batch.is( 'node' ) ).to.be.false;
  59. expect( batch.is( 'model:element' ) ).to.be.false;
  60. expect( batch.is( 'element', 'paragraph' ) ).to.be.false;
  61. } );
  62. } );
  63. } );