delta.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import transformations from '../../../../src/model/delta/basic-transformations'; // eslint-disable-line no-unused-vars
  6. import deltaTransform from '../../../../src/model/delta/transform';
  7. const transform = deltaTransform.transform;
  8. import Position from '../../../../src/model/position';
  9. import MoveOperation from '../../../../src/model/operation/moveoperation';
  10. import Delta from '../../../../src/model/delta/delta';
  11. import {
  12. expectDelta,
  13. getFilledDocument,
  14. } from '../../../../tests/model/delta/transform/_utils/utils';
  15. describe( 'Delta', () => {
  16. let doc, root, baseVersion;
  17. beforeEach( () => {
  18. doc = getFilledDocument();
  19. root = doc.getRoot();
  20. baseVersion = doc.version;
  21. } );
  22. it( 'should have baseVersion property, equal to the baseVersion of first operation in Delta or null', () => {
  23. const deltaA = new Delta();
  24. expect( deltaA.baseVersion ).to.be.null;
  25. const version = 5;
  26. deltaA.addOperation( new MoveOperation( new Position( root, [ 1, 2, 3 ] ), 4, new Position( root, [ 4, 0 ] ), version ) );
  27. expect( deltaA.baseVersion ).to.equal( 5 );
  28. } );
  29. it( 'should be transformable by another Delta', () => {
  30. const deltaA = new Delta();
  31. const deltaB = new Delta();
  32. deltaA.addOperation( new MoveOperation( new Position( root, [ 1, 2, 3 ] ), 4, new Position( root, [ 4, 0 ] ), baseVersion ) );
  33. deltaB.addOperation( new MoveOperation( new Position( root, [ 1, 2, 0 ] ), 2, new Position( root, [ 4, 1 ] ), baseVersion ) );
  34. const deltaAbyB = transform( deltaA, deltaB );
  35. const deltaBbyA = transform( deltaB, deltaA );
  36. expect( deltaAbyB.length ).to.equal( 1 );
  37. expectDelta( deltaAbyB[ 0 ], {
  38. type: Delta,
  39. operations: [
  40. {
  41. type: MoveOperation,
  42. sourcePosition: new Position( root, [ 1, 2, 1 ] ),
  43. howMany: 4,
  44. targetPosition: new Position( root, [ 4, 0 ] ),
  45. baseVersion: 1
  46. }
  47. ]
  48. } );
  49. expect( deltaBbyA.length ).to.equal( 1 );
  50. expectDelta( deltaBbyA[ 0 ], {
  51. type: Delta,
  52. operations: [
  53. {
  54. type: MoveOperation,
  55. sourcePosition: new Position( root, [ 1, 2, 0 ] ),
  56. howMany: 2,
  57. targetPosition: new Position( root, [ 4, 5 ] ),
  58. baseVersion: 1
  59. }
  60. ]
  61. } );
  62. } );
  63. } );