@@ -49,6 +49,18 @@ export const dragAndDrop = async (
4949 await page . mouse . up ( ) ;
5050} ;
5151
52+ const getTargetPosition = (
53+ canvasPosition : { x : number ; y : number } ,
54+ displacementQty : number ,
55+ multiplyFactor : number
56+ ) : Position => {
57+ const positionDisplacement = displacementQty * ( multiplyFactor + 1 ) ;
58+ return {
59+ x : canvasPosition . x + displacementQty + positionDisplacement ,
60+ y : canvasPosition . y + positionDisplacement ,
61+ } ;
62+ } ;
63+
5264export const addComponentsToCanvas = async (
5365 page : Page ,
5466 components : string [ ] ,
@@ -63,18 +75,12 @@ export const addComponentsToCanvas = async (
6375 await component . scrollIntoViewIfNeeded ( ) ;
6476 const position = await getLocatorPosition ( component ) ;
6577
66- const targetPosition = (
67- displacementQty : number ,
68- multiplyFactor : number
69- ) => {
70- const positionDisplacement = displacementQty * ( multiplyFactor + 1 ) ;
71- return {
72- x : canvasPosition . x + displacementQty + positionDisplacement ,
73- y : canvasPosition . y + positionDisplacement ,
74- } ;
75- } ;
76-
77- await dragAndDrop ( page , position , targetPosition ( displacementQty , index ) ) ;
78+ const targetPosition = getTargetPosition (
79+ canvasPosition ,
80+ displacementQty ,
81+ index
82+ ) ;
83+ await dragAndDrop ( page , position , targetPosition ) ;
7884 }
7985} ;
8086
@@ -133,18 +139,12 @@ export const addComponentsWithDifferentCategoriesToCanvas = async (
133139 await component . scrollIntoViewIfNeeded ( ) ;
134140 const position = await getLocatorPosition ( component ) ;
135141
136- const targetPosition = (
137- displacementQty : number ,
138- multiplyFactor : number
139- ) => {
140- const positionDisplacement = displacementQty * ( multiplyFactor + 1 ) ;
141- return {
142- x : canvasPosition . x + displacementQty + positionDisplacement ,
143- y : canvasPosition . y + positionDisplacement ,
144- } ;
145- } ;
146-
147- await dragAndDrop ( page , position , targetPosition ( displacementQty , index ) ) ;
142+ const targetPosition = getTargetPosition (
143+ canvasPosition ,
144+ displacementQty ,
145+ index
146+ ) ;
147+ await dragAndDrop ( page , position , targetPosition ) ;
148148 } catch ( error ) {
149149 const errorMessage =
150150 error instanceof Error ? error . message : String ( error ) ;
0 commit comments