Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Exposed these utils as public helpers and added minimal tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinmar committed Apr 13, 2020
1 parent 7ed764e commit ccb6985
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/model/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,6 @@ export default class Position {
* * {@link module:engine/model/position~getNodeAfterPosition}
* * {@link module:engine/model/position~getNodeBeforePosition}
*
* @protected
* @param {module:engine/model/position~Position} position
* @param {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment} positionParent The parent of the
* given position.
Expand Down Expand Up @@ -1114,7 +1113,6 @@ export function getTextNodeAtPosition( position, positionParent ) {
* * {@link module:engine/model/position~getTextNodeAtPosition}
* * {@link module:engine/model/position~getNodeBeforePosition}
*
* @protected
* @param {module:engine/model/position~Position} position
* @param {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment} positionParent The parent of the
* given position.
Expand All @@ -1139,7 +1137,6 @@ export function getNodeAfterPosition( position, positionParent, textNode ) {
* * {@link module:engine/model/position~getTextNodeAtPosition}
* * {@link module:engine/model/position~getNodeAfterPosition}
*
* @protected
* @param {module:engine/model/position~Position} position
* @param {module:engine/model/element~Element|module:engine/model/documentfragment~DocumentFragment} positionParent The parent of the
* given position.
Expand Down
50 changes: 46 additions & 4 deletions tests/model/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import DocumentFragment from '../../src/model/documentfragment';
import Element from '../../src/model/element';
import Text from '../../src/model/text';
import TextProxy from '../../src/model/textproxy';
import Position from '../../src/model/position';
import {
default as Position,
getTextNodeAtPosition,
getNodeAfterPosition,
getNodeBeforePosition
} from '../../src/model/position';
import Range from '../../src/model/range';
import MarkerOperation from '../../src/model/operation/markeroperation';
import AttributeOperation from '../../src/model/operation/attributeoperation';
Expand Down Expand Up @@ -485,10 +490,12 @@ describe( 'Position', () => {
} );
} );

it( 'should have proper parent path', () => {
const position = new Position( root, [ 1, 2, 3 ] );
describe( 'getParentPath()', () => {
it( 'should have proper parent path', () => {
const position = new Position( root, [ 1, 2, 3 ] );

expect( position.getParentPath() ).to.deep.equal( [ 1, 2 ] );
expect( position.getParentPath() ).to.deep.equal( [ 1, 2 ] );
} );
} );

describe( 'isBefore()', () => {
Expand Down Expand Up @@ -1275,4 +1282,39 @@ describe( 'Position', () => {
expect( positionB.getCommonAncestor( positionA ) ).to.equal( lca );
}
} );

describe( 'getTextNodeAtPosition() util', () => {
it( 'returns a text node at the given position', () => {
const position = new Position( root, [ 1, 0, 1 ] );
const positionParent = position.parent;

expect( getTextNodeAtPosition( position, positionParent ) ).to.equal( foz );
} );

// This util is covered with tests by Position#textNode tests.
} );

describe( 'getNodeAfterPosition() util', () => {
it( 'returns a node after the position', () => {
const position = new Position( root, [ 1, 0 ] );
const positionParent = position.parent;
const textNode = getTextNodeAtPosition( position, positionParent );

expect( getNodeAfterPosition( position, positionParent, textNode ) ).to.equal( li1 );
} );

// This util is covered with tests by Position#nodeAfter tests.
} );

describe( 'getNodeBeforePosition() util', () => {
it( 'returns a node before the position', () => {
const position = new Position( root, [ 1, 1 ] );
const positionParent = position.parent;
const textNode = getTextNodeAtPosition( position, positionParent );

expect( getNodeBeforePosition( position, positionParent, textNode ) ).to.equal( li1 );
} );

// This util is covered with tests by Position#nodeBefore tests.
} );
} );

0 comments on commit ccb6985

Please sign in to comment.