/** * @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( 'merge', () => { describe( 'by merge', () => { it( 'elements into paragraph', () => { john.setData( 'Foo[]BarAbc' ); kate.setData( 'FooBar[]Abc' ); john.merge(); kate.merge(); syncClients(); expectClients( 'FooBarAbc' ); } ); it( 'elements into paragraph with undo', () => { john.setData( 'Foo[]BarAbc' ); kate.setData( 'FooBar[]Abc' ); john.merge(); kate.merge(); syncClients(); kate.undo(); john.undo(); syncClients(); expectClients( 'FooBarAbc' ); } ); it.skip( 'same element with undo', () => { // Unnecessary SplitOperation. john.setData( 'Foo[]' ); kate.setData( 'Foo[]' ); john.merge(); kate.merge(); kate.undo(); syncClients(); expectClients( 'Foo' ); } ); it( 'merge to different element (insert) with undo', () => { john.setData( 'Foo[]Bar' ); kate.setData( 'Foo[]Bar' ); john.merge(); kate.insert( '' ); kate.setSelection( [ 2 ], [ 2 ] ); kate.merge(); syncClients(); expectClients( 'FooBar' ); john.undo(); syncClients(); expectClients( 'FooBar' ); kate.undo(); syncClients(); expectClients( 'FooBar' ); } ); it( 'merge to different element (wrap) with undo #1', () => { // Merging to an element happens during using BlockQuote plugin. `Foo` paragraph is first wrapped and // then merged to the existing `blockQuote`. john.setData( 'F[oo
B]ar
' ); kate.setData( 'F[oo
B]ar
' ); john._processExecute( 'blockQuote' ); kate._processExecute( 'blockQuote' ); syncClients(); expectClients( '
' + 'Foo' + 'Bar' + '
' ); john.undo(); syncClients(); expectClients( 'Foo' + '
' + 'Bar' + '
' ); kate.undo(); syncClients(); expectClients( 'Foo' + '
' + 'Bar' + '
' ); } ); it( 'merge to different element (wrap) with undo #2', () => { // Merging to an element happens during using BlockQuote plugin. `Foo` paragraph is first wrapped and // then merged to the existing `blockQuote`. john.setData( 'F[oo
B]ar
' ); kate.setData( 'F[oo
B]ar
' ); john._processExecute( 'blockQuote' ); kate._processExecute( 'blockQuote' ); syncClients(); expectClients( '
' + 'Foo' + 'Bar' + '
' ); kate.undo(); syncClients(); expectClients( '
' + 'Bar' + '
' + 'Foo' ); john.undo(); syncClients(); expectClients( 'Foo' ); } ); it( 'merge to different element (wrap) with undo #3', () => { // Merging to an element happens during using BlockQuote plugin. `Foo` paragraph is first wrapped and // then merged to the existing `blockQuote`. john.setData( 'F[oo
B]ar
' ); kate.setData( 'F[oo
B]ar
' ); john._processExecute( 'blockQuote' ); kate._processExecute( 'blockQuote' ); syncClients(); expectClients( '
' + 'Foo' + 'Bar' + '
' ); john.undo(); kate.undo(); syncClients(); expectClients( 'Foo' ); } ); } ); describe( 'by remove', () => { it( 'remove merged element', () => { john.setData( 'Foo[]Bar' ); kate.setData( 'Foo[Bar]' ); john.merge(); kate.remove(); syncClients(); expectClients( 'Foo' ); } ); it( 'remove merged element then undo #1', () => { john.setData( 'Foo[]Bar' ); kate.setData( 'Foo[Bar]' ); john.merge(); kate.remove(); syncClients(); expectClients( 'Foo' ); kate.undo(); syncClients(); expectClients( 'FooBar' ); } ); it( 'remove merged element then undo #2', () => { john.setData( 'Foo[]Bar' ); kate.setData( 'Foo[Bar]' ); john.merge(); kate.remove(); kate.undo(); syncClients(); expectClients( 'FooBar' ); } ); it( 'remove merged element then undo #3', () => { john.setData( '[AB]C' ); kate.setData( 'A[]BC' ); kate.merge(); john.remove(); syncClients(); expectClients( 'C' ); john.undo(); kate.undo(); syncClients(); expectClients( 'ABC' ); } ); it( 'remove merged element then undo #4', () => { john.setData( 'A[BC]' ); kate.setData( 'A[]BC' ); kate.merge(); john.remove(); syncClients(); expectClients( 'A' ); john.undo(); kate.undo(); syncClients(); expectClients( 'ABC' ); } ); } ); describe( 'by delete', () => { it( 'text from two elements', () => { john.setData( 'Foo[]Bar' ); kate.setData( 'Fo[oBa]r' ); john.merge(); kate.delete(); syncClients(); expectClients( 'For' ); } ); it( 'merged elements and some text', () => { john.setData( 'Foo[]Bar' ); kate.setData( 'F[ooBa]r' ); john.merge(); kate.delete(); syncClients(); expectClients( 'Fr' ); } ); } ); describe( 'by wrap', () => { it( 'wrap merged element', () => { john.setData( 'Foo[]Bar' ); kate.setData( 'Foo[Bar]' ); john.merge(); kate.wrap( 'blockQuote' ); syncClients(); expectClients( 'FooBar' ); john.undo(); kate.undo(); syncClients(); expectClients( 'FooBar' ); } ); it( 'wrap in merged element', () => { // 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' + 'C' + '' ); kate.setData( '' + 'A' + '' + '' + '[B' + 'C]' + '' ); john.merge(); kate.wrap( 'blockQuote' ); syncClients(); expectClients( '' + 'A' + '
' + 'B' + 'C' + '
' + '
' ); } ); } ); describe( 'by unwrap', () => { it( 'merge to unwrapped element', () => { john.setData( '
Foo
[]
Bar
' ); kate.setData( '
[]Foo
Bar
' ); john.merge(); kate.unwrap(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( 'FooBar' ); expectClients( 'Foo' ); } ); it( 'merge to unwrapped element with undo #1', () => { john.setData( '
Foo
[]
Bar
' ); kate.setData( '
[]Foo
Bar
' ); john.merge(); john.undo(); kate.unwrap(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( 'FooBar' ); expectClients( 'Foo
Bar
' ); } ); it( 'merge to unwrapped element with undo #2', () => { john.setData( '
Foo
[]
Bar
' ); kate.setData( '
[]Foo
Bar
' ); john.merge(); kate.unwrap(); kate.undo(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( '
Foo
Bar' ); expectClients( '
FooBar
' ); } ); it( 'unwrap in merged element', () => { // 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' + 'C' + '
' + '
' ); kate.setData( '' + 'A' + '' + '' + '
' + '[]B' + 'C' + '
' + '
' ); john.merge(); kate.unwrap(); syncClients(); expectClients( '' + 'A' + 'B' + 'C' + '' ); } ); } ); describe( 'by split', () => { it( 'merge element which got split (the element is in blockquote) and undo', () => { john.setData( 'Foo
[]Bar
' ); kate.setData( 'Foo
B[]ar
' ); john._processExecute( 'delete' ); kate.split(); syncClients(); expectClients( 'FooBar' ); john.undo(); syncClients(); expectClients( 'Foo
Bar
' ); } ); } ); } ); } );