@@ -234,15 +234,118 @@ async function dragNode(
234234 y : Math . round ( startPosition . y + 15 ) , // we're aiming for the header area (top of the node)
235235 } )
236236 . down ( { button : 0 } ) // Left mouse button
237- . move ( { duration : 1000 , origin : 'pointer' , ...pointerActionMoveParams } )
238- . pause ( 1000 )
239- . move ( { duration : 1000 , origin : 'pointer' , ...pointerActionMoveParams } )
237+ . move ( { duration : 250 , origin : 'pointer' , ...pointerActionMoveParams } )
238+ . pause ( 250 )
239+ . move ( { duration : 250 , origin : 'pointer' , ...pointerActionMoveParams } )
240240 . up ( { button : 0 } ) // Release the left mouse button
241241 . perform ( ) ;
242242 await browser . waitForAnimations ( node ) ;
243243 return startPosition ;
244244}
245245
246+ /**
247+ * Drags the diagram view to show the specified element until it's clickable and clicks.
248+ * This is useful when we're trying to interact with an element that may be partially outside
249+ * of the view. Note that there isn't any check that a node is covering the space that will be
250+ * dragged, so it can end up dragging nodes unintentionally.
251+ **/
252+ async function dragDiagramToShowAndClick (
253+ browser : CompassBrowser ,
254+ selector : string
255+ ) {
256+ const targetElement = browser . $ ( selector ) ;
257+
258+ let elementPosition = await targetElement . getLocation ( ) ;
259+ let elementSize = await targetElement . getSize ( ) ;
260+
261+ const DRAG_INCREMENT = 50 ;
262+
263+ let diagramBackgroundPosition = await browser
264+ . $ ( Selectors . DataModelPreview )
265+ . getLocation ( ) ;
266+
267+ function getDistanceToElementCenter ( ) {
268+ return (
269+ Math . floor (
270+ elementPosition . x +
271+ elementSize . width / 2 -
272+ ( diagramBackgroundPosition . x + 1 )
273+ ) ,
274+ Math . floor (
275+ elementPosition . y +
276+ elementSize . height / 2 -
277+ ( diagramBackgroundPosition . y + 1 )
278+ )
279+ ) ;
280+ }
281+
282+ async function attemptClick ( ) {
283+ try {
284+ // In the diagram the buttons on nodes will return true for `isClickable` and `isDisplayed`
285+ // withinViewport even when it errors on click. So we have to attempt a click to be sure.
286+ await targetElement . click ( ) ;
287+ } catch {
288+ return false ;
289+ }
290+
291+ return true ;
292+ }
293+
294+ while (
295+ ! ( await attemptClick ( ) ) &&
296+ getDistanceToElementCenter ( ) > DRAG_INCREMENT * 4
297+ ) {
298+ elementPosition = await targetElement . getLocation ( ) ;
299+ elementSize = await targetElement . getSize ( ) ;
300+
301+ diagramBackgroundPosition = await browser
302+ . $ ( Selectors . DataModelPreview )
303+ . getLocation ( ) ;
304+
305+ // Start a bit away from the origin 5 to give space for the drag to happen.
306+ const baseX = Math . round ( diagramBackgroundPosition . x + DRAG_INCREMENT + 5 ) ;
307+ const baseY = Math . round ( diagramBackgroundPosition . y + DRAG_INCREMENT + 5 ) ;
308+
309+ const moveX =
310+ Math . abs ( diagramBackgroundPosition . x - elementPosition . x ) >
311+ DRAG_INCREMENT * 2
312+ ? Math . round (
313+ DRAG_INCREMENT *
314+ ( diagramBackgroundPosition . x > elementPosition . x ? 1 : - 1 )
315+ )
316+ : 0 ;
317+ const moveY =
318+ Math . abs ( diagramBackgroundPosition . y - elementPosition . y ) >
319+ DRAG_INCREMENT * 2
320+ ? Math . round (
321+ DRAG_INCREMENT *
322+ ( diagramBackgroundPosition . y > elementPosition . y ? 1 : - 1 )
323+ )
324+ : 0 ;
325+
326+ await browser
327+ . action ( 'pointer' )
328+ . move ( {
329+ x : baseX ,
330+ y : baseY ,
331+ } )
332+ . down ( { button : 0 } ) // Left mouse button.
333+ . pause ( 250 )
334+ . move ( {
335+ duration : 250 ,
336+ origin : 'pointer' ,
337+ x : moveX ,
338+ y : moveY ,
339+ } )
340+ . up ( { button : 0 } ) // Release the left mouse button.
341+ . perform ( ) ;
342+
343+ await browser . waitForAnimations ( Selectors . DataModelPreview ) ;
344+ }
345+
346+ return elementPosition ;
347+ }
348+
246349describe ( 'Data Modeling tab' , function ( ) {
247350 let compass : Compass ;
248351 let browser : CompassBrowser ;
@@ -851,10 +954,13 @@ describe('Data Modeling tab', function () {
851954 . getText ( ) ;
852955 expect ( collectionText ) . to . not . include ( 'field-1' ) ;
853956
854- // Add two fields to the collection.
855- await browser . clickVisible (
957+ // Drag the node into view to ensure the add nested field button is visible.
958+ await dragDiagramToShowAndClick (
959+ browser ,
856960 Selectors . DataModelCollectionAddFieldBtn ( 'test.testCollection-one' )
857961 ) ;
962+
963+ // Add two fields to the collection.
858964 await browser . clickVisible (
859965 Selectors . DataModelCollectionAddFieldBtn ( 'test.testCollection-one' )
860966 ) ;
@@ -897,15 +1003,8 @@ describe('Data Modeling tab', function () {
8971003 await browser . $ ( Selectors . SideDrawer ) . click ( ) ; // Unfocus the input.
8981004
8991005 // Drag the node into view to ensure the add nested field button is visible.
900- await dragNode (
1006+ await dragDiagramToShowAndClick (
9011007 browser ,
902- Selectors . DataModelPreviewCollection ( 'test.testCollection-one' ) ,
903- { x : - 200 , y : - 200 }
904- ) ;
905- await browser . waitForAnimations ( dataModelEditor ) ;
906-
907- // Add two new fields to the new object.
908- await browser . clickVisible (
9091008 Selectors . DataModelAddNestedFieldBtn ( 'test.testCollection-one' , [
9101009 'renamedField' ,
9111010 ] )
0 commit comments