/**
* @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
/* bender-tags: view, browser-only */
import { breakAt } 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 break position.
*
* @param {String} input
* @param {String} expected
*/
function test( input, expected ) {
let { view, selection } = parse( input );
const newPosition = breakAt( selection.getFirstPosition() );
expect( stringify( view.root, newPosition, { showType: true, showPriority: true } ) ).to.equal( expected );
}
describe( 'breakAt', () => {
it( 'should not break text nodes if they are not in attribute elements - middle', () => {
test(
'foo{}bar',
'foo{}bar'
);
} );
it( 'should not break text nodes if they are not in attribute elements - beginning', () => {
test(
'{}foobar',
'{}foobar'
);
} );
it( 'should not break text nodes if they are not in attribute elements #2 - end', () => {
test(
'foobar{}',
'foobar{}'
);
} );
it( 'should split attribute element', () => {
test(
'foo{}bar',
'' +
'foo[]bar' +
''
);
} );
it( 'should move from beginning of the nested text node to the container', () => {
test(
'' +
'{}foobar' +
'',
'' +
'[]foobar' +
''
);
} );
it( 'should stick selection in text node if it is in container', () => {
test(
'foo{}bar',
'foo{}bar'
);
} );
it( 'should split nested attributes', () => {
test(
'' +
'foo{}bar' +
'',
'' +
'' +
'' +
'foo' +
'' +
'' +
'[]' +
'' +
'' +
'bar' +
'' +
'' +
''
);
} );
it( 'should move from end of the nested text node to the container', () => {
test(
'' +
'foobar{}' +
'',
'' +
'foobar[]' +
''
);
} );
it( 'should split attribute element directly in document fragment', () => {
test(
'foo{}bar',
'foo[]bar'
);
} );
it( 'should not split text directly in document fragment', () => {
test(
'foo{}bar',
'foo{}bar'
);
} );
} );
} );