/**
* @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/
/* bender-tags: treemodel, composer */
'use strict';
import Document from '/ckeditor5/engine/treemodel/document.js';
import modifySelection from '/ckeditor5/engine/treemodel/composer/modifyselection.js';
import { setData, getData } from '/tests/engine/_utils/model.js';
describe( 'Delete utils', () => {
let document;
beforeEach( () => {
document = new Document();
document.createRoot( 'main', '$root' );
} );
describe( 'modifySelection', () => {
describe( 'unit=character', () => {
describe( 'within element', () => {
test(
'does nothing on empty content',
'',
''
);
test(
'does nothing on empty content (with empty element)',
'
',
'
'
);
test(
'does nothing on empty content (backward)',
'',
'',
{ direction: 'BACKWARD' }
);
test(
'does nothing on root boundary',
'foo
',
'foo
'
);
test(
'does nothing on root boundary (backward)',
'foo
',
'foo
',
{ direction: 'BACKWARD' }
);
test(
'extends one character forward',
'foo
',
'foo
'
);
test(
'extends one character backward',
'foo
',
'foo
',
{ direction: 'BACKWARD' }
);
test(
'extends one character forward (non-collapsed)',
'foobar
',
'foobar
'
);
test(
'extends one character backward (non-collapsed)',
'foobar
',
'foobar
',
{ direction: 'BACKWARD' }
);
test(
'extends to element boundary',
'foo
',
'foo
'
);
test(
'extends to element boundary (backward)',
'foo
',
'foo
',
{ direction: 'BACKWARD' }
);
test(
'shrinks forward selection (to collapsed)',
'foobar
',
'foobar
',
{ direction: 'BACKWARD' }
);
test(
'shrinks backward selection (to collapsed)',
'foobar
',
'foobar
'
);
test(
'extends one element forward',
'f
oo
',
'f
oo
'
);
test(
'extends one non-empty element forward',
'f
xoo
',
'f
xoo
'
);
test(
'extends one element backward',
'fo
o
',
'fo
o
',
{ direction: 'BACKWARD' }
);
} );
describe( 'beyond element', () => {
test(
'extends over boundary of empty elements',
'
',
'
'
);
test(
'extends over boundary of empty elements (backward)',
'
',
'
',
{ direction: 'BACKWARD' }
);
test(
'extends over boundary of non-empty elements',
'a
bcd
',
'a
bcd
'
);
test(
'extends over boundary of non-empty elements (backward)',
'a
bcd
',
'a
bcd
',
{ direction: 'BACKWARD' }
);
test(
'extends over character after boundary',
'a
bcd
',
'a
bcd
'
);
test(
'extends over character after boundary (backward)',
'abc
d
',
'abc
d
',
{ direction: 'BACKWARD' }
);
test(
'extends over boundary when next element has nested elements',
'a
bcd
',
'a
bcd
'
);
test(
'extends over element when next element has nested elements',
'a
bcdef
',
'a
bcdef
'
);
test(
'extends over element when next node is a text',
'a
bc',
'a
bc'
);
test(
'extends over element when next node is a text (backward)',
'abc
',
'abc',
{ direction: 'BACKWARD' }
);
test(
'shrinks over boundary of empty elements',
'
',
'
'
);
test(
'shrinks over boundary of empty elements (backward)',
'
',
'
',
{ direction: 'BACKWARD' }
);
test(
'shrinks over boundary of non-empty elements',
'a
b
',
'a
b
'
);
test(
'shrinks over boundary of non-empty elements (backward)',
'a
b
',
'a
b
',
{ direction: 'BACKWARD' }
);
} );
} );
test(
'updates selection attributes',
'<$text bold=true>foo$text>b
',
'<$text bold=true>foo$text>b
',
{ direction: 'BACKWARD' }
);
} );
function test( title, input, output, options ) {
it( title, () => {
setData( document, input );
modifySelection( document.selection, options );
expect( getData( document ) ).to.equal( output );
} );
}
} );