@@ -357,8 +357,6 @@ describe("Events", () => {
357357
358358describe ( "Dialog general interaction" , ( ) => {
359359 it ( "tests dialog toggling" , ( ) => {
360-
361-
362360 cy . mount (
363361 < >
364362 < Dialog id = "dialog" accessibleName = "Resizable" stretch >
@@ -406,6 +404,62 @@ describe("Dialog general interaction", () => {
406404 . should ( "be.calledOnce" ) ;
407405 } ) ;
408406
407+ it ( "dynamic dialog initial positioning" , ( ) => {
408+ const dialog = document . createElement ( "ui5-dialog" ) as Dialog ;
409+ dialog . setAttribute ( "id" , "dynamic-dialog" ) ;
410+
411+ const content = document . createElement ( "div" ) ;
412+ content . style . height = "600px" ;
413+ content . style . width = "600px" ;
414+ content . textContent = "Content" ;
415+
416+ dialog . appendChild ( content ) ;
417+
418+ // Spy on Object.assign only for this dialog's style
419+ cy . window ( ) . then ( ( ) => {
420+ const originalAssign = Object . assign ;
421+ const topAndLeftStyles : Array < { top : number ; left : number } > = [ ] ;
422+
423+ cy . stub ( Object , "assign" ) . callsFake ( function ( target : any , ...sources : any [ ] ) {
424+ // Check if target is the dialog's style object
425+ if ( target === dialog . style ) {
426+ const styleObj = sources [ 0 ] ;
427+ if ( styleObj && styleObj . top !== undefined && styleObj . left !== undefined ) {
428+ topAndLeftStyles . push ( {
429+ top : parseInt ( styleObj . top ) ,
430+ left : parseInt ( styleObj . left )
431+ } ) ;
432+ }
433+ }
434+ return originalAssign . call ( this , target , ...sources ) ;
435+ } ) . as ( "objectAssignStub" ) ;
436+
437+ cy . wrap ( topAndLeftStyles ) . as ( "topAndLeftStyles" ) ;
438+
439+ dialog . setAttribute ( "open" , "true" ) ;
440+ document . body . appendChild ( dialog ) ;
441+ } ) ;
442+
443+ cy . get < Dialog > ( "#dynamic-dialog" ) . ui5DialogOpened ( ) ;
444+
445+ // Assert the captured style values
446+ cy . get < Array < { top : number ; left : number } > > ( "@topAndLeftStyles" )
447+ . should ( ( topAndLeftStyles ) => {
448+ expect ( topAndLeftStyles . length ) . to . be . greaterThan ( 1 , "'top' and 'left' styles should have been assigned" ) ;
449+
450+ // styles from initial call of _center method
451+ const firstStyles = topAndLeftStyles [ 0 ] ;
452+
453+ expect ( firstStyles . top ) . to . not . equal ( 0 , "top should not start from 0" ) ;
454+ expect ( firstStyles . left ) . to . not . equal ( 0 , "left should not start from 0" ) ;
455+
456+ // styles from _center method called as resize handler callback
457+ const secondStyles = topAndLeftStyles [ 1 ] ;
458+
459+ expect ( secondStyles . top ) . to . equal ( firstStyles . top , "top should remain the same after resize event" ) ;
460+ expect ( secondStyles . left ) . to . equal ( firstStyles . left , "left should remain the same after resize event" ) ;
461+ } ) ;
462+ } ) ;
409463
410464 it ( "dialog repositions after screen resize" , ( ) => {
411465 cy . mount (
@@ -516,46 +570,56 @@ describe("Dialog general interaction", () => {
516570 cy . get ( "#draggable-dialog" ) . invoke ( "attr" , "open" , true ) ;
517571 cy . get < Dialog > ( "#draggable-dialog" ) . ui5DialogOpened ( ) ;
518572
573+ let topBeforeDragging : number ;
574+ let leftBeforeDragging : number ;
575+
519576 // Capture position before dragging
520577 cy . get ( "#draggable-dialog" )
521- . then ( dialog => {
522- const topBeforeDragging = parseInt ( dialog . css ( "top" ) ) ;
523- const leftBeforeDragging = parseInt ( dialog . css ( "left" ) ) ;
578+ . should ( dialog => {
579+ topBeforeDragging = parseInt ( dialog . css ( "top" ) ) ;
580+ leftBeforeDragging = parseInt ( dialog . css ( "left" ) ) ;
524581
525- // Drag dialog
526- cy . get ( "#draggable-dialog" )
527- . find ( "#header-slot" )
528- . trigger ( "mousedown" , { which : 1 } )
529- . trigger ( "mousemove" , { clientX : 150 , clientY : 150 } )
530- . trigger ( "mouseup" ) ;
582+ expect ( topBeforeDragging ) . to . equal ( 492 ) ;
583+ expect ( leftBeforeDragging ) . to . equal ( 560 ) ;
584+ } ) ;
531585
532- // Capture position after dragging
533- cy . get ( "#draggable-dialog" )
534- . should ( dialogAfterDragging => {
535- const topAfterDragging = parseInt ( dialogAfterDragging . css ( "top" ) ) ;
536- const leftAfterDragging = parseInt ( dialogAfterDragging . css ( "left" ) ) ;
586+ // Drag dialog
587+ cy . get ( "#draggable-dialog" )
588+ . find ( "#header-slot" )
589+ . trigger ( "mousedown" , { which : 1 } )
590+ . trigger ( "mousemove" , { clientX : 200 , clientY : 150 , } )
591+ . trigger ( "mouseup" ) ;
537592
538- // Assert position changes
539- expect ( topBeforeDragging ) . not . to . equal ( topAfterDragging ) ;
540- expect ( leftBeforeDragging ) . not . to . equal ( leftAfterDragging ) ;
541- } ) ;
593+ cy . get ( "#draggable-dialog" )
594+ . should ( "have.css" , "top" , "141px" )
595+ . should ( "have.css" , "left" , "40px" ) ;
542596
543- // Close dialog
544- cy . get ( "#draggable-dialog" ) . invoke ( "attr" , "open" , false ) ;
597+ // Capture position after dragging
598+ cy . get ( "#draggable-dialog" )
599+ . should ( dialogAfterDragging => {
600+ const topAfterDragging = parseInt ( dialogAfterDragging . css ( "top" ) ) ;
601+ const leftAfterDragging = parseInt ( dialogAfterDragging . css ( "left" ) ) ;
545602
546- // Reopen dialog
547- cy . get ( "#draggable-dialog" ) . invoke ( "attr" , "open" , true ) ;
603+ // Assert position changes
604+ expect ( topBeforeDragging ) . not . to . equal ( topAfterDragging ) ;
605+ expect ( leftBeforeDragging ) . not . to . equal ( leftAfterDragging ) ;
606+ } ) ;
548607
549- // Capture position after reopening
550- cy . get ( "#draggable-dialog" )
551- . should ( dialogAfterReopening => {
552- const topAfterReopening = parseInt ( dialogAfterReopening . css ( "top" ) ) ;
553- const leftAfterReopening = parseInt ( dialogAfterReopening . css ( "left" ) ) ;
608+ // Close dialog
609+ cy . get ( "#draggable-dialog" ) . invoke ( "attr" , "open" , false ) ;
554610
555- // Assert position resets
556- expect ( topBeforeDragging ) . to . equal ( topAfterReopening ) ;
557- expect ( leftBeforeDragging ) . to . equal ( leftAfterReopening ) ;
558- } ) ;
611+ // Reopen dialog
612+ cy . get ( "#draggable-dialog" ) . invoke ( "attr" , "open" , true ) ;
613+
614+ // Capture position after reopening
615+ cy . get ( "#draggable-dialog" )
616+ . should ( dialogAfterReopening => {
617+ const topAfterReopening = parseInt ( dialogAfterReopening . css ( "top" ) ) ;
618+ const leftAfterReopening = parseInt ( dialogAfterReopening . css ( "left" ) ) ;
619+
620+ // Assert position resets
621+ expect ( topBeforeDragging ) . to . equal ( topAfterReopening ) ;
622+ expect ( leftBeforeDragging ) . to . equal ( leftAfterReopening ) ;
559623 } ) ;
560624 } ) ;
561625
@@ -631,7 +695,6 @@ describe("Dialog general interaction", () => {
631695 } ) ;
632696
633697 it ( "resizable - mouse support" , ( ) => {
634-
635698 cy . mount (
636699 < >
637700 < Dialog id = "resizable-dialog" resizable >
@@ -1583,4 +1646,4 @@ describe("Dialog initially open", () => {
15831646 // Assert dialog matches :popover-open selector
15841647 cy . get ( "#dialogOpen" ) . should ( "match" , ":popover-open" ) ;
15851648 } ) ;
1586- } ) ;
1649+ } ) ;
0 commit comments