@@ -40,50 +40,79 @@ export const waitForHoverOutline = async (options?: {
4040 timeout ?: number ;
4141 interval ?: number ;
4242} ) => {
43+ // First, wait for the outline element to exist (faster check)
4344 await waitFor (
4445 ( ) => {
4546 const hoverOutline = document . querySelector (
46- "[data-testid='visual-builder__hover-outline'][style] "
47+ "[data-testid='visual-builder__hover-outline']"
4748 ) ;
4849 expect ( hoverOutline ) . not . toBeNull ( ) ;
4950 } ,
5051 {
51- timeout : options ?. timeout ?? 2000 , // Reduced from 5s to 2s - mocks resolve immediately
52- interval : options ?. interval ?? 10 , // Faster polling: 10ms default
52+ timeout : options ?. timeout ?? 2000 ,
53+ interval : options ?. interval ?? 5 , // Faster polling: 5ms default
54+ }
55+ ) ;
56+
57+ // Then wait for style attribute to be set (more specific check)
58+ await waitFor (
59+ ( ) => {
60+ const hoverOutline = document . querySelector (
61+ "[data-testid='visual-builder__hover-outline']"
62+ ) as HTMLElement ;
63+ expect ( hoverOutline ) . not . toBeNull ( ) ;
64+ // Check if style has meaningful values (not empty)
65+ const hasStyle =
66+ hoverOutline ?. style &&
67+ ( hoverOutline . style . top ||
68+ hoverOutline . style . left ||
69+ hoverOutline . style . width ||
70+ hoverOutline . style . height ) ;
71+ expect ( hasStyle ) . toBeTruthy ( ) ;
72+ } ,
73+ {
74+ timeout : options ?. timeout ?? 2000 ,
75+ interval : options ?. interval ?? 5 , // Faster polling: 5ms default
5376 }
5477 ) ;
5578} ;
56-
57- export const waitForBuilderSDKToBeInitialized = async ( visualBuilderPostMessage : EventManager | undefined ) => {
79+
80+ export const waitForBuilderSDKToBeInitialized = async (
81+ visualBuilderPostMessage : EventManager | undefined
82+ ) => {
5883 await waitFor ( ( ) => {
5984 expect ( visualBuilderPostMessage ?. send ) . toBeCalledWith (
6085 VisualBuilderPostMessageEvents . INIT ,
6186 expect . any ( Object )
6287 ) ;
6388 } ) ;
64- }
89+ } ;
6590interface WaitForClickActionOptions {
6691 skipWaitForFieldType ?: boolean ;
6792}
68- export const triggerAndWaitForClickAction = async ( visualBuilderPostMessage : EventManager | undefined , element : HTMLElement , { skipWaitForFieldType} : WaitForClickActionOptions = { } ) => {
93+ export const triggerAndWaitForClickAction = async (
94+ visualBuilderPostMessage : EventManager | undefined ,
95+ element : HTMLElement ,
96+ { skipWaitForFieldType } : WaitForClickActionOptions = { }
97+ ) => {
6998 await waitForBuilderSDKToBeInitialized ( visualBuilderPostMessage ) ;
7099 await act ( async ( ) => {
71100 await fireEvent . click ( element ) ;
72- } )
73- if ( ! skipWaitForFieldType ) {
101+ } ) ;
102+ if ( ! skipWaitForFieldType ) {
74103 await waitFor ( ( ) => {
75- expect ( element ) . toHaveAttribute ( "data-cslp-field-type" )
76- } )
104+ expect ( element ) . toHaveAttribute ( "data-cslp-field-type" ) ;
105+ } ) ;
77106 }
78- }
107+ } ;
79108export const waitForToolbaxToBeVisible = async ( ) => {
80109 await waitFor ( ( ) => {
81110 const toolbar = document . querySelector (
82111 ".visual-builder__focused-toolbar__field-label-container"
83112 ) ;
84113 expect ( toolbar ) . not . toBeNull ( ) ;
85114 } ) ;
86- }
115+ } ;
87116
88117export const waitForCursorToBeVisible = async ( options ?: {
89118 timeout ?: number ;
@@ -129,17 +158,24 @@ const defaultRect = {
129158 bottom : 20 ,
130159 width : 10 ,
131160 height : 5 ,
132- }
133- export const mockGetBoundingClientRect = ( element : HTMLElement , rect = defaultRect ) => {
134- vi . spyOn ( element , "getBoundingClientRect" ) . mockImplementation ( ( ) => rect as DOMRect ) ;
135- }
161+ } ;
162+ export const mockGetBoundingClientRect = (
163+ element : HTMLElement ,
164+ rect = defaultRect
165+ ) => {
166+ vi . spyOn ( element , "getBoundingClientRect" ) . mockImplementation (
167+ ( ) => rect as DOMRect
168+ ) ;
169+ } ;
136170export const getElementBytestId = ( testId : string ) => {
137171 return document . querySelector ( `[data-testid="${ testId } "]` ) ;
138- }
139- export const asyncRender : ( componentChild : ComponentChild ) => ReturnType < typeof render > = async ( ...args ) => {
172+ } ;
173+ export const asyncRender : (
174+ componentChild : ComponentChild
175+ ) => ReturnType < typeof render > = async ( ...args ) => {
140176 let returnValue : ReturnType < typeof render > ;
141177 await act ( async ( ) => {
142178 returnValue = render ( ...args ) ;
143179 } ) ;
144180 return returnValue ;
145- }
181+ } ;
0 commit comments