nooperation.js 1.7 KB

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