/**
* @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 ) )
] ).then( () => {
john.editor.model.schema.register( 'div', { inheritAllFrom: 'blockQuote' } );
kate.editor.model.schema.register( 'div', { inheritAllFrom: 'blockQuote' } );
} );
} );
afterEach( () => {
clearBuffer();
return Promise.all( [ john.destroy(), kate.destroy() ] );
} );
describe( 'wrap', () => {
describe( 'by wrap', () => {
it( 'element in different path', () => {
john.setData( '[
' + 'Foo
' ); expectClients( 'Foo
' ); } ); it( 'intersecting wrap #1', () => { john.setData( '[Foo
' + // '' + // 'Foo ' + // 'Bar ' + // '
' ); } ); it( 'intersecting wrap #2', () => { john.setData( '[Foo Xyz Bar
' + // '' // ); expectClients( 'Foo ' + // 'Bar ' + // 'Abc ' + // '
' ); } ); it( 'intersecting wrap #3', () => { john.setData( '[Foo Bar Abc
' + // '' + // 'Foo ' + // 'Bar ' + // '
Foo Bar
' + // '' + // 'Foo ' + // 'Bar ' + // '
' ); john.undo(); kate.undo(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( // 'Foo Abc Bar
' + // '' + // 'Foo ' + // 'Bar ' + // '
' ); john.undo(); kate.undo(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( 'Foo Abc Bar
' ); } ); } ); describe( 'by unwrap', () => { it( 'element in different path', () => { john.setData( '[ Foo
' ); kate.setData( 'Bar
[' ); john.wrap( 'blockQuote' ); kate.unwrap(); syncClients(); expectClients( 'Bar ]
' + 'Foo
' ); kate.setData( 'Bar
' ); john.wrap( 'div' ); kate.unwrap(); syncClients(); expectClients( '[]Bar
Bar' ); } ); it( 'the same element through undo', () => { john.setData( '[
' ); kate.setSelection( [ 0, 0 ] ); kate.unwrap(); syncClients(); expectClients( 'Foo
[' ); kate.setData( 'Foo ]
[]' ); john.wrap( 'div' ); kate.unwrap(); syncClients(); // Below would be the expected effect with correct wrap transformation. // expectClients( 'Foo
structure for a while. So it should be possible to revert to it. john.setData( '
[' ); kate.setData( 'Foo ]
[]' ); john.wrap( 'div' ); kate.unwrap(); syncClients(); expectClients( 'Foo
' ); } ); it.skip( 'the same text, then undo', () => { // This is interesting scenario actually. Normally in wrap x wrap situation the stronger wrap just wins // so we won't get incorrect model. But John was actually to make a wrap like this then he had //Foo
' ); kate.setData( '[Foo]
' ); john.wrap( 'div' ); kate.unwrap(); syncClients(); expectClients( '[]Foo
' ); kate.undo(); syncClients(); expectClients( 'Foo
' ); } ); } ); describe( 'by delete', () => { it( 'text in two elements #1', () => { john.setData( '[ Foo
' + '' ); } ); it( 'text in two elements #2', () => { john.setData( 'For ' + '
' ); } ); it( 'delete all wrapped content and undo', () => { john.setData( '[c
' ); john.undo(); // There is a bug in undo for Kate. // Kate's content is: 'c
'. // Then goes undo and it returns "Foo" paragraph into block quote, but "Bar" goes after it. // There is a move (reinsert) x wrap transformation and the move is not included inside the wrap. kate.undo(); syncClients(); expectClients( 'c
' ); } ); it( 'remove all wrapped elements', () => { john.setData( '[Bar
' ); john.undo(); kate.undo(); syncClients(); expectClients( 'Bar
' ); } ); it( 'element into paragraph #2', () => { john.setData( 'FooBar