8
0
Просмотр исходного кода

Added tests to MutationObserver that checks integration with UIElement.

Szymon Kupś 8 лет назад
Родитель
Сommit
414d66ddcc

+ 2 - 2
packages/ckeditor5-engine/src/view/observer/mutationobserver.js

@@ -149,7 +149,7 @@ export default class MutationObserver extends Observer {
 			if ( mutation.type === 'childList' ) {
 				const element = domConverter.getCorrespondingViewElement( mutation.target );
 
-				// Prevent mutation from UIElements.
+				// Do not collect mutations from UIElements.
 				if ( element && element.is( 'uiElement' ) ) {
 					continue;
 				}
@@ -164,7 +164,7 @@ export default class MutationObserver extends Observer {
 		for ( const mutation of domMutations ) {
 			const element = domConverter.getCorrespondingViewElement( mutation.target );
 
-			// Prevent mutation from UIElements.
+			// Do not collect mutations from UIElements.
 			if ( element && element.is( 'uiElement' ) ) {
 				continue;
 			}

+ 36 - 0
packages/ckeditor5-engine/tests/view/observer/mutationobserver.js

@@ -7,6 +7,7 @@
 
 import ViewDocument from '../../../src/view/document';
 import MutationObserver from '../../../src/view/observer/mutationobserver';
+import UIElement from '../../../src/view/uielement';
 import { parse } from '../../../src/dev-utils/view';
 
 describe( 'MutationObserver', () => {
@@ -346,6 +347,41 @@ describe( 'MutationObserver', () => {
 		expect( lastMutations[ 0 ].oldChildren.length ).to.equal( 1 );
 	} );
 
+	describe( 'UIElement integration', () => {
+		class MyUIElement extends UIElement {
+			render( domDocument ) {
+				const root = super.render( domDocument );
+				root.innerHTML = 'foo bar';
+
+				return root;
+			}
+		}
+
+		beforeEach( () => {
+			const uiElement = new MyUIElement( 'div' );
+			viewRoot.appendChildren( uiElement );
+
+			viewDocument.render();
+		} );
+
+		it( 'should not collect text mutations from UIElement', () => {
+			domEditor.childNodes[ 2 ].childNodes[ 0 ].data = 'foom';
+
+			mutationObserver.flush();
+
+			expect( lastMutations.length ).to.equal( 0 );
+		} );
+
+		it( 'should not collect child mutations from UIElement', () => {
+			const span = document.createElement( 'span' );
+			domEditor.childNodes[ 2 ].appendChild( span );
+
+			mutationObserver.flush();
+
+			expect( lastMutations.length ).to.equal( 0 );
+		} );
+	} );
+
 	function expectDomEditorNotToChange() {
 		expect( domEditor.childNodes.length ).to.equal( 2 );
 		expect( domEditor.childNodes[ 0 ].tagName ).to.equal( 'P' );