/** * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ import ModelTestEditor from '/tests/ckeditor5/_utils/modeltesteditor.js'; import { default as EnterCommand, enterBlock } from '/ckeditor5/enter/entercommand.js'; import { getData, setData } from '/tests/engine/_utils/model.js'; let editor, doc, schema; beforeEach( () => { return ModelTestEditor.create() .then( newEditor => { editor = newEditor; doc = editor.document; const command = new EnterCommand( editor ); editor.commands.set( 'enter', command ); schema = doc.schema; // Note: We could use real names like 'paragraph', but that would make test patterns too long. // Plus, this is actually a good test that the algorithm can be used for any model. schema.registerItem( 'img', '$inline' ); schema.registerItem( 'p', '$block' ); schema.registerItem( 'h', '$block' ); } ); } ); describe( 'EnterCommand', () => { it( 'enters a block using enqueueChanges', () => { setData( doc, '
foo
foo
' ); expect( spy.calledOnce ).to.be.true; } ); it( 'uses paragraph as default block', () => { schema.registerItem( 'paragraph', '$block' ); setData( doc, 'x
foo
y
', 'x
foo
y
', { defaultBlockName: 'p' } ); test( 'splits block (other than default)', 'x
y
', 'x
y
', { defaultBlockName: 'p' } ); test( 'splits block at the end', 'x
foo
y
', 'x
foo
y
', { defaultBlockName: 'p' } ); test( 'splits block at the beginning', 'x
y
', 'x
y
', { defaultBlockName: 'p' } ); test( 'splits block at the beginning (other than default)', 'x
y
', 'x
y
', { defaultBlockName: 'p' } ); test( 'creates default block when leaving other block', 'x
', 'x
', { defaultBlockName: 'p' } ); test( 'does not rename when default block is not allowed', 'x
', 'x
', { defaultBlockName: 'xxx' } ); test( 'inserts new block after empty one', 'x
y
', 'x
y
', { defaultBlockName: 'p' } ); test( 'inserts new block after empty one (other than default)', 'x
y
', 'x
y
', { defaultBlockName: 'p' } ); } ); describe( 'non-collapsed selection', () => { test( 'only deletes the content when directly in the root', 'foab
ghi
', 'ab
ghi
', { defaultBlockName: 'p' } ); test( 'deletes text and splits (other than default)', 'def
ghi
', 'ghi
', { defaultBlockName: 'p' } ); test( 'leaves one empty element after one was fully selected', 'x
y
', 'x
y
', { defaultBlockName: 'p' } ); test( 'leaves one (default) empty element after one was fully selected', 'def
', 'def
', '