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' + '
' + '
' + 'Abc' + '
' ); } ); 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' + '
' + '
' + 'Abc' + '
' ); 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' + '
' + '
' + 'Abc' + '
' ); 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 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.skip( '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' ); } ); } ); } ); } );