@@ -278,4 +278,82 @@ describe("handleDeleteSubmit", () => {
278278 } )
279279 ) ;
280280 } ) ;
281+
282+ test ( "uses PANEL_SEARCH_CONFIG for catalog/servers refresh" , async ( ) => {
283+ const form = document . createElement ( "form" ) ;
284+ form . id = "test-form" ;
285+ form . action = "/test" ;
286+ document . body . appendChild ( form ) ;
287+
288+ const tableDiv = document . createElement ( "div" ) ;
289+ tableDiv . id = "servers-table" ; // Correct ID per PANEL_SEARCH_CONFIG for catalog
290+ document . body . appendChild ( tableDiv ) ;
291+
292+ const fetchMock = vi . fn ( ) . mockResolvedValue ( { ok : true } ) ;
293+ global . fetch = fetchMock ;
294+
295+ // Mock HTMX
296+ const htmxAjaxMock = vi . fn ( ) ;
297+ global . window . htmx = { ajax : htmxAjaxMock } ;
298+ global . window . ROOT_PATH = "" ;
299+
300+ const event = { preventDefault : vi . fn ( ) , target : form } ;
301+
302+ vi . spyOn ( window , "confirm" )
303+ . mockReturnValueOnce ( true )
304+ . mockReturnValueOnce ( false ) ;
305+
306+ await handleDeleteSubmit ( event , "server" , "test-server" , "catalog" ) ;
307+
308+ // Verify HTMX was called with correct partial path (servers/partial) and target selector (#servers-table)
309+ expect ( htmxAjaxMock ) . toHaveBeenCalledWith (
310+ 'GET' ,
311+ expect . stringContaining ( '/admin/servers/partial' ) ,
312+ expect . objectContaining ( {
313+ target : '#servers-table' , // targetSelector from PANEL_SEARCH_CONFIG for catalog
314+ swap : 'outerHTML'
315+ } )
316+ ) ;
317+ } ) ;
318+
319+ test ( "warns when PANEL_SEARCH_CONFIG is missing for a type" , async ( ) => {
320+ const form = document . createElement ( "form" ) ;
321+ form . id = "test-form" ;
322+ form . action = "/test" ;
323+ document . body . appendChild ( form ) ;
324+
325+ const fetchMock = vi . fn ( ) . mockResolvedValue ( { ok : true } ) ;
326+ global . fetch = fetchMock ;
327+
328+ // Mock HTMX
329+ const htmxAjaxMock = vi . fn ( ) ;
330+ global . window . htmx = { ajax : htmxAjaxMock } ;
331+ global . window . ROOT_PATH = "" ;
332+
333+ // Mock console.warn
334+ const consoleWarnSpy = vi . spyOn ( console , "warn" ) . mockImplementation ( ( ) => { } ) ;
335+
336+ const event = { preventDefault : vi . fn ( ) , target : form } ;
337+
338+ vi . spyOn ( window , "confirm" )
339+ . mockReturnValueOnce ( true )
340+ . mockReturnValueOnce ( false ) ;
341+
342+ await handleDeleteSubmit ( event , "unknown" , "test-unknown" , "unknown-type" ) ;
343+
344+ // Verify console.warn was called with appropriate message
345+ expect ( consoleWarnSpy ) . toHaveBeenCalledWith (
346+ expect . stringContaining ( 'No PANEL_SEARCH_CONFIG found for type: unknown-type' )
347+ ) ;
348+
349+ // Should still use fallback pattern
350+ expect ( htmxAjaxMock ) . toHaveBeenCalledWith (
351+ 'GET' ,
352+ expect . stringContaining ( '/admin/unknown-type/partial' ) ,
353+ expect . objectContaining ( {
354+ target : '#unknown-type-table' ,
355+ swap : 'outerHTML'
356+ } )
357+ ) ;
358+ } ) ;
281359} ) ;
0 commit comments