|
|
@@ -9,18 +9,19 @@ import InsertDelta from '@ckeditor/ckeditor5-engine/src/model/delta/insertdelta'
|
|
|
import { getData, setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
|
|
|
|
|
|
describe( 'EnterCommand', () => {
|
|
|
- let editor, doc, schema, command;
|
|
|
+ let editor, model, doc, schema, command;
|
|
|
|
|
|
beforeEach( () => {
|
|
|
return ModelTestEditor.create()
|
|
|
.then( newEditor => {
|
|
|
editor = newEditor;
|
|
|
- doc = editor.document;
|
|
|
+ model = editor.model;
|
|
|
+ doc = model.document;
|
|
|
|
|
|
command = new EnterCommand( editor );
|
|
|
editor.commands.add( 'enter', command );
|
|
|
|
|
|
- schema = doc.schema;
|
|
|
+ schema = model.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.
|
|
|
@@ -42,23 +43,18 @@ describe( 'EnterCommand', () => {
|
|
|
} );
|
|
|
|
|
|
describe( 'EnterCommand', () => {
|
|
|
- it( 'enters a block using enqueueChanges', () => {
|
|
|
- setData( doc, '<p>foo[]</p>' );
|
|
|
+ it( 'enters a block using parent batch', () => {
|
|
|
+ setData( model, '<p>foo[]</p>' );
|
|
|
|
|
|
- doc.enqueueChanges( () => {
|
|
|
+ model.change( writer => {
|
|
|
+ expect( writer.batch.deltas ).to.length( 0 );
|
|
|
editor.execute( 'enter' );
|
|
|
-
|
|
|
- // We expect that command is executed in enqueue changes block. Since we are already in
|
|
|
- // an enqueued block, the command execution will be postponed. Hence, no changes.
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal( '<p>foo</p>' );
|
|
|
+ expect( writer.batch.deltas ).to.length.above( 0 );
|
|
|
} );
|
|
|
-
|
|
|
- // After all enqueued changes are done, the command execution is reflected.
|
|
|
- expect( getData( doc, { withoutSelection: true } ) ).to.equal( '<p>foo</p><p></p>' );
|
|
|
} );
|
|
|
|
|
|
it( 'creates InsertDelta if enter is at the beginning of block', () => {
|
|
|
- setData( doc, '<p>[]foo</p>' );
|
|
|
+ setData( model, '<p>[]foo</p>' );
|
|
|
|
|
|
editor.execute( 'enter' );
|
|
|
|
|
|
@@ -68,7 +64,7 @@ describe( 'EnterCommand', () => {
|
|
|
} );
|
|
|
|
|
|
it( 'creates InsertDelta if enter is at the end of block', () => {
|
|
|
- setData( doc, '<p>foo[]</p>' );
|
|
|
+ setData( model, '<p>foo[]</p>' );
|
|
|
|
|
|
editor.execute( 'enter' );
|
|
|
|
|
|
@@ -167,13 +163,13 @@ describe( 'EnterCommand', () => {
|
|
|
);
|
|
|
|
|
|
it( 'leaves one empty element after two were fully selected (backward)', () => {
|
|
|
- setData( doc, '<p>[abc</p><p>def]</p>' );
|
|
|
+ setData( model, '<p>[abc</p><p>def]</p>' );
|
|
|
// @TODO: Add option for setting selection direction to model utils.
|
|
|
doc.selection._lastRangeBackward = true;
|
|
|
|
|
|
command.execute();
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( '<p>[]</p>' );
|
|
|
+ expect( getData( model ) ).to.equal( '<p>[]</p>' );
|
|
|
} );
|
|
|
|
|
|
it( 'uses DataController.deleteContent', () => {
|
|
|
@@ -181,7 +177,7 @@ describe( 'EnterCommand', () => {
|
|
|
|
|
|
editor.data.on( 'deleteContent', spy );
|
|
|
|
|
|
- setData( doc, '<p>[x]</p>' );
|
|
|
+ setData( model, '<p>[x]</p>' );
|
|
|
|
|
|
command.execute();
|
|
|
|
|
|
@@ -191,11 +187,11 @@ describe( 'EnterCommand', () => {
|
|
|
|
|
|
function test( title, input, output ) {
|
|
|
it( title, () => {
|
|
|
- setData( doc, input );
|
|
|
+ setData( model, input );
|
|
|
|
|
|
command.execute();
|
|
|
|
|
|
- expect( getData( doc ) ).to.equal( output );
|
|
|
+ expect( getData( model ) ).to.equal( output );
|
|
|
} );
|
|
|
}
|
|
|
} );
|