/** * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md. */ import ModelTestEditor from 'tests/core/_utils/modeltesteditor.js'; import DeleteCommand from 'ckeditor5/typing/deletecommand.js'; import UndoEngine from 'ckeditor5/undo/undoengine.js'; import { getData, setData } from 'ckeditor5/engine/dev-utils/model.js'; let editor, doc; beforeEach( () => { return ModelTestEditor.create( { features: [ 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' } ); } ); } ); 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

' ); } ); } );