operation.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /**
  2. * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Batch from '../../../src/model/batch';
  6. import Operation from '../../../src/model/operation/operation';
  7. import { jsonParseStringify } from '../../../tests/model/_utils/utils';
  8. describe( 'Operation', () => {
  9. it( 'should save its base version', () => {
  10. const op = new Operation( 4 );
  11. expect( op.baseVersion ).to.equal( 4 );
  12. } );
  13. describe( 'isDocumentOperation', () => {
  14. it( 'operation is a document operation if it has base version set', () => {
  15. const op = new Operation( 0 );
  16. expect( op.isDocumentOperation ).to.be.true;
  17. } );
  18. it( 'operation is not a document operation if base version is null', () => {
  19. const op = new Operation( null );
  20. expect( op.isDocumentOperation ).to.be.false;
  21. } );
  22. } );
  23. describe( 'toJSON', () => {
  24. it( 'should create proper json object #1', () => {
  25. const op = new Operation( 4 );
  26. const serialized = jsonParseStringify( op );
  27. expect( serialized ).to.deep.equal( {
  28. __className: 'engine.model.operation.Operation',
  29. baseVersion: 4
  30. } );
  31. } );
  32. it( 'should create proper json object #1', () => {
  33. const op = new Operation( 4 );
  34. const batch = new Batch();
  35. batch.addOperation( op );
  36. const serialized = jsonParseStringify( op );
  37. expect( serialized ).to.deep.equal( {
  38. __className: 'engine.model.operation.Operation',
  39. baseVersion: 4
  40. } );
  41. } );
  42. } );
  43. describe( 'fromJSON', () => {
  44. it( 'should create proper Operation from json object', () => {
  45. const op = new Operation( 4 );
  46. const serialized = jsonParseStringify( op );
  47. const deserialized = Operation.fromJSON( serialized );
  48. expect( deserialized ).to.deep.equal( op );
  49. } );
  50. } );
  51. } );