/** * @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( 'unwrap', () => { describe( 'by unwrap', () => { it( 'unwrap two siblings', () => { john.setData( '
[]' + 'Foo
' ); kate.setData( 'Bar
' + 'Foo
[]' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( 'Bar
[]' + 'Foo
' ); kate.setData( 'Bar
' + 'Foo
[]' ); john.unwrap(); kate.unwrap(); syncClients(); john.undo(); kate.undo(); syncClients(); expectClients( 'Bar
' + 'Foo
' ); } ); it( 'text in different path', () => { john.setData( 'Bar
' + '[]Foo
' ); kate.setData( 'Bar
' + 'Foo
' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( '[]Bar
Foo' + '
Bar' ); } ); it( 'the same element', () => { john.setData( '
[' ); kate.setData( 'Foo ]
[' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( 'Foo ]
[]' ); kate.setData( 'Foo
[]' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( 'Foo
' ); kate.undo(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( 'Foo
' ); } ); } ); describe( 'by delete', () => { it( 'text from two elements #1', () => { john.setData( 'Foo
[Foo ]
Fo[o
[' ); kate.setData( 'Foo ]
' ); john.unwrap(); kate.delete(); syncClients(); expectClients( 'F[oo]
[' ); kate.setData( 'Foo ]Bar
' ); john.unwrap(); kate.merge(); syncClients(); expectClients( 'Foo []Bar
[' ); kate.setData( 'Foo Bar ]
' ); john.unwrap(); kate.merge(); syncClients(); expectClients( 'Foo []Bar
[' ); kate.setData( 'Bar ]
' ); john.unwrap(); kate.merge(); syncClients(); expectClients( 'Bar
[]Foo
' ); kate.setData( 'Bar
[]Foo
' ); john.unwrap(); kate.merge(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( // 'Bar
' + '[]' + '' + 'A ' + 'B ' + '
' + '[]' + '' + 'A ' + 'B ' + '
A B
A B
' + '[]' + '' ); kate.setData( 'A ' + 'B ' + 'C ' + '
' + '[]' + '' ); john.unwrap(); syncClients(); expectClients( 'A ' + 'B ' + 'C ' + '
' + '' ); } ); it( 'unwrap, then undo and wrap #2', () => { john.setData( 'A ' + 'B ' + 'C ' + '
' + '[]' + '' + 'B ' + '
' + '[]' + '' + 'B ' + '
' + '' + 'B ' + '