nooperation.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. 'use strict';
  7. import Document from '/ckeditor5/engine/model/document.js';
  8. import NoOperation from '/ckeditor5/engine/model/operation/nooperation.js';
  9. import { jsonParseStringify, wrapInDelta } from '/tests/engine/model/_utils/utils.js';
  10. describe( 'NoOperation', () => {
  11. let noop, doc, root;
  12. beforeEach( () => {
  13. noop = new NoOperation( 0 );
  14. doc = new Document();
  15. root = doc.createRoot();
  16. } );
  17. it( 'should not throw an error when applied', () => {
  18. expect( () => doc.applyOperation( wrapInDelta( noop ) ) ).to.not.throw( Error );
  19. } );
  20. it( 'should create a NoOperation as a reverse', () => {
  21. const reverse = noop.getReversed();
  22. expect( reverse ).to.be.an.instanceof( NoOperation );
  23. expect( reverse.baseVersion ).to.equal( 1 );
  24. } );
  25. it( 'should create a do-nothing operation having same parameters when cloned', () => {
  26. const clone = noop.clone();
  27. expect( clone ).to.be.an.instanceof( NoOperation );
  28. expect( clone.baseVersion ).to.equal( 0 );
  29. } );
  30. describe( 'toJSON', () => {
  31. it( 'should create proper json object', () => {
  32. const serialized = jsonParseStringify( noop );
  33. expect( serialized ).to.deep.equal( {
  34. __className: 'engine.model.operation.NoOperation',
  35. baseVersion: 0
  36. } );
  37. } );
  38. } );
  39. describe( 'fromJSON', () => {
  40. it( 'should create proper NoOperation from json object', () => {
  41. const serialized = jsonParseStringify( noop );
  42. const deserialized = NoOperation.fromJSON( serialized, doc );
  43. expect( deserialized ).to.deep.equal( noop );
  44. } );
  45. } );
  46. } );