operation.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /**
  2. * @license Copyright (c) 2003-2018, 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( 'isDocumentOperation', () => {
  22. it( 'operation is a document operation if it has base version set', () => {
  23. const op = new Operation( 0 );
  24. expect( op.isDocumentOperation ).to.be.true;
  25. } );
  26. it( 'operation is not a document operation if base version is null', () => {
  27. const op = new Operation( null );
  28. expect( op.isDocumentOperation ).to.be.false;
  29. } );
  30. } );
  31. describe( 'toJSON', () => {
  32. it( 'should create proper json object', () => {
  33. const op = new Operation( 4 );
  34. const serialized = jsonParseStringify( op );
  35. expect( serialized ).to.deep.equal( {
  36. __className: 'engine.model.operation.Operation',
  37. baseVersion: 4
  38. } );
  39. } );
  40. } );
  41. describe( 'fromJSON', () => {
  42. it( 'should create proper Operation from json object', () => {
  43. const op = new Operation( 4 );
  44. const serialized = jsonParseStringify( op );
  45. const deserialized = Operation.fromJSON( serialized );
  46. expect( deserialized ).to.deep.equal( op );
  47. } );
  48. } );
  49. } );