nooperation.js 1.6 KB

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