8
0
فهرست منبع

Tests: Simplified point handling (it's no longer immutable).

Marek Lewandowski 6 سال پیش
والد
کامیت
5fbd045cdc
2فایلهای تغییر یافته به همراه15 افزوده شده و 33 حذف شده
  1. 8 8
      packages/ckeditor5-widget/tests/widgetresize.js
  2. 7 25
      packages/ckeditor5-widget/tests/widgetresize/_utils/utils.js

+ 8 - 8
packages/ckeditor5-widget/tests/widgetresize.js

@@ -89,7 +89,7 @@ describe( 'WidgetResize', () => {
 			const usedResizer = 'top-right';
 			const domParts = getWidgetDomParts( widget, usedResizer );
 			const initialPointerPosition = getHandleCenterPoint( domParts.widget, usedResizer );
-			const finalPointerPosition = initialPointerPosition.moveBy( 20, 0 );
+			const finalPointerPosition = initialPointerPosition.clone().moveBy( 20, 0 );
 
 			mouseMock.dragTo( editor, domParts.resizeHandle, finalPointerPosition );
 
@@ -137,10 +137,10 @@ describe( 'WidgetResize', () => {
 			const domParts = getWidgetDomParts( widget, usedResizer );
 			const initialPointerPosition = getHandleCenterPoint( domParts.widget, usedResizer );
 
-			const intermediatePointerPosition = initialPointerPosition.moveBy( 50, 0 );
+			const intermediatePointerPosition = initialPointerPosition.clone().moveBy( 50, 0 );
 			mouseMock.dragTo( editor, domParts.resizeHandle, intermediatePointerPosition );
 
-			const finalPointerPosition = intermediatePointerPosition.moveBy( 50, 0 );
+			const finalPointerPosition = intermediatePointerPosition.clone().moveBy( 50, 0 );
 			mouseMock.dragTo( editor, domParts.resizeHandle, finalPointerPosition );
 
 			expect( commitStub.callCount ).to.be.equal( 2 );
@@ -168,10 +168,10 @@ describe( 'WidgetResize', () => {
 			const domParts = getWidgetDomParts( widget, usedResizer );
 			const initialPointerPosition = getHandleCenterPoint( domParts.widget, usedResizer );
 
-			const intermediatePointerPosition = initialPointerPosition.moveBy( 100, 0 );
+			const intermediatePointerPosition = initialPointerPosition.clone().moveBy( 100, 0 );
 			mouseMock.dragTo( editor, domParts.resizeHandle, intermediatePointerPosition );
 
-			const finalPointerPosition = intermediatePointerPosition.moveBy( 100, 0 );
+			const finalPointerPosition = intermediatePointerPosition.clone().moveBy( 100, 0 );
 			mouseMock.dragTo( editor, domParts.resizeHandle, finalPointerPosition );
 
 			expect( commitStub.callCount ).to.be.equal( 2 );
@@ -260,15 +260,15 @@ describe( 'WidgetResize', () => {
 	 */
 	function getHandleCenterPoint( domWrapper, handlePosition ) {
 		const wrapperRect = new Rect( domWrapper );
-		let returnValue = new Point( wrapperRect.left, wrapperRect.top );
+		const returnValue = new Point( wrapperRect.left, wrapperRect.top );
 		const cornerPositionParts = handlePosition.split( '-' );
 
 		if ( cornerPositionParts.includes( 'right' ) ) {
-			returnValue = returnValue.moveToX( wrapperRect.right );
+			returnValue.x = wrapperRect.right;
 		}
 
 		if ( cornerPositionParts.includes( 'bottom' ) ) {
-			returnValue = returnValue.moveToY( wrapperRect.bottom );
+			returnValue.y = wrapperRect.bottom;
 		}
 
 		return returnValue;

+ 7 - 25
packages/ckeditor5-widget/tests/widgetresize/_utils/utils.js

@@ -51,45 +51,27 @@ export const mouseMock = {
 
 export class Point {
 	constructor( x, y ) {
-		/**
-		 * @readonly
-		 */
 		this.x = x;
-
-		/**
-		 * @readonly
-		 */
 		this.y = y;
 	}
 
 	/**
-	 * Moves the point by a given `changeX` and `changeY` and returns it as a **new instance**.
+	 * Moves the point by a given `changeX` and `changeY`.
 	 *
 	 * @param {Number} changeX
 	 * @param {Number} changeY
-	 * @returns {Point}
+	 * @returns {Point} Returns current instance.
 	 */
 	moveBy( changeX, changeY ) {
-		return new Point( this.x + changeX, this.y + changeY );
+		this.x += changeX;
+		this.y += changeY;
+		return this;
 	}
 
 	/**
-	 * Moves the point to a given position in x axis and returns it as a **new instance**.
-	 *
-	 * @param {Number} x
-	 * @returns {Point}
-	 */
-	moveToX( x ) {
-		return new Point( x, this.y );
-	}
-
-	/**
-	 * Moves the point to a given position in y axis and returns it as a **new instance**.
-	 *
-	 * @param {Number} y
 	 * @returns {Point}
 	 */
-	moveToY( y ) {
-		return new Point( this.x, y );
+	clone() {
+		return new Point( this.x, this.y );
 	}
 }