nooperation.js 1.6 KB

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