import { Client, syncClients, expectClients } 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( () => {
return Promise.all( [ john.destroy(), kate.destroy() ] );
} );
describe( 'wrap', () => {
describe( 'by wrap', () => {
it( 'element in different path', () => {
john.setData( '[Foo]Bar' );
kate.setData( 'Foo[Bar]' );
john.wrap( 'blockQuote' );
kate.wrap( 'blockQuote2' );
syncClients();
expectClients(
'
Foo
' +
'Bar'
);
} );
it( 'the same element', () => {
john.setData( '[Foo]' );
kate.setData( '[Foo]' );
john.wrap( 'blockQuote' );
kate.wrap( 'blockQuote2' );
syncClients();
expectClients( 'Foo
' );
} );
it( 'intersecting wrap #1', () => {
john.setData( '[FooBar]Abc' );
kate.setData( 'Foo[BarAbc]' );
john.wrap( 'blockQuote' );
kate.wrap( 'div' );
syncClients();
expectClients(
'' +
'Foo' +
'Bar' +
'
' +
''
);
} );
it( 'intersecting wrap #2', () => {
john.setData( '[FooBarAbc]' );
kate.setData( 'Foo[Bar]Abc' );
john.wrap( 'blockQuote' );
kate.wrap( 'div' );
syncClients();
expectClients(
'' +
'Foo' +
'Bar' +
'Abc' +
'
'
);
} );
it( 'intersecting wrap, then undo #1', () => {
john.setData( '[FooBar]Abc' );
kate.setData( 'Foo[BarAbc]' );
john.wrap( 'blockQuote' );
kate.wrap( 'div' );
syncClients();
expectClients(
'' +
'Foo' +
'Bar' +
'
' +
''
);
john.undo();
kate.undo();
syncClients();
expectClients(
'Foo' +
'Bar' +
'Abc'
);
} );
it( 'intersecting wrap, then undo #2', () => {
john.setData( '[FooBar]Abc' );
kate.setData( 'Foo[BarAbc]' );
john.wrap( 'blockQuote' );
kate.wrap( 'div' );
syncClients();
expectClients(
'' +
'Foo' +
'Bar' +
'
' +
''
);
john.undo();
kate.undo();
syncClients();
expectClients( 'FooBarAbc' );
} );
it( 'element and text', () => {
john.setData( '[Foo]' );
kate.setData( '[Foo]' );
john.wrap( 'blockQuote' );
kate.wrap( 'div' );
syncClients();
expectClients( 'Foo
' );
} );
} );
describe( 'by unwrap', () => {
it( 'element in different path', () => {
john.setData( '[Foo]Bar
' );
kate.setData( 'Foo[Bar]
' );
john.wrap( 'blockQuote' );
kate.unwrap();
syncClients();
expectClients(
'Foo
' +
'Bar'
);
} );
it( 'the same element', () => {
john.setData( '[Foo]
' );
kate.setData( '[Foo]
' );
john.wrap( 'blockQuote2' );
kate.unwrap();
syncClients();
expectClients( 'Foo' );
} );
it( 'the same element, then undo', () => {
john.setData( '[Foo]
' );
kate.setData( '[Foo]
' );
john.wrap( 'blockQuote2' );
kate.unwrap();
syncClients();
kate.undo();
syncClients();
expectClients( 'Foo
' );
} );
} );
describe( 'by delete', () => {
it( 'text in two elements', () => {
john.setData( '[Foo]Bar' );
kate.setData( 'Fo[oBa]r' );
john.wrap( 'blockQuote' );
kate.delete();
syncClients();
expectClients(
'' +
'For' +
'
'
);
} );
} );
describe( 'by remove', () => {
it( 'remove the only wrapped element', () => {
john.setData( '[Foo]Bar' );
kate.setData( '[Foo]Bar' );
john.wrap( 'blockQuote' );
kate.remove();
syncClients();
expectClients( 'Bar' );
} );
it( 'remove one of two wrapped elements', () => {
john.setData( '[FooBar]' );
kate.setData( '[Foo]Bar' );
john.wrap( 'blockQuote' );
kate.remove();
syncClients();
expectClients( 'Bar
' );
} );
it( 'remove all wrapped elements', () => {
john.setData( '[FooBar]Xyz' );
kate.setData( '[Foo]BarXyz' );
john.wrap( 'blockQuote' );
kate.remove();
kate.setSelection( [ 0 ], [ 1 ] );
kate.remove();
syncClients();
expectClients( 'Xyz' );
} );
it( 'remove the only wrapped element with undo', () => {
john.setData( '[Foo]Bar' );
kate.setData( '[Foo]Bar' );
john.wrap( 'blockQuote' );
kate.remove();
syncClients();
expectClients( 'Bar' );
john.undo();
kate.undo();
syncClients();
expectClients( 'FooBar' );
} );
it( 'remove one of two wrapped elements with undo', () => {
john.setData( '[FooBar]' );
kate.setData( '[Foo]Bar' );
john.wrap( 'blockQuote' );
kate.remove();
syncClients();
expectClients( 'Bar
' );
john.undo();
kate.undo();
syncClients();
expectClients( 'FooBar' );
} );
it( 'remove all wrapped elements with undo', () => {
john.setData( '[FooBar]Xyz' );
kate.setData( '[Foo]BarXyz' );
john.wrap( 'blockQuote' );
kate.remove();
kate.setSelection( [ 0 ], [ 1 ] );
kate.remove();
syncClients();
expectClients( 'Xyz' );
john.undo();
kate.undo();
kate.undo();
syncClients();
expectClients( 'FooBarXyz' );
} );
} );
describe( 'by merge', () => {
it( 'element into paragraph #1', () => {
john.setData( '[Foo]Bar' );
kate.setData( 'Foo[]Bar' );
john.wrap( 'blockQuote' );
kate.merge();
syncClients();
expectClients( 'FooBar
' );
} );
it( 'element into paragraph #2', () => {
john.setData( '[Foo]Bar' );
kate.setData( 'Foo[]Bar' );
john.wrap( 'div' );
kate.merge();
syncClients();
john.undo();
kate.undo();
syncClients();
expectClients( 'FooBar' );
} );
it( 'element into paragraph, then undo', () => {
john.setData( 'Foo[Bar]' );
kate.setData( 'Foo[]Bar' );
john.wrap( 'blockQuote' );
kate.merge();
syncClients();
expectClients( 'FooBar' );
john.undo();
kate.undo();
syncClients();
expectClients( 'FooBar' );
} );
} );
} );
} );