wrapoperation.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 Element from '../../../src/model/element';
  7. import WrapOperation from '../../../src/model/operation/wrapoperation';
  8. import Position from '../../../src/model/position';
  9. describe( 'WrapOperation', () => {
  10. let model, doc, root;
  11. beforeEach( () => {
  12. model = new Model();
  13. doc = model.document;
  14. root = doc.createRoot();
  15. } );
  16. describe( 'type', () => {
  17. it( 'should be wrap', () => {
  18. const op = new WrapOperation(
  19. new Position( root, [ 0 ] ),
  20. 1,
  21. new Position( doc.graveyard, [ 0 ] ),
  22. doc.version
  23. );
  24. expect( op.type ).to.equal( 'wrap' );
  25. } );
  26. } );
  27. describe( 'toJSON', () => {
  28. it( 'should create proper serialized object #1', () => {
  29. const op = new WrapOperation(
  30. new Position( root, [ 0 ] ),
  31. 1,
  32. new Position( doc.graveyard, [ 0 ] ),
  33. doc.version
  34. );
  35. const serialized = op.toJSON();
  36. expect( serialized ).to.deep.equal( {
  37. __className: 'WrapOperation',
  38. baseVersion: 0,
  39. position: op.position.toJSON(),
  40. graveyardPosition: op.graveyardPosition.toJSON(),
  41. howMany: 1
  42. } );
  43. } );
  44. it( 'should create proper serialized object #2', () => {
  45. const op = new WrapOperation(
  46. new Position( root, [ 0 ] ),
  47. 1,
  48. new Element( 'paragraph' ),
  49. doc.version
  50. );
  51. const serialized = op.toJSON();
  52. expect( serialized ).to.deep.equal( {
  53. __className: 'WrapOperation',
  54. baseVersion: 0,
  55. position: op.position.toJSON(),
  56. element: op.element.toJSON(),
  57. howMany: 1
  58. } );
  59. } );
  60. } );
  61. describe( 'fromJSON', () => {
  62. it( 'should create proper WrapOperation from json object', () => {
  63. const op = new WrapOperation(
  64. new Position( root, [ 0 ] ),
  65. 1,
  66. new Position( doc.graveyard, [ 0 ] ),
  67. doc.version
  68. );
  69. const serialized = op.toJSON();
  70. const deserialized = WrapOperation.fromJSON( serialized, doc );
  71. expect( deserialized ).to.deep.equal( op );
  72. } );
  73. } );
  74. } );