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

Tests: Improved dragTo - it now can accept explicit from and to pointer positions.

Marek Lewandowski 6 лет назад
Родитель
Сommit
64b6e9a27b
1 измененных файлов с 32 добавлено и 8 удалено
  1. 32 8
      packages/ckeditor5-widget/tests/widgetresize/_utils/utils.js

+ 32 - 8
packages/ckeditor5-widget/tests/widgetresize/_utils/utils.js

@@ -42,21 +42,35 @@ export const mouseMock = {
 	 * Emulates mouse drag gesture by triggering:
 	 *
 	 * * the `mousedown` event on the `domTarget`,
-	 * * the `mousemove` event on `domTarget`, with the pointer coordinates at `finalPosition`,
+	 * * the `mousemove` event on `domTarget`, with the pointer coordinates at `position.from`,
+	 * * the `mousemove` event on `domTarget`, with the pointer coordinates at `position.to` (fired
+	 *	only if `position.to` differs from `position.from`),
 	 * * the `mouseup` event.
 	 *
 	 * @param {module:core/editor/editor~Editor} editor
 	 * @param {HTMLElement} domTarget
-	 * @param {Point} finalPosition
+	 * @param {Object/Point} position If a `Point` instance is given, the drag is performed without acutal pointer move.
+	 * @param {Point} position.from Coordinates of where the drag begins.
+	 * @param {Point} position.to Coordinates of where the drag ends.
 	 */
-	dragTo( editor, domTarget, finalPosition ) {
-		const moveEventData = {
-			pageX: finalPosition.x,
-			pageY: finalPosition.y
-		};
+	dragTo( editor, domTarget, position ) {
+		const fromPosition = position.from || position;
+		const finalPosition = position.to || position;
 
 		this.down( editor, domTarget );
-		this.move( editor, domTarget, moveEventData );
+
+		this.move( editor, domTarget, {
+			pageX: fromPosition.x,
+			pageY: fromPosition.y
+		} );
+
+		if ( !finalPosition.equals( fromPosition ) ) {
+			this.move( editor, domTarget, {
+				pageX: finalPosition.x,
+				pageY: finalPosition.y
+			} );
+		}
+
 		this.up( editor );
 	},
 
@@ -101,6 +115,16 @@ export class Point {
 	clone() {
 		return new Point( this.x, this.y );
 	}
+
+	/**
+	 * Checks if two points are equal.
+	 *
+	 * @param {Point} pointB
+	 * @returns {Boolean}
+	 */
+	equals( pointB ) {
+		return pointB.x == this.x && pointB.y == this.y;
+	}
 }
 
 /**