/** * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ 'use strict'; import VirtualTestEditor from '/tests/ckeditor5/_utils/virtualtesteditor.js'; import { default as EnterCommand, enterBlock } from '/ckeditor5/enter/entercommand.js'; import { getData, setData } from '/tests/engine/_utils/model.js'; let editor, doc; beforeEach( () => { return VirtualTestEditor.create( ) .then( newEditor => { editor = newEditor; doc = editor.document; doc.createRoot(); const command = new EnterCommand( editor ); editor.commands.set( 'enter', command ); const 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', () => { const spy = sinon.spy( doc, 'enqueueChanges' ); setData( doc, '
foo
foo
' ); expect( spy.calledOnce ).to.be.true; } ); } ); describe( 'enterBlock', () => { describe( 'collapsed selection', () => { test( 'does nothing in the root', 'foox
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
', '