/**
* @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
/* bender-tags: model, composer */
'use strict';
import Document from '/ckeditor5/engine/model/document.js';
import deleteContents from '/ckeditor5/engine/model/composer/deletecontents.js';
import { setData, getData } from '/tests/engine/_utils/model.js';
describe( 'Delete utils', () => {
let document;
beforeEach( () => {
document = new Document();
document.createRoot( 'main', '$root' );
const schema = document.schema;
// Note: We used short names instead of "image", "paragraph", etc. to make the tests shorter.
// We could use any random names in fact, but using HTML tags may explain the tests a bit better.
schema.registerItem( 'img', '$inline' );
schema.registerItem( 'p', '$block' );
schema.registerItem( 'h1', '$block' );
schema.registerItem( 'pchild' );
schema.allow( { name: 'pchild', inside: 'p' } );
schema.allow( { name: '$text', attributes: [ 'bold', 'italic' ] } );
schema.allow( { name: 'p', attributes: [ 'align' ] } );
} );
describe( 'deleteContents', () => {
describe( 'in simple scenarios', () => {
test(
'does nothing on collapsed selection',
'f',
'
'
);
test(
'deletes an element',
'x
y
y
x
y
', 'x
y
' ); test( 'leaves selection attributes when text contains them', 'x<$text bold=true>a
x<$text bold=true>a
x
y
', 'x
y
', { merge: true } ); test( 'merges second element into the first one (same name)', 'x
fo
bar
y
', 'x
fo
y
', { merge: true } ); test( 'does not merge second element into the first one (same name, !option.merge)', 'x
fo
bar
y
', 'x
fo
ar
y
' ); test( 'merges second element into the first one (same name)', 'x
fo
bar
y
', 'x
fo
y
', { merge: true } ); test( 'merges second element into the first one (different name)', 'x
bar
y
', 'x
y
', { merge: true } ); test( 'merges second element into the first one (different name, backward selection)', 'x
bar
y
', 'x
y
', { merge: true } ); test( 'merges second element into the first one (different attrs)', 'x
fo
bar
y
', 'x
fo
y
', { merge: true } ); test( 'merges second element to an empty first element', 'x
foo
y
', 'x
y
', { merge: true } ); test( 'merges elements when deep nested', 'x
x
x
bary
', 'x
xfo
xfo
xfo
ba
xfo
foo
y
', '