|
|
@@ -271,14 +271,21 @@ describe( 'MutationObserver', () => {
|
|
|
|
|
|
// https://github.com/ckeditor/ckeditor5/issues/692 Scenario 1.
|
|
|
it( 'should handle space after inline filler at the end of container', () => {
|
|
|
- const { view, selection } = parse( '<container:p>foo<attribute:b>[]</attribute:b></container:p>' );
|
|
|
+ const { view, selection } = parse(
|
|
|
+ '<container:p>' +
|
|
|
+ 'foo' +
|
|
|
+ '<attribute:b>[]</attribute:b>' +
|
|
|
+ '</container:p>'
|
|
|
+ );
|
|
|
|
|
|
viewRoot.appendChildren( view );
|
|
|
viewDocument.selection.setTo( selection );
|
|
|
|
|
|
viewDocument.render();
|
|
|
|
|
|
- const inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 1 ].childNodes[ 0 ];
|
|
|
+ // Appended container is third in the tree.
|
|
|
+ const container = domEditor.childNodes[ 2 ];
|
|
|
+ const inlineFiller = container.childNodes[ 1 ].childNodes[ 0 ];
|
|
|
|
|
|
inlineFiller.data += ' ';
|
|
|
|
|
|
@@ -286,19 +293,31 @@ describe( 'MutationObserver', () => {
|
|
|
|
|
|
expect( lastMutations.length ).to.equal( 1 );
|
|
|
expect( lastMutations[ 0 ].type ).to.equal( 'children' );
|
|
|
+ expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 0 );
|
|
|
+ expect( lastMutations[ 0 ].newChildren.length ).to.equal( 1 );
|
|
|
+ expect( lastMutations[ 0 ].newChildren[ 0 ].is( 'text' ) ).to.be.true;
|
|
|
+ expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( ' ' );
|
|
|
expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent );
|
|
|
} );
|
|
|
|
|
|
// https://github.com/ckeditor/ckeditor5/issues/692 Scenario 3.
|
|
|
it( 'should handle space after inline filler at the end of container #2', () => {
|
|
|
- const { view, selection } = parse( '<container:p>foo<attribute:b>bar</attribute:b>[]</container:p>' );
|
|
|
+ const { view, selection } = parse(
|
|
|
+ '<container:p>' +
|
|
|
+ 'foo' +
|
|
|
+ '<attribute:b>bar</attribute:b>' +
|
|
|
+ '[]' +
|
|
|
+ '</container:p>'
|
|
|
+ );
|
|
|
|
|
|
viewRoot.appendChildren( view );
|
|
|
viewDocument.selection.setTo( selection );
|
|
|
|
|
|
viewDocument.render();
|
|
|
|
|
|
- const inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 2 ];
|
|
|
+ // Appended container is third in the tree.
|
|
|
+ const container = domEditor.childNodes[ 2 ];
|
|
|
+ const inlineFiller = container.childNodes[ 2 ];
|
|
|
|
|
|
inlineFiller.data += ' ';
|
|
|
|
|
|
@@ -306,19 +325,42 @@ describe( 'MutationObserver', () => {
|
|
|
|
|
|
expect( lastMutations.length ).to.equal( 1 );
|
|
|
expect( lastMutations[ 0 ].type ).to.equal( 'children' );
|
|
|
+ expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 2 );
|
|
|
+ expect( lastMutations[ 0 ].newChildren.length ).to.equal( 3 );
|
|
|
+
|
|
|
+ // Foo and attribute is removed and reinserted.
|
|
|
+ expect( lastMutations[ 0 ].oldChildren[ 0 ].is( 'text' ) ).to.be.true;
|
|
|
+ expect( lastMutations[ 0 ].oldChildren[ 0 ].data ).to.equal( 'foo' );
|
|
|
+ expect( lastMutations[ 0 ].newChildren[ 0 ].is( 'text' ) ).to.be.true;
|
|
|
+ expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( 'foo' );
|
|
|
+
|
|
|
+ expect( lastMutations[ 0 ].oldChildren[ 1 ].is( 'attributeElement' ) ).to.be.true;
|
|
|
+ expect( lastMutations[ 0 ].oldChildren[ 1 ].name ).to.equal( 'b' );
|
|
|
+ expect( lastMutations[ 0 ].newChildren[ 1 ].is( 'attributeElement' ) ).to.be.true;
|
|
|
+ expect( lastMutations[ 0 ].newChildren[ 1 ].name ).to.equal( 'b' );
|
|
|
+
|
|
|
+ expect( lastMutations[ 0 ].newChildren[ 2 ].is( 'text' ) ).to.be.true;
|
|
|
+ expect( lastMutations[ 0 ].newChildren[ 2 ].data ).to.equal( ' ' );
|
|
|
expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent );
|
|
|
} );
|
|
|
|
|
|
// https://github.com/ckeditor/ckeditor5/issues/692 Scenario 2.
|
|
|
it( 'should handle space after inline filler at the beginning of container', () => {
|
|
|
- const { view, selection } = parse( '<container:p><attribute:b>[]</attribute:b>foo</container:p>' );
|
|
|
+ const { view, selection } = parse(
|
|
|
+ '<container:p>' +
|
|
|
+ '<attribute:b>[]</attribute:b>' +
|
|
|
+ 'foo' +
|
|
|
+ '</container:p>'
|
|
|
+ );
|
|
|
|
|
|
viewRoot.appendChildren( view );
|
|
|
viewDocument.selection.setTo( selection );
|
|
|
|
|
|
viewDocument.render();
|
|
|
|
|
|
- const inlineFiller = domEditor.childNodes[ 2 ].childNodes[ 0 ].childNodes[ 0 ];
|
|
|
+ // Appended container is third in the tree.
|
|
|
+ const container = domEditor.childNodes[ 2 ];
|
|
|
+ const inlineFiller = container.childNodes[ 0 ].childNodes[ 0 ];
|
|
|
|
|
|
inlineFiller.data += ' ';
|
|
|
|
|
|
@@ -326,6 +368,10 @@ describe( 'MutationObserver', () => {
|
|
|
|
|
|
expect( lastMutations.length ).to.equal( 1 );
|
|
|
expect( lastMutations[ 0 ].type ).to.equal( 'children' );
|
|
|
+ expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 0 );
|
|
|
+ expect( lastMutations[ 0 ].newChildren.length ).to.equal( 1 );
|
|
|
+ expect( lastMutations[ 0 ].newChildren[ 0 ].is( 'text' ) ).to.be.true;
|
|
|
+ expect( lastMutations[ 0 ].newChildren[ 0 ].data ).to.equal( ' ' );
|
|
|
expect( lastMutations[ 0 ].node ).to.equal( selection.getFirstPosition().parent );
|
|
|
} );
|
|
|
|