|
@@ -19,7 +19,7 @@ const modules = bender.amd.require(
|
|
|
describe( 'position', () => {
|
|
describe( 'position', () => {
|
|
|
let Element, Character, Document, NodeList, Position, CKEditorError;
|
|
let Element, Character, Document, NodeList, Position, CKEditorError;
|
|
|
|
|
|
|
|
- let doc, root, p, ul, li1, li2, f, o, z, b, a, r;
|
|
|
|
|
|
|
+ let doc, root, otherRoot, p, ul, li1, li2, f, o, z, b, a, r;
|
|
|
|
|
|
|
|
// root
|
|
// root
|
|
|
// |- p Before: [ 0 ] After: [ 1 ]
|
|
// |- p Before: [ 0 ] After: [ 1 ]
|
|
@@ -43,6 +43,7 @@ describe( 'position', () => {
|
|
|
doc = new Document();
|
|
doc = new Document();
|
|
|
|
|
|
|
|
root = doc.createRoot( 'root' );
|
|
root = doc.createRoot( 'root' );
|
|
|
|
|
+ otherRoot = doc.createRoot( 'otherRoot' );
|
|
|
|
|
|
|
|
f = new Character( 'f' );
|
|
f = new Character( 'f' );
|
|
|
o = new Character( 'o' );
|
|
o = new Character( 'o' );
|
|
@@ -70,6 +71,16 @@ describe( 'position', () => {
|
|
|
expect( position ).to.have.property( 'root' ).that.equals( root );
|
|
expect( position ).to.have.property( 'root' ).that.equals( root );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should throw error if given root is not a RootElement instance', () => {
|
|
|
|
|
+ expect( () => {
|
|
|
|
|
+ new Position( [ 0 ] )
|
|
|
|
|
+ } ).to.throw( CKEditorError, /position-root-not-rootelement/ );
|
|
|
|
|
+
|
|
|
|
|
+ expect( () => {
|
|
|
|
|
+ new Position( [ 0 ], new Element( 'p' ) );
|
|
|
|
|
+ } ).to.throw( CKEditorError, /position-root-not-rootelement/ );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should make positions form node and offset', () => {
|
|
it( 'should make positions form node and offset', () => {
|
|
|
expect( Position.createFromParentAndOffset( root, 0 ) ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
|
|
expect( Position.createFromParentAndOffset( root, 0 ) ).to.have.property( 'path' ).that.deep.equals( [ 0 ] );
|
|
|
expect( Position.createFromParentAndOffset( root, 1 ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
|
|
expect( Position.createFromParentAndOffset( root, 1 ) ).to.have.property( 'path' ).that.deep.equals( [ 1 ] );
|
|
@@ -106,11 +117,9 @@ describe( 'position', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should throw error if one try to make positions before root', () => {
|
|
it( 'should throw error if one try to make positions before root', () => {
|
|
|
- expect(
|
|
|
|
|
- () => {
|
|
|
|
|
- Position.createBefore( root );
|
|
|
|
|
- }
|
|
|
|
|
- ).to.throw( CKEditorError, /position-before-root/ );
|
|
|
|
|
|
|
+ expect( () => {
|
|
|
|
|
+ Position.createBefore( root );
|
|
|
|
|
+ } ).to.throw( CKEditorError, /position-before-root/ );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should make positions after elements', () => {
|
|
it( 'should make positions after elements', () => {
|
|
@@ -132,11 +141,9 @@ describe( 'position', () => {
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should throw error if one try to make positions after root', () => {
|
|
it( 'should throw error if one try to make positions after root', () => {
|
|
|
- expect(
|
|
|
|
|
- () => {
|
|
|
|
|
- Position.createAfter( root );
|
|
|
|
|
- }
|
|
|
|
|
- ).to.throw( CKEditorError, /position-after-root/ );
|
|
|
|
|
|
|
+ expect( () => {
|
|
|
|
|
+ Position.createAfter( root );
|
|
|
|
|
+ } ).to.throw( CKEditorError, /position-after-root/ );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
it( 'should have parent', () => {
|
|
it( 'should have parent', () => {
|
|
@@ -173,6 +180,14 @@ describe( 'position', () => {
|
|
|
expect( new Position( [ 1, 0, 3 ], root ) ).to.have.property( 'offset' ).that.equals( 3 );
|
|
expect( new Position( [ 1, 0, 3 ], root ) ).to.have.property( 'offset' ).that.equals( 3 );
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
|
|
+ it( 'should be able to set offset', () => {
|
|
|
|
|
+ let position = new Position( [ 1, 0, 2 ], root );
|
|
|
|
|
+ position.offset = 4;
|
|
|
|
|
+
|
|
|
|
|
+ expect( position.offset ).to.equal( 4 );
|
|
|
|
|
+ expect( position.path ).to.deep.equal( [ 1, 0, 4 ] );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
it( 'should have nodeBefore', () => {
|
|
it( 'should have nodeBefore', () => {
|
|
|
expect( new Position( [ 0 ], root ) ).to.have.property( 'nodeBefore' ).that.is.null;
|
|
expect( new Position( [ 0 ], root ) ).to.have.property( 'nodeBefore' ).that.is.null;
|
|
|
expect( new Position( [ 1 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( p );
|
|
expect( new Position( [ 1 ], root ) ).to.have.property( 'nodeBefore' ).that.equals( p );
|
|
@@ -221,9 +236,18 @@ describe( 'position', () => {
|
|
|
expect( position.isEqual( differentNode ) ).to.be.false;
|
|
expect( position.isEqual( differentNode ) ).to.be.false;
|
|
|
} );
|
|
} );
|
|
|
|
|
|
|
|
- it( 'should have proper parent path', () => {
|
|
|
|
|
|
|
+ it( 'should have correct parent path property', () => {
|
|
|
let position = new Position( [ 1, 2, 3 ], root );
|
|
let position = new Position( [ 1, 2, 3 ], root );
|
|
|
|
|
|
|
|
- expect( position.getParentPath() ).to.deep.equal( [ 1, 2 ] );
|
|
|
|
|
|
|
+ expect( position.parentPath ).to.deep.equal( [ 1, 2 ] );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'should return a new, equal position when cloned', () => {
|
|
|
|
|
+ const position = new Position( [ 1, 2, 3 ], root );
|
|
|
|
|
+ const clone = position.clone();
|
|
|
|
|
+
|
|
|
|
|
+ expect( clone ).not.to.be.equal( position ); // clone is not pointing to the same object as position
|
|
|
|
|
+ expect( clone.isEqual( position ) ).to.be.true; // but they are equal in the position-sense
|
|
|
|
|
+ expect( clone.path ).not.to.be.equal( position.path ); // make sure the paths are not the same array
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|