@@ -84,4 +84,68 @@ describe('UIResourceRendererWC', () => {
8484 const dispatchedEvent = onUIAction . mock . calls [ 0 ] [ 0 ] as CustomEvent ;
8585 expect ( dispatchedEvent . detail ) . toEqual ( mockEventPayload ) ;
8686 } ) ;
87+
88+ describe ( 'connectedMoveCallback (atomic move support)' , ( ) => {
89+ it ( 'should implement connectedMoveCallback method' , ( ) => {
90+ const el = document . createElement ( 'ui-resource-renderer' ) ;
91+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
92+ expect ( typeof ( el as any ) . connectedMoveCallback ) . toBe ( 'function' ) ;
93+ } ) ;
94+
95+ it ( 'connectedMoveCallback should be callable without throwing' , ( ) => {
96+ const el = document . createElement ( 'ui-resource-renderer' ) ;
97+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
98+ expect ( ( ) => ( el as any ) . connectedMoveCallback ( ) ) . not . toThrow ( ) ;
99+ } ) ;
100+
101+ it ( 'should allow element to be moved between containers (simulating moveBefore)' , async ( ) => {
102+ const el = document . createElement ( 'ui-resource-renderer' ) ;
103+ const container1 = document . createElement ( 'div' ) ;
104+ const container2 = document . createElement ( 'div' ) ;
105+
106+ document . body . appendChild ( container1 ) ;
107+ document . body . appendChild ( container2 ) ;
108+ container1 . appendChild ( el ) ;
109+
110+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
111+ ( el as any ) . resource = resource ;
112+
113+ // Wait for the component to render
114+ await waitFor ( ( ) => {
115+ expect ( UIResourceRenderer ) . toHaveBeenCalled ( ) ;
116+ } ) ;
117+
118+ // Verify initial position
119+ expect ( el . parentElement ) . toBe ( container1 ) ;
120+
121+ // In browsers that support moveBefore with atomic moves:
122+ // - moveBefore() is called
123+ // - connectedMoveCallback is invoked instead of disconnectedCallback/connectedCallback
124+ // - The element preserves its state (iframes don't reload)
125+ //
126+ // Here we verify that connectedMoveCallback doesn't throw and the element can be moved.
127+ // Full atomic move behavior requires browser support that jsdom doesn't have.
128+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
129+ expect ( ( ) => ( el as any ) . connectedMoveCallback ( ) ) . not . toThrow ( ) ;
130+
131+ // Move the element to a new container
132+ container2 . appendChild ( el ) ;
133+
134+ // Verify element moved successfully
135+ expect ( el . parentElement ) . toBe ( container2 ) ;
136+ expect ( container1 . contains ( el ) ) . toBe ( false ) ;
137+ expect ( container2 . contains ( el ) ) . toBe ( true ) ;
138+ } ) ;
139+
140+ it ( 'element should be an instance of the extended class with connectedMoveCallback' , ( ) => {
141+ const el = document . createElement ( 'ui-resource-renderer' ) ;
142+
143+ // Verify the element has the connectedMoveCallback method
144+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
145+ expect ( 'connectedMoveCallback' in el ) . toBe ( true ) ;
146+
147+ // The element should be an HTMLElement
148+ expect ( el instanceof HTMLElement ) . toBe ( true ) ;
149+ } ) ;
150+ } ) ;
87151} ) ;
0 commit comments