8
0
Просмотр исходного кода

Added test for the DeltaReplayer constructor.

Maciej Bukowski 8 лет назад
Родитель
Сommit
4b4d241106

+ 6 - 6
packages/ckeditor5-engine/src/dev-utils/deltareplayer.js

@@ -31,15 +31,14 @@ export default class DeltaReplayer {
 	 */
 	setStringifiedDeltas( stringifiedDeltas ) {
 		if ( stringifiedDeltas === '' ) {
-			this._deltaToReplay = [];
+			this._deltasToReplay = [];
 
 			return;
 		}
 
-		this._deltaToReplay = stringifiedDeltas
+		this._deltasToReplay = stringifiedDeltas
 			.split( this._logSeparator )
-			.map( stringifiedDelta => JSON.parse( stringifiedDelta ) )
-			.map( jsonDelta => DeltaFactory.fromJSON( jsonDelta, this._document ) );
+			.map( stringifiedDelta => JSON.parse( stringifiedDelta ) );
 	}
 
 	/**
@@ -48,7 +47,7 @@ export default class DeltaReplayer {
 	 * @param {Number} timeInterval
 	 */
 	play( timeInterval = 1000 ) {
-		if ( this._deltaToReplay.length === 0 ) {
+		if ( this._deltasToReplay.length === 0 ) {
 			return;
 		}
 
@@ -88,7 +87,8 @@ export default class DeltaReplayer {
 
 		return new Promise( ( res, rej ) => {
 			document.enqueueChanges( () => {
-				const delta = this._deltaToReplay.shift();
+				const jsonDelta = this._deltasToReplay.shift();
+				const delta = DeltaFactory.fromJSON( jsonDelta, this._document );
 
 				if ( !delta ) {
 					return rej( new Error( 'No deltas to replay' ) );

+ 29 - 1
packages/ckeditor5-engine/tests/dev-utils/deltareplayer.js

@@ -4,6 +4,7 @@
  */
 
 import DeltaReplayer from '../../src/dev-utils/deltareplayer';
+import Document from '../../src/model/document';
 
 describe( 'DeltaReplayer', () => {
 	describe( 'constructor()', () => {
@@ -12,9 +13,36 @@ describe( 'DeltaReplayer', () => {
 			const stringifiedDeltas = '';
 			const deltaReplayer = new DeltaReplayer( fakeDocument, '---', stringifiedDeltas );
 
-			expect( deltaReplayer._deltaToReplay ).to.deep.equal( [] );
+			expect( deltaReplayer._deltasToReplay ).to.deep.equal( [] );
 			expect( deltaReplayer._document ).to.deep.equal( fakeDocument );
 			expect( deltaReplayer._logSeparator ).to.deep.equal( '---' );
 		} );
+
+		it( 'should be able to initialize replayer with deltas', () => {
+			const doc = new Document();
+			doc.createRoot( 'main' );
+
+			const delta = {
+				operations: [ {
+					baseVersion: 0,
+					position: {
+						root: 'main',
+						path: [ 0 ]
+					},
+					nodes: [ {
+						name: 'heading1',
+						children: [ {
+							data: 'The great world of open Web standards'
+						} ]
+					} ],
+					__className: 'engine.model.operation.InsertOperation'
+				} ],
+				__className: 'engine.model.delta.InsertDelta'
+			};
+
+			const deltaReplayer = new DeltaReplayer( doc, '---', JSON.stringify( delta ) );
+
+			expect( deltaReplayer._deltasToReplay ).to.deep.equal( [ delta ] );
+		} );
 	} );
 } );