Piotr Jasiun 10 роки тому
батько
коміт
34b1714dc3

+ 67 - 0
packages/ckeditor5-engine/tests/document/deltas/delta.js

@@ -0,0 +1,67 @@
+/**
+ * @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* bender-tags: document, delta */
+
+/* bender-include: ../../_tools/tools.js */
+
+'use strict';
+
+const getIteratorCount = bender.tools.core.getIteratorCount;
+
+const modules = bender.amd.require(
+	'document/deltas/delta' );
+
+describe( 'Delta', () => {
+	let Delta;
+
+	before( () => {
+		Delta = modules[ 'document/deltas/delta' ];
+	} );
+
+	describe( 'constructor', () => {
+		it( 'should create an delta with empty properties', () => {
+			const delta = new Delta();
+
+			expect( delta ).to.have.property( 'transaction' ).that.is.null;
+			expect( delta ).to.have.property( 'operations' ).that.a( 'array' ).and.have.length( 0 );
+		} );
+	} );
+
+	describe( 'addOperation', () => {
+		it( 'should add operation to the delta', () => {
+			const delta = new Delta();
+			const operation = {};
+
+			delta.addOperation( operation );
+
+			expect( delta.operations ).to.have.length( 1 );
+			expect( delta.operations[ 0 ] ).to.equal( operation );
+		} );
+
+		it( 'should add delta property to the operation', () => {
+			const delta = new Delta();
+			const operation = {};
+
+			delta.addOperation( operation );
+
+			expect( operation.delta ).to.equal( delta );
+		} );
+	} );
+
+	describe( 'iterator', () => {
+		it( 'should iterate over delta operations', () => {
+			const delta = new Delta();
+
+			delta.addOperation( {} );
+			delta.addOperation( {} );
+			delta.addOperation( {} );
+
+			const count = getIteratorCount( delta );
+
+			expect( count ).to.equal( 3 );
+		} );
+	} );
+} );