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( 'unwrap', () => { describe( 'by unwrap', () => { it( 'element in different path', () => { john.setData( '
[Foo]
' + '
Bar
' ); kate.setData( '
Foo
' + '
[Bar]
' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( 'Foo' + 'Bar' ); } ); it( 'text in different path', () => { john.setData( '
[Foo]
' + '
Bar
' ); kate.setData( '
Foo
' + '
[Bar]
' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( '
Foo
' + '
Bar
' ); } ); it( 'the same element', () => { john.setData( '
[Foo]
' ); kate.setData( '
[Foo]
' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( 'Foo' ); } ); it.skip( 'the same element, then undo', () => { john.setData( '
[]Foo
' ); kate.setData( '
[]Foo
' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( 'Foo' ); john.undo(); syncClients(); // Actual content for Kate: // Foo // Kate has a different order of nodes in graveyard after syncing. expectClients( '
Foo
' ); } ); it( 'the same text', () => { john.setData( '
[Foo]
' ); kate.setData( '
[Foo]
' ); john.unwrap(); kate.unwrap(); syncClients(); expectClients( '
Foo
' ); } ); it( 'the same text, then undo', () => { john.setData( '
[Foo]
' ); kate.setData( '
[Foo]
' ); john.unwrap(); kate.unwrap(); syncClients(); john.undo(); syncClients(); expectClients( '
Foo
' ); } ); } ); describe( 'by delete', () => { it( 'text from two elements #1', () => { john.setData( '
[Foo]
Bar' ); kate.setData( '
Fo[o
Ba]r' ); john.unwrap(); kate.delete(); syncClients(); expectClients( 'For' ); } ); it( 'text in same path', () => { john.setData( '
[Foo]
' ); kate.setData( '
F[oo]
' ); john.unwrap(); kate.delete(); syncClients(); expectClients( 'F' ); } ); } ); describe( 'by merge', () => { it( 'element into paragraph #1', () => { john.setData( '
[Foo]Bar
' ); kate.setData( '
Foo[]Bar
' ); john.unwrap(); kate.merge(); syncClients(); expectClients( 'FooBar' ); } ); it( 'element into paragraph #2', () => { john.setData( '
[FooBar]
' ); kate.setData( '
Foo[]Bar
' ); john.unwrap(); kate.merge(); syncClients(); expectClients( 'FooBar' ); } ); it( 'unwrapped element', () => { john.setData( 'Foo
[Bar]
' ); kate.setData( 'Foo[]
Bar
' ); john.unwrap(); kate.merge(); syncClients(); expectClients( 'Foo' + 'Bar' ); } ); } ); } ); } );