operation.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Delta from '../../../src/model/delta/delta';
  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. it( 'should be correctly transformed to JSON', () => {
  14. const delta = new Delta();
  15. const opInDelta = new Operation( 0 );
  16. delta.addOperation( opInDelta );
  17. const opOutsideDelta = new Operation( 0 );
  18. const parsedOutside = jsonParseStringify( opOutsideDelta );
  19. expect( parsedOutside.delta ).to.be.undefined;
  20. } );
  21. describe( 'toJSON', () => {
  22. it( 'should create proper json object', () => {
  23. const op = new Operation( 4 );
  24. const serialized = jsonParseStringify( op );
  25. expect( serialized ).to.deep.equal( {
  26. __className: 'engine.model.operation.Operation',
  27. baseVersion: 4
  28. } );
  29. } );
  30. } );
  31. describe( 'fromJSON', () => {
  32. it( 'should create proper Operation from json object', () => {
  33. const op = new Operation( 4 );
  34. const serialized = jsonParseStringify( op );
  35. const deserialized = Operation.fromJSON( serialized );
  36. expect( deserialized ).to.deep.equal( op );
  37. } );
  38. } );
  39. } );