/** * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ /* bender-tags: view, browser-only */ 'use strict'; import { breakAt } from '/ckeditor5/engine/view/writer.js'; import DocumentFragment from '/ckeditor5/engine/view/documentfragment.js'; import AttributeElement from '/ckeditor5/engine/view/attributeelement.js'; import Text from '/ckeditor5/engine/view/text.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 ); // Wrap attributes and text into DocumentFragment. if ( view instanceof AttributeElement || view instanceof Text ) { view = new DocumentFragment( view ); } const newPosition = breakAt( selection.getFirstPosition() ); expect( stringify( view, 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' ); } ); } ); } );