Преглед на файлове

Fixed failing tests after view changes.

Szymon Kupś преди 7 години
родител
ревизия
c581612a69
променени са 2 файла, в които са добавени 33 реда и са изтрити 35 реда
  1. 3 3
      packages/ckeditor5-link/src/link.js
  2. 30 32
      packages/ckeditor5-link/tests/link.js

+ 3 - 3
packages/ckeditor5-link/src/link.js

@@ -341,7 +341,7 @@ export default class Link extends Plugin {
 
 		const editingView = this.editor.editing.view;
 
-		this.stopListening( editingView, 'render' );
+		this.stopListening( editingView.document, 'change' );
 
 		// Remove form first because it's on top of the stack.
 		this._removeFormView();
@@ -369,7 +369,7 @@ export default class Link extends Plugin {
 		let prevSelectedLink = this._getSelectedLinkElement();
 		let prevSelectionParent = getSelectionParent();
 
-		this.listenTo( editingView, 'render', () => {
+		this.listenTo( editingView.document, 'change', () => {
 			const selectedLink = this._getSelectedLinkElement();
 			const selectionParent = getSelectionParent();
 
@@ -402,7 +402,7 @@ export default class Link extends Plugin {
 		} );
 
 		function getSelectionParent() {
-			return editingView.selection.focus.getAncestors()
+			return editingView.document.selection.focus.getAncestors()
 				.reverse()
 				.find( node => node.is( 'element' ) );
 		}

+ 30 - 32
packages/ckeditor5-link/tests/link.js

@@ -111,7 +111,7 @@ describe( 'Link', () => {
 
 		beforeEach( () => {
 			balloonAddSpy = testUtils.sinon.spy( balloon, 'add' );
-			editor.editing.view.isFocused = true;
+			editor.editing.view.document.isFocused = true;
 		} );
 
 		it( 'should not work if the link command is disabled', () => {
@@ -227,27 +227,30 @@ describe( 'Link', () => {
 			expect( formView.urlInputView.inputView.element.value ).to.equal( '' );
 		} );
 
-		describe( 'response to view#render', () => {
-			it( 'should not duplicate #render listeners', () => {
-				const viewDocument = editor.editing.view;
+		describe( 'response to view#change', () => {
+			let view, viewDocument;
 
+			beforeEach( () => {
+				view = editor.editing.view;
+				viewDocument = view.document;
+			} );
+
+			it( 'should not duplicate #change listeners', () => {
 				setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
 
 				linkFeature._showUI();
-				viewDocument.render();
+				view.change( () => {} );
 				linkFeature._hideUI();
 
 				linkFeature._showUI();
-				viewDocument.render();
+				view.change( () => {} );
 				sinon.assert.calledTwice( spy );
 			} );
 
 			// https://github.com/ckeditor/ckeditor5-link/issues/113
 			it( 'updates the position of the panel – editing a link, then the selection remains in the link', () => {
-				const viewDocument = editor.editing.view;
-
 				setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 
 				linkFeature._showUI();
@@ -257,30 +260,29 @@ describe( 'Link', () => {
 				const text = root.getChild( 0 ).getChild( 0 ).getChild( 0 );
 
 				// Move selection to foo[].
-				viewDocument.selection.setTo( Range.createFromParentsAndOffsets( text, 3, text, 3 ), true );
-				viewDocument.render();
+				view.change( writer => {
+					writer.setSelection( Range.createFromParentsAndOffsets( text, 3, text, 3 ), true );
+				} );
 
 				sinon.assert.calledOnce( spy );
 				sinon.assert.calledWithExactly( spy, {
-					target: viewDocument.domConverter.mapViewToDom( root.getChild( 0 ).getChild( 0 ) )
+					target: view.domConverter.mapViewToDom( root.getChild( 0 ).getChild( 0 ) )
 				} );
 			} );
 
 			// https://github.com/ckeditor/ckeditor5-link/issues/113
 			it( 'updates the position of the panel – creating a new link, then the selection moved', () => {
-				const viewDocument = editor.editing.view;
-
 				setModelData( editor.model, '<paragraph>f[]oo</paragraph>' );
 
 				linkFeature._showUI();
 				const spy = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
 
-				// Fires #render.
 				const root = viewDocument.getRoot();
 				const text = root.getChild( 0 ).getChild( 0 );
 
-				viewDocument.selection.setTo( Range.createFromParentsAndOffsets( text, 3, text, 3 ), true );
-				viewDocument.render();
+				view.change( writer => {
+					writer.setSelection( Range.createFromParentsAndOffsets( text, 3, text, 3 ), true );
+				} );
 
 				sinon.assert.calledOnce( spy );
 				sinon.assert.calledWithExactly( spy, {
@@ -290,8 +292,6 @@ describe( 'Link', () => {
 
 			// https://github.com/ckeditor/ckeditor5-link/issues/113
 			it( 'hides of the panel – editing a link, then the selection moved out of the link', () => {
-				const viewDocument = editor.editing.view;
-
 				setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text>bar</paragraph>' );
 
 				linkFeature._showUI();
@@ -303,8 +303,9 @@ describe( 'Link', () => {
 				const text = root.getChild( 0 ).getChild( 1 );
 
 				// Move selection to b[]ar.
-				viewDocument.selection.setTo( Range.createFromParentsAndOffsets( text, 1, text, 1 ), true );
-				viewDocument.render();
+				view.change( writer => {
+					writer.setSelection( Range.createFromParentsAndOffsets( text, 1, text, 1 ), true );
+				} );
 
 				sinon.assert.calledOnce( spyHide );
 				sinon.assert.notCalled( spyUpdate );
@@ -312,8 +313,6 @@ describe( 'Link', () => {
 
 			// https://github.com/ckeditor/ckeditor5-link/issues/113
 			it( 'hides the panel – editing a link, then the selection expands', () => {
-				const viewDocument = editor.editing.view;
-
 				setModelData( editor.model, '<paragraph><$text linkHref="url">f[]oo</$text></paragraph>' );
 
 				linkFeature._showUI();
@@ -325,8 +324,9 @@ describe( 'Link', () => {
 				const text = root.getChild( 0 ).getChild( 0 ).getChild( 0 );
 
 				// Move selection to f[o]o.
-				viewDocument.selection.setTo( Range.createFromParentsAndOffsets( text, 1, text, 2 ), true );
-				viewDocument.render();
+				view.change( writer => {
+					writer.setSelection( Range.createFromParentsAndOffsets( text, 1, text, 2 ), true );
+				} );
 
 				sinon.assert.calledOnce( spyHide );
 				sinon.assert.notCalled( spyUpdate );
@@ -334,8 +334,6 @@ describe( 'Link', () => {
 
 			// https://github.com/ckeditor/ckeditor5-link/issues/113
 			it( 'hides the panel – creating a new link, then the selection moved to another parent', () => {
-				const viewDocument = editor.editing.view;
-
 				setModelData( editor.model, '<paragraph>f[]oo</paragraph><paragraph>bar</paragraph>' );
 
 				linkFeature._showUI();
@@ -343,13 +341,13 @@ describe( 'Link', () => {
 				const spyUpdate = testUtils.sinon.stub( balloon, 'updatePosition' ).returns( {} );
 				const spyHide = testUtils.sinon.spy( linkFeature, '_hideUI' );
 
-				// Fires #render.
 				const root = viewDocument.getRoot();
 				const text = root.getChild( 1 ).getChild( 0 );
 
 				// Move selection to f[o]o.
-				viewDocument.selection.setTo( Range.createFromParentsAndOffsets( text, 1, text, 2 ), true );
-				viewDocument.render();
+				view.change( writer => {
+					writer.setSelection( Range.createFromParentsAndOffsets( text, 1, text, 2 ), true );
+				} );
 
 				sinon.assert.calledOnce( spyHide );
 				sinon.assert.notCalled( spyUpdate );
@@ -389,12 +387,12 @@ describe( 'Link', () => {
 			} ).to.not.throw();
 		} );
 
-		it( 'should clear #render listener from the ViewDocument', () => {
+		it( 'should clear #change listener from the ViewDocument', () => {
 			const spy = sinon.spy();
 
-			linkFeature.listenTo( editor.editing.view, 'render', spy );
+			linkFeature.listenTo( editor.editing.view.document, 'change', spy );
 			linkFeature._hideUI();
-			editor.editing.view.render();
+			editor.editing.view.change( () => {} );
 
 			sinon.assert.notCalled( spy );
 		} );