operation.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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( 'Operation', () => {
  8. it( 'should save its base version', () => {
  9. const op = new Operation( 4 );
  10. expect( op.baseVersion ).to.equal( 4 );
  11. } );
  12. describe( 'isDocumentOperation', () => {
  13. it( 'operation is a document operation if it has base version set', () => {
  14. const op = new Operation( 0 );
  15. expect( op.isDocumentOperation ).to.be.true;
  16. } );
  17. it( 'operation is not a document operation if base version is null', () => {
  18. const op = new Operation( null );
  19. expect( op.isDocumentOperation ).to.be.false;
  20. } );
  21. } );
  22. describe( 'toJSON', () => {
  23. it( 'should create proper json object #1', () => {
  24. const op = new Operation( 4 );
  25. const serialized = op.toJSON();
  26. expect( serialized ).to.deep.equal( {
  27. __className: 'Operation',
  28. baseVersion: 4
  29. } );
  30. } );
  31. it( 'should create proper json object #2', () => {
  32. const op = new Operation( 4 );
  33. const batch = new Batch();
  34. batch.addOperation( op );
  35. const serialized = op.toJSON();
  36. expect( serialized ).to.deep.equal( {
  37. __className: 'Operation',
  38. baseVersion: 4
  39. } );
  40. } );
  41. } );
  42. describe( 'fromJSON', () => {
  43. it( 'should create proper Operation from json object', () => {
  44. const op = new Operation( 4 );
  45. const serialized = op.toJSON();
  46. const deserialized = Operation.fromJSON( serialized );
  47. expect( deserialized ).to.deep.equal( op );
  48. } );
  49. } );
  50. } );