/** * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor'; import DeleteCommand from '../src/deletecommand'; import UndoEngine from '@ckeditor/ckeditor5-undo/src/undoengine'; import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; describe( 'DeleteCommand integration', () => { let editor, doc; beforeEach( () => { return ModelTestEditor.create( { plugins: [ UndoEngine ], undo: { step: 3 } } ) .then( newEditor => { editor = newEditor; doc = editor.document; const command = new DeleteCommand( editor, 'backward' ); editor.commands.set( 'delete', command ); doc.schema.registerItem( 'p', '$block' ); doc.schema.registerItem( 'img', '$inline' ); doc.schema.allow( { name: '$text', inside: 'img' } ); doc.schema.objects.add( 'img' ); } ); } ); function assertOutput( output ) { expect( getData( doc ) ).to.equal( output ); } describe( 'DeleteCommand integration', () => { it( 'deletes characters (and group changes in batches) and rollbacks', () => { setData( doc, '

123456789[]

' ); for ( let i = 0; i < 3; ++i ) { editor.execute( 'delete' ); } editor.execute( 'undo' ); assertOutput( '

123456789[]

' ); } ); it( 'deletes characters (and group changes in batches) and rollbacks - test step', () => { setData( doc, '

123456789[]

' ); for ( let i = 0; i < 6; ++i ) { editor.execute( 'delete' ); } editor.execute( 'undo' ); assertOutput( '

123456[]

' ); editor.execute( 'undo' ); assertOutput( '

123456789[]

' ); } ); it( 'deletes elements (and group changes in batches) and rollbacks', () => { setData( doc, '

123456[]

' ); for ( let i = 0; i < 3; ++i ) { editor.execute( 'delete' ); } editor.execute( 'undo' ); assertOutput( '

123456[]

' ); } ); it( 'merges elements (and group changes in batches) and rollbacks', () => { setData( doc, '

123456

[]78

' ); for ( let i = 0; i < 6; ++i ) { editor.execute( 'delete' ); } editor.execute( 'undo' ); // Deleted 6,5,4,

does not count. // It's not the most elegant solution, but is the best if we don't want to make complicated algorithm. assertOutput( '

123[]78

' ); editor.execute( 'undo' ); assertOutput( '

123456

[]78

' ); } ); it( 'merges elements (and group changes in batches) and rollbacks - non-collapsed selection', () => { setData( doc, '

12345[6

7]8

' ); editor.execute( 'delete' ); editor.execute( 'delete' ); editor.execute( 'delete' ); editor.execute( 'undo' ); assertOutput( '

1234[]8

' ); editor.execute( 'undo' ); assertOutput( '

12345[6

7]8

' ); } ); } ); } );