8
0

operation.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. 'use strict';
  7. import Delta from '/ckeditor5/engine/model/delta/delta.js';
  8. import Operation from '/ckeditor5/engine/model/operation/operation.js';
  9. import { jsonParseStringify } from '/tests/engine/model/_utils/utils.js';
  10. describe( 'Operation', () => {
  11. it( 'should save its base version', () => {
  12. let op = new Operation( 4 );
  13. expect( op.baseVersion ).to.equal( 4 );
  14. } );
  15. it( 'should be correctly transformed to JSON', () => {
  16. let delta = new Delta();
  17. let opInDelta = new Operation( 0 );
  18. delta.addOperation( opInDelta );
  19. let opOutsideDelta = new Operation( 0 );
  20. let parsedOutside = jsonParseStringify( opOutsideDelta );
  21. expect( parsedOutside.delta ).to.be.undefined;
  22. } );
  23. describe( 'toJSON', () => {
  24. it( 'should create proper json object', () => {
  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. } );
  33. describe( 'fromJSON', () => {
  34. it( 'should create proper Operation from json object', () => {
  35. const op = new Operation( 4 );
  36. const serialized = jsonParseStringify( op );
  37. const deserialized = Operation.fromJSON( serialized );
  38. expect( deserialized ).to.deep.equal( op );
  39. } );
  40. } );
  41. } );