/**
* @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
/* bender-tags: treeview */
'use strict';
import Writer from '/ckeditor5/engine/treeview/writer.js';
import { stringify, parse } from '/tests/engine/_utils/view.js';
describe( 'Writer', () => {
let 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 ) {
const { view, selection } = parse( input );
const newPosition = writer.breakAttributes( selection.getFirstPosition() );
expect( stringify( view, newPosition, { showType: true, showPriority: true } ) ).to.equal( expected );
}
beforeEach( () => {
writer = new Writer();
} );
describe( 'breakAttributes', () => {
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[]'
);
} );
} );
} );