|
|
@@ -6,7 +6,6 @@
|
|
|
import findLinkRange from '../src/findlinkrange';
|
|
|
import Model from '@ckeditor/ckeditor5-engine/src/model/model';
|
|
|
import Range from '@ckeditor/ckeditor5-engine/src/model/range';
|
|
|
-import Position from '@ckeditor/ckeditor5-engine/src/model/position';
|
|
|
import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
|
|
|
describe( 'findLinkRange', () => {
|
|
|
@@ -23,91 +22,91 @@ describe( 'findLinkRange', () => {
|
|
|
it( 'should find link range searching from the center of the link #1', () => {
|
|
|
setData( model, '<$text linkHref="url">foobar</$text>' );
|
|
|
|
|
|
- const startPosition = new Position( root, [ 3 ] );
|
|
|
- const result = findLinkRange( startPosition, 'url' );
|
|
|
+ const startPosition = model.createPositionAt( root, [ 3 ] );
|
|
|
+ const result = findLinkRange( startPosition, 'url', model );
|
|
|
|
|
|
expect( result ).to.instanceOf( Range );
|
|
|
- expect( result.isEqual( Range.createFromParentsAndOffsets( root, 0, root, 6 ) ) ).to.true;
|
|
|
+ expect( result.isEqual( model.createRange( model.createPositionAt( root, 0 ), model.createPositionAt( root, 6 ) ) ) ).to.true;
|
|
|
} );
|
|
|
|
|
|
it( 'should find link range searching from the center of the link #2', () => {
|
|
|
setData( model, 'abc <$text linkHref="url">foobar</$text> abc' );
|
|
|
|
|
|
- const startPosition = new Position( root, [ 7 ] );
|
|
|
- const result = findLinkRange( startPosition, 'url' );
|
|
|
+ const startPosition = model.createPositionAt( root, [ 7 ] );
|
|
|
+ const result = findLinkRange( startPosition, 'url', model );
|
|
|
|
|
|
expect( result ).to.instanceOf( Range );
|
|
|
- expect( result.isEqual( Range.createFromParentsAndOffsets( root, 4, root, 10 ) ) ).to.true;
|
|
|
+ expect( result.isEqual( model.createRange( model.createPositionAt( root, 4 ), model.createPositionAt( root, 10 ) ) ) ).to.true;
|
|
|
} );
|
|
|
|
|
|
it( 'should find link range searching from the beginning of the link #1', () => {
|
|
|
setData( model, '<$text linkHref="url">foobar</$text>' );
|
|
|
|
|
|
- const startPosition = new Position( root, [ 0 ] );
|
|
|
- const result = findLinkRange( startPosition, 'url' );
|
|
|
+ const startPosition = model.createPositionAt( root, [ 0 ] );
|
|
|
+ const result = findLinkRange( startPosition, 'url', model );
|
|
|
|
|
|
expect( result ).to.instanceOf( Range );
|
|
|
- expect( result.isEqual( Range.createFromParentsAndOffsets( root, 0, root, 6 ) ) ).to.true;
|
|
|
+ expect( result.isEqual( model.createRange( model.createPositionAt( root, 0 ), model.createPositionAt( root, 6 ) ) ) ).to.true;
|
|
|
} );
|
|
|
|
|
|
it( 'should find link range searching from the beginning of the link #2', () => {
|
|
|
setData( model, 'abc <$text linkHref="url">foobar</$text> abc' );
|
|
|
|
|
|
- const startPosition = new Position( root, [ 4 ] );
|
|
|
- const result = findLinkRange( startPosition, 'url' );
|
|
|
+ const startPosition = model.createPositionAt( root, [ 4 ] );
|
|
|
+ const result = findLinkRange( startPosition, 'url', model );
|
|
|
|
|
|
expect( result ).to.instanceOf( Range );
|
|
|
- expect( result.isEqual( Range.createFromParentsAndOffsets( root, 4, root, 10 ) ) ).to.true;
|
|
|
+ expect( result.isEqual( model.createRange( model.createPositionAt( root, 4 ), model.createPositionAt( root, 10 ) ) ) ).to.true;
|
|
|
} );
|
|
|
|
|
|
it( 'should find link range searching from the end of the link #1', () => {
|
|
|
setData( model, '<$text linkHref="url">foobar</$text>' );
|
|
|
|
|
|
- const startPosition = new Position( root, [ 6 ] );
|
|
|
- const result = findLinkRange( startPosition, 'url' );
|
|
|
+ const startPosition = model.createPositionAt( root, [ 6 ] );
|
|
|
+ const result = findLinkRange( startPosition, 'url', model );
|
|
|
|
|
|
expect( result ).to.instanceOf( Range );
|
|
|
- expect( result.isEqual( Range.createFromParentsAndOffsets( root, 0, root, 6 ) ) ).to.true;
|
|
|
+ expect( result.isEqual( model.createRange( model.createPositionAt( root, 0 ), model.createPositionAt( root, 6 ) ) ) ).to.true;
|
|
|
} );
|
|
|
|
|
|
it( 'should find link range searching from the end of the link #2', () => {
|
|
|
setData( model, 'abc <$text linkHref="url">foobar</$text> abc' );
|
|
|
|
|
|
- const startPosition = new Position( root, [ 10 ] );
|
|
|
- const result = findLinkRange( startPosition, 'url' );
|
|
|
+ const startPosition = model.createPositionAt( root, [ 10 ] );
|
|
|
+ const result = findLinkRange( startPosition, 'url', model );
|
|
|
|
|
|
expect( result ).to.instanceOf( Range );
|
|
|
- expect( result.isEqual( Range.createFromParentsAndOffsets( root, 4, root, 10 ) ) ).to.true;
|
|
|
+ expect( result.isEqual( model.createRange( model.createPositionAt( root, 4 ), model.createPositionAt( root, 10 ) ) ) ).to.true;
|
|
|
} );
|
|
|
|
|
|
it( 'should find link range when link stick to other link searching from the center of the link', () => {
|
|
|
setData( model, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
|
|
|
|
|
|
- const startPosition = new Position( root, [ 6 ] );
|
|
|
- const result = findLinkRange( startPosition, 'url' );
|
|
|
+ const startPosition = model.createPositionAt( root, [ 6 ] );
|
|
|
+ const result = findLinkRange( startPosition, 'url', model );
|
|
|
|
|
|
expect( result ).to.instanceOf( Range );
|
|
|
- expect( result.isEqual( Range.createFromParentsAndOffsets( root, 3, root, 9 ) ) ).to.true;
|
|
|
+ expect( result.isEqual( model.createRange( model.createPositionAt( root, 3 ), model.createPositionAt( root, 9 ) ) ) ).to.true;
|
|
|
} );
|
|
|
|
|
|
it( 'should find link range when link stick to other link searching from the beginning of the link', () => {
|
|
|
setData( model, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
|
|
|
|
|
|
- const startPosition = new Position( root, [ 3 ] );
|
|
|
- const result = findLinkRange( startPosition, 'url' );
|
|
|
+ const startPosition = model.createPositionAt( root, [ 3 ] );
|
|
|
+ const result = findLinkRange( startPosition, 'url', model );
|
|
|
|
|
|
expect( result ).to.instanceOf( Range );
|
|
|
- expect( result.isEqual( Range.createFromParentsAndOffsets( root, 3, root, 9 ) ) ).to.true;
|
|
|
+ expect( result.isEqual( model.createRange( model.createPositionAt( root, 3 ), model.createPositionAt( root, 9 ) ) ) ).to.true;
|
|
|
} );
|
|
|
|
|
|
it( 'should find link range when link stick to other link searching from the end of the link', () => {
|
|
|
setData( model, '<$text linkHref="other">abc</$text><$text linkHref="url">foobar</$text><$text linkHref="other">abc</$text>' );
|
|
|
|
|
|
- const startPosition = new Position( root, [ 9 ] );
|
|
|
- const result = findLinkRange( startPosition, 'url' );
|
|
|
+ const startPosition = model.createPositionAt( root, [ 9 ] );
|
|
|
+ const result = findLinkRange( startPosition, 'url', model );
|
|
|
|
|
|
expect( result ).to.instanceOf( Range );
|
|
|
- expect( result.isEqual( Range.createFromParentsAndOffsets( root, 3, root, 9 ) ) ).to.true;
|
|
|
+ expect( result.isEqual( model.createRange( model.createPositionAt( root, 3 ), model.createPositionAt( root, 9 ) ) ) ).to.true;
|
|
|
} );
|
|
|
|
|
|
it( 'should find link range only inside current parent', () => {
|
|
|
@@ -118,10 +117,14 @@ describe( 'findLinkRange', () => {
|
|
|
'<p><$text linkHref="url">foobar</$text></p>'
|
|
|
);
|
|
|
|
|
|
- const startPosition = new Position( root, [ 1, 3 ] );
|
|
|
- const result = findLinkRange( startPosition, 'url' );
|
|
|
+ const startPosition = model.createPositionAt( root.getNodeByPath( [ 1 ] ), 3 );
|
|
|
+ const result = findLinkRange( startPosition, 'url', model );
|
|
|
|
|
|
expect( result ).to.instanceOf( Range );
|
|
|
- expect( result.isEqual( new Range( new Position( root, [ 1, 0 ] ), new Position( root, [ 1, 6 ] ) ) ) ).to.true;
|
|
|
+ const expectedRange = new Range(
|
|
|
+ model.createPositionAt( root.getNodeByPath( [ 1 ] ), 0 ),
|
|
|
+ model.createPositionAt( root.getNodeByPath( [ 1 ] ), 6 )
|
|
|
+ );
|
|
|
+ expect( result.isEqual( expectedRange ) ).to.true;
|
|
|
} );
|
|
|
} );
|