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