/** * @license Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license */ import { Client, syncClients, expectClients, clearBuffer } from './utils.js'; describe( 'transform', () => { let john, kate; beforeEach( () => { return Promise.all( [ Client.get( 'john' ).then( client => ( john = client ) ), Client.get( 'kate' ).then( client => ( kate = client ) ) ] ); } ); afterEach( () => { clearBuffer(); return Promise.all( [ john.destroy(), kate.destroy() ] ); } ); describe( 'remove', () => { describe( 'by remove', () => { it( 'text in different path', () => { john.setData( 'F[oo]Bar' ); kate.setData( 'FooB[ar]' ); john.remove(); kate.remove(); syncClients(); expectClients( 'FB' ); } ); it( 'text in same path', () => { john.setData( 'F[oo] Bar' ); kate.setData( 'Foo B[ar]' ); john.remove(); kate.remove(); syncClients(); expectClients( 'F B' ); } ); it( 'text in other user\'s selection #1', () => { john.setData( '[Foo Bar]' ); kate.setData( 'Fo[o B]ar' ); john.remove(); kate.remove(); syncClients(); expectClients( '' ); } ); it( 'text in other user\'s selection #2', () => { john.setData( '[Foo Bar]' ); kate.setData( '[Foo Bar]' ); john.remove(); kate.remove(); syncClients(); expectClients( '' ); } ); it( 'element in different path', () => { john.setData( '[Foo]Bar' ); kate.setData( 'Foo[Bar]' ); john.remove(); kate.remove(); syncClients(); expectClients( '' ); } ); it( 'text in other user\'s selection, then undo', () => { john.setData( '[Foo Bar]' ); kate.setData( 'Fo[o B]ar' ); john.remove(); kate.remove(); syncClients(); john.undo(); kate.undo(); syncClients(); expectClients( 'Foo Bar' ); } ); } ); describe( 'by wrap', () => { it( 'element in different path', () => { john.setData( '[Foo]Bar' ); kate.setData( 'Foo[Bar]' ); john.remove(); kate.wrap( 'blockQuote' ); syncClients(); expectClients( '' + '
' + 'Bar' + '
' ); } ); it( 'element in same path', () => { john.setData( '[Foo]' ); kate.setData( '[Foo]' ); john.remove(); kate.wrap( 'blockQuote' ); syncClients(); expectClients( '
' ); } ); it( 'element while removing', () => { john.setData( 'Foo[Bar]' ); kate.setData( 'Foo[Bar]' ); john.remove(); kate.wrap( 'blockQuote' ); syncClients(); expectClients( 'Foo' ); } ); it( 'element while removing, then undo', () => { john.setData( 'Foo[Bar]' ); kate.setData( 'Foo[Bar]' ); john.remove(); kate.wrap( 'blockQuote' ); syncClients(); expectClients( 'Foo' ); john.undo(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( // 'Foo' + // '
' + // 'Bar' + // '
' // ); expectClients( 'FooBar' ); } ); it( 'element while removing, then undo #2', () => { john.setData( 'Foo[Bar]' ); kate.setData( 'Foo[Bar]' ); john.remove(); john.undo(); kate.wrap( 'blockQuote' ); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( // 'Foo' + // '
' + // 'Bar' + // '
' // ); expectClients( 'FooBar' ); } ); } ); describe( 'by unwrap', () => { it( 'element in different path', () => { john.setData( '[Foo]
Bar
' ); kate.setData( 'Foo
[Bar]
' ); john.remove(); kate.unwrap(); syncClients(); expectClients( '' + 'Bar' ); } ); it( 'text in different path', () => { john.setData( '[Foo]
Bar
' ); kate.setData( 'Foo
[]Bar
' ); john.remove(); kate.unwrap(); syncClients(); expectClients( '' + '
Bar
' ); } ); it( 'element in same path', () => { john.setData( '
[Foo]
' ); kate.setData( '
[Foo]
' ); john.remove(); kate.unwrap(); syncClients(); expectClients( '' ); } ); it( 'element while removing', () => { john.setData( 'Foo
[Bar]
' ); kate.setData( 'Foo
[Bar]
' ); john.remove(); kate.unwrap(); syncClients(); expectClients( 'Foo' ); } ); it( 'element while removing, then undo', () => { john.setData( 'Foo
[Bar]
' ); kate.setData( 'Foo
[]Bar
' ); john.remove(); kate.unwrap(); syncClients(); expectClients( 'Foo' ); john.undo(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( // 'Foo' + // 'Bar' // ); expectClients( 'Foo
Bar
' ); } ); } ); describe( 'by split', () => { it( 'text in different path', () => { john.setData( 'F[oo]Bar' ); kate.setData( 'FooB[]ar' ); john.remove(); kate.split(); syncClients(); expectClients( 'F' + 'B' + 'ar' ); } ); it( 'text in same path', () => { john.setData( '[Foo] Bar' ); kate.setData( 'Foo []Bar' ); john.remove(); kate.split(); syncClients(); expectClients( ' ' + 'Bar' ); } ); it( 'text in other user\'s selection #1', () => { john.setData( '[Foo] Bar' ); kate.setData( 'F[]oo Bar' ); john.remove(); kate.split(); syncClients(); expectClients( '' + ' Bar' ); } ); it( 'text in other user\'s selection #2', () => { john.setData( '[Foo Bar]' ); kate.setData( 'F[]oo Bar' ); john.remove(); kate.split(); syncClients(); expectClients( '' + '' ); } ); it( 'text, then remove and undo', () => { john.setData( '[Foo ]Bar' ); kate.setData( 'Foo []Bar' ); john.remove(); kate.split(); syncClients(); john.setSelection( [ 1, 0 ], [ 1, 3 ] ); john.remove(); kate.undo(); syncClients(); expectClients( '' ); } ); it( 'remove split element', () => { john.setData( '[Foo]Bar' ); kate.setData( 'Fo[]oBar' ); john.remove(); kate.split(); syncClients(); expectClients( 'Bar' ); } ); } ); describe( 'by merge', () => { it( 'element into paragraph #1', () => { john.setData( 'F[oo]Bar' ); kate.setData( 'Foo[]Bar' ); john.remove(); kate.merge(); syncClients(); expectClients( 'FBar' ); } ); it( 'element into paragraph #2', () => { john.setData( 'FooB[ar]' ); kate.setData( 'Foo[]Bar' ); john.remove(); kate.merge(); syncClients(); expectClients( 'FooB' ); } ); it( 'element into paragraph, then undo', () => { john.setData( 'F[oo]Bar' ); kate.setData( 'Foo[]Bar' ); john.remove(); kate.merge(); syncClients(); expectClients( 'FBar' ); john.undo(); syncClients(); expectClients( 'FooBar' ); } ); it( 'wrapped element into wrapped paragraph #1', () => { john.setData( '
F[oo]Bar
' ); kate.setData( '
Foo[]Bar
' ); john.remove(); kate.merge(); syncClients(); expectClients( '
FBar
' ); } ); it( 'wrapped element into wrapped paragraph #2', () => { john.setData( '
FooB[ar]
' ); kate.setData( '
Foo[]Bar
' ); john.remove(); kate.merge(); syncClients(); expectClients( '
FooB
' ); } ); it( 'removed element, then undo', () => { john.setData( 'Foo[Bar]' ); kate.setData( 'Foo[]Bar' ); john.remove(); kate.merge(); syncClients(); expectClients( 'Foo' ); john.undo(); syncClients(); expectClients( 'FooBar' ); } ); } ); describe( 'by rename', () => { it( 'element in different path', () => { john.setData( 'Foo[Bar]' ); kate.setData( 'F[]ooBar' ); john.remove(); kate.rename( 'heading1' ); syncClients(); expectClients( 'Foo' + '' ); } ); it( 'element in same path', () => { john.setData( 'F[o]o' ); kate.setData( '[]Foo' ); john.remove(); kate.rename( 'heading1' ); syncClients(); expectClients( 'Fo' ); } ); it( 'element in other user\'s selection', () => { kate.setData( '[Foo]' ); john.setData( '[Foo]' ); kate.remove(); john.rename( 'heading1' ); syncClients(); expectClients( '' ); } ); } ); } ); } );