|
|
@@ -30,7 +30,7 @@ describe( 'Delete utils', () => {
|
|
|
it( 'returns empty fragment for no selection', () => {
|
|
|
setData( doc, 'abc' );
|
|
|
|
|
|
- const frag = getSelectedContent( doc.selection );
|
|
|
+ const frag = getSelectedContent( doc.selection, doc.batch() );
|
|
|
|
|
|
expect( frag ).instanceOf( DocumentFragment );
|
|
|
expect( frag.isEmpty ).to.be.true;
|
|
|
@@ -39,7 +39,7 @@ describe( 'Delete utils', () => {
|
|
|
it( 'returns empty fragment for empty selection', () => {
|
|
|
setData( doc, 'a[]bc' );
|
|
|
|
|
|
- const frag = getSelectedContent( doc.selection );
|
|
|
+ const frag = getSelectedContent( doc.selection, doc.batch() );
|
|
|
|
|
|
expect( frag ).instanceOf( DocumentFragment );
|
|
|
expect( frag.isEmpty ).to.be.true;
|
|
|
@@ -48,7 +48,7 @@ describe( 'Delete utils', () => {
|
|
|
it( 'gets one character', () => {
|
|
|
setData( doc, 'a[b]c' );
|
|
|
|
|
|
- const frag = getSelectedContent( doc.selection );
|
|
|
+ const frag = getSelectedContent( doc.selection, doc.batch() );
|
|
|
const content = stringify( frag );
|
|
|
|
|
|
expect( frag ).instanceOf( DocumentFragment );
|
|
|
@@ -58,49 +58,49 @@ describe( 'Delete utils', () => {
|
|
|
it( 'gets full text', () => {
|
|
|
setData( doc, '[abc]' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( 'abc' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets text with an attribute', () => {
|
|
|
setData( doc, 'xxx<$text bold="true">a[b]c</$text>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<$text bold="true">b</$text>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets text with attributes', () => {
|
|
|
setData( doc, 'x<$text bold="true">a[b</$text><$text italic="true">c]d</$text>x' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<$text bold="true">b</$text><$text italic="true">c</$text>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets text with and without attribute', () => {
|
|
|
setData( doc, '<$text bold="true">a[b</$text>c]d' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<$text bold="true">b</$text>c' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets text and element', () => {
|
|
|
setData( doc, '[ab<image></image>c]' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( 'ab<image></image>c' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets one element', () => {
|
|
|
setData( doc, 'a[<image></image>]b' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<image></image>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets multiple elements', () => {
|
|
|
setData( doc, '[<image></image><image></image>]' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<image></image><image></image>' );
|
|
|
} );
|
|
|
} );
|
|
|
@@ -128,63 +128,63 @@ describe( 'Delete utils', () => {
|
|
|
it( 'gets one character', () => {
|
|
|
setData( doc, '<paragraph>a[b]c</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( 'b' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets entire paragraph content', () => {
|
|
|
setData( doc, '<paragraph>[a<image></image>b]</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( 'a<image></image>b' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets two blocks - partial, partial', () => {
|
|
|
setData( doc, '<heading1>a[bc</heading1><paragraph>de]f</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<heading1>bc</heading1><paragraph>de</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets two blocks - full, partial', () => {
|
|
|
setData( doc, '<heading1>[abc</heading1><paragraph>de]f</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<heading1>abc</heading1><paragraph>de</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets two blocks - full, partial 2', () => {
|
|
|
setData( doc, '<heading1>[abc</heading1><paragraph>de<image></image>]f</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<heading1>abc</heading1><paragraph>de<image></image></paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets two blocks - full, partial 3', () => {
|
|
|
setData( doc, '<heading1>x</heading1><heading1>[abc</heading1><paragraph><image></image>de]f</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<heading1>abc</heading1><paragraph><image></image>de</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets two blocks - full, partial 4', () => {
|
|
|
setData( doc, '<heading1>[abc</heading1><paragraph>de]f<image></image></paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<heading1>abc</heading1><paragraph>de</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets two blocks - partial, full', () => {
|
|
|
setData( doc, '<heading1>a[bc</heading1><paragraph>def]</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<heading1>bc</heading1><paragraph>def</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets two blocks - partial, full 2', () => {
|
|
|
setData( doc, '<heading1>a[<image></image>bc</heading1><paragraph>def]</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<heading1><image></image>bc</heading1><paragraph>def</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
@@ -192,7 +192,7 @@ describe( 'Delete utils', () => {
|
|
|
it( 'gets two blocks - empty, full', () => {
|
|
|
setData( doc, '<heading1>abc[</heading1><paragraph>def]</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<paragraph>def</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
@@ -200,28 +200,28 @@ describe( 'Delete utils', () => {
|
|
|
it( 'gets two blocks - partial, empty', () => {
|
|
|
setData( doc, '<heading1>a[bc</heading1><paragraph>]def</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<heading1>bc</heading1>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets three blocks', () => {
|
|
|
setData( doc, '<heading1>a[bc</heading1><paragraph>x</paragraph><paragraph>de]f</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<heading1>bc</heading1><paragraph>x</paragraph><paragraph>de</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets block image', () => {
|
|
|
setData( doc, '<paragraph>a</paragraph>[<blockImage><caption>Foo</caption></blockImage>]<paragraph>b</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<blockImage><caption>Foo</caption></blockImage>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets two blocks', () => {
|
|
|
setData( doc, '<paragraph>a</paragraph>[<blockImage></blockImage><blockImage></blockImage>]<paragraph>b</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<blockImage></blockImage><blockImage></blockImage>' );
|
|
|
} );
|
|
|
|
|
|
@@ -229,7 +229,7 @@ describe( 'Delete utils', () => {
|
|
|
it( 'gets content when multiple text items needs to be removed from the right excess', () => {
|
|
|
setData( doc, '<paragraph>a[b</paragraph><paragraph>c]d<$text bold="true">e</$text>f</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content )
|
|
|
.to.equal( '<paragraph>b</paragraph><paragraph>c</paragraph>' );
|
|
|
} );
|
|
|
@@ -238,7 +238,7 @@ describe( 'Delete utils', () => {
|
|
|
it( 'gets content when multiple text items needs to be removed from the left excess', () => {
|
|
|
setData( doc, '<paragraph>a<$text bold="true">b</$text>c[d</paragraph><paragraph>e]f</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content )
|
|
|
.to.equal( '<paragraph>d</paragraph><paragraph>e</paragraph>' );
|
|
|
} );
|
|
|
@@ -262,28 +262,28 @@ describe( 'Delete utils', () => {
|
|
|
it( 'gets content when ends are equally deeply nested', () => {
|
|
|
setData( doc, '<heading1>x</heading1><quote><paragraph>a[bc</paragraph><paragraph>de]f</paragraph></quote>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<paragraph>bc</paragraph><paragraph>de</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets content when left end nested deeper', () => {
|
|
|
setData( doc, '<quote><paragraph>a[bc</paragraph></quote><paragraph>de]f</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<quote><paragraph>bc</paragraph></quote><paragraph>de</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets content when left end nested deeper 2', () => {
|
|
|
setData( doc, '<quote><paragraph>a[bc</paragraph><heading1>x</heading1></quote><paragraph>de]f</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<quote><paragraph>bc</paragraph><heading1>x</heading1></quote><paragraph>de</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets content when left end nested deeper 3', () => {
|
|
|
setData( doc, '<quote><heading1>x</heading1><paragraph>a[bc</paragraph></quote><paragraph>de]f</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<quote><paragraph>bc</paragraph></quote><paragraph>de</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
@@ -291,21 +291,21 @@ describe( 'Delete utils', () => {
|
|
|
it( 'gets content when left end nested deeper 4', () => {
|
|
|
setData( doc, '<quote><heading1>x[</heading1><paragraph>abc</paragraph></quote><paragraph>de]f</paragraph>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<quote><paragraph>abc</paragraph></quote><paragraph>de</paragraph>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets content when right end nested deeper', () => {
|
|
|
setData( doc, '<paragraph>a[bc</paragraph><quote><paragraph>de]f</paragraph></quote>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content ).to.equal( '<paragraph>bc</paragraph><quote><paragraph>de</paragraph></quote>' );
|
|
|
} );
|
|
|
|
|
|
it( 'gets content when both ends nested deeper than the middle element', () => {
|
|
|
setData( doc, '<quote><heading1>a[bc</heading1></quote><heading1>x</heading1><quote><heading1>de]f</heading1></quote>' );
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content )
|
|
|
.to.equal( '<quote><heading1>bc</heading1></quote><heading1>x</heading1><quote><heading1>de</heading1></quote>' );
|
|
|
} );
|
|
|
@@ -325,7 +325,7 @@ describe( 'Delete utils', () => {
|
|
|
'</quote>'
|
|
|
);
|
|
|
|
|
|
- const content = stringify( getSelectedContent( doc.selection ) );
|
|
|
+ const content = stringify( getSelectedContent( doc.selection, doc.batch() ) );
|
|
|
expect( content )
|
|
|
.to.equal( '<paragraph>ar</paragraph>bo' );
|
|
|
} );
|