nooperation.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Document from '../../../src/model/document';
  6. import NoOperation from '../../../src/model/operation/nooperation';
  7. import { jsonParseStringify, wrapInDelta } from '../../../tests/model/_utils/utils';
  8. describe( 'NoOperation', () => {
  9. let noop, doc;
  10. beforeEach( () => {
  11. noop = new NoOperation( 0 );
  12. doc = new Document();
  13. } );
  14. it( 'should not throw an error when applied', () => {
  15. expect( () => doc.applyOperation( wrapInDelta( noop ) ) ).to.not.throw( Error );
  16. } );
  17. it( 'should create a NoOperation as a reverse', () => {
  18. const reverse = noop.getReversed();
  19. expect( reverse ).to.be.an.instanceof( NoOperation );
  20. expect( reverse.baseVersion ).to.equal( 1 );
  21. } );
  22. it( 'should create a do-nothing operation having same parameters when cloned', () => {
  23. const clone = noop.clone();
  24. expect( clone ).to.be.an.instanceof( NoOperation );
  25. expect( clone.baseVersion ).to.equal( 0 );
  26. } );
  27. describe( 'toJSON', () => {
  28. it( 'should create proper json object', () => {
  29. const serialized = jsonParseStringify( noop );
  30. expect( serialized ).to.deep.equal( {
  31. __className: 'engine.model.operation.NoOperation',
  32. baseVersion: 0
  33. } );
  34. } );
  35. } );
  36. describe( 'fromJSON', () => {
  37. it( 'should create proper NoOperation from json object', () => {
  38. const serialized = jsonParseStringify( noop );
  39. const deserialized = NoOperation.fromJSON( serialized, doc );
  40. expect( deserialized ).to.deep.equal( noop );
  41. } );
  42. } );
  43. } );