nooperation.js 1.8 KB

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