|
|
@@ -11,6 +11,7 @@ import Position from '/ckeditor5/engine/view/position.js';
|
|
|
import Node from '/ckeditor5/engine/view/node.js';
|
|
|
import Element from '/ckeditor5/engine/view/element.js';
|
|
|
import Text from '/ckeditor5/engine/view/text.js';
|
|
|
+import TextProxy from '/ckeditor5/engine/view/textproxy.js';
|
|
|
|
|
|
import CKEditorError from '/ckeditor5/utils/ckeditorerror.js';
|
|
|
|
|
|
@@ -289,7 +290,13 @@ describe( 'Position', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'createBefore', () => {
|
|
|
- it( 'should create positions before nodes', () => {
|
|
|
+ it( 'should throw error if one try to create positions before root', () => {
|
|
|
+ expect( () => {
|
|
|
+ Position.createBefore( parse( '<p></p>' ) );
|
|
|
+ } ).to.throw( CKEditorError, /position-before-root/ );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should create positions before `Node`', () => {
|
|
|
const { selection } = parse( '<p>[]<b></b></p>' );
|
|
|
const position = selection.getFirstPosition();
|
|
|
const nodeAfter = position.nodeAfter;
|
|
|
@@ -297,15 +304,25 @@ describe( 'Position', () => {
|
|
|
expect( Position.createBefore( nodeAfter ).isEqual( position ) ).to.be.true;
|
|
|
} );
|
|
|
|
|
|
- it( 'should throw error if one try to create positions before root', () => {
|
|
|
- expect( () => {
|
|
|
- Position.createBefore( parse( '<p></p>' ) );
|
|
|
- } ).to.throw( CKEditorError, /position-before-root/ );
|
|
|
+ it( 'should create positions before `TextProxy`', () => {
|
|
|
+ const text = new Text( 'abc' );
|
|
|
+ const paragraph = new Element( 'p', [], [ text ] );
|
|
|
+
|
|
|
+ const textProxy = new TextProxy( 'b', paragraph, text, 1 );
|
|
|
+ const position = new Position( text, 1 );
|
|
|
+
|
|
|
+ expect( Position.createBefore( textProxy ).isEqual( position ) ).to.be.true;
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
describe( 'createAfter', () => {
|
|
|
- it( 'should create positions after nodes', () => {
|
|
|
+ it( 'should throw error if one try to create positions after root', () => {
|
|
|
+ expect( () => {
|
|
|
+ Position.createAfter( parse( '<p></p>' ) );
|
|
|
+ } ).to.throw( CKEditorError, /position-after-root/ );
|
|
|
+ } );
|
|
|
+
|
|
|
+ it( 'should create positions after `Node`', () => {
|
|
|
const { selection } = parse( '<p><b></b>[]</p>' );
|
|
|
const position = selection.getFirstPosition();
|
|
|
const nodeBefore = position.nodeBefore;
|
|
|
@@ -313,10 +330,14 @@ describe( 'Position', () => {
|
|
|
expect( Position.createAfter( nodeBefore ).isEqual( position ) ).to.be.true;
|
|
|
} );
|
|
|
|
|
|
- it( 'should throw error if one try to create positions after root', () => {
|
|
|
- expect( () => {
|
|
|
- Position.createAfter( parse( '<p></p>' ) );
|
|
|
- } ).to.throw( CKEditorError, /position-after-root/ );
|
|
|
+ it( 'should create positions after `TextProxy`', () => {
|
|
|
+ const text = new Text( 'abc' );
|
|
|
+ const paragraph = new Element( 'p', [], [ text ] );
|
|
|
+
|
|
|
+ const textProxy = new TextProxy( 'b', paragraph, text, 1 );
|
|
|
+ const position = new Position( text, 2 );
|
|
|
+
|
|
|
+ expect( Position.createAfter( textProxy ).isEqual( position ) ).to.be.true;
|
|
|
} );
|
|
|
} );
|
|
|
} );
|