8
0

nooperation.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 return empty object when executed', () => {
  18. expect( noop._execute() ).to.deep.equal( {} );
  19. } );
  20. it( 'should create a NoOperation as a reverse', () => {
  21. const reverse = noop.getReversed();
  22. expect( reverse ).to.be.an.instanceof( NoOperation );
  23. expect( reverse.baseVersion ).to.equal( 1 );
  24. } );
  25. it( 'should create NoOperation having same parameters when cloned', () => {
  26. const clone = noop.clone();
  27. expect( clone ).to.be.an.instanceof( NoOperation );
  28. expect( clone.baseVersion ).to.equal( 0 );
  29. } );
  30. describe( 'toJSON', () => {
  31. it( 'should create proper json object', () => {
  32. const serialized = jsonParseStringify( noop );
  33. expect( serialized ).to.deep.equal( {
  34. __className: 'engine.model.operation.NoOperation',
  35. baseVersion: 0
  36. } );
  37. } );
  38. } );
  39. describe( 'fromJSON', () => {
  40. it( 'should create proper NoOperation from json object', () => {
  41. const serialized = jsonParseStringify( noop );
  42. const deserialized = NoOperation.fromJSON( serialized, doc );
  43. expect( deserialized ).to.deep.equal( noop );
  44. } );
  45. } );
  46. } );