/**
* @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
import DowncastWriter from '../../../src/view/downcastwriter';
import ContainerElement from '../../../src/view/containerelement';
import Text from '../../../src/view/text';
import Position from '../../../src/view/position';
import { stringify, parse } from '../../../src/dev-utils/view';
import Document from '../../../src/view/document';
import { StylesProcessor } from '../../../src/view/stylesmap';
describe( 'DowncastWriter', () => {
describe( 'mergeAttributes', () => {
let writer, document;
// Executes test using `parse` and `stringify` utils functions. Uses range delimiters `[]{}` to create and
// test merge position.
//
// @param {String} input
// @param {String} expected
function testMerge( input, expected ) {
const { view, selection } = parse( input );
const newPosition = writer.mergeAttributes( selection.getFirstPosition() );
expect( stringify( view, newPosition, { showType: true, showPriority: true } ) ).to.equal( expected );
}
before( () => {
document = new Document( new StylesProcessor() );
writer = new DowncastWriter( document );
} );
it( 'should not merge if inside text node', () => {
testMerge( '
foobar
->foo|bar
const t1 = new Text( document, 'foo' ); const t2 = new Text( document, 'bar' ); const p = new ContainerElement( document, 'p', null, [ t1, t2 ] ); const position = new Position( p, 1 ); const newPosition = writer.mergeAttributes( position ); expect( stringify( p, newPosition ) ).to.equal( 'foo{}bar
' ); } ); it( 'should merge when placed between similar attribute nodes', () => { testMerge( '