|
@@ -46,6 +46,38 @@ describe( 'ChangeOperation', function() {
|
|
|
expect( doc.root.children[ 2 ].attrs.length ).to.be.equal( 0 );
|
|
expect( doc.root.children[ 2 ].attrs.length ).to.be.equal( 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should insert attribute to multiple ranges', function() {
|
|
|
|
|
+ var Document = modules[ 'document/document' ];
|
|
|
|
|
+ var ChangeOperation = modules[ 'document/changeoperation' ];
|
|
|
|
|
+ var Position = modules[ 'document/position' ];
|
|
|
|
|
+ var Range = modules[ 'document/range' ];
|
|
|
|
|
+ var Character = modules[ 'document/character' ];
|
|
|
|
|
+ var Attribute = modules[ 'document/attribute' ];
|
|
|
|
|
+
|
|
|
|
|
+ var doc = new Document();
|
|
|
|
|
+
|
|
|
|
|
+ var newAttr = new Attribute( 'isNew', true );
|
|
|
|
|
+
|
|
|
|
|
+ doc.root.children.push( new Character( doc.root, 'b' ) );
|
|
|
|
|
+ doc.root.children.push( new Character( doc.root, 'a' ) );
|
|
|
|
|
+ doc.root.children.push( new Character( doc.root, 'r' ) );
|
|
|
|
|
+
|
|
|
|
|
+ doc.applyOperation( new ChangeOperation(
|
|
|
|
|
+ [
|
|
|
|
|
+ new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
|
|
|
|
|
+ new Range( new Position( [ 2 ], doc ), new Position( [ 3 ], doc ) )
|
|
|
|
|
+ ],
|
|
|
|
|
+ null,
|
|
|
|
|
+ newAttr,
|
|
|
|
|
+ doc.version ) );
|
|
|
|
|
+
|
|
|
|
|
+ expect( doc.version ).to.be.equal( 1 );
|
|
|
|
|
+ expect( doc.root.children.length ).to.be.equal( 3 );
|
|
|
|
|
+ expect( doc.root.children[ 0 ].hasAttr( newAttr ) ).to.be.true;
|
|
|
|
|
+ expect( doc.root.children[ 1 ].attrs.length ).to.be.equal( 0 );
|
|
|
|
|
+ expect( doc.root.children[ 2 ].hasAttr( newAttr ) ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should add attribute to the existing attributes', function() {
|
|
it( 'should add attribute to the existing attributes', function() {
|
|
|
var Document = modules[ 'document/document' ];
|
|
var Document = modules[ 'document/document' ];
|
|
|
var ChangeOperation = modules[ 'document/changeoperation' ];
|
|
var ChangeOperation = modules[ 'document/changeoperation' ];
|
|
@@ -76,6 +108,42 @@ describe( 'ChangeOperation', function() {
|
|
|
expect( doc.root.children[ 0 ].hasAttr( barAttr ) ).to.be.true;
|
|
expect( doc.root.children[ 0 ].hasAttr( barAttr ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should change attributes on multiple ranges', function() {
|
|
|
|
|
+ var Document = modules[ 'document/document' ];
|
|
|
|
|
+ var ChangeOperation = modules[ 'document/changeoperation' ];
|
|
|
|
|
+ var Position = modules[ 'document/position' ];
|
|
|
|
|
+ var Range = modules[ 'document/range' ];
|
|
|
|
|
+ var Character = modules[ 'document/character' ];
|
|
|
|
|
+ var Attribute = modules[ 'document/attribute' ];
|
|
|
|
|
+
|
|
|
|
|
+ var doc = new Document();
|
|
|
|
|
+
|
|
|
|
|
+ var oldAttr = new Attribute( 'isNew', false );
|
|
|
|
|
+ var newAttr = new Attribute( 'isNew', true );
|
|
|
|
|
+
|
|
|
|
|
+ doc.root.children.push( new Character( doc.root, 'b', [ oldAttr ] ) );
|
|
|
|
|
+ doc.root.children.push( new Character( doc.root, 'a', [ oldAttr ] ) );
|
|
|
|
|
+ doc.root.children.push( new Character( doc.root, 'r', [ oldAttr ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ doc.applyOperation( new ChangeOperation(
|
|
|
|
|
+ [
|
|
|
|
|
+ new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
|
|
|
|
|
+ new Range( new Position( [ 2 ], doc ), new Position( [ 3 ], doc ) )
|
|
|
|
|
+ ],
|
|
|
|
|
+ oldAttr,
|
|
|
|
|
+ newAttr,
|
|
|
|
|
+ doc.version ) );
|
|
|
|
|
+
|
|
|
|
|
+ expect( doc.version ).to.be.equal( 1 );
|
|
|
|
|
+ expect( doc.root.children.length ).to.be.equal( 3 );
|
|
|
|
|
+ expect( doc.root.children[ 0 ].attrs.length ).to.be.equal( 1 );
|
|
|
|
|
+ expect( doc.root.children[ 0 ].hasAttr( newAttr ) ).to.be.true;
|
|
|
|
|
+ expect( doc.root.children[ 1 ].attrs.length ).to.be.equal( 1 );
|
|
|
|
|
+ expect( doc.root.children[ 1 ].hasAttr( oldAttr ) ).to.be.true;
|
|
|
|
|
+ expect( doc.root.children[ 2 ].attrs.length ).to.be.equal( 1 );
|
|
|
|
|
+ expect( doc.root.children[ 2 ].hasAttr( newAttr ) ).to.be.true;
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should change attribute to the set of nodes', function() {
|
|
it( 'should change attribute to the set of nodes', function() {
|
|
|
var Document = modules[ 'document/document' ];
|
|
var Document = modules[ 'document/document' ];
|
|
|
var ChangeOperation = modules[ 'document/changeoperation' ];
|
|
var ChangeOperation = modules[ 'document/changeoperation' ];
|
|
@@ -169,6 +237,38 @@ describe( 'ChangeOperation', function() {
|
|
|
expect( doc.root.children[ 0 ].hasAttr( barAttr ) ).to.be.true;
|
|
expect( doc.root.children[ 0 ].hasAttr( barAttr ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should remove attributes on multiple ranges', function() {
|
|
|
|
|
+ var Document = modules[ 'document/document' ];
|
|
|
|
|
+ var ChangeOperation = modules[ 'document/changeoperation' ];
|
|
|
|
|
+ var Position = modules[ 'document/position' ];
|
|
|
|
|
+ var Range = modules[ 'document/range' ];
|
|
|
|
|
+ var Character = modules[ 'document/character' ];
|
|
|
|
|
+ var Attribute = modules[ 'document/attribute' ];
|
|
|
|
|
+
|
|
|
|
|
+ var doc = new Document();
|
|
|
|
|
+
|
|
|
|
|
+ var fooAttr = new Attribute( 'foo', true );
|
|
|
|
|
+
|
|
|
|
|
+ doc.root.children.push( new Character( doc.root, 'b', [ fooAttr ] ) );
|
|
|
|
|
+ doc.root.children.push( new Character( doc.root, 'a', [ fooAttr ] ) );
|
|
|
|
|
+ doc.root.children.push( new Character( doc.root, 'r', [ fooAttr ] ) );
|
|
|
|
|
+
|
|
|
|
|
+ doc.applyOperation( new ChangeOperation(
|
|
|
|
|
+ [
|
|
|
|
|
+ new Range( new Position( [ 0 ], doc ), new Position( [ 1 ], doc ) ),
|
|
|
|
|
+ new Range( new Position( [ 2 ], doc ), new Position( [ 3 ], doc ) )
|
|
|
|
|
+ ],
|
|
|
|
|
+ fooAttr,
|
|
|
|
|
+ null,
|
|
|
|
|
+ doc.version ) );
|
|
|
|
|
+
|
|
|
|
|
+ expect( doc.version ).to.be.equal( 1 );
|
|
|
|
|
+ expect( doc.root.children.length ).to.be.equal( 3 );
|
|
|
|
|
+ expect( doc.root.children[ 0 ].attrs.length ).to.be.equal( 0 );
|
|
|
|
|
+ expect( doc.root.children[ 1 ].hasAttr( fooAttr ) ).to.be.true;
|
|
|
|
|
+ expect( doc.root.children[ 2 ].attrs.length ).to.be.equal( 0 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should create a change operation as a reverse', function() {
|
|
it( 'should create a change operation as a reverse', function() {
|
|
|
var Document = modules[ 'document/document' ];
|
|
var Document = modules[ 'document/document' ];
|
|
|
var ChangeOperation = modules[ 'document/changeoperation' ];
|
|
var ChangeOperation = modules[ 'document/changeoperation' ];
|
|
@@ -181,15 +281,15 @@ describe( 'ChangeOperation', function() {
|
|
|
var oldAttr = new Attribute( 'x', 'old' );
|
|
var oldAttr = new Attribute( 'x', 'old' );
|
|
|
var newAttr = new Attribute( 'x', 'new' );
|
|
var newAttr = new Attribute( 'x', 'new' );
|
|
|
|
|
|
|
|
- var range = new Range( new Position( [ 0 ], doc ), new Position( [ 3 ], doc ) );
|
|
|
|
|
|
|
+ var ranges = [ new Range( new Position( [ 0 ], doc ), new Position( [ 3 ], doc ) ) ];
|
|
|
|
|
|
|
|
- var oppertaion = new ChangeOperation( range, oldAttr, newAttr, doc.version );
|
|
|
|
|
|
|
+ var oppertaion = new ChangeOperation( ranges, oldAttr, newAttr, doc.version );
|
|
|
|
|
|
|
|
var reverse = oppertaion.reverseOperation();
|
|
var reverse = oppertaion.reverseOperation();
|
|
|
|
|
|
|
|
expect( reverse ).to.be.an.instanceof( ChangeOperation );
|
|
expect( reverse ).to.be.an.instanceof( ChangeOperation );
|
|
|
expect( reverse.baseVersion ).to.be.equals( 1 );
|
|
expect( reverse.baseVersion ).to.be.equals( 1 );
|
|
|
- expect( reverse.range ).to.be.equals( range );
|
|
|
|
|
|
|
+ expect( reverse.ranges ).to.be.equals( ranges );
|
|
|
expect( reverse.oldAttr ).to.be.equals( newAttr );
|
|
expect( reverse.oldAttr ).to.be.equals( newAttr );
|
|
|
expect( reverse.newAttr ).to.be.equals( oldAttr );
|
|
expect( reverse.newAttr ).to.be.equals( oldAttr );
|
|
|
} );
|
|
} );
|