|
@@ -12,7 +12,6 @@ import Element from '/ckeditor5/core/treemodel/element.js';
|
|
|
import AttributeOperation from '/ckeditor5/core/treemodel/operation/attributeoperation.js';
|
|
import AttributeOperation from '/ckeditor5/core/treemodel/operation/attributeoperation.js';
|
|
|
import Position from '/ckeditor5/core/treemodel/position.js';
|
|
import Position from '/ckeditor5/core/treemodel/position.js';
|
|
|
import Range from '/ckeditor5/core/treemodel/range.js';
|
|
import Range from '/ckeditor5/core/treemodel/range.js';
|
|
|
-import Attribute from '/ckeditor5/core/treemodel/attribute.js';
|
|
|
|
|
import Text from '/ckeditor5/core/treemodel/text.js';
|
|
import Text from '/ckeditor5/core/treemodel/text.js';
|
|
|
import CKEditorError from '/ckeditor5/core/ckeditorerror.js';
|
|
import CKEditorError from '/ckeditor5/core/ckeditorerror.js';
|
|
|
|
|
|
|
@@ -27,8 +26,9 @@ describe( 'AttributeOperation', () => {
|
|
|
it( 'should have proper type', () => {
|
|
it( 'should have proper type', () => {
|
|
|
const op = new AttributeOperation(
|
|
const op = new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
|
|
|
|
|
+ 'isNew',
|
|
|
null,
|
|
null,
|
|
|
- new Attribute( 'isNew', true ),
|
|
|
|
|
|
|
+ true,
|
|
|
doc.version
|
|
doc.version
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -36,111 +36,98 @@ describe( 'AttributeOperation', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should insert attribute to the set of nodes', () => {
|
|
it( 'should insert attribute to the set of nodes', () => {
|
|
|
- let newAttr = new Attribute( 'isNew', true );
|
|
|
|
|
-
|
|
|
|
|
root.insertChildren( 0, 'bar' );
|
|
root.insertChildren( 0, 'bar' );
|
|
|
|
|
|
|
|
doc.applyOperation(
|
|
doc.applyOperation(
|
|
|
new AttributeOperation(
|
|
new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
|
|
|
|
|
+ 'isNew',
|
|
|
null,
|
|
null,
|
|
|
- newAttr,
|
|
|
|
|
|
|
+ true,
|
|
|
doc.version
|
|
doc.version
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
expect( doc.version ).to.equal( 1 );
|
|
expect( doc.version ).to.equal( 1 );
|
|
|
expect( root.getChildCount() ).to.equal( 3 );
|
|
expect( root.getChildCount() ).to.equal( 3 );
|
|
|
- expect( root.getChild( 0 ).attrs.has( newAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 1 ).attrs.has( newAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 2 ).attrs.size ).to.equal( 0 );
|
|
|
|
|
|
|
+ expect( root.getChild( 0 ).hasAttribute( 'isNew' ) ).to.be.true;
|
|
|
|
|
+ expect( root.getChild( 1 ).hasAttribute( 'isNew' ) ).to.be.true;
|
|
|
|
|
+ expect( root.getChild( 2 )._attrs.size ).to.equal( 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should add attribute to the existing attributes', () => {
|
|
it( 'should add attribute to the existing attributes', () => {
|
|
|
- let newAttr = new Attribute( 'isNew', true );
|
|
|
|
|
- let fooAttr = new Attribute( 'foo', true );
|
|
|
|
|
- let barAttr = new Attribute( 'bar', true );
|
|
|
|
|
-
|
|
|
|
|
- root.insertChildren( 0, new Text( 'x', [ fooAttr, barAttr ] ) );
|
|
|
|
|
|
|
+ root.insertChildren( 0, new Text( 'x', { foo: true, bar: true } ) );
|
|
|
|
|
|
|
|
doc.applyOperation(
|
|
doc.applyOperation(
|
|
|
new AttributeOperation(
|
|
new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
|
|
|
|
|
+ 'isNew',
|
|
|
null,
|
|
null,
|
|
|
- newAttr,
|
|
|
|
|
|
|
+ true,
|
|
|
doc.version
|
|
doc.version
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
expect( doc.version ).to.equal( 1 );
|
|
expect( doc.version ).to.equal( 1 );
|
|
|
expect( root.getChildCount() ).to.equal( 1 );
|
|
expect( root.getChildCount() ).to.equal( 1 );
|
|
|
- expect( root.getChild( 0 ).attrs.size ).to.equal( 3 );
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( newAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( fooAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( barAttr ) ).to.be.true;
|
|
|
|
|
|
|
+ expect( root.getChild( 0 )._attrs.size ).to.equal( 3 );
|
|
|
|
|
+ expect( root.getChild( 0 ).hasAttribute( 'isNew' ) ).to.be.true;
|
|
|
|
|
+ expect( root.getChild( 0 ).hasAttribute( 'foo' ) ).to.be.true;
|
|
|
|
|
+ expect( root.getChild( 0 ).hasAttribute( 'bar' ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should change attribute to the set of nodes', () => {
|
|
it( 'should change attribute to the set of nodes', () => {
|
|
|
- let oldAttr = new Attribute( 'isNew', false );
|
|
|
|
|
- let newAttr = new Attribute( 'isNew', true );
|
|
|
|
|
-
|
|
|
|
|
- root.insertChildren( 0, new Text( 'bar', [ oldAttr ] ) );
|
|
|
|
|
|
|
+ root.insertChildren( 0, new Text( 'bar', { isNew: false } ) );
|
|
|
|
|
|
|
|
doc.applyOperation(
|
|
doc.applyOperation(
|
|
|
new AttributeOperation(
|
|
new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 2 ] ) ),
|
|
|
- oldAttr,
|
|
|
|
|
- newAttr,
|
|
|
|
|
|
|
+ 'isNew',
|
|
|
|
|
+ false,
|
|
|
|
|
+ true,
|
|
|
doc.version
|
|
doc.version
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
expect( doc.version ).to.equal( 1 );
|
|
expect( doc.version ).to.equal( 1 );
|
|
|
expect( root.getChildCount() ).to.equal( 3 );
|
|
expect( root.getChildCount() ).to.equal( 3 );
|
|
|
- expect( root.getChild( 0 ).attrs.size ).to.equal( 1 );
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( newAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 1 ).attrs.size ).to.equal( 1 );
|
|
|
|
|
- expect( root.getChild( 1 ).attrs.has( newAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 2 ).attrs.size ).to.equal( 1 );
|
|
|
|
|
- expect( root.getChild( 2 ).attrs.has( oldAttr ) ).to.be.true;
|
|
|
|
|
|
|
+ expect( root.getChild( 0 )._attrs.size ).to.equal( 1 );
|
|
|
|
|
+ expect( root.getChild( 0 ).getAttribute( 'isNew' ) ).to.be.true;
|
|
|
|
|
+ expect( root.getChild( 1 )._attrs.size ).to.equal( 1 );
|
|
|
|
|
+ expect( root.getChild( 1 ).getAttribute( 'isNew' ) ).to.be.true;
|
|
|
|
|
+ expect( root.getChild( 2 )._attrs.size ).to.equal( 1 );
|
|
|
|
|
+ expect( root.getChild( 2 ).getAttribute( 'isNew' ) ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should change attribute in the middle of existing attributes', () => {
|
|
it( 'should change attribute in the middle of existing attributes', () => {
|
|
|
- let fooAttr = new Attribute( 'foo', true );
|
|
|
|
|
- let x1Attr = new Attribute( 'x', 1 );
|
|
|
|
|
- let x2Attr = new Attribute( 'x', 2 );
|
|
|
|
|
- let barAttr = new Attribute( 'bar', true );
|
|
|
|
|
-
|
|
|
|
|
- root.insertChildren( 0, new Text( 'x', [ fooAttr, x1Attr, barAttr ] ) );
|
|
|
|
|
|
|
+ root.insertChildren( 0, new Text( 'x', { foo: true, x: 1, bar: true } ) );
|
|
|
|
|
|
|
|
doc.applyOperation(
|
|
doc.applyOperation(
|
|
|
new AttributeOperation(
|
|
new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
|
|
|
- x1Attr,
|
|
|
|
|
- x2Attr,
|
|
|
|
|
|
|
+ 'x',
|
|
|
|
|
+ 1,
|
|
|
|
|
+ 2,
|
|
|
doc.version
|
|
doc.version
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
expect( doc.version ).to.equal( 1 );
|
|
expect( doc.version ).to.equal( 1 );
|
|
|
expect( root.getChildCount() ).to.equal( 1 );
|
|
expect( root.getChildCount() ).to.equal( 1 );
|
|
|
- expect( root.getChild( 0 ).attrs.size ).to.equal( 3 );
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( fooAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( x2Attr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( barAttr ) ).to.be.true;
|
|
|
|
|
|
|
+ expect( root.getChild( 0 )._attrs.size ).to.equal( 3 );
|
|
|
|
|
+ expect( root.getChild( 0 ).getAttribute( 'foo' ) ).to.be.true;
|
|
|
|
|
+ expect( root.getChild( 0 ).getAttribute( 'x' ) ).to.equal( 2 );
|
|
|
|
|
+ expect( root.getChild( 0 ).getAttribute( 'bar' ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should remove attribute', () => {
|
|
it( 'should remove attribute', () => {
|
|
|
- let fooAttr = new Attribute( 'foo', true );
|
|
|
|
|
- let xAttr = new Attribute( 'x', true );
|
|
|
|
|
- let barAttr = new Attribute( 'bar', true );
|
|
|
|
|
-
|
|
|
|
|
- root.insertChildren( 0, new Text( 'x', [ fooAttr, xAttr, barAttr ] ) );
|
|
|
|
|
|
|
+ root.insertChildren( 0, new Text( 'x', { foo: true, x: true, bar: true } ) );
|
|
|
|
|
|
|
|
doc.applyOperation(
|
|
doc.applyOperation(
|
|
|
new AttributeOperation(
|
|
new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
|
|
|
- xAttr,
|
|
|
|
|
|
|
+ 'x',
|
|
|
|
|
+ true,
|
|
|
null,
|
|
null,
|
|
|
doc.version
|
|
doc.version
|
|
|
)
|
|
)
|
|
@@ -148,34 +135,32 @@ describe( 'AttributeOperation', () => {
|
|
|
|
|
|
|
|
expect( doc.version ).to.equal( 1 );
|
|
expect( doc.version ).to.equal( 1 );
|
|
|
expect( root.getChildCount() ).to.equal( 1 );
|
|
expect( root.getChildCount() ).to.equal( 1 );
|
|
|
- expect( root.getChild( 0 ).attrs.size ).to.equal( 2 );
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( fooAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( barAttr ) ).to.be.true;
|
|
|
|
|
|
|
+ expect( root.getChild( 0 )._attrs.size ).to.equal( 2 );
|
|
|
|
|
+ expect( root.getChild( 0 ).hasAttribute( 'foo' ) ).to.be.true;
|
|
|
|
|
+ expect( root.getChild( 0 ).hasAttribute( 'bar' ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should create an AttributeOperation as a reverse', () => {
|
|
it( 'should create an AttributeOperation as a reverse', () => {
|
|
|
- let oldAttr = new Attribute( 'x', 'old' );
|
|
|
|
|
- let newAttr = new Attribute( 'x', 'new' );
|
|
|
|
|
let range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) );
|
|
let range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) );
|
|
|
- let operation = new AttributeOperation( range, oldAttr, newAttr, doc.version );
|
|
|
|
|
|
|
+ let operation = new AttributeOperation( range, 'x', 'old', 'new', doc.version );
|
|
|
let reverse = operation.getReversed();
|
|
let reverse = operation.getReversed();
|
|
|
|
|
|
|
|
expect( reverse ).to.be.an.instanceof( AttributeOperation );
|
|
expect( reverse ).to.be.an.instanceof( AttributeOperation );
|
|
|
expect( reverse.baseVersion ).to.equal( 1 );
|
|
expect( reverse.baseVersion ).to.equal( 1 );
|
|
|
expect( reverse.range.isEqual( range ) ).to.be.true;
|
|
expect( reverse.range.isEqual( range ) ).to.be.true;
|
|
|
- expect( reverse.oldAttr ).to.equal( newAttr );
|
|
|
|
|
- expect( reverse.newAttr ).to.equal( oldAttr );
|
|
|
|
|
|
|
+ expect( reverse.key ).to.equal( 'x' );
|
|
|
|
|
+ expect( reverse.oldValue ).to.equal( 'new' );
|
|
|
|
|
+ expect( reverse.newValue ).to.equal( 'old' );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should undo adding attribute by applying reverse operation', () => {
|
|
it( 'should undo adding attribute by applying reverse operation', () => {
|
|
|
- let newAttr = new Attribute( 'isNew', true );
|
|
|
|
|
-
|
|
|
|
|
root.insertChildren( 0, 'bar' );
|
|
root.insertChildren( 0, 'bar' );
|
|
|
|
|
|
|
|
let operation = new AttributeOperation(
|
|
let operation = new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) ),
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) ),
|
|
|
|
|
+ 'isNew',
|
|
|
null,
|
|
null,
|
|
|
- newAttr,
|
|
|
|
|
|
|
+ true,
|
|
|
doc.version
|
|
doc.version
|
|
|
);
|
|
);
|
|
|
|
|
|
|
@@ -186,14 +171,12 @@ describe( 'AttributeOperation', () => {
|
|
|
|
|
|
|
|
expect( doc.version ).to.equal( 2 );
|
|
expect( doc.version ).to.equal( 2 );
|
|
|
expect( root.getChildCount() ).to.equal( 3 );
|
|
expect( root.getChildCount() ).to.equal( 3 );
|
|
|
- expect( root.getChild( 0 ).attrs.size ).to.equal( 0 );
|
|
|
|
|
- expect( root.getChild( 1 ).attrs.size ).to.equal( 0 );
|
|
|
|
|
- expect( root.getChild( 2 ).attrs.size ).to.equal( 0 );
|
|
|
|
|
|
|
+ expect( root.getChild( 0 )._attrs.size ).to.equal( 0 );
|
|
|
|
|
+ expect( root.getChild( 1 )._attrs.size ).to.equal( 0 );
|
|
|
|
|
+ expect( root.getChild( 2 )._attrs.size ).to.equal( 0 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not set attribute of element if change range starts in the middle of that element', () => {
|
|
it( 'should not set attribute of element if change range starts in the middle of that element', () => {
|
|
|
- let fooAttr = new Attribute( 'foo', true );
|
|
|
|
|
-
|
|
|
|
|
let eleA = new Element( 'a', [], 'abc' );
|
|
let eleA = new Element( 'a', [], 'abc' );
|
|
|
let eleB = new Element( 'b', [], 'xyz' );
|
|
let eleB = new Element( 'b', [], 'xyz' );
|
|
|
|
|
|
|
@@ -202,72 +185,70 @@ describe( 'AttributeOperation', () => {
|
|
|
doc.applyOperation(
|
|
doc.applyOperation(
|
|
|
new AttributeOperation(
|
|
new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 1, 2 ] ) ),
|
|
new Range( new Position( root, [ 0, 2 ] ), new Position( root, [ 1, 2 ] ) ),
|
|
|
|
|
+ 'foo',
|
|
|
null,
|
|
null,
|
|
|
- fooAttr,
|
|
|
|
|
|
|
+ true,
|
|
|
doc.version
|
|
doc.version
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( fooAttr ) ).to.be.false;
|
|
|
|
|
|
|
+ expect( root.getChild( 0 ).hasAttribute( 'foo' ) ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not remove attribute of element if change range starts in the middle of that element', () => {
|
|
it( 'should not remove attribute of element if change range starts in the middle of that element', () => {
|
|
|
- let fooAttr = new Attribute( 'foo', true );
|
|
|
|
|
|
|
+ let fooAttr = { foo: true };
|
|
|
|
|
|
|
|
- let eleA = new Element( 'a', [ fooAttr ], 'abc' );
|
|
|
|
|
- let eleB = new Element( 'b', [ fooAttr ], 'xyz' );
|
|
|
|
|
|
|
+ let eleA = new Element( 'a', fooAttr, 'abc' );
|
|
|
|
|
+ let eleB = new Element( 'b', fooAttr, 'xyz' );
|
|
|
|
|
|
|
|
root.insertChildren( 0, [ eleA, eleB ] );
|
|
root.insertChildren( 0, [ eleA, eleB ] );
|
|
|
|
|
|
|
|
doc.applyOperation(
|
|
doc.applyOperation(
|
|
|
new AttributeOperation(
|
|
new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0, 3 ] ), new Position( root, [ 1, 0 ] ) ),
|
|
new Range( new Position( root, [ 0, 3 ] ), new Position( root, [ 1, 0 ] ) ),
|
|
|
- fooAttr,
|
|
|
|
|
|
|
+ 'foo',
|
|
|
|
|
+ true,
|
|
|
null,
|
|
null,
|
|
|
doc.version
|
|
doc.version
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( fooAttr ) ).to.be.true;
|
|
|
|
|
|
|
+ expect( root.getChild( 0 ).hasAttribute( 'foo' ) ).to.be.true;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should undo changing attribute by applying reverse operation', () => {
|
|
it( 'should undo changing attribute by applying reverse operation', () => {
|
|
|
- let oldAttr = new Attribute( 'isNew', false );
|
|
|
|
|
- let newAttr = new Attribute( 'isNew', true );
|
|
|
|
|
-
|
|
|
|
|
- root.insertChildren( 0, new Text( 'bar', [ oldAttr ] ) );
|
|
|
|
|
|
|
+ root.insertChildren( 0, new Text( 'bar', { isNew: false } ) );
|
|
|
|
|
|
|
|
let operation = new AttributeOperation(
|
|
let operation = new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) ),
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) ),
|
|
|
- oldAttr,
|
|
|
|
|
- newAttr,
|
|
|
|
|
|
|
+ 'isNew',
|
|
|
|
|
+ false,
|
|
|
|
|
+ true,
|
|
|
doc.version
|
|
doc.version
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
let reverse = operation.getReversed();
|
|
let reverse = operation.getReversed();
|
|
|
|
|
|
|
|
doc.applyOperation( operation );
|
|
doc.applyOperation( operation );
|
|
|
-
|
|
|
|
|
doc.applyOperation( reverse );
|
|
doc.applyOperation( reverse );
|
|
|
|
|
|
|
|
expect( doc.version ).to.equal( 2 );
|
|
expect( doc.version ).to.equal( 2 );
|
|
|
expect( root.getChildCount() ).to.equal( 3 );
|
|
expect( root.getChildCount() ).to.equal( 3 );
|
|
|
- expect( root.getChild( 0 ).attrs.size ).to.equal( 1 );
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( oldAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 1 ).attrs.size ).to.equal( 1 );
|
|
|
|
|
- expect( root.getChild( 1 ).attrs.has( oldAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 2 ).attrs.size ).to.equal( 1 );
|
|
|
|
|
- expect( root.getChild( 2 ).attrs.has( oldAttr ) ).to.be.true;
|
|
|
|
|
|
|
+ expect( root.getChild( 0 )._attrs.size ).to.equal( 1 );
|
|
|
|
|
+ expect( root.getChild( 0 ).getAttribute( 'isNew' ) ).to.be.false;
|
|
|
|
|
+ expect( root.getChild( 1 )._attrs.size ).to.equal( 1 );
|
|
|
|
|
+ expect( root.getChild( 1 ).getAttribute( 'isNew' ) ).to.be.false;
|
|
|
|
|
+ expect( root.getChild( 2 )._attrs.size ).to.equal( 1 );
|
|
|
|
|
+ expect( root.getChild( 2 ).getAttribute( 'isNew' ) ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should undo remove attribute by applying reverse operation', () => {
|
|
it( 'should undo remove attribute by applying reverse operation', () => {
|
|
|
- let fooAttr = new Attribute( 'foo', false );
|
|
|
|
|
-
|
|
|
|
|
- root.insertChildren( 0, new Text( 'bar', [ fooAttr ] ) );
|
|
|
|
|
|
|
+ root.insertChildren( 0, new Text( 'bar', { foo: true } ) );
|
|
|
|
|
|
|
|
let operation = new AttributeOperation(
|
|
let operation = new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) ),
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 3 ] ) ),
|
|
|
- fooAttr,
|
|
|
|
|
|
|
+ 'foo',
|
|
|
|
|
+ true,
|
|
|
null,
|
|
null,
|
|
|
doc.version
|
|
doc.version
|
|
|
);
|
|
);
|
|
@@ -275,29 +256,27 @@ describe( 'AttributeOperation', () => {
|
|
|
let reverse = operation.getReversed();
|
|
let reverse = operation.getReversed();
|
|
|
|
|
|
|
|
doc.applyOperation( operation );
|
|
doc.applyOperation( operation );
|
|
|
-
|
|
|
|
|
doc.applyOperation( reverse );
|
|
doc.applyOperation( reverse );
|
|
|
|
|
|
|
|
expect( doc.version ).to.equal( 2 );
|
|
expect( doc.version ).to.equal( 2 );
|
|
|
expect( root.getChildCount() ).to.equal( 3 );
|
|
expect( root.getChildCount() ).to.equal( 3 );
|
|
|
- expect( root.getChild( 0 ).attrs.size ).to.equal( 1 );
|
|
|
|
|
- expect( root.getChild( 0 ).attrs.has( fooAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 1 ).attrs.size ).to.equal( 1 );
|
|
|
|
|
- expect( root.getChild( 1 ).attrs.has( fooAttr ) ).to.be.true;
|
|
|
|
|
- expect( root.getChild( 2 ).attrs.size ).to.equal( 1 );
|
|
|
|
|
- expect( root.getChild( 2 ).attrs.has( fooAttr ) ).to.be.true;
|
|
|
|
|
|
|
+ expect( root.getChild( 0 )._attrs.size ).to.equal( 1 );
|
|
|
|
|
+ expect( root.getChild( 0 ).getAttribute( 'foo' ) ).to.be.true;
|
|
|
|
|
+ expect( root.getChild( 1 )._attrs.size ).to.equal( 1 );
|
|
|
|
|
+ expect( root.getChild( 1 ).getAttribute( 'foo' ) ).to.be.true;
|
|
|
|
|
+ expect( root.getChild( 2 )._attrs.size ).to.equal( 1 );
|
|
|
|
|
+ expect( root.getChild( 2 ).getAttribute( 'foo' ) ).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 remove and the attribute does not exists', () => {
|
|
|
- let fooAttr = new Attribute( 'foo', true );
|
|
|
|
|
-
|
|
|
|
|
root.insertChildren( 0, 'x' );
|
|
root.insertChildren( 0, 'x' );
|
|
|
|
|
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
doc.applyOperation(
|
|
doc.applyOperation(
|
|
|
new AttributeOperation(
|
|
new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
|
|
|
- fooAttr,
|
|
|
|
|
|
|
+ 'foo',
|
|
|
|
|
+ true,
|
|
|
null,
|
|
null,
|
|
|
doc.version
|
|
doc.version
|
|
|
)
|
|
)
|
|
@@ -306,48 +285,26 @@ describe( 'AttributeOperation', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should throw an error when one try to insert and the attribute already exists', () => {
|
|
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 );
|
|
|
|
|
-
|
|
|
|
|
- root.insertChildren( 0, new Text( 'x', [ x1Attr ] ) );
|
|
|
|
|
|
|
+ root.insertChildren( 0, new Text( 'x', { x: 1 } ) );
|
|
|
|
|
|
|
|
expect( () => {
|
|
expect( () => {
|
|
|
doc.applyOperation(
|
|
doc.applyOperation(
|
|
|
new AttributeOperation(
|
|
new AttributeOperation(
|
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
|
|
new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
|
|
|
|
|
+ 'x',
|
|
|
null,
|
|
null,
|
|
|
- x2Attr,
|
|
|
|
|
|
|
+ 2,
|
|
|
doc.version
|
|
doc.version
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|
|
|
} ).to.throw( CKEditorError, /operation-attribute-attr-exists/ );
|
|
} ).to.throw( CKEditorError, /operation-attribute-attr-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' );
|
|
|
|
|
-
|
|
|
|
|
- expect( () => {
|
|
|
|
|
- doc.applyOperation(
|
|
|
|
|
- new AttributeOperation(
|
|
|
|
|
- new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) ),
|
|
|
|
|
- fooAttr,
|
|
|
|
|
- barAttr,
|
|
|
|
|
- doc.version
|
|
|
|
|
- )
|
|
|
|
|
- );
|
|
|
|
|
- } ).to.throw( CKEditorError, /operation-attribute-different-keys/ );
|
|
|
|
|
- } );
|
|
|
|
|
-
|
|
|
|
|
it( 'should create an AttributeOperation with the same parameters when cloned', () => {
|
|
it( 'should create an AttributeOperation with the same parameters when cloned', () => {
|
|
|
let range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) );
|
|
let range = new Range( new Position( root, [ 0 ] ), new Position( root, [ 1 ] ) );
|
|
|
- let oldAttr = new Attribute( 'foo', 'old' );
|
|
|
|
|
- let newAttr = new Attribute( 'foo', 'bar' );
|
|
|
|
|
let baseVersion = doc.version;
|
|
let baseVersion = doc.version;
|
|
|
|
|
|
|
|
- let op = new AttributeOperation( range, oldAttr, newAttr, baseVersion );
|
|
|
|
|
|
|
+ let op = new AttributeOperation( range, 'foo', 'old', 'new', baseVersion );
|
|
|
|
|
|
|
|
let clone = op.clone();
|
|
let clone = op.clone();
|
|
|
|
|
|
|
@@ -356,23 +313,25 @@ describe( 'AttributeOperation', () => {
|
|
|
|
|
|
|
|
expect( clone ).to.be.instanceof( AttributeOperation );
|
|
expect( clone ).to.be.instanceof( AttributeOperation );
|
|
|
expect( clone.range.isEqual( range ) ).to.be.true;
|
|
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.key ).to.equal( 'foo' );
|
|
|
|
|
+ expect( clone.oldValue ).to.equal( 'old' );
|
|
|
|
|
+ expect( clone.newValue ).to.equal( 'new' );
|
|
|
expect( clone.baseVersion ).to.equal( baseVersion );
|
|
expect( clone.baseVersion ).to.equal( baseVersion );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should merge characters in node list', () => {
|
|
it( 'should merge characters in node list', () => {
|
|
|
- let attrA = new Attribute( 'foo', 'a' );
|
|
|
|
|
- let attrB = new Attribute( 'foo', 'b' );
|
|
|
|
|
|
|
+ let attrA = { foo: 'a' };
|
|
|
|
|
+ let attrB = { foo: 'b' };
|
|
|
|
|
|
|
|
- root.insertChildren( 0, new Text( 'abc', [ attrA ] ) );
|
|
|
|
|
- root.insertChildren( 3, new Text( 'xyz', [ attrB ] ) );
|
|
|
|
|
|
|
+ root.insertChildren( 0, new Text( 'abc', attrA ) );
|
|
|
|
|
+ root.insertChildren( 3, new Text( 'xyz', attrB ) );
|
|
|
|
|
|
|
|
doc.applyOperation(
|
|
doc.applyOperation(
|
|
|
new AttributeOperation(
|
|
new AttributeOperation(
|
|
|
new Range( new Position( root, [ 1 ] ), new Position( root, [ 3 ] ) ),
|
|
new Range( new Position( root, [ 1 ] ), new Position( root, [ 3 ] ) ),
|
|
|
- attrA,
|
|
|
|
|
- attrB,
|
|
|
|
|
|
|
+ 'foo',
|
|
|
|
|
+ 'a',
|
|
|
|
|
+ 'b',
|
|
|
doc.version
|
|
doc.version
|
|
|
)
|
|
)
|
|
|
);
|
|
);
|