| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552 |
- /**
- * @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( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
- kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
- john.wrap( 'blockQuote' );
- kate.wrap( 'div' );
- syncClients();
- expectClients(
- '<blockQuote><paragraph>Foo</paragraph></blockQuote>' +
- '<div><paragraph>Bar</paragraph></div>'
- );
- } );
- it( 'the same element', () => {
- john.setData( '[<paragraph>Foo</paragraph>]' );
- kate.setData( '[<paragraph>Foo</paragraph>]' );
- john.wrap( 'blockQuote' );
- kate.wrap( 'div' );
- syncClients();
- // Below would be the expected effect with correct wrap transformation.
- // expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote>' );
- expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote><div></div>' );
- } );
- it( 'intersecting wrap #1', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]<paragraph>Xyz</paragraph>' );
- kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph><paragraph>Xyz</paragraph>]' );
- john.wrap( 'blockQuote' );
- kate.wrap( 'div' );
- syncClients();
- // Below would be the expected effect with correct wrap transformation.
- // expectClients(
- // '<blockQuote>' +
- // '<paragraph>Foo</paragraph>' +
- // '<paragraph>Bar</paragraph>' +
- // '</blockQuote>' +
- // '<div>' +
- // '<paragraph>Xyz</paragraph>' +
- // '</div>'
- // );
- expectClients(
- '<blockQuote><paragraph>Foo</paragraph><div><paragraph>Xyz</paragraph></div><paragraph>Bar</paragraph></blockQuote>'
- );
- } );
- it( 'intersecting wrap #2', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph><paragraph>Abc</paragraph>]' );
- kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]<paragraph>Abc</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.wrap( 'div' );
- syncClients();
- // Below would be the expected effect with correct wrap transformation.
- // expectClients(
- // '<blockQuote>' +
- // '<paragraph>Foo</paragraph>' +
- // '<paragraph>Bar</paragraph>' +
- // '<paragraph>Abc</paragraph>' +
- // '</blockQuote>'
- // );
- expectClients(
- '<blockQuote><paragraph>Foo</paragraph><div><paragraph>Bar</paragraph></div><paragraph>Abc</paragraph></blockQuote>'
- );
- } );
- it( 'intersecting wrap #3', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]<paragraph>Abc</paragraph>' );
- kate.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph><paragraph>Abc</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.wrap( 'div' );
- syncClients();
- // Below would be the expected effect with correct wrap transformation.
- // expectClients(
- // '<blockQuote>' +
- // '<paragraph>Foo</paragraph>' +
- // '<paragraph>Bar</paragraph>' +
- // '</blockQuote>' +
- // '<paragraph>Abc</paragraph>'
- // );
- expectClients(
- '<blockQuote><paragraph>Foo</paragraph><paragraph>Bar</paragraph></blockQuote><div></div><paragraph>Abc</paragraph>'
- );
- } );
- it( 'intersecting wrap, then undo #1', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]<paragraph>Abc</paragraph>' );
- kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph><paragraph>Abc</paragraph>]' );
- john.wrap( 'blockQuote' );
- kate.wrap( 'div' );
- syncClients();
- // Below would be the expected effect with correct wrap transformation.
- // expectClients(
- // '<blockQuote>' +
- // '<paragraph>Foo</paragraph>' +
- // '<paragraph>Bar</paragraph>' +
- // '</blockQuote>' +
- // '<div>' +
- // '<paragraph>Abc</paragraph>' +
- // '</div>'
- // );
- expectClients(
- '<blockQuote><paragraph>Foo</paragraph><div><paragraph>Abc</paragraph></div><paragraph>Bar</paragraph></blockQuote>'
- );
- john.undo();
- kate.undo();
- syncClients();
- // Below would be the expected effect with correct wrap transformation.
- // expectClients(
- // '<paragraph>Foo</paragraph>' +
- // '<paragraph>Bar</paragraph>' +
- // '<paragraph>Abc</paragraph>'
- // );
- expectClients( '<paragraph>Abc</paragraph><paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
- } );
- it( 'intersecting wrap, then undo #2', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]<paragraph>Abc</paragraph>' );
- kate.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph><paragraph>Abc</paragraph>]' );
- john.wrap( 'blockQuote' );
- kate.wrap( 'div' );
- syncClients();
- // Below would be the expected effect with correct wrap transformation.
- // expectClients(
- // '<blockQuote>' +
- // '<paragraph>Foo</paragraph>' +
- // '<paragraph>Bar</paragraph>' +
- // '</blockQuote>' +
- // '<div>' +
- // '<paragraph>Abc</paragraph>' +
- // '</div>'
- // );
- expectClients(
- '<blockQuote><paragraph>Foo</paragraph><div><paragraph>Abc</paragraph></div><paragraph>Bar</paragraph></blockQuote>'
- );
- john.undo();
- kate.undo();
- syncClients();
- // Below would be the expected effect with correct wrap transformation.
- // expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph><paragraph>Abc</paragraph>' );
- expectClients( '<paragraph>Abc</paragraph><paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
- } );
- it( 'intersecting wrap, then undo #3', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]<paragraph>Abc</paragraph>' );
- kate.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph><paragraph>Abc</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.wrap( 'div' );
- syncClients();
- john.undo();
- kate.undo();
- syncClients();
- expectClients(
- '<paragraph>Foo</paragraph>' +
- '<paragraph>Bar</paragraph>' +
- '<paragraph>Abc</paragraph>'
- );
- } );
- it( 'element and text', () => {
- john.setData( '[<paragraph>Foo</paragraph>]' );
- kate.setData( '<paragraph>[Foo]</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.wrap( 'div' );
- syncClients();
- expectClients( '<blockQuote><paragraph><div>Foo</div></paragraph></blockQuote>' );
- } );
- } );
- describe( 'by unwrap', () => {
- it( 'element in different path', () => {
- john.setData( '[<paragraph>Foo</paragraph>]<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
- kate.setData( '<paragraph>Foo</paragraph><blockQuote>[<paragraph>Bar</paragraph>]</blockQuote>' );
- john.wrap( 'blockQuote' );
- kate.unwrap();
- syncClients();
- expectClients(
- '<blockQuote><paragraph>Foo</paragraph></blockQuote>' +
- '<paragraph>Bar</paragraph>'
- );
- } );
- it( 'text in different path', () => {
- john.setData( '<paragraph>[Foo]</paragraph><blockQuote><paragraph>Bar</paragraph></blockQuote>' );
- kate.setData( '<paragraph>Foo</paragraph><blockQuote><paragraph>[]Bar</paragraph></blockQuote>' );
- john.wrap( 'div' );
- kate.unwrap();
- syncClients();
- expectClients(
- '<paragraph><div>Foo</div></paragraph>' +
- '<blockQuote>Bar</blockQuote>'
- );
- } );
- it( 'the same element through undo', () => {
- john.setData( '[<paragraph>Foo</paragraph>]' );
- kate.setData( '<paragraph>[]Foo</paragraph>' );
- john.wrap( 'blockQuote' );
- syncClients();
- expectClients( '<blockQuote><paragraph>Foo</paragraph></blockQuote>' );
- kate.setSelection( [ 0, 0 ] );
- kate.unwrap();
- syncClients();
- expectClients( '<paragraph>Foo</paragraph>' );
- john.undo();
- kate.undo();
- syncClients();
- expectClients( '<paragraph>Foo</paragraph>' );
- } );
- it( 'wrap in unwrapped element', () => {
- john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
- kate.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' );
- john.wrap( 'div' );
- kate.unwrap();
- syncClients();
- // Below would be the expected effect with correct wrap transformation.
- // expectClients( '<div><paragraph>Foo</paragraph></div>' );
- expectClients( '<paragraph></paragraph>' );
- } );
- it.skip( 'wrap in unwrapped element, 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
- // <bq><div><p> structure for a while. So it should be possible to revert to it.
- john.setData( '<blockQuote>[<paragraph>Foo</paragraph>]</blockQuote>' );
- kate.setData( '<blockQuote>[]<paragraph>Foo</paragraph></blockQuote>' );
- john.wrap( 'div' );
- kate.unwrap();
- syncClients();
- expectClients( '<div><paragraph>Foo</paragraph></div>' );
- kate.undo();
- syncClients();
- expectClients( '<blockQuote><div><paragraph>Foo</paragraph></div></blockQuote>' );
- } );
- 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
- // <bq><p><div> structure for a while. So it should be possible to revert to it.
- john.setData( '<blockQuote><paragraph>[Foo]</paragraph></blockQuote>' );
- kate.setData( '<blockQuote><paragraph>[]Foo</paragraph></blockQuote>' );
- john.wrap( 'div' );
- kate.unwrap();
- syncClients();
- expectClients( '<blockQuote><div>Foo</div></blockQuote>' );
- kate.undo();
- syncClients();
- expectClients( '<blockQuote><paragraph><div>Foo</div></paragraph></blockQuote>' );
- } );
- } );
- describe( 'by delete', () => {
- it( 'text in two elements #1', () => {
- john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
- kate.setData( '<paragraph>Fo[o</paragraph><paragraph>Ba]r</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.delete();
- syncClients();
- expectClients(
- '<blockQuote>' +
- '<paragraph>For</paragraph>' +
- '</blockQuote>'
- );
- } );
- it( 'text in two elements #2', () => {
- john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
- kate.setData( '<paragraph>Fo[o</paragraph><paragraph>Ba]r</paragraph>' );
- john.wrap( 'div' );
- kate.delete();
- syncClients();
- expectClients( '<paragraph><div>Fo</div>r</paragraph>' );
- } );
- it( 'delete all wrapped content', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph><paragraph>Abc</paragraph>]' );
- kate.setData( '<paragraph>[Foo</paragraph><paragraph>Bar</paragraph><paragraph>Ab]c</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.delete();
- syncClients();
- expectClients( '<blockQuote><paragraph>c</paragraph></blockQuote>' );
- } );
- it( 'delete all wrapped content and undo', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph><paragraph>Abc</paragraph>]' );
- kate.setData( '<paragraph>[Foo</paragraph><paragraph>Bar</paragraph><paragraph>Ab]c</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.delete();
- syncClients();
- expectClients( '<blockQuote><paragraph>c</paragraph></blockQuote>' );
- john.undo();
- // There is a bug in undo for Kate.
- // Kate's content is: '<blockQuote><paragraph>c</paragraph></blockQuote>'.
- // 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( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph><paragraph>Abc</paragraph>' );
- } );
- } );
- describe( 'by remove', () => {
- it( 'remove the only wrapped element', () => {
- john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
- kate.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.remove();
- syncClients();
- expectClients( '<paragraph>Bar</paragraph>' );
- } );
- it( 'remove one of two wrapped elements', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]' );
- kate.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.remove();
- syncClients();
- expectClients( '<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
- } );
- it( 'remove all wrapped elements', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]<paragraph>Xyz</paragraph>' );
- kate.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph><paragraph>Xyz</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.remove();
- kate.setSelection( [ 0 ], [ 1 ] );
- kate.remove();
- syncClients();
- expectClients( '<paragraph>Xyz</paragraph>' );
- } );
- it( 'remove the only wrapped element with undo', () => {
- john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
- kate.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.remove();
- syncClients();
- expectClients( '<paragraph>Bar</paragraph>' );
- john.undo();
- kate.undo();
- syncClients();
- expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
- } );
- it( 'remove one of two wrapped elements with undo', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]' );
- kate.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.remove();
- syncClients();
- expectClients( '<blockQuote><paragraph>Bar</paragraph></blockQuote>' );
- john.undo();
- kate.undo();
- syncClients();
- expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
- } );
- it( 'remove all wrapped elements with undo', () => {
- john.setData( '[<paragraph>Foo</paragraph><paragraph>Bar</paragraph>]<paragraph>Xyz</paragraph>' );
- kate.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph><paragraph>Xyz</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.remove();
- kate.setSelection( [ 0 ], [ 1 ] );
- kate.remove();
- syncClients();
- expectClients( '<paragraph>Xyz</paragraph>' );
- john.undo();
- kate.undo();
- kate.undo();
- syncClients();
- expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph><paragraph>Xyz</paragraph>' );
- } );
- } );
- describe( 'by merge', () => {
- it( 'element into paragraph #1', () => {
- john.setData( '[<paragraph>Foo</paragraph>]<paragraph>Bar</paragraph>' );
- kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.merge();
- syncClients();
- expectClients( '<blockQuote><paragraph>FooBar</paragraph></blockQuote>' );
- } );
- it( 'element into paragraph #2', () => {
- john.setData( '<paragraph>[Foo]</paragraph><paragraph>Bar</paragraph>' );
- kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
- john.wrap( 'div' );
- kate.merge();
- syncClients();
- john.undo();
- kate.undo();
- syncClients();
- expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
- } );
- it( 'element into paragraph, then undo', () => {
- john.setData( '<paragraph>Foo</paragraph>[<paragraph>Bar</paragraph>]' );
- kate.setData( '<paragraph>Foo</paragraph>[]<paragraph>Bar</paragraph>' );
- john.wrap( 'blockQuote' );
- kate.merge();
- syncClients();
- expectClients( '<paragraph>FooBar</paragraph>' );
- john.undo();
- kate.undo();
- syncClients();
- expectClients( '<paragraph>Foo</paragraph><paragraph>Bar</paragraph>' );
- } );
- } );
- } );
- } );
|