|
|
@@ -258,8 +258,9 @@ describe( 'ChangeOperation', () => {
|
|
|
expect( root.getChild( 2 ).hasAttr( fooAttr ) ).to.be.true;
|
|
|
} );
|
|
|
|
|
|
- it( 'should throw an error when one try to remove and the attribute does not exists', () => {
|
|
|
+ it( 'should throw an error when one try to change and the new and old attributes have different keys', () => {
|
|
|
let fooAttr = new Attribute( 'foo', true );
|
|
|
+ let barAttr = new Attribute( 'bar', true );
|
|
|
|
|
|
root.insertChildren( 0, 'x' );
|
|
|
|
|
|
@@ -269,51 +270,36 @@ describe( 'ChangeOperation', () => {
|
|
|
new ChangeOperation(
|
|
|
new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) ),
|
|
|
fooAttr,
|
|
|
- null,
|
|
|
+ barAttr,
|
|
|
doc.version
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
- ).to.throw( CKEditorError, /operation-change-no-attr-to-remove/ );
|
|
|
+ ).to.throw( CKEditorError, /operation-change-different-keys/ );
|
|
|
} );
|
|
|
|
|
|
- it( 'should throw an error when one try to insert and the attribute already exists', () => {
|
|
|
- let x1Attr = new Attribute( 'x', 1 );
|
|
|
- let x2Attr = new Attribute( 'x', 2 );
|
|
|
+ it( 'should create operation with the same parameters when cloned', () => {
|
|
|
+ let range = new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) );
|
|
|
+ let oldAttr = new Attribute( 'foo', 'old' );
|
|
|
+ let newAttr = new Attribute( 'foo', 'bar' );
|
|
|
+ let baseVersion = doc.version;
|
|
|
|
|
|
- root.insertChildren( 0, new Character( 'x', [ x1Attr ] ) );
|
|
|
+ let op = new ChangeOperation( range, oldAttr, newAttr, baseVersion );
|
|
|
|
|
|
- expect(
|
|
|
- () => {
|
|
|
- doc.applyOperation(
|
|
|
- new ChangeOperation(
|
|
|
- new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) ),
|
|
|
- null,
|
|
|
- x2Attr,
|
|
|
- doc.version
|
|
|
- )
|
|
|
- );
|
|
|
- }
|
|
|
- ).to.throw( CKEditorError, /operation-change-attr-exists/ );
|
|
|
+ let clone = op.clone();
|
|
|
+
|
|
|
+ // New instance rather than a pointer to the old instance.
|
|
|
+ expect( clone ).not.to.be.equal( op );
|
|
|
+
|
|
|
+ expect( clone ).to.be.instanceof( ChangeOperation );
|
|
|
+ expect( clone.range.isEqual( range ) ).to.be.true;
|
|
|
+ expect( clone.oldAttr.isEqual( oldAttr ) ).to.be.true;
|
|
|
+ expect( clone.newAttr.isEqual( newAttr ) ).to.be.true;
|
|
|
+ expect( clone.baseVersion ).to.equal( baseVersion );
|
|
|
} );
|
|
|
|
|
|
- it( 'should throw an error when one try to change and the new and old attributes have different keys', () => {
|
|
|
- let fooAttr = new Attribute( 'foo', true );
|
|
|
- let barAttr = new Attribute( 'bar', true );
|
|
|
|
|
|
- root.insertChildren( 0, 'x' );
|
|
|
|
|
|
- expect(
|
|
|
- () => {
|
|
|
- doc.applyOperation(
|
|
|
- new ChangeOperation(
|
|
|
- new Range( new Position( [ 0 ], root ), new Position( [ 1 ], root ) ),
|
|
|
- fooAttr,
|
|
|
- barAttr,
|
|
|
- doc.version
|
|
|
- )
|
|
|
- );
|
|
|
}
|
|
|
- ).to.throw( CKEditorError, /operation-change-different-keys/ );
|
|
|
} );
|
|
|
} );
|