From c20d05b7bd961d6a93d4c8db69e77714c377514e Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Mon, 4 Sep 2017 11:51:21 +0200 Subject: [PATCH] Tests: Fixed tests. --- tests/undoengine-integration.js | 153 ++++++++++++++++++++++---------- 1 file changed, 107 insertions(+), 46 deletions(-) diff --git a/tests/undoengine-integration.js b/tests/undoengine-integration.js index c710ebd..ab11581 100644 --- a/tests/undoengine-integration.js +++ b/tests/undoengine-integration.js @@ -69,7 +69,9 @@ describe( 'UndoEngine integration', () => { it( 'add and undo', () => { input( 'fo[]obar' ); - doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' ); + doc.enqueueChanges( () => { + doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' ); + } ); output( 'fozzz[]obar' ); editor.execute( 'undo' ); @@ -81,13 +83,19 @@ describe( 'UndoEngine integration', () => { it( 'multiple adding and undo', () => { input( 'fo[]obar' ); - doc.batch() - .insert( doc.selection.getFirstPosition(), 'zzz' ) - .insert( new Position( root, [ 1, 0 ] ), 'xxx' ); + doc.enqueueChanges( () => { + doc.batch() + .insert( doc.selection.getFirstPosition(), 'zzz' ) + .insert( new Position( root, [ 1, 0 ] ), 'xxx' ); + } ); + output( 'fozzz[]oxxxbar' ); - setSelection( [ 1, 0 ], [ 1, 0 ] ); - doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' ); + doc.enqueueChanges( () => { + setSelection( [ 1, 0 ], [ 1, 0 ] ); + doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' ); + } ); + output( 'fozzzoyyy[]xxxbar' ); editor.execute( 'undo' ); @@ -102,18 +110,25 @@ describe( 'UndoEngine integration', () => { it( 'multiple adding mixed with undo', () => { input( 'fo[]obar' ); - doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' ); + doc.enqueueChanges( () => { + doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' ); + } ); output( 'fozzz[]obar' ); - setSelection( [ 1, 0 ], [ 1, 0 ] ); - doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' ); + doc.enqueueChanges( () => { + setSelection( [ 1, 0 ], [ 1, 0 ] ); + doc.batch().insert( doc.selection.getFirstPosition(), 'yyy' ); + } ); + output( 'fozzzoyyy[]bar' ); editor.execute( 'undo' ); output( 'fozzzo[]bar' ); - setSelection( [ 0, 0 ], [ 0, 0 ] ); - doc.batch().insert( doc.selection.getFirstPosition(), 'xxx' ); + doc.enqueueChanges( () => { + setSelection( [ 0, 0 ], [ 0, 0 ] ); + doc.batch().insert( doc.selection.getFirstPosition(), 'xxx' ); + } ); output( 'xxx[]fozzzobar' ); editor.execute( 'undo' ); @@ -128,11 +143,15 @@ describe( 'UndoEngine integration', () => { it( 'multiple remove and undo', () => { input( '[]foobar' ); - doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) ); + doc.enqueueChanges( () => { + doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) ); + } ); output( '[]obar' ); - setSelection( [ 1, 1 ], [ 1, 1 ] ); - doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) ); + doc.enqueueChanges( () => { + setSelection( [ 1, 1 ], [ 1, 1 ] ); + doc.batch().remove( Range.createFromPositionAndShift( doc.selection.getFirstPosition(), 2 ) ); + } ); output( 'ob[]' ); editor.execute( 'undo' ); @@ -149,11 +168,15 @@ describe( 'UndoEngine integration', () => { it( 'add and remove different parts and undo', () => { input( 'fo[]obar' ); - doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' ); + doc.enqueueChanges( () => { + doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' ); + } ); output( 'fozzz[]obar' ); - setSelection( [ 1, 2 ], [ 1, 2 ] ); - doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 1, 1 ] ), 1 ) ); + doc.enqueueChanges( () => { + setSelection( [ 1, 2 ], [ 1, 2 ] ); + doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 1, 1 ] ), 1 ) ); + } ); output( 'fozzzob[]r' ); editor.execute( 'undo' ); @@ -168,10 +191,14 @@ describe( 'UndoEngine integration', () => { it( 'add and remove same part and undo', () => { input( 'fo[]obar' ); - doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' ); + doc.enqueueChanges( () => { + doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' ); + } ); output( 'fozzz[]obar' ); - doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 0, 2 ] ), 3 ) ); + doc.enqueueChanges( () => { + doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 0, 2 ] ), 3 ) ); + } ); output( 'fo[]obar' ); editor.execute( 'undo' ); @@ -188,10 +215,14 @@ describe( 'UndoEngine integration', () => { it( 'move same content twice then undo', () => { input( 'f[o]zbar' ); - doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) ); + doc.enqueueChanges( () => { + doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) ); + } ); output( 'fz[o]bar' ); - doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0, 2 ] ) ); + doc.enqueueChanges( () => { + doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0, 2 ] ) ); + } ); output( 'fz[o]bar' ); editor.execute( 'undo' ); @@ -206,11 +237,15 @@ describe( 'UndoEngine integration', () => { it( 'move content and new parent then undo', () => { input( 'f[o]zbar' ); - doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) ); + doc.enqueueChanges( () => { + doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 1, 0 ] ) ); + } ); output( 'fz[o]bar' ); - setSelection( [ 1 ], [ 2 ] ); - doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) ); + doc.enqueueChanges( () => { + setSelection( [ 1 ], [ 2 ] ); + doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) ); + } ); output( '[obar]fz' ); editor.execute( 'undo' ); @@ -227,11 +262,15 @@ describe( 'UndoEngine integration', () => { it( 'attributes then insert inside then undo', () => { input( 'fo[ob]ar' ); - doc.batch().setAttribute( doc.selection.getFirstRange(), 'bold', true ); + doc.enqueueChanges( () => { + doc.batch().setAttribute( doc.selection.getFirstRange(), 'bold', true ); + } ); output( 'fo[<$text bold="true">ob]ar' ); - setSelection( [ 0, 3 ], [ 0, 3 ] ); - doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' ); + doc.enqueueChanges( () => { + setSelection( [ 0, 3 ], [ 0, 3 ] ); + doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' ); + } ); output( 'fo<$text bold="true">ozzz<$text bold="true">[]bar' ); expect( doc.selection.getAttribute( 'bold' ) ).to.true; @@ -251,7 +290,9 @@ describe( 'UndoEngine integration', () => { doc.schema.allow( { name: '$text', inside: '$root' } ); input( 'fo[zb]ar' ); - doc.batch().wrap( doc.selection.getFirstRange(), 'paragraph' ); + doc.enqueueChanges( () => { + doc.batch().wrap( doc.selection.getFirstRange(), 'paragraph' ); + } ); output( 'fo[zb]ar' ); editor.execute( 'undo' ); @@ -264,12 +305,16 @@ describe( 'UndoEngine integration', () => { doc.schema.allow( { name: '$text', inside: '$root' } ); input( 'fo[zb]ar' ); - doc.batch().wrap( doc.selection.getFirstRange(), 'paragraph' ); + doc.enqueueChanges( () => { + doc.batch().wrap( doc.selection.getFirstRange(), 'paragraph' ); + } ); // Would be better if selection was inside P. output( 'fo[zb]ar' ); - setSelection( [ 2, 0 ], [ 2, 1 ] ); - doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) ); + doc.enqueueChanges( () => { + setSelection( [ 2, 0 ], [ 2, 1 ] ); + doc.batch().move( doc.selection.getFirstRange(), new Position( root, [ 0 ] ) ); + } ); output( '[z]fobar' ); editor.execute( 'undo' ); @@ -284,7 +329,9 @@ describe( 'UndoEngine integration', () => { it( 'unwrap and undo', () => { input( 'foo[]bar' ); - doc.batch().unwrap( doc.selection.getFirstPosition().parent ); + doc.enqueueChanges( () => { + doc.batch().unwrap( doc.selection.getFirstPosition().parent ); + } ); output( 'foo[]bar' ); editor.execute( 'undo' ); @@ -296,9 +343,11 @@ describe( 'UndoEngine integration', () => { it( 'merge and undo', () => { input( 'foo[]bar' ); - doc.batch().merge( new Position( root, [ 1 ] ) ); - // Because selection is stuck with it ends up in graveyard. We have to manually move it to correct node. - setSelection( [ 0, 3 ], [ 0, 3 ] ); + doc.enqueueChanges( () => { + doc.batch().merge( new Position( root, [ 1 ] ) ); + // Because selection is stuck with it ends up in graveyard. We have to manually move it to correct node. + setSelection( [ 0, 3 ], [ 0, 3 ] ); + } ); output( 'foo[]bar' ); editor.execute( 'undo' ); @@ -310,9 +359,11 @@ describe( 'UndoEngine integration', () => { it( 'split and undo', () => { input( 'foo[]bar' ); - doc.batch().split( doc.selection.getFirstPosition() ); - // Because selection is stuck with it ends up in wrong node. We have to manually move it to correct node. - setSelection( [ 1, 0 ], [ 1, 0 ] ); + doc.enqueueChanges( () => { + doc.batch().split( doc.selection.getFirstPosition() ); + // Because selection is stuck with it ends up in wrong node. We have to manually move it to correct node. + setSelection( [ 1, 0 ], [ 1, 0 ] ); + } ); output( 'foo[]bar' ); editor.execute( 'undo' ); @@ -761,25 +812,33 @@ describe( 'UndoEngine integration', () => { // ckeditor5-engine#t/1055 it( 'selection attribute setting: split, bold, merge, undo, undo, undo', () => { - input( '

Foo[]

Bar

' ); + input( 'Foo[]Bar' ); editor.execute( 'enter' ); - output( '

Foo

[]

Bar

' ); + output( 'Foo[]Bar' ); editor.execute( 'bold' ); - output( '

Foo

<$text bold="true">[]

Bar

' ); + output( + 'Foo' + + '<$text bold="true">[]' + + 'Bar' + ); editor.execute( 'forwardDelete' ); - output( '

Foo

[]Bar

' ); + output( 'Foo[]Bar' ); editor.execute( 'undo' ); - output( '

Foo

<$text bold="true">[]

Bar

' ); + output( + 'Foo' + + '<$text bold="true">[]' + + 'Bar' + ); editor.execute( 'undo' ); - output( '

Foo

[]

Bar

' ); + output( 'Foo[]Bar' ); editor.execute( 'undo' ); - output( '

Foo[]

Bar

' ); + output( 'Foo[]Bar' ); } ); } ); @@ -829,7 +888,9 @@ describe( 'UndoEngine integration', () => { it( 'deleteContent between two nodes', () => { input( 'fo[ob]ar' ); - editor.data.deleteContent( doc.selection, doc.batch() ); + doc.enqueueChanges( () => { + editor.data.deleteContent( doc.selection, doc.batch() ); + } ); output( 'fo[]ar' ); editor.execute( 'undo' );