8
0

operation.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import Batch from '../../../src/model/batch';
  6. import Operation from '../../../src/model/operation/operation';
  7. describe( 'Operation', () => {
  8. it( 'should save its base version', () => {
  9. const op = new Operation( 4 );
  10. expect( op.baseVersion ).to.equal( 4 );
  11. } );
  12. describe( 'isDocumentOperation', () => {
  13. it( 'operation is a document operation if it has base version set', () => {
  14. const op = new Operation( 0 );
  15. expect( op.isDocumentOperation ).to.be.true;
  16. } );
  17. it( 'operation is not a document operation if base version is null', () => {
  18. const op = new Operation( null );
  19. expect( op.isDocumentOperation ).to.be.false;
  20. } );
  21. } );
  22. describe( 'is()', () => {
  23. let operation;
  24. before( () => {
  25. operation = new Operation( null );
  26. } );
  27. it( 'should return true for all valid names of operation', () => {
  28. expect( operation.is( 'operation' ) ).to.be.true;
  29. expect( operation.is( 'model:operation' ) ).to.be.true;
  30. } );
  31. it( 'should return false for invalid parameters', () => {
  32. expect( operation.is( 'operation:attribute' ) ).to.be.false;
  33. expect( operation.is( 'model:operation:insert' ) ).to.be.false;
  34. expect( operation.is( 'noOperation' ) ).to.be.false;
  35. expect( operation.is( 'detachOperation' ) ).to.be.false;
  36. expect( operation.is( 'rootAttributeOperation' ) ).to.be.false;
  37. expect( operation.is( 'model:operation:rootAttribute' ) ).to.be.false;
  38. } );
  39. } );
  40. describe( 'toJSON', () => {
  41. it( 'should create proper json object #1', () => {
  42. const op = new Operation( 4 );
  43. const serialized = op.toJSON();
  44. expect( serialized ).to.deep.equal( {
  45. __className: 'Operation',
  46. baseVersion: 4
  47. } );
  48. } );
  49. it( 'should create proper json object #1', () => {
  50. const op = new Operation( 4 );
  51. const batch = new Batch();
  52. batch.addOperation( op );
  53. const serialized = op.toJSON();
  54. expect( serialized ).to.deep.equal( {
  55. __className: 'Operation',
  56. baseVersion: 4
  57. } );
  58. } );
  59. } );
  60. describe( 'fromJSON', () => {
  61. it( 'should create proper Operation from json object', () => {
  62. const op = new Operation( 4 );
  63. const serialized = op.toJSON();
  64. const deserialized = Operation.fromJSON( serialized );
  65. expect( deserialized ).to.deep.equal( op );
  66. } );
  67. } );
  68. } );