|
|
@@ -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 );
|
|
|
+ } );
|
|
|
+ } );
|
|
|
+} );
|