|
@@ -10,13 +10,47 @@
|
|
|
import Position from '/ckeditor5/core/treeview/position.js';
|
|
import Position from '/ckeditor5/core/treeview/position.js';
|
|
|
|
|
|
|
|
describe( 'Position', () => {
|
|
describe( 'Position', () => {
|
|
|
|
|
+ const parentMock = {};
|
|
|
|
|
+
|
|
|
describe( 'constructor', () => {
|
|
describe( 'constructor', () => {
|
|
|
it( 'should create element without attributes', () => {
|
|
it( 'should create element without attributes', () => {
|
|
|
- const parentMock = {};
|
|
|
|
|
const elem = new Position( parentMock, 5 );
|
|
const elem = new Position( parentMock, 5 );
|
|
|
|
|
|
|
|
expect( elem ).to.have.property( 'parent' ).that.equals( parentMock );
|
|
expect( elem ).to.have.property( 'parent' ).that.equals( parentMock );
|
|
|
expect( elem ).to.have.property( 'offset' ).that.equals( 5 );
|
|
expect( elem ).to.have.property( 'offset' ).that.equals( 5 );
|
|
|
} );
|
|
} );
|
|
|
} );
|
|
} );
|
|
|
-} );
|
|
|
|
|
|
|
+
|
|
|
|
|
+ describe( 'getShiftedBy', () => {
|
|
|
|
|
+ it( 'returns new instance with shifted offset', () => {
|
|
|
|
|
+ const position = new Position( parentMock, 10 );
|
|
|
|
|
+ const shifted = position.getShiftedBy( 12 );
|
|
|
|
|
+ expect( shifted.offset ).to.equal( 22 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'accepts negative values', () => {
|
|
|
|
|
+ const position = new Position( parentMock, 10 );
|
|
|
|
|
+ const shifted = position.getShiftedBy( -5 );
|
|
|
|
|
+ expect( shifted.offset ).to.equal( 5 );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ it( 'prevents offset to be a negative value', () => {
|
|
|
|
|
+ const position = new Position( parentMock, 10 );
|
|
|
|
|
+ const shifted = position.getShiftedBy( -20 );
|
|
|
|
|
+
|
|
|
|
|
+ expect( shifted.offset ).to.equal( 0 );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+
|
|
|
|
|
+ describe( 'createFromPosition', () => {
|
|
|
|
|
+ it( 'creates new Position with same parent and offset', () => {
|
|
|
|
|
+ const offset = 50;
|
|
|
|
|
+ const position = new Position( parentMock, offset );
|
|
|
|
|
+ const newPosition = Position.createFromPosition( position );
|
|
|
|
|
+
|
|
|
|
|
+ expect( position ).to.not.equal( newPosition );
|
|
|
|
|
+ expect( position.offset ).to.equal( offset );
|
|
|
|
|
+ expect( position.parent ).to.equal( parentMock );
|
|
|
|
|
+ } );
|
|
|
|
|
+ } );
|
|
|
|
|
+} );
|