8
0

operation.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* bender-tags: model, delta */
  6. import Delta from '/ckeditor5/engine/model/delta/delta.js';
  7. import Operation from '/ckeditor5/engine/model/operation/operation.js';
  8. import { jsonParseStringify } from '/tests/engine/model/_utils/utils.js';
  9. describe( 'Operation', () => {
  10. it( 'should save its base version', () => {
  11. let op = new Operation( 4 );
  12. expect( op.baseVersion ).to.equal( 4 );
  13. } );
  14. it( 'should be correctly transformed to JSON', () => {
  15. let delta = new Delta();
  16. let opInDelta = new Operation( 0 );
  17. delta.addOperation( opInDelta );
  18. let opOutsideDelta = new Operation( 0 );
  19. let parsedOutside = jsonParseStringify( opOutsideDelta );
  20. expect( parsedOutside.delta ).to.be.undefined;
  21. } );
  22. describe( 'toJSON', () => {
  23. it( 'should create proper json object', () => {
  24. const op = new Operation( 4 );
  25. const serialized = jsonParseStringify( op );
  26. expect( serialized ).to.deep.equal( {
  27. __className: 'engine.model.operation.Operation',
  28. baseVersion: 4
  29. } );
  30. } );
  31. } );
  32. describe( 'fromJSON', () => {
  33. it( 'should create proper Operation from json object', () => {
  34. const op = new Operation( 4 );
  35. const serialized = jsonParseStringify( op );
  36. const deserialized = Operation.fromJSON( serialized );
  37. expect( deserialized ).to.deep.equal( op );
  38. } );
  39. } );
  40. } );