/** * @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
' + '
Bar
' ); kate.setData( '
Foo
' + '
[]Bar
' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( 'Foo' + 'Bar' ); } ); it( 'unwrap two siblings then undo', () => { john.setData( '
[]Foo
' + '
Bar
' ); kate.setData( '
Foo
' + '
[]Bar
' ); john.unwrap(); kate.unwrap(); syncClients(); john.undo(); kate.undo(); syncClients(); expectClients( '
Foo
' + '
Bar
' ); } ); it( 'text in different path', () => { john.setData( '
[]Foo
' + '
Bar
' ); kate.setData( '
Foo
' + '
[]Bar
' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( '
Foo
' + '
Bar
' ); } ); it( 'the same element', () => { john.setData( '
[Foo]
' ); kate.setData( '
[Foo]
' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( 'Foo' ); } ); it( 'the same element, then undo', () => { john.setData( '
[]Foo
' ); kate.setData( '
[]Foo
' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( 'Foo' ); john.undo(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( 'Foo' ); expectClients( '
Foo
' ); kate.undo(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( 'Foo' ); expectClients( '
Foo
' ); } ); } ); describe( 'by delete', () => { it( 'text from two elements #1', () => { john.setData( '
[Foo]
Bar' ); kate.setData( '
Fo[o
Ba]r' ); john.unwrap(); kate.delete(); syncClients(); expectClients( 'For' ); } ); it( 'text in same path', () => { john.setData( '
[Foo]
' ); kate.setData( '
F[oo]
' ); john.unwrap(); kate.delete(); syncClients(); expectClients( 'F' ); } ); } ); describe( 'by merge', () => { it( 'element into paragraph #1', () => { john.setData( '
[Foo]Bar
' ); kate.setData( '
Foo[]Bar
' ); john.unwrap(); kate.merge(); syncClients(); expectClients( 'FooBar' ); } ); it( 'element into paragraph #2', () => { john.setData( '
[FooBar]
' ); kate.setData( '
Foo[]Bar
' ); john.unwrap(); kate.merge(); syncClients(); expectClients( 'FooBar' ); } ); it( 'unwrapped element', () => { john.setData( 'Foo
[Bar]
' ); kate.setData( 'Foo[]
Bar
' ); john.unwrap(); kate.merge(); syncClients(); expectClients( 'Foo' + 'Bar' ); } ); it( 'unwrap merge target element', () => { john.setData( '
[]Foo
Bar
' ); kate.setData( '
Foo
[]
Bar
' ); john.unwrap(); kate.merge(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( // 'Foo' + // 'Bar' // ); expectClients( 'Foo' ); } ); } ); describe( 'by split', () => { it( 'unwrap, then split and undo', () => { // This is pretty weird case. Right now it cannot be reproduced with the features that we have. john.editor.model.schema.extend( 'paragraph', { allowIn: 'listItem' } ); john.editor.model.schema.extend( 'blockQuote', { allowIn: 'listItem' } ); kate.editor.model.schema.extend( 'paragraph', { allowIn: 'listItem' } ); kate.editor.model.schema.extend( 'blockQuote', { allowIn: 'listItem' } ); john.setData( '' + '
' + '[]' + 'A' + 'B' + '
' + '
' ); kate.setData( '' + '
' + '[]' + 'A' + 'B' + '
' + '
' ); john.unwrap(); syncClients(); expectClients( '' + 'A' + 'B' + '' ); john.undo(); kate.setSelection( [ 0, 1 ] ); kate.split(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( // '' + // 'A' + // '' + // '' + // 'B' + // '' // ); expectClients( '
AB
' ); kate.undo(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( // '' + // 'A' + // 'B' + // '' // ); expectClients( '
AB
' ); } ); } ); describe( 'by wrap', () => { it( 'unwrap, then undo and wrap #1', () => { john.setData( '
' + '[]' + 'A' + 'B' + 'C' + '
' ); kate.setData( '
' + '[]' + 'A' + 'B' + 'C' + '
' ); john.unwrap(); syncClients(); expectClients( 'A' + 'B' + 'C' ); john.undo(); kate.setSelection( [ 1 ], [ 2 ] ); kate.wrap( 'blockQuote' ); syncClients(); expectClients( '
' + 'A' + 'B' + 'C' + '
' ); } ); it( 'unwrap, then undo and wrap #2', () => { john.setData( 'A' + '
' + '[]' + 'B' + '
' + 'C' ); kate.setData( 'A' + '
' + '[]' + 'B' + '
' + 'C' ); john.unwrap(); syncClients(); expectClients( 'A' + 'B' + 'C' ); john.undo(); kate.setSelection( [ 1 ], [ 2 ] ); kate.wrap( 'blockQuote' ); syncClients(); expectClients( 'A' + '
' + 'B' + '
' + 'C' ); } ); } ); } ); } );