import { Client, expectClients, clearBuffer } from './utils.js'; describe( 'transform', () => { let john; beforeEach( () => { return Client.get( 'john' ).then( client => ( john = client ) ); } ); afterEach( () => { clearBuffer(); return john.destroy(); } ); it( 'split, remove', () => { john.setData( 'Foo[]Bar' ); john.split(); john.setSelection( [ 1 ], [ 2 ] ); john.remove(); john.undo(); john.undo(); expectClients( 'FooBar' ); } ); it( 'move, merge', () => { john.setData( '[Foo]Bar' ); john.move( [ 2 ] ); john.setSelection( [ 1 ] ); john.merge(); john.undo(); john.undo(); expectClients( 'FooBar' ); } ); it.skip( 'move multiple, merge', () => { john.setData( '[FooBar]Xyz' ); john.move( [ 3 ] ); expectClients( 'XyzFooBar' ); john.setSelection( [ 1 ] ); john.merge(); expectClients( 'XyzFooBar' ); john.undo(); expectClients( 'XyzFooBar' ); john.undo(); // Wrong move is done. expectClients( 'FooBarXyz' ); } ); it( 'move inside unwrapped content', () => { john.setData( '
[Foo]Bar
' ); john.move( [ 0, 2 ] ); john.setSelection( [ 0, 0 ] ); john.unwrap(); john.undo(); john.undo(); expectClients( '
' + 'Foo' + 'Bar' + '
' ); } ); it( 'remove node, merge', () => { john.setData( 'Foo[Bar]' ); john.remove(); john.setSelection( [ 1 ] ); john.merge(); john.undo(); john.undo(); expectClients( 'FooBar' ); } ); it( 'merge, merge #1', () => { john.setData( '
' + 'Foo' + 'Bar' + '
' + '[]' + '
' + 'Xyz' + '
' ); john.merge(); john.setSelection( [ 0, 2 ] ); john.merge(); expectClients( '
' + 'Foo' + 'BarXyz' + '
' ); john.undo(); john.undo(); expectClients( '
' + 'Foo' + 'Bar' + '
' + '
' + 'Xyz' + '
' ); } ); it( 'merge, merge #2', () => { john.setData( '
' + 'Foo' + '
' + '[]' + '
' + 'Bar' + 'Xyz' + '
' ); john.merge(); john.setSelection( [ 0, 1 ] ); john.merge(); expectClients( '
' + 'FooBar' + 'Xyz' + '
' ); john.undo(); john.undo(); expectClients( '
' + 'Foo' + '
' + '
' + 'Bar' + 'Xyz' + '
' ); } ); it( 'merge, unwrap', () => { john.setData( '[]Foo' ); john.merge(); john.setSelection( [ 0, 0 ] ); john.unwrap(); john.undo(); john.undo(); expectClients( 'Foo' ); } ); it( 'remove node at the split position #1', () => { john.setData( 'Ab[]Xy' ); john.merge(); john.setSelection( [ 0, 1 ], [ 0, 2 ] ); john.remove(); john.undo(); john.undo(); expectClients( 'AbXy' ); } ); it( 'remove node at the split position #2', () => { john.setData( 'Ab[]Xy' ); john.merge(); john.setSelection( [ 0, 2 ], [ 0, 3 ] ); john.remove(); john.undo(); john.undo(); expectClients( 'AbXy' ); } ); it( 'undoing split after the element created by split has been removed', () => { // This example is ported here from ckeditor5-undo to keep 100% CC in ckeditor5-engine alone. john.setData( 'Foo[]bar' ); john.split(); john.setSelection( [ 0, 3 ], [ 1, 3 ] ); john.delete(); expectClients( 'Foo' ); john.undo(); expectClients( 'Foobar' ); john.undo(); expectClients( 'Foobar' ); } ); it( 'remove text from paragraph and merge it', () => { john.setData( 'Foo[Bar]' ); john.remove(); john.setSelection( [ 1 ] ); john.merge(); expectClients( 'Foo' ); john.undo(); expectClients( 'Foo' ); john.undo(); expectClients( 'FooBar' ); } ); it.skip( 'delete split paragraphs', () => { john.setData( 'FooB[]ar' ); john.split(); john.setSelection( [ 2, 1 ] ); john.split(); john.setSelection( [ 1, 0 ], [ 3, 1 ] ); john.delete(); john.setSelection( [ 1 ] ); john.merge(); expectClients( 'Foo' ); john.undo(); expectClients( 'Foo' ); john.undo(); expectClients( 'FooBar' ); john.undo(); expectClients( 'FooBar' ); john.undo(); expectClients( 'FooBar' ); john.redo(); expectClients( 'FooBar' ); john.redo(); expectClients( 'FooBar' ); john.redo(); expectClients( 'Foo' ); john.redo(); expectClients( 'Foo' ); } ); } );