Procházet zdrojové kódy

Added: Delta.baseVersion setter + tests.

Szymon Cofalik před 9 roky
rodič
revize
cc8a67c055

+ 9 - 0
packages/ckeditor5-engine/src/model/delta/delta.js

@@ -57,6 +57,15 @@ export default class Delta {
 	}
 
 	/**
+	 * @param {Number} baseVersion
+	 */
+	set baseVersion( baseVersion ) {
+		for ( let operation of this.operations ) {
+			operation.baseVersion = baseVersion++;
+		}
+	}
+
+	/**
 	 * A class that will be used when creating reversed delta.
 	 *
 	 * @private

+ 26 - 0
packages/ckeditor5-engine/tests/model/delta/delta.js

@@ -59,6 +59,32 @@ describe( 'Delta', () => {
 		} );
 	} );
 
+	describe( 'baseVersion', () => {
+		it( 'should return baseVersion of first operation in the delta', () => {
+			const delta = new Delta();
+
+			delta.addOperation( { baseVersion: 0 } );
+			delta.addOperation( { baseVersion: 1 } );
+			delta.addOperation( { baseVersion: 2 } );
+
+			expect( delta.baseVersion ).to.equal( 0 );
+		} );
+
+		it( 'should change baseVersion of it\'s operations', () => {
+			const delta = new Delta();
+
+			delta.addOperation( { baseVersion: 0 } );
+			delta.addOperation( { baseVersion: 1 } );
+			delta.addOperation( { baseVersion: 2 } );
+
+			delta.baseVersion = 10;
+
+			expect( delta.operations[ 0 ].baseVersion ).to.equal( 10 );
+			expect( delta.operations[ 1 ].baseVersion ).to.equal( 11 );
+			expect( delta.operations[ 2 ].baseVersion ).to.equal( 12 );
+		} );
+	} );
+
 	describe( 'addOperation', () => {
 		it( 'should add operation to the delta', () => {
 			const delta = new Delta();