/**
* @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
/* bender-tags: view, browser-only */
import { move } from '/ckeditor5/engine/view/writer.js';
import { stringify, parse } from '/tests/engine/_utils/view.js';
describe( 'writer', () => {
/**
* Executes test using `parse` and `stringify` utils functions. Uses range delimiters `[]{}` to create and
* test ranges.
*
* @param {String} input
* @param {String} expectedResult
* @param {String} expectedRemoved
*/
function test( source, destination, sourceAfterMove, destinationAfterMove ) {
let { view: srcView, selection: srcSelection } = parse( source );
let { view: dstView, selection: dstSelection } = parse( destination );
const newRange = move( srcSelection.getFirstRange(), dstSelection.getFirstPosition() );
expect( stringify( dstView, newRange, { showType: true, showPriority: true } ) ).to.equal( destinationAfterMove );
expect( stringify( srcView, null, { showType: true, showPriority: true } ) ).to.equal( sourceAfterMove );
}
describe( 'move', () => {
it( 'should move single text node', () => {
test(
'[foobar]',
'[]',
'',
'[foobar]'
);
} );
it( 'should not leave empty text nodes', () => {
test(
'{foobar}',
'[]',
'',
'[foobar]'
);
} );
it( 'should move part of the text node', () => {
test(
'f{oob}ar',
'[]',
'far',
'[oob]'
);
} );
it( 'should support unicode', () => {
test(
'நி{லை}க்கு',
'நி{}கு',
'நிக்கு',
'நி{லை}கு'
);
} );
it( 'should move parts of nodes', () => {
test(
'f{ooba}r',
'[]qux',
'fr',
'[ooba}qux'
);
} );
it( 'should merge after moving #1', () => {
test(
'' +
'foo[bar]bazqux' +
'',
'foo{}bazqux',
'foobazqux',
'' +
'foo[bar]bazqux' +
''
);
} );
it( 'should merge after moving #2', () => {
test(
'' +
'fo{obarba}zqux' +
'',
'fo{}zqux',
'fozqux',
'' +
'fo{obarba}zqux' +
''
);
} );
it( 'should move part of the text node in document fragment', () => {
test( 'fo{ob}ar', 'fo{}ar', 'foar', 'fo{ob}ar' );
} );
} );
} );