8
0

nooperation.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. it( 'should be a document operation', () => {
  31. expect( noop.isDocumentOperation ).to.true;
  32. } );
  33. describe( 'toJSON', () => {
  34. it( 'should create proper json object', () => {
  35. const serialized = jsonParseStringify( noop );
  36. expect( serialized ).to.deep.equal( {
  37. __className: 'engine.model.operation.NoOperation',
  38. baseVersion: 0
  39. } );
  40. } );
  41. } );
  42. describe( 'fromJSON', () => {
  43. it( 'should create proper NoOperation from json object', () => {
  44. const serialized = jsonParseStringify( noop );
  45. const deserialized = NoOperation.fromJSON( serialized, doc );
  46. expect( deserialized ).to.deep.equal( noop );
  47. } );
  48. } );
  49. } );