nooperation.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. import Model from '../../../src/model/model';
  6. import NoOperation from '../../../src/model/operation/nooperation';
  7. describe( 'NoOperation', () => {
  8. let model, noop, doc;
  9. beforeEach( () => {
  10. noop = new NoOperation( 0 );
  11. model = new Model();
  12. doc = model.document;
  13. } );
  14. it( 'should not throw an error when applied', () => {
  15. expect( () => model.applyOperation( 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 NoOperation 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 = noop.toJSON();
  30. expect( serialized ).to.deep.equal( {
  31. __className: 'NoOperation',
  32. baseVersion: 0
  33. } );
  34. } );
  35. } );
  36. describe( 'fromJSON', () => {
  37. it( 'should create proper NoOperation from json object', () => {
  38. const serialized = noop.toJSON();
  39. const deserialized = NoOperation.fromJSON( serialized, doc );
  40. expect( deserialized ).to.deep.equal( noop );
  41. } );
  42. } );
  43. } );