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

Prepare a set of tests to test if transformSets returns proper values.

Dominik Szczepaniak 6 лет назад
Родитель
Сommit
a4a05dcb94
1 измененных файлов с 67 добавлено и 0 удалено
  1. 67 0
      packages/ckeditor5-engine/tests/model/operation/transform.js

+ 67 - 0
packages/ckeditor5-engine/tests/model/operation/transform.js

@@ -4,6 +4,7 @@
  */
 
 import { transform } from '../../../src/model/operation/transform';
+import { transformSets } from '@ckeditor/ckeditor5-engine/src/model/operation/transform';
 
 import Model from '../../../src/model/model';
 import RootElement from '../../../src/model/rootelement';
@@ -2607,3 +2608,69 @@ describe( 'transform', () => {
 		} );
 	} );
 } );
+
+describe( 'transformSets', () => {
+	let model, doc, root, node;
+
+	beforeEach( () => {
+		model = new Model();
+		doc = model.document;
+		root = doc.createRoot();
+
+		node = new Node();
+	} );
+
+	it( 'originalOperations should correctly link transformed operations with original operations #1', () => {
+		const position = new Position( root, [ 0 ] );
+
+		const a = new InsertOperation( position, [ node ], 0 );
+
+		const { operationsA, originalOperations } = transformSets( [ a ], [], {
+			document: doc,
+			useRelations: false,
+			padWithNoOps: false
+		} );
+
+		expect( originalOperations.get( operationsA[ 0 ] ) ).to.equal( a );
+	} );
+
+	it( 'originalOperations should correctly link transformed operations with original operations #2', () => {
+		const position = new Position( root, [ 0 ] );
+
+		const b = new InsertOperation( position, [ node ], 0 );
+
+		const { operationsB, originalOperations } = transformSets( [], [ b ], {
+			document: doc,
+			useRelations: false,
+			padWithNoOps: false
+		} );
+
+		expect( originalOperations.get( operationsB[ 0 ] ) ).to.equal( b );
+	} );
+
+	it( 'originalOperations should correctly link transformed operations with original operations #3', () => {
+		const position = new Position( root, [ 4 ] );
+
+		const a = new InsertOperation( position, [ node ], 0 );
+		const b = new AttributeOperation(
+			new Range(
+				new Position( root, [ 2 ] ),
+				new Position( root, [ 11 ] )
+			),
+			'foo',
+			'bar',
+			'xyz',
+			0
+		);
+
+		const { operationsA, operationsB, originalOperations } = transformSets( [ a ], [ b ], {
+			document: doc,
+			useRelations: false,
+			padWithNoOps: false
+		} );
+
+		expect( originalOperations.get( operationsA[ 0 ] ) ).to.equal( a );
+		expect( originalOperations.get( operationsB[ 0 ] ) ).to.equal( b );
+		expect( originalOperations.get( operationsB[ 1 ] ) ).to.equal( b );
+	} );
+} );