|
|
@@ -14,7 +14,6 @@ import Collection from '@ckeditor/ckeditor5-utils/src/collection';
|
|
|
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
|
import count from '@ckeditor/ckeditor5-utils/src/count';
|
|
|
import { jsonParseStringify } from './_utils/utils';
|
|
|
-import { setData, getData } from '../../src/dev-utils/model';
|
|
|
|
|
|
describe( 'Document', () => {
|
|
|
let model, doc;
|
|
|
@@ -168,238 +167,6 @@ describe( 'Document', () => {
|
|
|
} );
|
|
|
} );
|
|
|
|
|
|
- describe( 'getNearestSelectionRange()', () => {
|
|
|
- let selection;
|
|
|
-
|
|
|
- beforeEach( () => {
|
|
|
- model.schema.register( 'paragraph', { inheritAllFrom: '$block' } );
|
|
|
-
|
|
|
- model.schema.register( 'emptyBlock', { allowIn: '$root' } );
|
|
|
-
|
|
|
- model.schema.register( 'widget', {
|
|
|
- allowIn: '$root',
|
|
|
- isObject: true
|
|
|
- } );
|
|
|
-
|
|
|
- model.schema.register( 'blockWidget', {
|
|
|
- allowIn: '$root',
|
|
|
- allowContentOf: '$block',
|
|
|
- isObject: true
|
|
|
- } );
|
|
|
-
|
|
|
- doc.createRoot();
|
|
|
- selection = doc.selection;
|
|
|
- } );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should return collapsed range if text node can be placed at that position - both',
|
|
|
- '<paragraph>[]</paragraph>',
|
|
|
- 'both',
|
|
|
- '<paragraph>[]</paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should return collapsed range if text node can be placed at that position - forward',
|
|
|
- '<paragraph>[]</paragraph>',
|
|
|
- 'forward',
|
|
|
- '<paragraph>[]</paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should return collapsed range if text node can be placed at that position - backward',
|
|
|
- '<paragraph>[]</paragraph>',
|
|
|
- 'backward',
|
|
|
- '<paragraph>[]</paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test( 'should return null in empty document - both', '', 'both', null );
|
|
|
-
|
|
|
- test( 'should return null in empty document - backward', '', 'backward', null );
|
|
|
-
|
|
|
- test( 'should return null in empty document - forward', '', 'forward', null );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should find range before when searching both ways',
|
|
|
- '<paragraph></paragraph>[]<paragraph></paragraph>',
|
|
|
- 'both',
|
|
|
- '<paragraph>[]</paragraph><paragraph></paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should find range before when searching backward',
|
|
|
- '<paragraph></paragraph>[]<paragraph></paragraph>',
|
|
|
- 'backward',
|
|
|
- '<paragraph>[]</paragraph><paragraph></paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should find range after when searching forward',
|
|
|
- '<paragraph></paragraph>[]<paragraph></paragraph>',
|
|
|
- 'forward',
|
|
|
- '<paragraph></paragraph><paragraph>[]</paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should find range after when searching both ways when it is closer',
|
|
|
- '<paragraph></paragraph><emptyBlock></emptyBlock>[]<paragraph></paragraph>',
|
|
|
- 'both',
|
|
|
- '<paragraph></paragraph><emptyBlock></emptyBlock><paragraph>[]</paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should find range before when searching both ways when it is closer',
|
|
|
- '<paragraph></paragraph><emptyBlock></emptyBlock>[]<emptyBlock></emptyBlock><emptyBlock></emptyBlock><paragraph></paragraph>',
|
|
|
- 'both',
|
|
|
- '<paragraph>[]</paragraph><emptyBlock></emptyBlock><emptyBlock></emptyBlock><emptyBlock></emptyBlock><paragraph></paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should return null if there is no valid range',
|
|
|
- '[]<emptyBlock></emptyBlock>',
|
|
|
- 'both',
|
|
|
- null
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should return null if there is no valid range in given direction - backward',
|
|
|
- '[]<paragraph></paragraph>',
|
|
|
- 'backward',
|
|
|
- null
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should return null if there is no valid range in given direction - forward',
|
|
|
- '<paragraph></paragraph>[]',
|
|
|
- 'forward',
|
|
|
- null
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should move forward when placed at root start',
|
|
|
- '[]<paragraph></paragraph><paragraph></paragraph>',
|
|
|
- 'both',
|
|
|
- '<paragraph>[]</paragraph><paragraph></paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should move backward when placed at root end',
|
|
|
- '<paragraph></paragraph><paragraph></paragraph>[]',
|
|
|
- 'both',
|
|
|
- '<paragraph></paragraph><paragraph>[]</paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- describe( 'in case of objects which do not allow text inside', () => {
|
|
|
- test(
|
|
|
- 'should select nearest object (o[]o) - both',
|
|
|
- '<widget></widget>[]<widget></widget>',
|
|
|
- 'both',
|
|
|
- '[<widget></widget>]<widget></widget>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should select nearest object (o[]o) - forward',
|
|
|
- '<widget></widget>[]<widget></widget>',
|
|
|
- 'forward',
|
|
|
- '<widget></widget>[<widget></widget>]'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should select nearest object (o[]o) - backward',
|
|
|
- '<widget></widget>[]<widget></widget>',
|
|
|
- 'both',
|
|
|
- '[<widget></widget>]<widget></widget>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should select nearest object (p[]o) - forward',
|
|
|
- '<paragraph></paragraph>[]<widget></widget>',
|
|
|
- 'forward',
|
|
|
- '<paragraph></paragraph>[<widget></widget>]'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should select nearest object (o[]p) - both',
|
|
|
- '<widget></widget>[]<paragraph></paragraph>',
|
|
|
- 'both',
|
|
|
- '[<widget></widget>]<paragraph></paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should select nearest object (o[]p) - backward',
|
|
|
- '<widget></widget>[]<paragraph></paragraph>',
|
|
|
- 'backward',
|
|
|
- '[<widget></widget>]<paragraph></paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should select nearest object ([]o) - both',
|
|
|
- '[]<widget></widget><paragraph></paragraph>',
|
|
|
- 'both',
|
|
|
- '[<widget></widget>]<paragraph></paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should select nearest object ([]o) - forward',
|
|
|
- '[]<widget></widget><paragraph></paragraph>',
|
|
|
- 'forward',
|
|
|
- '[<widget></widget>]<paragraph></paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should select nearest object (o[]) - both',
|
|
|
- '<paragraph></paragraph><widget></widget>[]',
|
|
|
- 'both',
|
|
|
- '<paragraph></paragraph>[<widget></widget>]'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should select nearest object (o[]) - backward',
|
|
|
- '<paragraph></paragraph><widget></widget>[]',
|
|
|
- 'both',
|
|
|
- '<paragraph></paragraph>[<widget></widget>]'
|
|
|
- );
|
|
|
- } );
|
|
|
-
|
|
|
- describe( 'in case of objects which allow text inside', () => {
|
|
|
- test(
|
|
|
- 'should select nearest object which allows text (o[]o) - both',
|
|
|
- '<blockWidget></blockWidget>[]<blockWidget></blockWidget>',
|
|
|
- 'both',
|
|
|
- '[<blockWidget></blockWidget>]<blockWidget></blockWidget>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should select nearest object (o[]p) - both',
|
|
|
- '<blockWidget></blockWidget>[]<paragraph></paragraph>',
|
|
|
- 'both',
|
|
|
- '[<blockWidget></blockWidget>]<paragraph></paragraph>'
|
|
|
- );
|
|
|
-
|
|
|
- test(
|
|
|
- 'should select nearest object which allows text ([]o) - both',
|
|
|
- '[]<blockWidget></blockWidget><paragraph></paragraph>',
|
|
|
- 'both',
|
|
|
- '[<blockWidget></blockWidget>]<paragraph></paragraph>'
|
|
|
- );
|
|
|
- } );
|
|
|
-
|
|
|
- function test( testName, data, direction, expected ) {
|
|
|
- it( testName, () => {
|
|
|
- setData( model, data );
|
|
|
- const range = doc.getNearestSelectionRange( selection.anchor, direction );
|
|
|
-
|
|
|
- if ( expected === null ) {
|
|
|
- expect( range ).to.be.null;
|
|
|
- } else {
|
|
|
- model.change( writer => {
|
|
|
- writer.setSelection( range );
|
|
|
- } );
|
|
|
- expect( getData( model ) ).to.equal( expected );
|
|
|
- }
|
|
|
- } );
|
|
|
- }
|
|
|
- } );
|
|
|
-
|
|
|
describe( '_getDefaultRoot()', () => {
|
|
|
it( 'should return graveyard root if there are no other roots in the document', () => {
|
|
|
expect( doc._getDefaultRoot() ).to.equal( doc.graveyard );
|